Project

General

Profile

copy _FillValue value and locations from one file to antoher

Added by Ray Bell about 7 years ago

There are a number of similar questions on this topic, e.g.
https://code.zmaw.de/boards/1/topics/4148?r=4153#message-4153
https://code.zmaw.de/boards/1/topics/2920?r=3532#message-3532

However, In these instances they have a mask.nc file which is Boolean.

I have an SST file with _FillValue = -999.f and I would like to copy the locations of these values to another file.
My other file is a radiative surface temperature (which should be used as sst but has values everywhere). This file does have an attribute _FillValue = 1.e+20f but it is not used in the file. There may be others case where the files don't have _FillValue.

As an attempt I tried:
cdo -f nc -setmissval,-999.f -mul -eqc,-999.f a.nc b.nc out.nc
Where I would like to copy the locations of the missing values from a.nc to b.nc.
However, out.nc picks up the new _FillValue but it is empty everywhere.

I've attached the files.

Cheers,
Ray

a.nc (69.9 KB) a.nc obs
b.nc (93.1 KB) b.nc model

Replies (2)

RE: copy _FillValue value and locations from one file to antoher - Added by Ralf Mueller about 7 years ago

Hi Ray!

What about this:

cdo -div b.nc -setmisstoc,0 -div -addc,1  -abs a.nc -addc,1 -abs a.nc masked_b.nc

Here I use the feature Uwe introduced here: create missing values by definition with zero.

  • -setmisstoc,0 -div -addc,1  -abs a.nc -addc,1 -abs a.nc
    creates a 0-1-mask from a.nc (0 for missing values, 1 elsewhere)
  • cdo -div b.nc
    create the missing values by division with zero
    (1-2/2)