|
2 | 2 | import os |
3 | 3 |
|
4 | 4 | import xarray as xr |
| 5 | +from xarray.coders import CFDatetimeCoder |
5 | 6 |
|
6 | 7 | # create mapping dictionary of ISMIP6 variables to MALI variable names |
7 | 8 | {"thermal_forcing": "ismip6_2dThermalForcing", |
@@ -82,6 +83,7 @@ def get_filename(self, GCM, scenario, variable, start=1950, end=2100): |
82 | 83 | # get a list of all the yearly files within the period of intrest |
83 | 84 | yearly_files = self.__find_yearly_files(GCM, scenario, variable, |
84 | 85 | start, end) |
| 86 | + |
85 | 87 | # still need to make the output filename to write combined files to |
86 | 88 | out_fn = f"MAR3.9_{GCM}_{scenario}_{variable}_{start}--{end}.nc" |
87 | 89 | # relative to the workdir, which we've already checked if if existed |
@@ -129,9 +131,12 @@ def __find_yearly_files(self, GCM, scenario, variable, start, end): |
129 | 131 | def __combine_files(self, files, out_fn): |
130 | 132 | """ |
131 | 133 | """ |
132 | | - ds = xr.open_mfdataset(files, concat_dim="time", combine="nested", |
| 134 | + decoder = CFDatetimeCoder(use_cftime=True) |
| 135 | + |
| 136 | + ds = xr.open_mfdataset(files, decode_times=decoder, |
| 137 | + concat_dim="time", combine="nested", |
133 | 138 | data_vars='minimal', coords='minimal', |
134 | 139 | compat="broadcast_equals", |
135 | | - combine_attrs="override") |
| 140 | + combine_attrs="override", engine='netcdf4') |
136 | 141 |
|
137 | | - ds.to_netcdf(out_fn) |
| 142 | + ds.to_netcdf(out_fn, engine='netcdf4') |
0 commit comments