Skip to content

Commit

Permalink
Reveresed migration to h5netcdf
Browse files Browse the repository at this point in the history
  • Loading branch information
rosepearson committed Oct 10, 2024
1 parent db17f68 commit 53d9804
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion environment_CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ dependencies:
- python-pdal >= 3.3.0
- dask >= 2023.6.0
- distributed >= 2023.6.0
- h5netcdf
- netcdf4
- libgdal-hdf5
15 changes: 4 additions & 11 deletions src/geofabrics/dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,10 @@ def save_dem(
compression["dtype"] = dem[key].dtype
encoding[key] = compression
dem.to_netcdf(
filename, format="NETCDF4", engine="h5netcdf", encoding=encoding
filename, format="NETCDF4", engine="netcdf4", encoding=encoding
)
else:
dem.to_netcdf(filename, format="NETCDF4", engine="h5netcdf")
dem.to_netcdf(filename, format="NETCDF4", engine="netcdf4")
elif filename.suffix.lower() == ".tif":
for key, array in dem.data_vars.items():
filename_layer = (
Expand Down Expand Up @@ -438,20 +438,13 @@ def _write_netcdf_conventions_in_place(
A dict with horizontal and vertical CRS information.
"""

reserved_names = ["_NCProperties", "_Netcdf4Coordinates", "_Netcdf4Dimid"]

dem.rio.write_crs(crs_dict["horizontal"], inplace=True)
dem.rio.write_transform(inplace=True)
for reserved_name in reserved_names:
if reserved_name in dem.attrs.keys():
del dem.attrs[reserved_name]
for layer in ["z", "data_source", "lidar_source", "zo"]:
if layer in dem:
dem[layer].rio.write_crs(crs_dict["horizontal"], inplace=True)
dem[layer].rio.write_nodata(numpy.nan, encoded=True, inplace=True)
for reserved_name in reserved_names:
if reserved_name in dem[layer].attrs.keys():
del dem[layer].attrs[reserved_name]
dem[layer] = dem[layer].rio.write_crs(crs_dict["horizontal"])
dem[layer] = dem[layer].rio.write_nodata(numpy.nan, encoded=True)

def _extents_from_mask(self, mask: numpy.ndarray, transform: dict):
"""Define the spatial extents of the pixels in the DEM as defined by the mask
Expand Down

0 comments on commit 53d9804

Please sign in to comment.