Skip to content

Commit

Permalink
reversed changes to saving netcdf files
Browse files Browse the repository at this point in the history
  • Loading branch information
rosepearson committed Oct 29, 2024
1 parent 811b77c commit 86b386c
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions src/geofabrics/dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,24 +356,11 @@ def save_dem(
self._write_netcdf_conventions_in_place(dem, self.catchment_geometry.crs)
if filename.suffix.lower() == ".nc":
if compression is not None:
encoding_keys = (
"_FillValue",
"dtype",
"scale_factor",
"add_offset",
"grid_mapping",
)
compression["grid_mapping"] = dem.encoding["grid_mapping"]
encoding = {}
for key in dem.data_vars:
dem[key] = dem[key].astype(geometry.RASTER_TYPE)
encoding[key] = {
encoding_key: value
for encoding_key, value in dem[key].encoding.items()
if encoding_key in encoding_keys
}
if "dtype" not in encoding[key]:
encoding[key]["dtype"] = dem[key].dtype
encoding[key] = {**encoding[key], **compression}
compression["dtype"] = dem[key].dtype
encoding[key] = compression
dem.to_netcdf(
filename, format="NETCDF4", engine="netcdf4", encoding=encoding
)
Expand Down

0 comments on commit 86b386c

Please sign in to comment.