Skip to content

Commit 2a3c8d7

Browse files
author
tintino
committed
Make topoclass horizon I/O compatible with zarr output
compute_horizon() in topoclass now: - Accepts format='netcdf' | 'zarr' and passes it to tp.compute_horizon() - Auto-detects existing horizon files in either netCDF or zarr format - Loads zarr horizons with engine='zarr' instead of hardcoded h5netcdf This ensures the zarr horizon output added to topo_param.py is fully usable through the high-level Topoclass workflow, matching the zarr I/O optimizations in topo_scale_zarr.py.
1 parent 380762c commit 2a3c8d7

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

TopoPyScale/topoclass.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,20 +568,32 @@ def compute_solar_geometry(self):
568568
self.config.outputs.file.ds_solar,
569569
self.config.outputs.path)
570570

571-
def compute_horizon(self):
571+
def compute_horizon(self, format='netcdf'):
572572
"""
573573
Function to compute horizon angle and sample values for list of points
574+
575+
Parameters
576+
----------
577+
format : str
578+
Output format: 'netcdf' or 'zarr'. Zarr enables faster point lookups
579+
and parallel reads during downscaling.
574580
"""
575581
fname = self.config.outputs.path / self.config.outputs.file.da_horizon
582+
fname_zarr = fname.with_suffix('.zarr')
583+
576584
if fname.is_file():
577-
self.da_horizon = xr.open_dataarray(fname, engine='h5netcdf')
578585
print(f'---> Horizon file {self.config.outputs.file.da_horizon} exists and loaded')
586+
self.da_horizon = xr.open_dataarray(fname, engine='h5netcdf')
587+
elif fname_zarr.is_dir():
588+
print(f'---> Horizon zarr store {fname_zarr.name} exists and loaded')
589+
self.da_horizon = xr.open_dataarray(str(fname_zarr), engine='zarr')
579590
else:
580591
self.da_horizon = tp.compute_horizon(self.config.dem.filepath,
581592
self.config.dem.horizon_increments,
582593
self.config.project.parallelization.setting.multicore.CPU_cores,
583594
self.config.outputs.file.da_horizon,
584-
self.config.outputs.path)
595+
self.config.outputs.path,
596+
format=format)
585597
tgt_x = tp.xr.DataArray(self.toposub.df_centroids.x.values, dims="points")
586598
tgt_y = tp.xr.DataArray(self.toposub.df_centroids.y.values, dims="points")
587599

0 commit comments

Comments
 (0)