Opened 5 years ago

Last modified 5 years ago

#3891 new defect

t.rast.algebra: if clause with two conditions does not work properly

Reported by: veroandreo Owned by: grass-dev@…
Priority: normal Milestone: 7.8.3
Component: Temporal Version: unspecified
Keywords: t.rast.algebra, r.mapcalc Cc:
CPU: Unspecified Platform: Unspecified

Description

I have a daily lst time series that I converted to celsius degrees. I want to count how many days per year have LST >= 20 and <= 30. So, I first do the following:

t.rast.algebra expression="tmean_higher20_lower30 = if(lst_daily_celsius >= 20.0 && lst_daily_celsius <= 30.0, lst_daily_celsius, null())" basename=tmean_higher20_lower30 suffix=gran nprocs=7

with the intention of using t.rast.aggregate afterwards.

However, without any error, the t.rast.algebra command produces either an empty STRDS or one full of null maps if I use the -n flag.

If I run the corresponding r.mapcalc command for a single date, it works as expected. Region is properly set, input maps have values in the proper range. No idea what's wrong. I have used this command before and it worked just fine. It is indeed something very simple for t.rast.algebra.

The only odd thing I see when I do a dry run is how it builds the r.mapcalc command, that in the second part of the condition it puts parenthesis, but I don't know much python as to judge that.

['EQUAL'] False False False True && & False False False
lst_2014_01_01@italy_LST_1km_daily_reconstructed_daily >= 20.0&&(lst_2014_01_01@italy_LST_1km_daily_reconstructed_daily <= 30.0)
lst_2014_01_02@italy_LST_1km_daily_reconstructed_daily >= 20.0&&(lst_2014_01_02@italy_LST_1km_daily_reconstructed_daily <= 30.0)

[rest skipped]

lst_2018_12_31@italy_LST_1km_daily_reconstructed_daily >= 20.0&&(lst_2018_12_31@italy_LST_1km_daily_reconstructed_daily <= 30.0)
build_condition_cmd_list ['EQUAL']
['EQUAL'] False False False False None None False False False
{'STDS': {'name': 'tmean_higher20_lower30',
          'stdstype': 'strds',
          'temporal_type': 'absolute'},
 'processes': [{'flags': ['overwrite'],
                'inputs': [('expression',
                            'tmean_higher20_lower30_2014_01_01=if(lst_2014_01_01@italy_LST_1km_daily_reconstructed_daily '
                            '>= '
                            '20.0&&(lst_2014_01_01@italy_LST_1km_daily_reconstructed_daily '
                            '<= 30.0), '
                            'lst_2014_01_01@italy_LST_1km_daily_reconstructed_daily, '
                            'null())'),
                           ('region', 'current')],
                'name': 'r.mapcalc',
                'outputs': []},

[rest skipped]

 'register': [('tmean_higher20_lower30_2014_01_01',
               '2014-01-01 00:00:00',
               '2014-01-02 00:00:00'),
              ('tmean_higher20_lower30_2014_01_02',
               '2014-01-02 00:00:00',
               '2014-01-03 00:00:00'),

[rest skipped]

              ('tmean_higher20_lower30_2018_12_31',
               '2018-12-31 00:00:00',
               '2019-01-01 00:00:00')],
 'remove': []}

I attach the full output of the dry run.

I tested with python2 and python3, same behavior. I use grass-dev in Fedora 30.

Change History (6)

comment:1 by veroandreo, 5 years ago

full dry run output is bigger than allowed... I hope the snippets copied above are enough...

comment:2 by veroandreo, 5 years ago

Ok, this is odd... If I replace the former command, with the following:

t.rast.algebra -n   expression="tmean_higher20_lower30 = if(lst_daily_celsius >= 20.0 && lst_daily_celsius <= 30.0, 1, null())" basename=tmean_higher20_lower30 suffix=gran nprocs=7 --o

i.e., putting 1 instead of leaving the value that the map has, all works fine... why does it fail to keep the value that was there originally if it meets the condition???

comment:3 by neteler, 5 years ago

Milestone: 7.8.07.8.1

Ticket retargeted after milestone closed

comment:4 by neteler, 5 years ago

Milestone: 7.8.17.8.2

Ticket retargeted after milestone closed

comment:5 by neteler, 5 years ago

Milestone: 7.8.2

Ticket retargeted after milestone closed

comment:6 by neteler, 5 years ago

Milestone: 7.8.3
Note: See TracTickets for help on using tickets.