1

I want to subset a NetCDF file to extract a sub-period with cdo.

I run the following code in spyder

 from cdo import *
cdo = Cdo()

cdo.select('startdate=2003-01-01,end_date=2016-12-31', input='PATH/temperature.nc', output='output.nc')

I use spyder 3.10 and have the message :

TypeError: expected str, bytes or os.PathLike object, not NoneType

when I run cdo = Cdo()

  1. Maybe I should not run cdo in spyder?
  2. Does the command is correct?
ele_al_12
  • 23
  • 6
  • I do not follow the question. Spyder is for Python. CDO is run from the command line. How are you actually running CDO from Spyder? – Robert Wilson May 20 '22 at 10:40
  • 1
    That code should work. Though it could be a Python versioning issue. As an alternative you could use my package nctoolkit, which uses CDO as a backend. https://nctoolkit.readthedocs.io/en/latest/index.html – Robert Wilson May 20 '22 at 12:49

1 Answers1

0

I recently had an issue with the Cdo() command after a homebrew upgrade on a mac, and uninstalling the cdo package and then reinstalling it solved it for me...

However, are you sure the error is in the cdo=Cdo() command? I notice you have an underscore in "end_date", is that a typo in your question or also in your code?

What about using seldate if you are only selecting dates?

from cdo import *
cdo = Cdo()
cdo.seldate('2003-01-01,2016-12-31', input='PATH/temperature.nc', output='output.nc')
ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86