Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#3727 closed defect (fixed)

t.rast.aggregate fails with python3

Reported by: veroandreo Owned by: grass-dev@…
Priority: major Milestone: 7.8.0
Component: Temporal Version: svn-trunk
Keywords: t.rast.aggregate, t.rast.algebra, python3 Cc:
CPU: Unspecified Platform: Unspecified

Description

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.

Attachments (1)

st_patch.diff (502 bytes ) - added by veroandreo 6 years ago.
small patch as suggested by Soeren

Download all attachments as: .zip

Change History (8)

comment:1 by veroandreo, 6 years ago

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

comment:2 by veroandreo, 6 years ago

Keywords: t.rast.algebra added
Priority: normalmajor

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

comment:3 by huhabla, 6 years ago

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

by veroandreo, 6 years ago

Attachment: st_patch.diff added

small patch as suggested by Soeren

comment:4 by veroandreo, 6 years ago

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

in reply to:  3 comment:5 by neteler, 6 years ago

Replying to 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!

comment:6 by veroandreo, 6 years ago

Resolution: fixed
Status: newclosed

In 74089:

temporal lib: wrap list() around dictionary as suggested by huhabla, fixes #3727

comment:7 by veroandreo, 6 years ago

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.

Note: See TracTickets for help on using tickets.