Skip to content

Commit

Permalink
Added nodata value to raster before writing (#199)
Browse files Browse the repository at this point in the history
* Added nodata value to raster before writing

* checked variable type to set nodata

* removed trailing whitespace

* removed trailing whitespace
  • Loading branch information
gutierrad authored Jun 3, 2024
1 parent 89a1e76 commit c84c590
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hydromt_sfincs/sfincs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3398,6 +3398,9 @@ def write_raster(
f"Variable {attr}.{layer} has more than 2 dimensions: skipping."
)
continue
# If the raster type is float, set nodata to np.nan
if da.dtype == "float32" or da.dtype == "float64":
da.raster.set_nodata(np.nan)
# only write active cells to gis files
da = da.where(self.mask > 0, da.raster.nodata).raster.mask_nodata()
if da.raster.res[1] > 0: # make sure orientation is N->S
Expand Down

0 comments on commit c84c590

Please sign in to comment.