Project

General

Profile

Masking does not work on this specific cdo-generated file

Added by XR Chua about 2 years ago

Hi everyone,

I am using cdo to create a land mask but am running into some unexpected behavior.

  1. Setup: creating a land mask with 1 over land and miss otherwise, has attribute topo:missing_value = -9.e+33f ;
    cdo -f nc4 -setctomiss,0 -gec,0 -topo,r240x120 topo_gec0_miss0.nc
  1. Setup: creating an example data file with 1 over land and 0 otherwise
    cdo -f nc4 -gec,0 -topo,r240x120 topo_gec0.nc
  1. expect this to have 1 over land and miss otherwise, but has 1 over land and 0 otherwise, no longer has attribute topo:missing_value = -9.e+33f ;
    cdo mul topo_gec0.nc topo_gec0_miss0.nc topo_mul.nc

By the way, I obtain the expected behavior for a file generated with const:
cdo -f nc4 -const,1,r240x120 const1.nc # 1 everywhere
cdo mul const1.nc topo_gec0_miss0.nc topo_const1.nc # 1 over land and miss otherwise

I ran the above commands in cdo v2.0.5 and inspected the output in ncview.

An explanation would be very much appreciated. Thanks!


Replies (2)

RE: Masking does not work on this specific cdo-generated file - Added by Karin Meier-Fleischer about 2 years ago

Hi,

you have to set the missing value to 0 for your constant field and the mask file.

cdo -f nc4 -setmissval,0 -const,1,r240x120 const1.nc

cdo -f nc4 -setmissval,0 -gec,0 -topo,r240x120 topo_gec0_miss0.nc

cdo -f nc4 -mul const1.nc topo_gec0_miss0.nc topo_mul.nc

-Karin

RE: Masking does not work on this specific cdo-generated file - Added by XR Chua about 2 years ago

Hi Karin,

Thanks for the quick response, it helped me realize that in CDO, 0*miss = 0 rather than miss as I had previously assumed.

So if I have data [0, 0] and wish to only mask the value on the right, I cannot multiply by the mask [1, miss], which would give me [0, 0]. What would you suggest in this case? Adding to the mask [0, miss] to get [0, miss]?

    (1-2/2)