Repository navigation
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 valuesNegative to positive0 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? |
petrasovaa
left a comment
There was a problem hiding this comment.
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.
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.
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.
|
Solved conflicts |
|
I've made an agent try this old PR out. One bigger issue: the hard-coded With a 0..1 raster and Other notes
|
| struct FPRange fprange, render_range; | ||
| CELL min_ind, max_ind; | ||
| DCELL dmin, dmax, val; | ||
| DCELL dmin, dmax, val, eps_min, eps = 1.0; |
There was a problem hiding this comment.
A fixed eps = 1.0 floor breaks the legend for any raster with dmax <= 1 (e.g. 0..1 gives a single-color bar with no labels, and 0..0.45 gives an inverted scale because eps_min > dmax). Derive the floor from the data (a fraction of dmax, or the smallest positive cell value), or fail with an error when no sensible floor exists.
Also, eps_min is uninitialized when -l is not used. It is only read under log_sc, but initializing it would be safer.
| "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.
The warning says colors for cells <= 1 are discarded, but with 0 < dmin < 1 (e.g. 0.2) everything below 1 is discarded too, not just non-positive cells. And when dmax <= eps, nothing tells the user the legend is wrong: it exits 0 and draws a degenerate legend.
| if (log_sc) { /* logarithmic scale */ | ||
| num = k / lleg; | ||
| val = dmin * pow(dmax / dmin, num); | ||
| /* XXX: for log scale, if the entire raster is not |
There was a problem hiding this comment.
dmax <= 0 is already rejected by the fatal error at lines 326-328, so this XXX block and the dmax <= 0 ? dmax : ... on line 416 are dead code. I'd drop them and keep the fatal error, which also settles the question in the comment.
| /* Format text */ | ||
| if (!fp) { /* cut down labelnum so they don't repeat */ | ||
| if (fp) { | ||
| if (log_sc && dmax <= 0) /* label min and max only */ |
There was a problem hiding this comment.
Same unreachable dmax <= 0 handling here (steps = 2), and in the matching branches at lines 558, 594, 629 and 761-770 (the k == 0 / t_start == 0 special cases and the 1.5 * t_step loop bound). They can all go.
Thanks for looking into this, old, yet (in my view) relevant PR. |
|
To make it go forward, a decision on the expected behaviour needs to be made, until then, it'll take another 6 years? |
|
I am working on this. We should probably take approach from #1937. |
|
Since #8060 was merged that solves this problem, I will close this. |








Attempt to address #1482