Menu

How to get rid NaN values

2017-01-25
2021-11-07
  • Nikos Evangeliou

    Hi,
    I have a netcdf file with a 3D variable that contains NaN values. These NAN values are written in the form of "" (underscores). All I want is to remove these "underscores" and put 0 instead.
    What I have done was to (A) create a cdl file: ncdump BB.nc > BB.cdl
    then (B) edit it with vim and substitute "
    " with zeros: :%s,_,0,*g
    and finally (C) recreate the netcdf with ncgen -o BB.nc BB.cdl, but the underscore values persist. :-(

    I also used ncap2 command to substitute these values: ncap2 -O -s 'where(EMIS_BB="_") EMIS_BB=0' BB.nc out.nc, but I got an empty variable (EMI_BB).

    If anyone has a better idea, I would appreciate! The netcdf file I am talking about is here: https://www.dropbox.com/s/xcd3unbto0wyvc9/BB.nc?dl=0 .
    Thanks in advance!

     
  • henry Butowsky

    henry Butowsky - 2017-01-25

    Hi Nikos,
    Your are mixing things up
    The underscore in the ncdump indicates that that value is a FillValue (or missing value) Which is currently set to zero ( EMIS_BB:FillValue = 0. ;) If you wish to delete this fill value use the following command.

    ncatted -a _FillValue,EMIS_BB,d,d,1.0 bb.nc

    ( After this you will be able to see all the zero's )

    If you wish to change the FillValue to say -1e-6 use the command

    ncatted -a _FillValue,EMIS_BB,o,d,1e-6 bb.nc

    For a lot of reasons it is a bad idea to have FillValue as zero -So I suggest you change it

    ...Henry

     
  • Nikos Evangeliou

    Although long time after, I appreciate for helping me understand what I misunderstood!
    Of course, your suggestion worked perfect!
    Nikos

     

Log in to post a comment.