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

trap confusing 'key error' related to missing time units #249

Open
andywood opened this issue Jun 9, 2021 · 0 comments
Open

trap confusing 'key error' related to missing time units #249

andywood opened this issue Jun 9, 2021 · 0 comments

Comments

@andywood
Copy link

andywood commented Jun 9, 2021

Some operations on input forcing files can leave them missing the proper time unit. If a file has 'seconds' instead of 'seconds since [some datum]', metsim fails complaining about a 'key error' (see below). It's fairly hard to figure out what's wrong, so trapping that particular error with a clear message would be useful.


Traceback (most recent call last):
File "pandas/_libs/tslibs/timedeltas.pyx", line 528, in pandas._libs.tslibs.timedeltas.parse_timedelta_unit
KeyError: '/'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/glade/u/home/andywood/miniconda3/bin/ms", line 10, in
sys.exit(main())
File "/glade/u/home/andywood/miniconda3/lib/python3.6/site-packages/metsim/cli/ms.py", line 61, in main
ms = MetSim(setup)
File "/glade/u/home/andywood/miniconda3/lib/python3.6/site-packages/metsim/metsim.py", line 220, in init
period_ending=self.params['period_ending'])
File "/glade/u/home/andywood/miniconda3/lib/python3.6/site-packages/metsim/metsim.py", line 527, in _get_output_times
prototype = self.met_data
File "/glade/u/home/andywood/miniconda3/lib/python3.6/site-packages/metsim/metsim.py", line 291, in met_data
self._met_data = io.read_met_data(self.params, self.domain)
File "/glade/u/home/andywood/miniconda3/lib/python3.6/site-packages/metsim/io.py", line 182, in read_met_data
return process_funcs[params['forcing_fmt']](params, domain)
File "/glade/u/home/andywood/miniconda3/lib/python3.6/site-packages/metsim/io.py", line 210, in process_nc
calendar=params['calendar'], var_dict=params.get('forcing_vars', None))
File "/glade/u/home/andywood/miniconda3/lib/python3.6/site-packages/metsim/io.py", line 298, in read_netcdf
ds = ds.sel(time=slice(start, stop))
File "/glade/u/home/andywood/miniconda3/lib/python3.6/site-packages/xarray/core/dataset.py", line 2057, in sel
self, indexers=indexers, method=method, tolerance=tolerance
File "/glade/u/home/andywood/miniconda3/lib/python3.6/site-packages/xarray/core/coordinates.py", line 392, in remap_label_indexers
obj, v_indexers, method=method, tolerance=tolerance
File "/glade/u/home/andywood/miniconda3/lib/python3.6/site-packages/xarray/core/indexing.py", line 270, in remap_label_indexers
idxr, new_idx = convert_label_indexer(index, label, dim, method, tolerance)
File "/glade/u/home/andywood/miniconda3/lib/python3.6/site-packages/xarray/core/indexing.py", line 124, in convert_label_indexer
_sanitize_slice_element(label.step),
File "/glade/u/home/andywood/miniconda3/lib/python3.6/site-packages/pandas/core/indexes/base.py", line 4712, in slice_indexer
start_slice, end_slice = self.slice_locs(start, end, step=step, kind=kind)
File "/glade/u/home/andywood/miniconda3/lib/python3.6/site-packages/pandas/core/indexes/base.py", line 4925, in slice_locs
start_slice = self.get_slice_bound(start, "left", kind)
File "/glade/u/home/andywood/miniconda3/lib/python3.6/site-packages/pandas/core/indexes/base.py", line 4837, in get_slice_bound
label = self._maybe_cast_slice_bound(label, side, kind)
File "/glade/u/home/andywood/miniconda3/lib/python3.6/site-packages/pandas/core/indexes/timedeltas.py", line 321, in _maybe_cast_slice_bound
parsed = Timedelta(label)
File "pandas/_libs/tslibs/timedeltas.pyx", line 1217, in pandas._libs.tslibs.timedeltas.Timedelta.new
File "pandas/_libs/tslibs/timedeltas.pyx", line 371, in pandas._libs.tslibs.timedeltas.parse_timedelta_string
File "pandas/_libs/tslibs/timedeltas.pyx", line 509, in pandas._libs.tslibs.timedeltas.timedelta_from_spec
File "pandas/_libs/tslibs/timedeltas.pyx", line 530, in pandas._libs.tslibs.timedeltas.parse_timedelta_unit
ValueError: invalid unit abbreviation: /
distributed.process - WARNING - reaping stray process <ForkServerProcess(ForkServerProcess-15, started daemon)>
distributed.nanny - WARNING - Worker process 33682 was killed by unknown signal

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

1 participant