Skip to content

Commit

Permalink
Add comments re: netcdf4 for wwatch3 file writes
Browse files Browse the repository at this point in the history
Added comments to make_ww3_wind_file and make_ww3_current_file workers re: the
need to use netcdf4 instead of h5netcdf for dataset file writes. This is
necessary because the wwatch3 wind and current file pre-processors raise errors
from files generated by h5netcdf.
  • Loading branch information
douglatornell committed Jun 28, 2024
1 parent ffed73d commit e74c540
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
51 changes: 45 additions & 6 deletions nowcast/workers/make_ww3_current_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,51 @@ def make_ww3_current_file(parsed_args, config, *args):
run_date, nemo_dir, nemo_file_tmpl, dest_dir
)
drop_vars = {
'gphiu', 'vmask', 'gdept_0', 'gdepw_0', 'umask', 'gphif', 'e3v_0', 'time_counter',
'isfdraft', 'glamu', 'e1f', 'vmaskutil', 'mbathy', 'e2t', 'e2u', 'e3u_0', 'ff', 'gdept_1d',
'gphit', 'e3w_0', 'e1u', 'e1t', 'e2v', 'fmaskutil', 'tmaskutil', 'gdepv', 'misf', 'gphiv',
'e3t_1d', 'fmask', 'tmask', 'e3t_0', 'gdepw_1d', 'gdepu', 'glamt', 'glamf',
'e3w_1d', 'e1v', 'umaskutil', 'glamv', 'e2f',
"gphiu",
"vmask",
"gdept_0",
"gdepw_0",
"umask",
"gphif",
"e3v_0",
"time_counter",
"isfdraft",
"glamu",
"e1f",
"vmaskutil",
"mbathy",
"e2t",
"e2u",
"e3u_0",
"ff",
"gdept_1d",
"gphit",
"e3w_0",
"e1u",
"e1t",
"e2v",
"fmaskutil",
"tmaskutil",
"gdepv",
"misf",
"gphiv",
"e3t_1d",
"fmask",
"tmask",
"e3t_0",
"gdepw_1d",
"gdepu",
"glamt",
"glamf",
"e3w_1d",
"e1v",
"umaskutil",
"glamv",
"e2f",
}
with xarray.open_dataset(mesh_mask, drop_variables=drop_vars, engine="h5netcdf") as grid:
with xarray.open_dataset(
mesh_mask, drop_variables=drop_vars, engine="h5netcdf"
) as grid:
lats = grid.nav_lat[1:, 1:]
lons = grid.nav_lon[1:, 1:] + 360
logger.debug(f"lats and lons from: {mesh_mask}")
Expand Down Expand Up @@ -180,6 +218,7 @@ def make_ww3_current_file(parsed_args, config, *args):
"max_workers": 8,
}
ds.compute(**dask_scheduler)
# write using netcdf4 because wwatch3 doesn't like files generated by h5netcdf
ds.to_netcdf(nc_filepath, engine="netcdf4")
logger.debug(f"stored currents forcing file: {nc_filepath}")
checklist = {
Expand Down
15 changes: 10 additions & 5 deletions nowcast/workers/make_ww3_wind_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,18 @@ def make_ww3_wind_file(parsed_args, config, *args):
"u_wind",
"v_wind",
}
with xarray.open_dataset(datasets[0], drop_variables=drop_vars, engine = "h5netcdf") as lats_lons:
with xarray.open_dataset(
datasets[0], drop_variables=drop_vars, engine="h5netcdf"
) as lats_lons:
lats = lats_lons.nav_lat
lons = lats_lons.nav_lon
logger.debug(f"lats and lons from: {datasets[0]}")
drop_vars = drop_vars.union({
"nav_lon",
"nav_lat",
})
drop_vars = drop_vars.union(
{
"nav_lon",
"nav_lat",
}
)
drop_vars = drop_vars.difference({"u_wind", "v_wind"})
chunks = {
"time_counter": 24,
Expand All @@ -153,6 +157,7 @@ def make_ww3_wind_file(parsed_args, config, *args):
"max_workers": 8,
}
ds.compute(**dask_scheduler)
# write using netcdf4 because wwatch3 doesn't like files generated by h5netcdf
ds.to_netcdf(nc_filepath, engine="netcdf4")
logger.debug(f"stored wind forcing file: {nc_filepath}")
checklist = {run_type: os.fspath(nc_filepath)}
Expand Down

0 comments on commit e74c540

Please sign in to comment.