Project

General

Profile

Formulation problem (conditional)

Added by Aleksandar Janković about 6 years ago

Hello. I just started using the CDO and I stumbled on a pretty simple thing. I have a NetCdF file with daily surface temperature data during the year. The name of the variable is 'tas'. The files contain the following data: Date / Time / Level / Gridsize / Miss / Minimum / Mean / Maximum / Parameter_ID. I want to calculate the daily temperature deficit relative to 19, provided that the temperature is lower than 12 degrees Celsius. In case the temperature is higher than 12 degrees Celsius, the temperature deficit is equal to zero:

IF (tas <12) THEN dt = 19-tas ELSE dt = 0

I've tried different formulations, but I did not get the right results:

1. Formulation: cdo expr, 'tas = (tas <12) ? 19-tas : 0.0; '1.nc 2.nc
2. Formulation: cdo expr,'dt = 19-tas; hdd = ((dt >= 7)) ? dt : 0.0;' 1.nc 2.nc
3. formulation: cdo addc,-19 1.nc 2.nc
cdo mulc,-1 2.nc 3.nc
cdo setrtoc,-1.e99,7,0 3.nc 4.nc

Is there any way to delete the columns 'minimum' and 'maximum' and to leave only the 'mean' column? The problem is that the operations are performed at both minimum and maximum values, and I would like them to be executed only at mean values (ie mean columns). The problem is that operations are performed at both minimum and maximum values, and I would like them to be executed only at mean values (ie, mean column).

Any help would be appreciated!


Replies (6)

RE: Formulation problem (conditional) - Added by Karin Meier-Fleischer about 6 years ago

Hi Aleksander,

do you mean the cdo output using 'cdo info'?
-1 : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter ID

This is just the output of the info operator (see documentation). If you want to compute the mean of the variable tas e.g. field mean you have to use the
fldmean operator first and then the expr operator like your first suggestion. My tip, have a look at the documentation or the online tutorial.

If your data file contains more variables than the variable tas something like this should work:

cdo -expr,'tas = ((tas < 12)) ? tas-19.0 : (0.0)' -fldmean -selname,tas n1.nc n2.nc

-Karin

RE: Formulation problem (conditional) - Added by Aleksandar Janković about 6 years ago

Karin,

you are right. Output format of cdo info gives table with those information. The only variable is tas. I checked manual so many times in those three days, but I simply stuck with the solution. I will try recommended code right now and let you know about the results soon.

Thanx a lot,
Best regards,
Aleksandar.

RE: Formulation problem (conditional) - Added by Karin Meier-Fleischer about 6 years ago

If you have only tas in your file you don't need to use '-selname,tas'.

RE: Formulation problem (conditional) - Added by Aleksandar Janković about 6 years ago

Karin, actually after your suggestions, I realized that the problem was in my head. 'CDO info' give me information about field mean and you suggested me solution to find temperature deficit for field mean temperature:

cdo -expr, 'tas = ((tas <12))? tas-19.0: (0.0) '-fldmean n1.nc n2.nc

I persistently used the following formulation:

cdo -expr, 'tas = ((tas <12))? tas-19.0: (0.0) ' n1.nc n2.nc

thinking that 'CDO info' refers only to one particular cell in the domain. Where was my mind ? :(. Of course it gives information about field mean for domain with many cells. When the operator below applies to all cells in the domain (2nd formulation), it will not give the same results as is applied to the field mean value (1st formulation).
For example:

cdo addc,-19 1.nc 2.nc
cdo mulc,-1 2.nc 3.nc

both operators will give the same results as if they were applied to a field mean value, but as soon as I introduce the conditional formulation:

cdo setrtoc, -1.e99,7,0 3.nc 4.nc

the results will no longer be the same.

Thanx Karin, you helped me a lot. Problem solved.

RE: Formulation problem (conditional) - Added by Kasra Keshavarz almost 2 years ago

I am wondering if there is a way to do manipulations on coordinate variables.

RE: Formulation problem (conditional) - Added by Karin Meier-Fleischer almost 2 years ago

Hi Kasra,

to manipulate the coordinate variables you can use NCO http://nco.sourceforge.net/.

    (1-6/6)