numpypython-xarraycdo-climatencopynco

change dtype with pynco in Netcdf


I was wondering how to change the dtype from float32 to float64 of coordinates.

I can run the following code in the terminal

ncap2 -s 'lat=double(lat); lon=double(lon)' infile.nc outfile.nc

However when I try the following ncap2 command in python I get the error too many input files.

nco.ncap2(input='infile.nc', output='outfile.nc', options=['-s','lat=double(lat); lon=double(lon);'])

also tried with ncatted2

nco.ncatted(input='infile.nc', output='out.nc', options=['-a','lat=double(lat);  lon=double(lon);'])

This one just compiles without doing anything.


Solution

  • I think that it is the spaces in the options string messing it up, the cdo and nco bindings don't like padding spaces when there is more than one option (i.e. it would be like trying your direct terminal command without the surrounding quote marks on the -s option).

    This should work, it did for me:

    nco.ncap2(input='infile.nc', output='outfile.nc', options=['-s','lat=double(lat);lon=double(lon)'])