Project

General

Profile

div operator failing

Added by Miles Sowden 5 months ago

I was trying to calculate the slope (y/x) but the results were not expected (both Y and X are matrices)

I investigated with a simple file (Australian terrain height with one parameter band1)
Using expr operator works, divc does not

cdo divc,1 -setrtoc,0,10,10 ausdem.nc test_divc.nc
cdo expr,'reciprocal=1/Band1' -setrtoc,0,10,10 ausdem.nc test_expr.nc

cdo infov ausdem.nc
-1 : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter name
1 : 0000-00-00 00:00:00 0 326151 106721 : 0.0000 257.83 2064.4 : Band1

cdo infov test_divc.nc
-1 : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter name
1 : 0000-00-00 00:00:00 0 326151 106721 : 10.000 257.88 2064.4 : Band1

cdo infov test_expr.nc
-1 : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter name
1 : 0000-00-00 00:00:00 0 326151 106721 : 0.00048441 0.0086902 0.10000 : reciprocal

using cdo -v CDO version 2.0.4, Copyright (C) 2003-2022

ausdem.nc (756 KB) ausdem.nc

Replies (3)

RE: div operator failing - Added by Karin Meier-Fleischer 5 months ago

You missunderstand the meaning of '-divc,1', which means that the data will be devided by 1, so nothing is changed here.

You are looking for the operator reci for 'reciprocal value'.

cdo -reci -setrtoc,0,10,10 ausdem.nc test_expr.nc

RE: div operator failing - Added by Miles Sowden 5 months ago

Thanks,

The problem is not the divc. The problem is that cdo div y.nc x.nc slope.nc fails (essentially gives high values).
This is most likely due to the division by small values approaching infinity, notwithstanding chaining div -setrtoc
Using expr to calculate the recipricol and then multiplying by y works.

I have also tested the reci operator which works
cdo mul wgs_log_dY_2019121000.nc -reci -setrtoc,-0.01,0.01,0.01 wgs_dX_2019121000_B07.nc temp.nc

RE: div operator failing - Added by Karin Meier-Fleischer 5 months ago

I would expect high values using -divc,1.

-divc,1                     -->  data / 1

-reci                       --> 1 / data

-expr,'reciprocal=1/data'   --> 1 / data

    (1-3/3)