Skip to content

Commit

Permalink
bugfix: catch edge case where time is included in initial condition a…
Browse files Browse the repository at this point in the history
…s both a dimension and a variable. This happens with the new copernicus api downloads
  • Loading branch information
ashjbarnes committed Jan 16, 2024
1 parent 6e7952f commit dc8d4fd
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions regional_mom6/regional_mom6.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,15 +590,11 @@ def ocean_forcing(
## pull out the initial velocity on MOM5's Bgrid
ic_raw = xr.open_dataset(path / "ic_unprocessed")

if 'time' in ic_raw.variables:
if varnames["time"] in ic_raw.variables:
ic_raw = ic_raw.drop_vars('time')
elif varnames["time"] in ic_raw.dims:
if varnames["time"] in ic_raw.dims:
ic_raw = ic_raw.isel({varnames["time"]: 0})



if varnames["time"] in ic_raw

print(ic_raw)
## Separate out tracers from two velocity fields of IC
try:
ic_raw_tracers = ic_raw[
Expand Down Expand Up @@ -1454,13 +1450,13 @@ def setup_era5(self, era5_path):

q.q.attrs = {"long_name": "Specific Humidity", "units": "kg/kg"}
q.to_netcdf(
f"{self.mom_input_dir}/forcing/q_ERA5",
f"{self.mom_input_dir}/forcing/q_ERA5.nc",
unlimited_dims="time",
encoding={"q": {"dtype": "double"}},
)
else:
rawdata[fname].to_netcdf(
f"{self.mom_input_dir}/forcing/{fname}_ERA5",
f"{self.mom_input_dir}/forcing/{fname}_ERA5.nc",
unlimited_dims="time",
encoding={vname: {"dtype": "double"}},
)
Expand Down

0 comments on commit dc8d4fd

Please sign in to comment.