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

subset with time_components fails for day values which are not in the netcdf file #230

Closed
cehbrecht opened this issue May 16, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@cehbrecht
Copy link
Collaborator

cehbrecht commented May 16, 2022

  • clisops version: 0.9.0
  • Python version: 3.7
  • Operating System:

Description

Run the subset with time_components on a cmip6 netcdf file with monthly data and choose a day component which does not exist, like day:01, then you get the following exception:

File "/usr/local/anaconda/envs/rook/lib/python3.7/site-packages/clisops/ops/subset.py", line 244, in subset
    return op.process()
  File "/usr/local/anaconda/envs/rook/lib/python3.7/site-packages/clisops/ops/base_operation.py", line 107, in process
    processed_ds = self._calculate()
  File "/usr/local/anaconda/envs/rook/lib/python3.7/site-packages/clisops/ops/subset.py", line 160, in _calculate
    result = subset_time_by_components(result, time_components=time_comps)
  File "/usr/local/anaconda/envs/rook/lib/python3.7/site-packages/clisops/core/subset.py", line 1641, in subset_time_by_components
    {idx for tc in req_t_comp for idx in t_comp_indices[tc]}
  File "/usr/local/anaconda/envs/rook/lib/python3.7/site-packages/clisops/core/subset.py", line 1641, in <setcomp>
    {idx for tc in req_t_comp for idx in t_comp_indices[tc]}
KeyError: 1

What I Did

See this notebook:
https://github.com/roocs/rooki/blob/master/notebooks/tests/test-c3s-cmip6-subset-by-point.ipynb

wf = ops.Subset(
        ops.Input(
            'tas', ['c3s-cmip6.CMIP.NCAR.CESM2-WACCM-FV2.historical.r1i1p1f1.Amon.tas.gn.v20191120']
        ),
        time="1998/2000",
        time_components="year:1998,1999,2000|month:jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec|day:01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31"
        #time_components="year:1998,1999,2000|month:jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec|day:14,15"
)
resp = wf.orchestrate()
resp.ok
@cehbrecht cehbrecht added the bug Something isn't working label May 16, 2022
@cehbrecht
Copy link
Collaborator Author

In the example I have chosen monthly data and using a “day” selector which does not exist in the data, like “day:01”. It works with “day:14,15”.

The expected behaviour should probably be to ignore non-existing selectors. This happens already … but if the selector does not appear at all in the data we get an exception. Day 14,15 appears in the data … but no other days.

ping @JamesVarndell

@agstephens
Copy link
Collaborator

@cehbrecht, the offending code is maybe mixing up index values with actual values:

https://github.com/roocs/clisops/blob/master/clisops/core/subset.py#L1639-L1644

So, maybe "day:01" is looking for the_selected_days[1] - so it will fail if there is only one value in the array of selected days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants