0

I have a netcdf file with global temperature (tas, degC) data over the 1990-2001 period at daily time-steps in a 1x1deg lat-lon grid.

I am interested only in tas days > 10degC.

Is there a way I can subset with CDO the netcdf file and create a new one with only tas days > 10degC?

The gtc operator can be related to my issue but it only creates a mask with 0s and 1s, while I need true values >10degC.

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
aaaaa
  • 149
  • 2
  • 18
  • 44

2 Answers2

2

I'm not quite sure what you want... if you want to set all the values where T<10C to missing, then you can do that as follows:

cdo gtc,10 tas.nc mask1.nc 
# set zeros to missing 
cdo setctomiss,0 mask1.nc mask2.nc 
cdo mul tas.nc mask2.nc tas_masked.nc 

This technique is the same as one would use for a land-sea mask - see my videos on masking and creating a land sea mask for further details.

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
  • thanks. that is a work-around. I will wait a bit before confirming as the best answer. – aaaaa Feb 26 '22 at 14:13
  • 1
    But otherwise what do you want? You can't have "only" the cells above the threshold in a netcdf, it is a gridded dataset format. The way netcdf handles this is through the missing value. Otherwise you need to move to a format which is unstructured, like hdf, but that would be a nightmare to implement i think... – ClimateUnboxed Feb 26 '22 at 15:07
  • Agreed. In my view this is essentially converting the data to a format without the benefits of netCDF, so it's not clear why you would do it. Though as I note below you can in fact do it in CDO with reducegrid. Not something I would ever use, but presumably there are some good use cases for it. – Robert Wilson Feb 28 '22 at 09:43
2

I agree with Adrian Tompkins that the workflow proposed is not overly sensible as any subsetting will throw away the grid info and essentially negate the purpose of using netCDF data in the first place. The work flow proposed would make more sense using dataframes either in R or pandas in Python.

However, if you have to do this in CDO you can use the reducegrid operator which will reduce the netCDF file to grid cells without missing values, as follows (adapated from Adrian Tompkins' answer):

cdo gtc,10 tas.nc mask1.nc 
# set zeros to missing 
cdo setctomiss,0 mask1.nc mask2.nc 
cdo reducegrid,mask2.nc tas.nc tas_subsetted.nc 
Robert Wilson
  • 3,192
  • 11
  • 19
  • nice, I didn't know this function! @aaaaa if you are doing this to keep the file size down, depending on how many points fall above your threshold this can actually expand your file size, due to the need to include the specific lat/lon info for every single cell in the unstructured format. – ClimateUnboxed Feb 28 '22 at 10:25
  • 1
    thank you all. helpful solutions – aaaaa Feb 28 '22 at 17:29