geoschem / gcpy

Python toolkit for GEOS-Chem. Contains basic plotting scripts, plus the suite of GEOS-Chem benchmarking utilities.
https://gcpy.readthedocs.io
Other
51 stars 24 forks source link

[BUG/ISSUE] Error generating mass table and radionuclide budget for the GCHP 1-year transport tracers benchmarks #265

Closed msulprizio closed 1 year ago

msulprizio commented 1 year ago

Describe the bug

When trying to generate the mass table for the GCHP 14.2.0-rc.2 1-year TransportTracer benchmark using the latest dev branch (commit a64c81), I received the following error.

%%% Creating GCHP dev mass conservation table %%%
/n/holyscratch01/jacob_lab/msulprizio/GC/benchmarks/1yr/14.2.0-rc.2/GCHP/TransportTracers/Restarts/GEOSChem.Restart.20190101_0000z.c24.nc4
Traceback (most recent call last):
  File "pandas/_libs/tslibs/conversion.pyx", line 132, 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:

Traceback (most recent call last):
  File "pandas/_libs/tslibs/timedeltas.pyx", line 379, in pandas._libs.tslibs.timedeltas._maybe_cast_from_unit
  File "pandas/_libs/tslibs/conversion.pyx", line 134, in pandas._libs.tslibs.conversion.cast_from_unit
pandas._libs.tslibs.np_datetime.OutOfBoundsDatetime: cannot convert input 9.969209968386869e+36 with the unit 'm'
The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/n/home05/msulprizio/python/mamba/envs/gcpy_env/lib/python3.9/site-packages/xarray/coding/times.py", line 289, in decode_cf_datetime
    dates = _decode_datetime_with_pandas(flat_num_dates, units, calendar)
  File "/n/home05/msulprizio/python/mamba/envs/gcpy_env/lib/python3.9/site-packages/xarray/coding/times.py", line 240, in _decode_datetime_with_pandas
    pd.to_timedelta(flat_num_dates.min(), delta) + ref_date
  File "/n/home05/msulprizio/python/mamba/envs/gcpy_env/lib/python3.9/site-packages/pandas/core/tools/timedeltas.py", line 211, in to_timedelta
    return _coerce_scalar_to_timedelta_type(arg, unit=unit, errors=errors)
  File "/n/home05/msulprizio/python/mamba/envs/gcpy_env/lib/python3.9/site-packages/pandas/core/tools/timedeltas.py", line 221, in _coerce_scalar_to_timedelta_type
    result = Timedelta(r, unit)
  File "pandas/_libs/tslibs/timedeltas.pyx", line 1806, in pandas._libs.tslibs.timedeltas.Timedelta.__new__
  File "pandas/_libs/tslibs/timedeltas.pyx", line 358, in pandas._libs.tslibs.timedeltas.convert_to_timedelta64
  File "pandas/_libs/tslibs/timedeltas.pyx", line 381, in pandas._libs.tslibs.timedeltas._maybe_cast_from_unit
pandas._libs.tslibs.np_datetime.OutOfBoundsTimedelta: Cannot cast 9.969209968386869e+36 from m to 'ns' without overflow.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/n/home05/msulprizio/python/mamba/envs/gcpy_env/lib/python3.9/site-packages/xarray/coding/times.py", line 186, in _decode_cf_datetime_dtype
    result = decode_cf_datetime(example_value, units, calendar, use_cftime)
  File "/n/home05/msulprizio/python/mamba/envs/gcpy_env/lib/python3.9/site-packages/xarray/coding/times.py", line 291, in decode_cf_datetime
    dates = _decode_datetime_with_cftime(
  File "/n/home05/msulprizio/python/mamba/envs/gcpy_env/lib/python3.9/site-packages/xarray/coding/times.py", line 210, 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 "/n/home05/msulprizio/python/mamba/envs/gcpy_env/lib/python3.9/site-packages/xarray/conventions.py", line 431, in decode_cf_variables
    new_vars[k] = decode_cf_variable(
  File "/n/home05/msulprizio/python/mamba/envs/gcpy_env/lib/python3.9/site-packages/xarray/conventions.py", line 281, in decode_cf_variable
    var = times.CFDatetimeCoder(use_cftime=use_cftime).decode(var, name=name)
  File "/n/home05/msulprizio/python/mamba/envs/gcpy_env/lib/python3.9/site-packages/xarray/coding/times.py", line 724, in decode
    dtype = _decode_cf_datetime_dtype(data, units, calendar, self.use_cftime)
  File "/n/home05/msulprizio/python/mamba/envs/gcpy_env/lib/python3.9/site-packages/xarray/coding/times.py", line 196, in _decode_cf_datetime_dtype
    raise ValueError(msg)
ValueError: unable to decode time units 'minutes since 2019-01-01 00:00:00' with "calendar 'gregorian'". 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 "/n/home05/msulprizio/gcpy/gcpy/benchmark/run_benchmark.py", line 1606, in <module>
    main(sys.argv)
  File "/n/home05/msulprizio/gcpy/gcpy/benchmark/run_benchmark.py", line 1602, in main
    choose_benchmark_type(config)
  File "/n/home05/msulprizio/gcpy/gcpy/benchmark/run_benchmark.py", line 100, in choose_benchmark_type
    run_1yr_tt_benchmark(
  File "/n/home05/msulprizio/python/gcpy/gcpy/benchmark/modules/run_1yr_tt_benchmark.py", line 1275, in run_benchmark
    bmk.make_benchmark_mass_conservation_table(
  File "/n/home05/msulprizio/python/gcpy/gcpy/benchmark_funcs.py", line 5002, in make_benchmark_mass_conservation_table
    ds = xr.open_dataset(f, drop_variables=gcon.skip_these_vars)
  File "/n/home05/msulprizio/python/mamba/envs/gcpy_env/lib/python3.9/site-packages/xarray/backends/api.py", line 570, in open_dataset
    backend_ds = backend.open_dataset(
  File "/n/home05/msulprizio/python/mamba/envs/gcpy_env/lib/python3.9/site-packages/xarray/backends/netCDF4_.py", line 616, in open_dataset
    ds = store_entrypoint.open_dataset(
  File "/n/home05/msulprizio/python/mamba/envs/gcpy_env/lib/python3.9/site-packages/xarray/backends/store.py", line 46, in open_dataset
    vars, attrs, coord_names = conventions.decode_cf_variables(
  File "/n/home05/msulprizio/python/mamba/envs/gcpy_env/lib/python3.9/site-packages/xarray/conventions.py", line 442, 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 'minutes since 2019-01-01 00:00:00' with "calendar 'gregorian'". Try opening your dataset with decode_times=False or installing cftime if it is not installed.
real 17.08
user 12.60
sys 2.93  

A similar error was encountered when trying to generate the radionuclide budget table:

%%% Creating GCHP vs. GCC radionuclides budget table %%%
Traceback (most recent call last):
  File "pandas/_libs/tslibs/conversion.pyx", line 132, in pandas._libs.tslibs.conversion.c
ast_from_unit
OverflowError: Python int too large to convert to C long

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

Traceback (most recent call last):
  File "pandas/_libs/tslibs/timedeltas.pyx", line 379, in pandas._libs.tslibs.timedeltas._
maybe_cast_from_unit
  File "pandas/_libs/tslibs/conversion.pyx", line 134, in pandas._libs.tslibs.conversion.c
ast_from_unit

...

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/n/home05/msulprizio/gcpy/gcpy/benchmark/run_benchmark.py", line 1606, in <module>
    main(sys.argv)
  File "/n/home05/msulprizio/gcpy/gcpy/benchmark/run_benchmark.py", line 1602, in main
    choose_benchmark_type(config)
  File "/n/home05/msulprizio/gcpy/gcpy/benchmark/run_benchmark.py", line 100, in choose_benchmark_type
    run_1yr_tt_benchmark(
  File "/n/home05/msulprizio/python/gcpy/gcpy/benchmark/modules/run_1yr_tt_benchmark.py", line 780, in run_benchmark
    ttbdg.transport_tracers_budgets(
  File "/n/home05/msulprizio/python/gcpy/gcpy/budget_tt.py", line 834, in transport_tracers_budgets
    globvars = _GlobVars(
    ...

These errors were encountered using the configuration /n/holyscratch01/jacob_lab/msulprizio/GC/benchmarks/1yr/14.2.0-rc.2/GCHP/TransportTracers/BenchmarkResults/1yr_tt_benchmark.yml (on Harvard's Cannon cluster) and the output files specified within that file.

msulprizio commented 1 year ago

The file that was triggering this error was a c24 restart file generated from the csregridtool. It turns out the time dimension was empty:

 time = _ ;

Setting time to zero using cdo settime,0 GEOSChem.Restart.20190101_0000z.c24.nc4.orig GEOSChem.Restart.20190101_0000z.c24.nc4 resolved the error in both instances described above.

This can be avoided by using gcpy to regrid files from lat-lon to cube sphere after https://github.com/geoschem/gcpy/issues/258 is addressed.