Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert NetCDF depth from Float to Double

I have a couple hundred NetCDF files that I want to process through a geospatial analysis tool, however the tool requires the depth variable to be a double, and it is currently a float. I have found the below article

convert all the variables and dimensions from int/float to double in netcdf file

But when trying to run:

ncap2 -s 'depth=double(depth)' C:\Users\***\input.nc C:\Users\***\output.nc 

a temporary file is created that has the header information for the netcdf but never completes processing, and also indicates that the depth field is still a float. Additionally, this does not address processing multiple files.

I have 0 experience with CDO and have found the nco sourgeforce info not to be obvious, my only other coding experience has been with Python.

like image 256
Laura808 Avatar asked Sep 20 '25 11:09

Laura808


2 Answers

You can also convert all variables to double precision using cdo:

cdo -b 64 copy input.nc output.nc

If you want to specify floating point type then it is

cdo -b f64 copy input.nc output.nc

Note this converts all variables from float to double, I'm not sure if with CDO you can only change one specific field as is the case with nco.

like image 92
Adrian Tompkins Avatar answered Sep 22 '25 02:09

Adrian Tompkins


The command you tried works well for me on all recent versions of NCO, though I do not have access to a Windows machine. Please try on Linux or MacOS if you have access, or make a bug report. For multiple file put the command in a loop over the files as shown in many examples such as this one. Ironically, I added a double->float conversion routine to ncpdq last year because a majority of people want to save space, not consume it. I will place adding a float->double in ncpdq on the TODO list.

like image 36
Charlie Zender Avatar answered Sep 22 '25 03:09

Charlie Zender