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

FieldList.select_by_ncvars throws an error #76

Closed
cjroberts opened this issue May 19, 2020 · 3 comments · Fixed by #77
Closed

FieldList.select_by_ncvars throws an error #76

cjroberts opened this issue May 19, 2020 · 3 comments · Fixed by #77
Labels
bug Something isn't working

Comments

@cjroberts
Copy link

I get the following error (using cf-python 3.4.0) when trying to use FieldList.select_by_ncvars to select a field by netCDF variable name:

In [1]: import cf                                                                                                                                                                                 
 
In [2]: fl = cf.read('ESACCI-OC-L3S-IOP-MERGED-5D_DAILY_4km_GEO_PML_OCx_QAA-20010101-fv4.2.nc')                                                                                                   
 
In [3]: fl.select_by_ncvar('atot_412')                                                                                                                                                            
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-3-0069b9e04a8b> in <module>
----> 1 fl.select_by_ncvar('atot_412')
 
~/miniconda3/envs/cci/lib/python3.7/site-packages/cf/fieldlist.py in select_by_ncvar(self, *rank)
   1044 
   1045         '''
-> 1046         return type(self)(f for f in self if f.match_by_ncvar(*ncvars))
   1047 
   1048     def select_by_property(self, *mode, **properties):
 
~/miniconda3/envs/cci/lib/python3.7/site-packages/cf/fieldlist.py in __init__(self, fields)
     54                 self.append(fields)
     55             else:
---> 56                 self.extend(fields)
     57 
     58     def __call__(self, *identities):
 
~/miniconda3/envs/cci/lib/python3.7/site-packages/cf/fieldlist.py in <genexpr>(.0)
   1044 
   1045         '''
-> 1046         return type(self)(f for f in self if f.match_by_ncvar(*ncvars))
   1047 
   1048     def select_by_property(self, *mode, **properties):
 
NameError: name 'ncvars' is not defined

I tried this too:

In [6]: fl.select_by_ncvar(ncvars='atot_412')                                                                                                                                                     
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-37ac3193cda2> in <module>
----> 1 fl.select_by_ncvar(ncvars='atot_412')
 
TypeError: select_by_ncvar() got an unexpected keyword argument 'ncvars'

Please would you be able to help?

@cjroberts cjroberts added the bug Something isn't working label May 19, 2020
@cjroberts
Copy link
Author

I worked out I can work around this issue by using fl.select_by_identity('ncvar%atot_412'), but select_by_ncvar does not seem to work. The docstring has a TODO, so it is possible I am using it incorrectly, but cannot see how.

@davidhassell
Copy link
Collaborator

Hi Charles - bug fixed, and will be in next release. Thanks for spotting it.

@cjroberts
Copy link
Author

Thanks David.

davidhassell added a commit to davidhassell/cf-python that referenced this issue Jun 3, 2020
davidhassell added a commit that referenced this issue Jun 3, 2020
Fixes #76 FieldList.select_by_ncvars throws an error
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

Successfully merging a pull request may close this issue.

2 participants