[GRASS-dev] [GRASS GIS] #3727: t.rast.aggregate fails with python3

#3727: t.rast.aggregate fails with python3
---------------------------------------+-------------------------
Reporter: veroandreo | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.8.0
Component: Temporal | Version: svn-trunk
Keywords: t.rast.aggregate, python3 | CPU: Unspecified
Platform: Unspecified |
---------------------------------------+-------------------------
Here's how to reproduce:

{{{
g.region raster=elevation
for map in `seq 1 10` ; do r.mapcalc "prueba_${map} = ${map}" ; done
t.create output=A type=strds temporaltype=absolute title="test"
description="test"
t.register input=A maps=`g.list rast pat=prueba* sep=, map=.`
start="2000-01-01" increment="1 months" -i
t.rast.aggregate in=A out=B granularity="2 months" method=average
basename=b_bimonthly suffix=gran
}}}

and this is the error I get:

{{{
Traceback (most recent call last):
   File "/home/veroandreo/software/grass7_trunk/dist.x86_64-pc-linux-
gnu/scripts/t.rast.aggregate", line 219, in <module>
     main()
   File "/home/veroandreo/software/grass7_trunk/dist.x86_64-pc-linux-
gnu/scripts/t.rast.aggregate", line 196, in main
     overwrite=gcore.overwrite(), file_limit=file_limit)
   File "/home/veroandreo/software/grass7_trunk/dist.x86_64-pc-linux-
gnu/etc/python/grass/temporal/aggregation.py", line 230, in
aggregate_by_topology
     topo_builder.build(mapsA=granularity_list, mapsB=map_list,
spatial=spatial)
   File "/home/veroandreo/software/grass7_trunk/dist.x86_64-pc-linux-
gnu/etc/python/grass/temporal/spatio_temporal_relationships.py", line 569,
in build
     self._build_internal_iteratable(mapsA, spatial)
   File "/home/veroandreo/software/grass7_trunk/dist.x86_64-pc-linux-
gnu/etc/python/grass/temporal/spatio_temporal_relationships.py", line 411,
in _build_internal_iteratable
     self._detect_first()
   File "/home/veroandreo/software/grass7_trunk/dist.x86_64-pc-linux-
gnu/etc/python/grass/temporal/spatio_temporal_relationships.py", line 378,
in _detect_first
     prev_ = self._store.values()[0]
TypeError: 'dict_values' object does not support indexing
WARNING:root:Needed to restart the libgis server, caller: Server check
thread
}}}

It works fine in 76 rel branch. I am using trunk r73904 in virtualenv with
python3.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3727&gt;
GRASS GIS <https://grass.osgeo.org>

#3727: t.rast.aggregate fails with python3
--------------------------+---------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.8.0
Component: Temporal | Version: svn-trunk
Resolution: | Keywords: t.rast.aggregate, python3
       CPU: Unspecified | Platform: Unspecified
--------------------------+---------------------------------------

Comment (by veroandreo):

For the record, all the temporal GUI tools: G7:g.gui.timeline,
G7:g.gui.animation and G7:g.gui.tplot also yield the same error (I can
create a new ticket if needed). Here's how to test following the previous
example:

{{{
g.gui.animation strds=A
g.gui.timeline inputs=A
g.gui.tplot strds=A coordinates=634816.901408,225066.901408
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3727#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>

#3727: t.rast.aggregate fails with python3
-------------------------+-------------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.8.0
Component: Temporal | Version: svn-trunk
Resolution: | Keywords: t.rast.aggregate, t.rast.algebra,
       CPU: | python3
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------
Changes (by veroandreo):

* priority: normal => major
* keywords: t.rast.aggregate, python3 => t.rast.aggregate, t.rast.algebra,
     python3

Comment:

G7:t.rast.algebra fails with the same error when trying to add 2 strds. To
test, just create another strds (B) and run:

{{{
for map in `seq -w 1 10` ; do r.mapcalc "bla_${map} = ${map}" ; done
t.create output=B type=strds temporaltype=absolute title="test"
description="test2"
t.register input=B maps=`g.list rast pat=bla* sep=, map=.`
start="2000-01-01" increment="1 months" -i
t.rast.algebra expression="C = A + B" basename=c_test
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3727#comment:2&gt;
GRASS GIS <https://grass.osgeo.org>

#3727: t.rast.aggregate fails with python3
-------------------------+-------------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.8.0
Component: Temporal | Version: svn-trunk
Resolution: | Keywords: t.rast.aggregate, t.rast.algebra,
       CPU: | python3
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by huhabla):

This problem can be solved by wrapping list() around the dictionary value
type in "temporal/spatio_temporal_relationships.py", line 378, in
_detect_first:

{{{
prev_ = list(self._store.values())[0]
}}}

Source: https://stackoverflow.com/questions/17431638/get-typeerror-dict-
values-object-does-not-support-indexing-when-using-python

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3727#comment:3&gt;
GRASS GIS <https://grass.osgeo.org>

#3727: t.rast.aggregate fails with python3
-------------------------+-------------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.8.0
Component: Temporal | Version: svn-trunk
Resolution: | Keywords: t.rast.aggregate, t.rast.algebra,
       CPU: | python3
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------
Changes (by veroandreo):

* Attachment "st_patch.diff" added.

small patch as suggested by Soeren

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3727&gt;
GRASS GIS <https://grass.osgeo.org>

#3727: t.rast.aggregate fails with python3
-------------------------+-------------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.8.0
Component: Temporal | Version: svn-trunk
Resolution: | Keywords: t.rast.aggregate, t.rast.algebra,
       CPU: | python3
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by veroandreo):

I just applied your modification, but when I compile in python 3
virtualenv as suggested here
https://trac.osgeo.org/grass/wiki/Python3Support#Howtotest, I get
compilation errors everywhere.

I guess I'm doing something wrong. Can someone else try, please? I just
attached the small patch as to ease testing

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3727#comment:4&gt;
GRASS GIS <https://grass.osgeo.org>

#3727: t.rast.aggregate fails with python3
-------------------------+-------------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: major | Milestone: 7.8.0
Component: Temporal | Version: svn-trunk
Resolution: | Keywords: t.rast.aggregate, t.rast.algebra,
       CPU: | python3
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by neteler):

Replying to [comment:3 huhabla]:
> This problem can be solved by wrapping list() around the dictionary
value type in "temporal/spatio_temporal_relationships.py", line 378, in
_detect_first:
>
> {{{
> prev_ = list(self._store.values())[0]
> }}}

I tested this as well via Vero's patch:

{{{
t.create output=A type=strds temporaltype=absolute title="test"
description="test"
Creates a space time dataset.

Usage:
  t.create output=name maps=name[,name,...] [type=name]
    semantictype=string title=string description=string [--overwrite]
    [--help] [--verbose] [--quiet] [--ui]

Flags:

Parameters:
         output Name of the output space time dataset
           maps Type of the output space time dataset
           type Type of the input map
                  options: raster,vector,raster_3d
                  default: raster
   semantictype Semantic type of the space time dataset
                  options: min,max,sum,mean
                  default: mean
          title Title of the new space time dataset
    description Description of the new space time dataset

ERROR: t.create: Sorry, <temporaltype> is not a valid parameter
ERROR: Value <strds> out of range for parameter <type>
         Legal range: raster,vector,raster_3d
ERROR: Required parameter <maps> not set:
         (Type of the output space time dataset)
}}}

... quite weird!

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3727#comment:5&gt;
GRASS GIS <https://grass.osgeo.org>

#3727: t.rast.aggregate fails with python3
-------------------------+-------------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: major | Milestone: 7.8.0
Component: Temporal | Version: svn-trunk
Resolution: fixed | Keywords: t.rast.aggregate, t.rast.algebra,
       CPU: | python3
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------
Changes (by veroandreo):

* status: new => closed
* resolution: => fixed

Comment:

In [changeset:"74089" 74089]:
{{{
#!CommitTicketReference repository="" revision="74089"
temporal lib: wrap list() around dictionary as suggested by huhabla, fixes
#3727
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3727#comment:6&gt;
GRASS GIS <https://grass.osgeo.org>

#3727: t.rast.aggregate fails with python3
-------------------------+-------------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: major | Milestone: 7.8.0
Component: Temporal | Version: svn-trunk
Resolution: fixed | Keywords: t.rast.aggregate, t.rast.algebra,
       CPU: | python3
  Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------

Comment (by veroandreo):

So, compilation problem was a different issue, i.e., i updated my system
and was using an old virtualenv. I trashed it, created a new one, compiled
grass there and the patch solved the reported error. Thanks, Soeren!

However, there are new errors now in G7:g.gui.animation, G7:g.gui.timeline
and G7:g.gui.tplot that I'll report in separate tickets.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3727#comment:7&gt;
GRASS GIS <https://grass.osgeo.org>