Skip to content
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

[Bug] r.fuzzy.set rounds shape/converts parameter decimal value to 0 #930

Closed
ecodiv opened this issue Jul 10, 2023 · 6 comments
Closed

[Bug] r.fuzzy.set rounds shape/converts parameter decimal value to 0 #930

ecodiv opened this issue Jul 10, 2023 · 6 comments

Comments

@ecodiv
Copy link
Contributor

ecodiv commented Jul 10, 2023

Name of the addon
r.fuzzy.set

Describe the bug
Decimal values for the shape parameter results in the same result as filling in 0. It seems decimal values are rounded to 0.

To Reproduce
Steps to reproduce the behaviour:

  1. Open r.fuzzy.set and run it using any input raster layer of type float or double. Set the Shape parameter to 0, the boundary type to ' S-shaped', and the fuzzy range to 'Left'
  2. Repeat the same, but this time, set the Shape parameter to 0.5
  3. Compare the two outcomes: they are the same. Using the

Expected behavior
Function

Screenshots
The screenshot shows the command, with the shape=0.1 and shape=0.5. The result is the same. As the bivariate plots show, the results are what one would be expected for shape=0.

screenshotexample

System description (please complete the following information):

  • Operating System: [Windows 10, Ubuntu 22.04]
  • GRASS GIS version [e.g. 8.3]
ecodiv added a commit that referenced this issue Jul 10, 2023
The calculation of the Sshape for when the shape parameter < 0 seems to be incorrect. 

I haven't checked (yet) the other shape formulas

Note; there is another issue I am not sure how to solve. See #930
@YannChemin
Copy link
Contributor

Using code from August 22, rebuilt grass + grass-addons from main, using the blue band of BMNG https://visibleearth.nasa.gov/images/57752/blue-marble-land-surface-shallow-water-and-shaded-topography.

Make it Float

r.mapcalc expression="bmngfloat=bmng.blue/100.0"

Map 1

r.fuzzy.set --overwrite input=bmngfloat@PERMANENT output=out1 points=0.5,0.6 side=left shape=0.5

image

Map 2

r.fuzzy.set --overwrite input=bmngfloat@PERMANENT output=out points=0.5,0.6 side=left shape=0.1

image

@ecodiv
Copy link
Contributor Author

ecodiv commented Aug 22, 2023

Thanks, I wonder if I introduced an error in #931. I'll do some further testing.

@ecodiv
Copy link
Contributor Author

ecodiv commented Aug 23, 2023

Hi @YannChemin, below a reproducible example.

The example data used in this example is the landsat layer lsat5_1987_10@landsat from the North Carolina full dataset (https://grass.osgeo.org/download/data/).

Step 1. Set the region to match the raster layer and create a floating raster layer.

g.region raster=lsat5_1987_10
r.mapcalc "inputmap = lsat5_1987_10 / 10.0"

Step 2. Install the r.fuzzy_set addon, if not done already.

g.extension extension=r.fuzzy.set                                               

Step 3. Run the function using as input the lsat5_1987_10 raster layer as input. Fill in the output name test01, set minimum (A) and maximum inflection points to match the minimum and maximum value of the raster layer and the side to left. Keep the default input for the other parameters. That is, shape modifier (shape) = 0 and membership height (height) = 1.

# Get the minimum, maximum and mean values
r.univar map=inputmap

The minimum = 4.5 and maximum = 25.4. Use this to set the A (lower boundary) and B (upper boundary) inflection points.

r.fuzzy.set input=inputmap output=test00 points=4.5,25.4 side=left

Step 4. Repeat the above twice, changing the shape modifier (shape) to 0.1, 0.5 and 0.9.

r.fuzzy.set input=inputmap output=test01 points=4.5,25.4 side=left shape=0.1 --overwrite
r.fuzzy.set input=inputmap output=test05 points=4.5,25.4 side=left shape=0.5 --overwrite
r.fuzzy.set input=inputmap output=test09 points=4.5,25.4 side=left shape=0.9 --overwrite

Check if there are differences between the output maps.

r.mapcalc "diff00_01 = test00 - test01"
r.univar map=diff00_01
r.mapcalc "diff00_05 = test00 - test05"
r.univar map=diff00_05
r.mapcalc "diff01_05 = test01 - test05"
r.univar map=diff00_05
r.mapcalc "diff01_09 = test01 - test09"
r.univar map=diff01_09

The r.univar outcomes show that the maps are identical. Results correspond to what one would expect when using the shape=0 parameter.

Step 5. Now, let's try with negative values for the shape parameter.

r.fuzzy.set input=inputmap output=testmin01 points=4.5,25.4 side=left shape=-0.1 --overwrite
r.fuzzy.set input=inputmap output=testmin05 points=4.5,25.4 side=left shape=-0.5 --overwrite
r.fuzzy.set input=inputmap output=testmin09 points=4.5,25.4 side=left shape=-0.9 --overwrite

Check if there are differences between the output maps.

r.mapcalc "diffmin09_09 = testmin09 - test09"
r.univar map=diffmin09_09
r.mapcalc "diffmin01_min05 = testmin01 - testmin05"
r.univar map=diffmin01_min05
r.mapcalc "diffmin01_min09 = testmin01 - testmin09"
r.univar map=diffmin01_min09

Results based on negative shape values differ from those based on positive shape values. But, results show that outcomes for negative shape values are all the same, corresponding to what one would expect when using the shape=-1 parameter (note that there is a unrelated error in how the values are calculated as described in #931).

I am on Ubuntu 22.04, GRASS GIS 8.3.1dev (ce5a0a5694). Results are the same on Windows 10, GRASS GIS 8.3.

@ecodiv
Copy link
Contributor Author

ecodiv commented Sep 20, 2023

The problem was the use of the abs function, which works for integer values. Replacing it with the fabs function, which works with floating and double values, solves the problem. Tested using the code above. Solution included in the PR #931

@ecodiv
Copy link
Contributor Author

ecodiv commented Sep 20, 2023

Closing since the issue is solved with PR #931

@ecodiv ecodiv closed this as completed Sep 20, 2023
@wenzeslaus
Copy link
Member

@ecodiv You can link the issue from the PR using "Closes #XYZ". Merging PR with this in the commit message will close the issue automatically. You can also link them from the web interface under Development. That may save you some writing and clicks overall. This will also ensure the standard behavior: it is customary to close the issue only after the PR was merged.

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

No branches or pull requests

3 participants