Project

General

Profile

Changing missing value (NaN) to NA in netcdf file?

Added by DEEPAK KUMAR over 4 years ago

I want to Change missing value (NaN) to NA in netcdf file?

when I read the .nc file in a software I am getting this error "X.nc is not compliant netCDF; variable precip is numeric but has a character-type missing value! This is an error! Compensating, but you should fix the file!".
Here I have attached my sample file.


Replies (3)

RE: Changing missing value (NaN) to NA in netcdf file? - Added by DEEPAK KUMAR over 4 years ago

Actually in my file the grids having missing value is NaN and it is "Character type" while the precipitation values are of numeric type. so I want to change NaN character type into NA numeric type at missing value grids. Sample file is also attached. Thank you.

RE: Changing missing value (NaN) to NA in netcdf file? - Added by Karin Meier-Fleischer over 4 years ago

No, that's wrong. NaN just stands for 'not a number'. The precip data is of type double:

 precip =
  NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN,
  NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN,
  NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0.0194182622316302, 0.0207743832948452, 
    0.0224906020108419, 0.0239008333128143, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN,
  NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0.0203204828661555, 0.0215598507439178, 
    0.022873323889726, 0.0237029827275172, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN,
  NaN, NaN, NaN, NaN, 0.0107745583516222, 0.0177567596079048, 
    0.0203121983041776, 0.0214606755086297, 0.0224396993188238, 
    0.0238722131653847, 0.0240603399947405, 0.0242647490193357, 
    0.0243799116219515, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN,
  NaN, NaN, NaN, 0.0109710148230463, 0.0110865133819091, 0.0192955931035062, 
    0.0210692634580078, 0.0203281567570342, 0.0214986339787773, 
    0.0244318616804512, 0.0246490464641985, 0.0247606189125535, 
    0.0244137657379219, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN,
  NaN, NaN, 0.0115669042728689, 0.0115739386262425, 0.011409073585044, 
    0.0191413433965211, 0.0224514667182033, 0.0175539839740076, 
    0.0239092034999964, 0.0243471230402143, 0.0246485758097763, 
    0.025645124092836, 0.0248440864918398, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN,
...

To change the NaNs to a missing value see https://code.mpimet.mpg.de/projects/cdo/wiki/FAQ#How-can-I-set-or-change-the-missing-value-or-change-NaN-to-missing-value

    (1-3/3)