-
-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
d.legend: handle 0 for log (-l) #1507
base: main
Are you sure you want to change the base?
Conversation
TODO: This module needs |
@neteler Please test it with negative, non-positive, negative to positive, and 0 to positive rasters. It shouldn't affect positive rasters, but just in case test them too. It still doesn't support absolute logarithm. Noticed that the flag name ( |
Thanks a lot!
Here my user test:
|
@neteler I couldn't reproduce it. Can you share your data (worldpop_2000_1km_aggregated_UNadj)? |
I think you use GCC >= 7 (https://gcc.gnu.org/gcc-7/changes.html). I'm stuck with GCC 5 :-(. The warning is because DispFormat is not big enough. Buffer overflow can actually happen if maxCat is very large such that log10(maxCat)+1 >= 100. That is, maxCat >= 10^99, which looks pretty safe... One solution would be sprintf(DispFormat, "%%%dd", (char)(log10(fabs(maxCat))) + 1);
Now, if maxCat is very small and log10(fabs(maxCat)) becomes < -1, text will be left-aligned unintentionally. In general, I think this module needs a major refactoring including the above warnings, uninitialized variables, indentation, breaking long code, etc. |
(btw: gcc version 10.2.1 here) My use case is this one: but I'll test again to see if it happens again + (try to) provide synthetic test data generated with r.random.* etc. |
OK, I have set up some test cases (see below). Hope they are somehow meaningful...
Negative values
Negative to positive
0 to positive
|
I find the legends pretty odd, tbh, even the one for all positive numbers... I would expect colors to be more equally distributed as in my case 1 examples. Maybe the distribution of values plays a role? |
Let me summarize what this PR does:
|
I think your example 1 is a good case for a logarithmic legend. Data looks logarithmically distributed than linearly. The log legend looks good to me. |
Now, fatal error on a non-positive raster and warnings on min <= 0. |
This PR looks good, i.e., it improves the current situation. Merge it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this implementation is improvement, but the PR needs to be cleaned up, see my other comments.
"discarding colors for cells <= %g and " | ||
"assuming a positive min cell value of %g"), | ||
eps, eps); | ||
eps_min = eps; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if you couldn't just use dmin = eps_min
here, which would avoid all the changes below.
/* XXX: for log scale, if the entire raster is not | ||
* positive, use the max color only; actually, this is | ||
* incorrect because negative values can have different | ||
* colors on the monitor; maybe, we should throw a fatal | ||
* error in this case because using the max color only for | ||
* displaying a raster and its legend is different and the | ||
* legend must always match the display; well... unless the | ||
* raster is colorized using r.colors -g, but how do we | ||
* know that? */ | ||
val = dmax <= 0 ? dmax : eps_min * pow(dmax / eps_min, num); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these comments are somewhat confusing and perhaps not updated after introducing the fatal error for rasters with all negative values. I would suggest to summarize the reasoning and perhaps move it somewhere close to the fatal error call.
Given the fatal error in the beginning, these expressions don't need to test for the negative cases and can be simplified. This applies to all/most of the changes below.
Attempt to address #1482