Skip to content

Commit

Permalink
atm: fix for large files
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsail committed May 14, 2024
1 parent 62a6373 commit 6fc0633
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pyposeidon/telemac.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ def write_meteo(outpath, geo, ds, gtype="grid", ttype="time", input360=False):
"tmp": ("TAIR", "TEMPERATURE", "DEGREES C"),
}
final = []
logger.info(f"interpolating on {len(ds.time)} time steps")
netcdf_path = 'temporary_output.nc'
for it, t_ in enumerate(ds.time):
data_vars = {}
var_attrs = {}
Expand All @@ -245,9 +247,11 @@ def write_meteo(outpath, geo, ds, gtype="grid", ttype="time", input360=False):
atm_time_step = atm_time_step.assign_coords({time_dim: t_})
atm_time_step = atm_time_step.expand_dims(time_dim)

# Append the Dataset for the current time step to the list
final.append(atm_time_step)
xatm = xr.concat(final, dim="time")
# Write the Dataset for the current time step to a NetCDF file
write_mode = 'w' if it == 0 else 'a' # Overwrite if first iteration, append otherwise
atm_time_step.to_netcdf(netcdf_path, mode=write_mode, format='NETCDF4', unlimited_dims=[time_dim])

xatm = xr.open_dataset(netcdf_path)
# Add global attributes after concatenation
xatm.attrs["date_start"] = [t0.year, t0.month, t0.day, t0.hour, t0.minute, t0.second]
xatm.attrs["ikle2"] = geo.attrs["ikle2"]
Expand Down

0 comments on commit 6fc0633

Please sign in to comment.