Project

General

Profile

Input files as binary masks

Added by Martin Großhauser about 13 years ago

Hello,

first thanks for cdo, it's a great tool!

I'm trying to do some calculations with binary masks, but I have no idea how to do it with cdo. Here's what I want to do:

- I have an input file #1 with 3 or 4 dimensions: timestep, (level, ) latitude, longitude
- and I have another input file 2 with just the timestep dimension and a mask field with "1" and "0" (or missing) values
- I want to make calculations (e. g. mean, std) in #1 including only the timesteps where the mask field from #2 is set to "1"

Is that possibly with cdo?

Best regards,
Martin


Replies (4)

RE: Input files as binary masks - Added by Uwe Schulzweida about 13 years ago

Hello Martin,

Unfortunately this functionality is not implemented, sorry.

Best regards,
Uwe

RE: Input files as binary masks - Added by Uwe Schulzweida about 13 years ago

Submitted by mail from Lawson Hanson:

Hello,

Have you tried using the "ifthen" operator?

I think this will do what you want?

RE: Input files as binary masks - Added by Uwe Schulzweida about 13 years ago

Yes, in this case the mask file needs to have the same grid size as the input file. This can be achieved with the operator enlarge:

cdo <calculation> -ifthen -enlarge,ifile  maskfile  ifile  ofile
But I have never tried it with a netCDF maskfile which has only the timestep dimension.

Best regards,
Uwe

RE: Input files as binary masks - Added by Martin Großhauser about 13 years ago

Running cdo with "ifthen" like suggested above runs without an error, but ofile is identical to ifile. As maskfile I used an enlarged netcdf-file (also tried with grib), enlarging seems to work correctly: the whole lat-lon grid for each timestep is either zero or one, correctly computed from the 1D (time) mask. Creating the mask with missing/fill values instead of zeros doesn't work; enlarge accept missing values. I will attach NCL dumps of the input files. (I also tried with both inputs as netcdf).

ifile:

Variable: b (file variable)

filename:    CompEra40AllSfc
path:    CompEra40AllSfc.grib
   file global attributes:
   dimensions:
      initial_time0_hours = 528
      g0_lat_1 = 32
      g0_lon_2 = 33
   variables:
      float CI_GDS0_SFC_10 ( initial_time0_hours, g0_lat_1, g0_lon_2 )
         center :    European Center for Medium-Range Weather Forecasts (RSMC)
         long_name :    Sea-ice cover
         units :    (0 - 1)
         _FillValue :    1e+20
         level_indicator :    1
         gds_grid_type :    0
         parameter_table_version :    128
         parameter_number :    31
         forecast_time :    0
         forecast_time_units :    hours

      float SSTK_GDS0_SFC_10 ( initial_time0_hours, g0_lat_1, g0_lon_2 )
         center :    European Center for Medium-Range Weather Forecasts (RSMC)
         long_name :    Sea surface temperature
         units :    K
         _FillValue :    1e+20
         level_indicator :    1
         gds_grid_type :    0
         parameter_table_version :    128
         parameter_number :    34
         forecast_time :    0
         forecast_time_units :    hours

      float SWVL1_GDS0_DBLY_10 ( initial_time0_hours, g0_lat_1, g0_lon_2 )
         center :    European Center for Medium-Range Weather Forecasts (RSMC)
         long_name :    Volumetric soil water layer 1
         units :    m**3 m**-3
         _FillValue :    1e+20
         level_indicator :    112
         gds_grid_type :    0
         parameter_table_version :    128
         parameter_number :    39
         level :    ( 0, 7 )
         forecast_time :    0
         forecast_time_units :    hours

      float SWVL2_GDS0_DBLY_10 ( initial_time0_hours, g0_lat_1, g0_lon_2 )
         center :    European Center for Medium-Range Weather Forecasts (RSMC)
         long_name :    Volumetric soil water layer 2
         units :    m**3 m**-3
         _FillValue :    1e+20
         level_indicator :    112
         gds_grid_type :    0
         parameter_table_version :    128
         parameter_number :    40
         level :    ( 7, 28 )
         forecast_time :    0
         forecast_time_units :    hours

[... some more variables ...]

      float STL4_GDS0_DBLY_10 ( initial_time0_hours, g0_lat_1, g0_lon_2 )
         center :    European Center for Medium-Range Weather Forecasts (RSMC)
         long_name :    Soil temperature level 4
         units :    K
         _FillValue :    1e+20
         level_indicator :    112
         gds_grid_type :    0
         parameter_table_version :    128
         parameter_number :    236
         level :    ( 100, 255 )
         forecast_time :    0
         forecast_time_units :    hours

      double initial_time0_hours ( initial_time0_hours )
         long_name :    initial time
         units :    hours since 1800-01-01 00:00

      double initial_time0_encoded ( initial_time0_hours )
         long_name :    initial time encoded as double
         units :    yyyymmddhh.hh_frac

      float g0_lat_1 ( g0_lat_1 )
         long_name :    latitude
         GridType :    Cylindrical Equidistant Projection Grid
         units :    degrees_north
         Dj :    1.125
         Di :    1.125
         Lo2 :    298.125
         La2 :    -27
         Lo1 :    262.125
         La1 :    7.875

      float g0_lon_2 ( g0_lon_2 )
         long_name :    longitude
         GridType :    Cylindrical Equidistant Projection Grid
         units :    degrees_east
         Dj :    1.125
         Di :    1.125
         Lo2 :    298.125
         La2 :    -27
         Lo1 :    262.125
         La1 :    7.875

      string initial_time0 ( initial_time0_hours )
         long_name :    Initial time of first record
         units :    mm/dd/yyyy (hh:mm)

maskfile:

Variable: a (file variable)

filename:    enlarged
path:    enlarged.grib
   file global attributes:
   dimensions:
      initial_time0_hours = 528
      g0_lat_1 = 32
      g0_lon_2 = 33
   variables:
      float PRES_GDS0_SFC_10 ( initial_time0_hours, g0_lat_1, g0_lon_2 )
         long_name :    Pressure
         units :    Pa
         _FillValue :    1e+20
         level_indicator :    1
         gds_grid_type :    0
         parameter_table_version :    0
         parameter_number :    1
         forecast_time :    0
         forecast_time_units :    hours

      double initial_time0_hours ( initial_time0_hours )
         long_name :    initial time
         units :    hours since 1800-01-01 00:00

      double initial_time0_encoded ( initial_time0_hours )
         long_name :    initial time encoded as double
         units :    yyyymmddhh.hh_frac

      float g0_lat_1 ( g0_lat_1 )
         long_name :    latitude
         GridType :    Cylindrical Equidistant Projection Grid
         units :    degrees_north
         Dj :    1.125
         Di :    1.125
         Lo2 :    298.125
         La2 :    -27
         Lo1 :    262.125
         La1 :    7.875

      float g0_lon_2 ( g0_lon_2 )
         long_name :    longitude
         GridType :    Cylindrical Equidistant Projection Grid
         units :    degrees_east
         Dj :    1.125
         Di :    1.125
         Lo2 :    298.125
         La2 :    -27
         Lo1 :    262.125
         La1 :    7.875

      string initial_time0 ( initial_time0_hours )
         long_name :    Initial time of first record
         units :    mm/dd/yyyy (hh:mm)

    (1-4/4)