Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ds = neuralgcm.demo.load_data(model.data_coords)出现错误 #118

Open
2095099596 opened this issue Sep 3, 2024 · 2 comments
Open

ds = neuralgcm.demo.load_data(model.data_coords)出现错误 #118

2095099596 opened this issue Sep 3, 2024 · 2 comments

Comments

@2095099596
Copy link

Hello, I am a beginner. When running the code ds = neuralgcm.demo.load_data(model.data_coords) from the NeuralGCM documentation here, I keep encountering an OverflowError:
OverflowError Traceback (most recent call last)
File conversion.pyx:228, in pandas._libs.tslibs.conversion.cast_from_unit()

OverflowError: Python int too large to convert to C long

The above exception was the direct cause of the following exception:

OutOfBoundsDatetime Traceback (most recent call last)
File timedeltas.pyx:377, in pandas._libs.tslibs.timedeltas._maybe_cast_from_unit()

File conversion.pyx:230, in pandas._libs.tslibs.conversion.cast_from_unit()

OutOfBoundsDatetime: cannot convert input 24 with the unit 'h'

The above exception was the direct cause of the following exception:

OutOfBoundsTimedelta Traceback (most recent call last)
File C:\ProgramData\Anaconda3\envs\GCM\lib\site-packages\xarray\coding\times.py:326, in decode_cf_datetime(num_dates, units, calendar, use_cftime)
325 try:
--> 326 dates = _decode_datetime_with_pandas(flat_num_dates, units, calendar)
327 except (KeyError, OutOfBoundsDatetime, OutOfBoundsTimedelta, OverflowError):

File C:\ProgramData\Anaconda3\envs\GCM\lib\site-packages\xarray\coding\times.py:272, in _decode_datetime_with_pandas(flat_num_dates, units, calendar)
270 if flat_num_dates.size > 0:
271 # avoid size 0 datetimes GH1329
--> 272 pd.to_timedelta(flat_num_dates.min(), time_units) + ref_date
273 pd.to_timedelta(flat_num_dates.max(), time_units) + ref_date

File C:\ProgramData\Anaconda3\envs\GCM\lib\site-packages\pandas\core\tools\timedeltas.py:223, in to_timedelta(arg, unit, errors)
222 # ...so it must be a scalar value. Return scalar.
--> 223 return _coerce_scalar_to_timedelta_type(arg, unit=unit, errors=errors)

File C:\ProgramData\Anaconda3\envs\GCM\lib\site-packages\pandas\core\tools\timedeltas.py:233, in _coerce_scalar_to_timedelta_type(r, unit, errors)
232 try:
--> 233 result = Timedelta(r, unit)
234 except ValueError:

File timedeltas.pyx:1896, in pandas._libs.tslibs.timedeltas.Timedelta.new()

File timedeltas.pyx:354, in pandas._libs.tslibs.timedeltas.convert_to_timedelta64()

File timedeltas.pyx:379, in pandas._libs.tslibs.timedeltas._maybe_cast_from_unit()

OutOfBoundsTimedelta: Cannot cast 24 from h to 'ns' without overflow.

During handling of the above exception, another exception occurred:

ModuleNotFoundError Traceback (most recent call last)
Cell In[107], line 1
----> 1 ds = neuralgcm.demo.load_data(model.data_coords)

File C:\ProgramData\Anaconda3\envs\GCM\lib\site-packages\neuralgcm\demo.py:56, in load_data(coords)
54 package = importlib.resources.files(neuralgcm)
55 with package.joinpath('data/era5_tl31_19590102T00.nc').open('rb') as f:
---> 56 ds = xarray.load_dataset(f).expand_dims('time')
57 regridder = horizontal_interpolation.ConservativeRegridder(
58 spherical_harmonic.Grid.TL31(), coords.horizontal
59 )
60 return _horizontal_regrid(regridder, ds)

File C:\ProgramData\Anaconda3\envs\GCM\lib\site-packages\xarray\backends\api.py:278, in load_dataset(filename_or_obj, **kwargs)
275 raise TypeError("cache has no effect in this context")
277 with open_dataset(filename_or_obj, **kwargs) as ds:
--> 278 return ds.load()

File C:\ProgramData\Anaconda3\envs\GCM\lib\site-packages\xarray\core\dataset.py:875, in Dataset.load(self, **kwargs)
873 for k, v in self.variables.items():
874 if k not in lazy_data:
--> 875 v.load()
877 return self

File C:\ProgramData\Anaconda3\envs\GCM\lib\site-packages\xarray\core\variable.py:977, in Variable.load(self, **kwargs)
960 def load(self, **kwargs):
961 """Manually trigger loading of this variable's data from disk or a
962 remote source into memory and return this variable.
963
(...)
975 dask.array.compute
976 """
--> 977 self._data = to_duck_array(self._data, **kwargs)
978 return self

File C:\ProgramData\Anaconda3\envs\GCM\lib\site-packages\xarray\namedarray\pycompat.py:134, in to_duck_array(data, **kwargs)
131 return loaded_data
133 if isinstance(data, ExplicitlyIndexed):
--> 134 return data.get_duck_array() # type: ignore[no-untyped-call, no-any-return]
135 elif is_duck_array(data):
136 return data

File C:\ProgramData\Anaconda3\envs\GCM\lib\site-packages\xarray\core\indexing.py:837, in MemoryCachedArray.get_duck_array(self)
836 def get_duck_array(self):
--> 837 self._ensure_cached()
838 return self.array.get_duck_array()

File C:\ProgramData\Anaconda3\envs\GCM\lib\site-packages\xarray\core\indexing.py:831, in MemoryCachedArray._ensure_cached(self)
830 def _ensure_cached(self):
--> 831 self.array = as_indexable(self.array.get_duck_array())

File C:\ProgramData\Anaconda3\envs\GCM\lib\site-packages\xarray\core\indexing.py:788, in CopyOnWriteArray.get_duck_array(self)
787 def get_duck_array(self):
--> 788 return self.array.get_duck_array()

File C:\ProgramData\Anaconda3\envs\GCM\lib\site-packages\xarray\core\indexing.py:658, in LazilyIndexedArray.get_duck_array(self)
653 # self.array[self.key] is now a numpy array when
654 # self.array is a BackendArray subclass
655 # and self.key is BasicIndexer((slice(None, None, None),))
656 # so we need the explicit check for ExplicitlyIndexed
657 if isinstance(array, ExplicitlyIndexed):
--> 658 array = array.get_duck_array()
659 return _wrap_numpy_scalars(array)

File C:\ProgramData\Anaconda3\envs\GCM\lib\site-packages\xarray\coding\variables.py:81, in _ElementwiseFunctionArray.get_duck_array(self)
80 def get_duck_array(self):
---> 81 return self.func(self.array.get_duck_array())

File C:\ProgramData\Anaconda3\envs\GCM\lib\site-packages\xarray\coding\times.py:328, in decode_cf_datetime(num_dates, units, calendar, use_cftime)
326 dates = _decode_datetime_with_pandas(flat_num_dates, units, calendar)
327 except (KeyError, OutOfBoundsDatetime, OutOfBoundsTimedelta, OverflowError):
--> 328 dates = _decode_datetime_with_cftime(
329 flat_num_dates.astype(float), units, calendar
330 )
332 if (
333 dates[np.nanargmin(num_dates)].year < 1678
334 or dates[np.nanargmax(num_dates)].year >= 2262
335 ):
336 if _is_standard_calendar(calendar):

File C:\ProgramData\Anaconda3\envs\GCM\lib\site-packages\xarray\coding\times.py:239, in _decode_datetime_with_cftime(num_dates, units, calendar)
235 def _decode_datetime_with_cftime(
236 num_dates: np.ndarray, units: str, calendar: str
237 ) -> np.ndarray:
238 if cftime is None:
--> 239 raise ModuleNotFoundError("No module named 'cftime'")
240 if num_dates.size > 0:
241 return np.asarray(
242 cftime.num2date(num_dates, units, calendar, only_use_cftime_datetimes=True)
243 )

ModuleNotFoundError: No module named 'cftime'
How should I resolve such errors?

@kochkov92
Copy link
Collaborator

Hi @2095099596,

The error suggests that xarray tries to access package cftime that is not available. I would look into installing/updating all of the dependencies or potentially adding cftime to your environment.

@2095099596
Copy link
Author

您好 ,

该错误表明 xarray 尝试访问不可用的软件包 cftime。我会考虑安装/更新所有依赖项,或者可能将 cftime 添加到您的环境中。

"Okay, thank you very much!"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants