Skip to content

r.colors fix -g and -a (#1480) - #1923

Closed
susi wants to merge 3 commits into
OSGeo:mainfrom
susi:r.colors
Closed

susi wants to merge 3 commits into
OSGeo:mainfrom
susi:r.colors

Conversation

@susi

@susi susi commented Oct 3, 2021

Copy link
Copy Markdown
Contributor

This pr fixes the -g flag so that it clamps any values < 1.0 to 0.

For -a it does the same, and also uses log(fabs(min)) when calculating the interval instead of assuming 0.

r.colors map=censusblk_median_age col=plasma

r colors

r.colors map=censusblk_median_age col=plasma -g

r colors-g_fixed

r.colors map=censusblk_median_age col=plasma -a

r colors-a_fixed

@susi susi linked an issue Oct 3, 2021 that may be closed by this pull request
@nilason
nilason requested a review from HuidaeCho October 3, 2021 07:50
@susi susi added this to the 8.0.0 milestone Oct 3, 2021
@susi susi self-assigned this Oct 3, 2021
@veroandreo

Copy link
Copy Markdown
Contributor

Thanks @susi ! Would you mind updating/including a minimal explanation in the manual page?

@HuidaeCho

Copy link
Copy Markdown
Member

@susi Please check discussions in #1481, which tries to address the same issue.

@HuidaeCho

HuidaeCho commented Oct 4, 2021 •

Copy link
Copy Markdown
Member

Related PR #1507

@HuidaeCho HuidaeCho left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have to discuss how to address any questions raised in #1481 and #1507 rather than creating a new PR that conflicts with the earlier #1481 and duplicating the effort. This color issue should be addressed in both the display and legend.

@susi

susi commented Oct 4, 2021

Copy link
Copy Markdown
Contributor Author

Oh thanks @HuidaeCho I was not aware of any other PRs in progress, since there were not linked to the issue 😕 It wasn't my intention to override/conflict with existing work. Is there anything I can do to help with #1481? Would the stuff I did for this PR be applicable for #1481? If so I can rebase it on top of that.

@susi

susi commented Oct 4, 2021 •

Copy link
Copy Markdown
Contributor Author

Thanks @susi ! Would you mind updating/including a minimal explanation in the manual page?

Sure once we agree we want any of this 😝

@HuidaeCho

Copy link
Copy Markdown
Member

Oh thanks @HuidaeCho I was not aware of any other PRs in progress, since there were not linked to the issue 😕 It wasn't my intention to override/conflict with existing work. Is there anything I can do to help with #1481? Would the stuff I did for this PR be applicable for #1481? If so I can rebase it on top of that.

I understand. The link is in the middle of the long discussion, so it's hard to find ;-).
image

The current #1481 uses eps=1.0, which in effect does the same thing as your PR. Additionally, it tries to address non-positive rasters. I know, log negative doesn't make sense, but at least we want to display a single-color raster or throw a fatal error. The main thing is both the display (#1481) and legend (#1507) need to use the same colors for consistency.

Please read/test both PRs and let me know what you think.

@susi

susi commented Oct 4, 2021

Copy link
Copy Markdown
Contributor Author

Oh thanks @HuidaeCho I was not aware of any other PRs in progress, since there were not linked to the issue confused It wasn't my intention to override/conflict with existing work. Is there anything I can do to help with #1481? Would the stuff I did for this PR be applicable for #1481? If so I can rebase it on top of that.

I understand. The link is in the middle of the long discussion, so it's hard to find ;-).

Ah I was talking about the Linked Pull Requests, also there was no-one assigned to the bug, so it looked like there had been conversations that had just stalled 🤔
Screenshot_2021-10-04_21-36-47

The current #1481 uses eps=1.0, which in effect does the same thing as your PR. Additionally, it tries to address non-positive
rasters. I know, log negative doesn't make sense, but at least we want to display a single-color raster or throw a fatal error. The
main thing is both the display (#1481) and legend (#1507) need to use the same colors for consistency.

As you know, the way r.colors works, is that it uses the raster library functions like Rast_log_colors or Rast_abs_log_colors to set the color map, and then saves the color file with Rast_write_colors. Then d.legend also uses the raster library to read the same color map. So it seems to me to be a user error to run r.colors -g and d.legend -l And expect the color ramp to match the colors of the map. It means that you are essentially running log10 of whatever r.colors set (like log if you run with -g). 🤔

Please read/test both PRs and let me know what you think.

Sure, happy to! I'll leave comments on those PRs 🙂

Also fix Rast_abs_log_colors to actually work so that the color ramp
is symmetrical around 0.
@HuidaeCho

Copy link
Copy Markdown
Member

Please try this:

r.mapcalc ex=tmp="censusblk_median_age/85.599998/2" # to create a raster in [0, 0.5]
r.colors map=tmp col=plasma -g

In this case, lmin=1e-15 and lmax=-0.693147, and generates a color rule file between 0 and 0.99309249543703693, which is not its data range between 0 and 0.5.

% 0 0.99309249543703693
nv:255
*:255
0:13:8:135 0.99309249543703693:20:7:137
0.98623270449336009:27:6:141 0.99309249543703693:20:7:137
0.97942029758692783:33:6:143 0.98623270449336009:27:6:141
...
0.50697973989501455:243:239:39 0.51050606285359668:245:235:39
0.50347777502835933:241:244:38 0.50697973989501455:243:239:39
0.5:240:249:33 0.50347777502835933:241:244:38

Note that the value jumps to 0.99309 and slowly declines to 0.5.

@susi

susi commented Oct 15, 2021

Copy link
Copy Markdown
Contributor Author

Closing this as #1937 does it better :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] r.colors: -g (log) and -a (absolute log) don't work as expected

3 participants