-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add reclassify raster #197
Conversation
… in geometrical intervals
…ta in equal intervals
…e logic with the small array
@nialov, I have made the requested changes to the reclassify methods and tests. Is there anything more to add? |
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.
Looks good, only few small things:
- Remove
tests/data/small_raster.tif.aux.xml
file. It was probably just added by opening the raster in e.g. ArcGIS or QGIS. - Check that when you use the masked array you do not use
np.nan...
methods such asnp.nanmax
. Instead usenp.ma.max
and others fromnp.ma
.
After these, LGTM!
mask = band == nan_value | ||
masked_array = np.ma.masked_array(data=band, mask=mask) | ||
|
||
median_value = np.nanmedian(masked_array) |
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.
median_value = np.nanmedian(masked_array) | |
median_value = np.ma.median(masked_array) |
min_tail = np.nanmin(tail_values) | ||
max_tail = np.nanmax(tail_values) |
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.
min_tail = np.nanmin(tail_values) | |
max_tail = np.nanmax(tail_values) | |
min_tail = np.ma.min(tail_values) | |
max_tail = np.ma.max(tail_values) |
from eis_toolkit.exceptions import InvalidParameterValueException | ||
|
||
|
||
def _bands_non_negative(band: Sequence): |
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.
def _bands_non_negative(band: Sequence): | |
def _check_bands_non_negative(band: Sequence): |
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.
Hey, I took a quick look at this and wrote some comments. I would consider renaming this module to "reclassify.py" and the tool names to reclassify_<strategy>
or reclassify_with_<strategy>
. Any thoughts about these renamings @lehtonenp and @nialov ?
def _check_bands_non_negative(band: Sequence): | ||
if any(n < 0 for n in band): | ||
raise InvalidParameterValueException("The list bands contains negative values.") |
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 recommend taking this out and just using check_raster_bands
found in utilities -> checks -> raster module.
def raster_with_manual_breaks( # type: ignore[no-any-unimported] | ||
raster: rasterio.io.DatasetReader, | ||
breaks: Sequence[int], | ||
bands: Sequence[int], |
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.
This does not have any default value even thought the docstring claims so.
bands: Sequence[int], | |
bands: Optional[Sequence[int]] = None, |
This applies to all tools in this module.
|
||
@beartype | ||
def raster_with_geometrical_intervals( # type: ignore[no-any-unimported] | ||
raster: rasterio.io.DatasetReader, number_of_classes: int, nan_value: Union[int, float], bands: Sequence[int] |
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.
Because the input is a raster DatasetReader, I don't think a nan_value
parameter is strictly necessary. The raster should have nodata
value defined in its metadata/profile and that should be used in the mask. But if we want to let the user to work with a faulty raster and override nodata in these kind tools, I would atleast change the name to nodata_value
and the type Number
(imported like this: from numbers import Number
) which we have used for cases that allow floats and ints.
@nmaarnio, |
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.
LGTM now!
Since @nialov was the main reviewer of this PR, let's wait for his approval before merging.
A small note not regarding the implementation itself:I guess the original comment of this PR that "It is not to be merged to the EIS toolkit code base." could be removed at this point
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.
LGTM! Very well coded functionality!
I actually encountered a few issues when implementing CLI functions for these tools just now. I ended up creating a suggestion for refactored version of the public relcassification functions. Here cases where
|
…rding to feedback
…nto add-reclassify-raster
Some changes to |
This PR for reclassifying raster data functions.