dtcenter / METdataio

https://metdataio.readthedocs.io/en/latest/index.html
Apache License 2.0
5 stars 3 forks source link

Bugfix read netcdf not working on single time step zonal mean data #285

Open CPKalb opened 6 months ago

CPKalb commented 6 months ago

Describe the Problem

METdataio read_netcd work for zonal mean data when an array of times is input. However, with a single time step, the script fails with the following error: Traceback (most recent call last): File "/glade/work/dtcrt/METplus/derecho/miniconda/miniconda3/envs/metplus_v5.1_py3.10/lib/python3.10/site-packages/xarray/coding/times.py", line 285, in decode_cf_datetime dates = _decode_datetime_with_pandas(flat_num_dates, units, calendar) File "/glade/work/dtcrt/METplus/derecho/miniconda/miniconda3/envs/metplus_v5.1_py3.10/lib/python3.10/site-packages/xarray/coding/times.py", line 218, in _decode_datetime_with_pandas raise OutOfBoundsDatetime( pandas._libs.tslibs.np_datetime.OutOfBoundsDatetime: Cannot decode times from a non-standard calendar, 'julian', using pandas.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/glade/work/dtcrt/METplus/derecho/miniconda/miniconda3/envs/metplus_v5.1_py3.10/lib/python3.10/site-packages/xarray/coding/times.py", line 184, in _decode_cf_datetime_dtype result = decode_cf_datetime(example_value, units, calendar, use_cftime) File "/glade/work/dtcrt/METplus/derecho/miniconda/miniconda3/envs/metplus_v5.1_py3.10/lib/python3.10/site-packages/xarray/coding/times.py", line 287, in decode_cf_datetime dates = _decode_datetime_with_cftime( File "/glade/work/dtcrt/METplus/derecho/miniconda/miniconda3/envs/metplus_v5.1_py3.10/lib/python3.10/site-packages/xarray/coding/times.py", line 208, in _decode_datetime_with_cftime cftime.num2date(num_dates, units, calendar, only_use_cftime_datetimes=True) File "src/cftime/_cftime.pyx", line 617, in cftime._cftime.num2date File "src/cftime/_cftime.pyx", line 414, in cftime._cftime.cast_to_int OverflowError: time values outside range of 64 bit signed integers

During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/glade/work/dtcrt/METplus/derecho/miniconda/miniconda3/envs/metplus_v5.1_py3.10/lib/python3.10/site-packages/xarray/conventions.py", line 551, in decode_cf_variables new_vars[k] = decode_cf_variable( File "/glade/work/dtcrt/METplus/derecho/miniconda/miniconda3/envs/metplus_v5.1_py3.10/lib/python3.10/site-packages/xarray/conventions.py", line 397, in decode_cf_variable var = times.CFDatetimeCoder(use_cftime=use_cftime).decode(var, name=name) File "/glade/work/dtcrt/METplus/derecho/miniconda/miniconda3/envs/metplus_v5.1_py3.10/lib/python3.10/site-packages/xarray/coding/times.py", line 716, in decode dtype = _decode_cf_datetime_dtype(data, units, calendar, self.use_cftime) File "/glade/work/dtcrt/METplus/derecho/miniconda/miniconda3/envs/metplus_v5.1_py3.10/lib/python3.10/site-packages/xarray/coding/times.py", line 194, in _decode_cf_datetime_dtype raise ValueError(msg) ValueError: unable to decode time units 'days since 2018-02-12' with "calendar 'julian'". Try opening your dataset with decode_times=False or installing cftime if it is not installed.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/glade/u/home/kalb/stratosphere/METplus/parm/use_cases/model_applications/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratospherePolar/polar_t_u_driver.py", line 112, in main() File "/glade/u/home/kalb/stratosphere/METplus/parm/use_cases/model_applications/s2s_stratosphere/UserScript_fcstGFS_obsERA_StratospherePolar/polar_t_u_driver.py", line 47, in main dsO = file_reader.read_into_xarray(obs_infiles)[0] File "/glade/u/home/kalb/stratosphere/METdataio/METreadnc/util/read_netcdf.py", line 70, in read_into_xarray file_data = xr.open_dataset(file) File "/glade/work/dtcrt/METplus/derecho/miniconda/miniconda3/envs/metplus_v5.1_py3.10/lib/python3.10/site-packages/xarray/backends/api.py", line 541, in open_dataset backend_ds = backend.open_dataset( File "/glade/work/dtcrt/METplus/derecho/miniconda/miniconda3/envs/metplus_v5.1py3.10/lib/python3.10/site-packages/xarray/backends/netCDF4.py", line 592, in open_dataset ds = store_entrypoint.open_dataset( File "/glade/work/dtcrt/METplus/derecho/miniconda/miniconda3/envs/metplus_v5.1_py3.10/lib/python3.10/site-packages/xarray/backends/store.py", line 35, in open_dataset vars, attrs, coord_names = conventions.decode_cf_variables( File "/glade/work/dtcrt/METplus/derecho/miniconda/miniconda3/envs/metplus_v5.1_py3.10/lib/python3.10/site-packages/xarray/conventions.py", line 562, in decode_cf_variables raise type(e)(f"Failed to decode variable {k!r}: {e}") ValueError: Failed to decode variable 'time': unable to decode time units 'days since 2018-02-12' with "calendar 'julian'". Try opening your dataset with decode_times=False or installing cftime if it is not installed.

Expected Behavior

It should successfully read data with a single time step or an array of times

Environment

Describe your runtime environment: 1. derecho 2. linux 3. Software version number(s)

To Reproduce

Describe the steps to reproduce the behavior: 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' 4. See error Post relevant sample data following these instructions: https://dtcenter.org/community-code/model-evaluation-tools-met/met-help-desk#ftp

Relevant Deadlines

List relevant project deadlines here or state NONE.

Funding Source

Define the source of funding and account keys here or state NONE.

Define the Metadata

Assignee

Labels

Projects and Milestone

Define Related Issue(s)

Consider the impact to the other METplus components.

Bugfix Checklist

See the METplus Workflow for details.