Opened 7 years ago
Last modified 6 years ago
#3415 new defect
Mark raster NULL values as None in PyGRASS
Reported by: | marisn | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | 7.4.5 |
Component: | PyGRASS | Version: | unspecified |
Keywords: | Cc: | ||
CPU: | Unspecified | Platform: | Unspecified |
Description
At the moment PyGRASS is providing raster NULL values as is (i.e. for CELL type they are marked as -2147483648). There is no function to check if value is NULL (in C it is done with Rast_is_c/f/d_null_value).
The best would be to replace raster NULL values with None when raster is read and None with NULL representation when it is written back. Such approach would greatly simplify use of rasters in PyGRASS (i.e. "if myrast[row][col] is not None:")
Change History (8)
follow-up: 3 comment:1 by , 7 years ago
comment:2 by , 7 years ago
You have a good point. As long as loading/saving can cope with whatever is the NULL representation, a constant variable for grass.pygrass.raster would do. I.e. grass.pygrass.raster.NULL that gets set to representation of NULL for particular map when the map gets opened/created. Thus it wouldn't matter if map is CELL or FCELL. In code one could then use map[row][cell] != map.NULL
to check for not NULL and map[row][col] = map.NULL
to set to NULL.
If nobody comes up with objection why it is a bad idea, could you, please, implement it?
comment:3 by , 7 years ago
Replying to zarch:
Well, but then for CELL raster instead to have an array of integer you will have an array of objects, I did not perform any benchmark but it seems not very intuitive as well.
For FP data, NaN should be used for nulls. This avoids the need for explicit null handling in most cases.
For integer data, consider either (or both of):
- converting to a masked array. This isn't quite as transparent as NaN, but is typically easier than using a separate mask array.
- converting to double (np.float64), with NaN as null. But this isn't suitable if the data is to be used with e.g. bitwise operations, or used as indices.
comment:5 by , 6 years ago
Milestone: | 7.4.1 → 7.4.2 |
---|
Replying to marisn:
Well, but then for CELL raster instead to have an array of integer you will have an array of objects, I did not perform any benchmark but it seems not very intuitive as well. Perhaps we can define a
CELL_NULL
variable, and then you can write code as:if myrast[row] != CELL_NULL:
or an equivalent function instead ofnumpy.isnan
getpygrass.raster.isnull
. What do you think?