Project

General

Profile

Masking land and/or missing values

Added by Josh Butterworth over 5 years ago

Hello,

Once again I'm stuck with a dataset on sea surface temp over the following coords: -21.2 - 36.2 lon (by 0.1 degrees east) and 10.9 to 64.9 lat (by 0.1 degrees north).

When attempting to plot this dataset I am running into errors that are due to missing values/fill values over the land.

How can I go about masking the land from this dataset? I've tried using the -topo operator to no avail, which I assume is due to an error on my behalf. If there is any more information that could help clarify my situation, please let me know.

Many thanks


Replies (7)

RE: Masking land and/or missing values - Added by Karin Meier-Fleischer over 5 years ago

Hi Josh,

it is always better to give us the data your working with, so I can only guess what you should do.

infile.nc: input data file

If necessary select subregion:

cdo -f nc -sellonlatbox,-21.2,36.2,10.9,64.9 infile.nc subregion.nc

Create mask file (mask land):

cdo -f nc -ltc,0 -topo,subregion.nc mask_land_subregion.nc

Mask land of your data:

cdo ifthen mask_land_subregion.nc subregion.nc ocean_data_subregion.nc

Hope this helps.
-Karin

RE: Masking land and/or missing values - Added by Josh Butterworth over 5 years ago

Hi Karin,

Thank-you for your help. This has removed most of the 'wrong' values from my data. Do you have a link to an explanation of the bottom two lines of code you suggested? I'm really new to all this so could do with a good read (cdo ifthen mask_land_subregion.nc subregion.nc ocean_data_subregion.nc ; cdo -f nc -ltc,0 -topo,subregion.nc mask_land_subregion.nc).

One more thing, unfortunately I'm still experiencing issues as they are now appearing as missing values and I don't think the analysis software likes missing values. Not sure I am at liberty to post my data on here unfortunately so this will be a long-shot... Now that the 'land' values are masked, is there an operator in cdo that can replace the 'missing values' with some values that won't interfere while I'm plotting the data?

Thanks again and apologies for any confusion,

Josh

RE: Masking land and/or missing values - Added by Josh Butterworth over 5 years ago

Is there a function to remove values from a dataset (grid values)? E.g. if I wanted to remove all values of 1092 from my data.

RE: Masking land and/or missing values - Added by Karin Meier-Fleischer over 5 years ago

Please read the Wiki page https://code.mpimet.mpg.de/projects/cdo/wiki.

Tutorial https://code.mpimet.mpg.de/projects/cdo/wiki/Tutorial.
FAQ https://code.mpimet.mpg.de/projects/cdo/wiki/FAQ
CDO User Guide https://code.mpimet.mpg.de/projects/cdo/embedded/index.html

To set the missing value to a constant value use the setmisstoc operator, e.g. set to 0:

cdo setmisstoc,0 infile outfile

-Karin

RE: Masking land and/or missing values - Added by Karin Meier-Fleischer over 5 years ago

What do you mean with remove from data? Remove grid points or data values?

RE: Masking land and/or missing values - Added by Josh Butterworth over 5 years ago

Thanks for the links, appreciated. Well there are still values in the new file that represent the land, and I was wondering if there was just a blanket remove all "9.969E+36" (which is the land value in my dataset). So I have tried removing the grid points using:

cdo delgridcell,63.5N,9.4E, ocean_ns_subregion.nc 1removed.nc

Also tried without stating N or E, didn't seem to work...

RE: Masking land and/or missing values - Added by Josh Butterworth over 5 years ago

Issue solved: I needed to change certain values in the data to missing values using the following line of code after performing the cut/mask you suggested.

cdo setrtomiss,9E+35,9E+37 ocean_ns_subregion.nc new6.nc

I think this may have worked without the initial mask as I realise all that I needed to do was flag to the program I'm using that these values are missing and shouldn't be included in the calculation.

    (1-7/7)