Skip to content

Commit 65b7c9d

Browse files
committed
Remove convert_xarray_time_units (see #1919)
1 parent 56e9899 commit 65b7c9d

File tree

3 files changed

+1
-22
lines changed

3 files changed

+1
-22
lines changed

parcels/fieldfilebuffer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import xarray as xr
77

88
from parcels._typing import InterpMethodOption, PathLike
9-
from parcels.tools.converters import convert_xarray_time_units
109
from parcels.tools.warnings import FileWarning
1110

1211

@@ -148,7 +147,6 @@ def time_access(self):
148147
return np.array([None])
149148

150149
time_da = self.dataset[self.dimensions["time"]]
151-
convert_xarray_time_units(time_da, self.dimensions["time"])
152150
time = (
153151
np.array([time_da[self.dimensions["time"]].data])
154152
if len(time_da.shape) == 0

parcels/fieldset.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from parcels.gridset import GridSet
1515
from parcels.particlefile import ParticleFile
1616
from parcels.tools._helpers import fieldset_repr
17-
from parcels.tools.converters import TimeConverter, convert_xarray_time_units
17+
from parcels.tools.converters import TimeConverter
1818
from parcels.tools.loggers import logger
1919
from parcels.tools.warnings import FieldSetWarning
2020

@@ -1162,10 +1162,6 @@ def from_xarray_dataset(cls, ds, variables, dimensions, mesh="spherical", allow_
11621162
fields = {}
11631163
if "creation_log" not in kwargs.keys():
11641164
kwargs["creation_log"] = "from_xarray_dataset"
1165-
if "time" in dimensions:
1166-
if "units" not in ds[dimensions["time"]].attrs and "Unit" in ds[dimensions["time"]].attrs:
1167-
# Fix DataArrays that have time.Unit instead of expected time.units
1168-
convert_xarray_time_units(ds, dimensions["time"])
11691165

11701166
for var, name in variables.items():
11711167
dims = dimensions[var] if var in dimensions else dimensions

parcels/tools/converters.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import cftime
88
import numpy as np
99
import numpy.typing as npt
10-
import xarray as xr
1110

1211
__all__ = [
1312
"Geographic",
@@ -17,7 +16,6 @@
1716
"TimeConverter",
1817
"UnitConverter",
1918
"convert_to_flat_array",
20-
"convert_xarray_time_units",
2119
"unitconverters_map",
2220
]
2321

@@ -235,16 +233,3 @@ def to_source(self, value, z, y, x):
235233
"Kh_zonal": GeographicPolarSquare(),
236234
"Kh_meridional": GeographicSquare(),
237235
}
238-
239-
240-
def convert_xarray_time_units(ds, time):
241-
"""Fixes DataArrays that have time.Unit instead of expected time.units"""
242-
da = ds[time] if isinstance(ds, xr.Dataset) else ds
243-
if "units" not in da.attrs and "Unit" in da.attrs:
244-
da.attrs["units"] = da.attrs["Unit"]
245-
da2 = xr.Dataset({time: da})
246-
try:
247-
da2 = xr.decode_cf(da2)
248-
except ValueError:
249-
raise RuntimeError("Xarray could not convert the calendar.")
250-
ds[time] = da2[time]

0 commit comments

Comments
 (0)