[GRASS-dev] Using the pygrass "Mapset.glist" method and a dictionary

Nikos Alexandris nik at nikosalexandris.net
Thu May 23 17:33:52 PDT 2013


On Friday 24 of May 2013 00:23:28 Pietro Zambelli wrote:
> Ciao Nikos,

Ciao Pietro,

..
> > However, whenever the result is empty, i.e. there are no B1, B2 and so on
> > named raster maps, running the script fails with the error:
> > 	landsat_imagery['Spectral Bands'] = Mapset().glist('rast', pattern =
> > 
> > 'B[123457]')
> > 
> > 	TypeError: 'str' object is not callable
> > 
> > Running the instructions step-wise, from within ipython, doesn't appear to
> > be problematic.  What am I missing in this case?
> 
> Mmh...
> 
> I've tried your code... and it is working on my machine. In both: python
> shell and from file...

> Python shell:
> >>> from grass.pygrass.gis import Mapset
> >>> Mapset().glist('rast', pattern = 'B[123457]')
> 
> ['B4', 'B5', 'B1', 'B3', 'B2', 'B7']

This should be empty!  From the above result it means that the requested bands 
pre-exist.  Consider a Mapswet with bands named like B10, B20, B30, B40, B50, 
B70, B80.

(Sure, we can erase that ending "0" while importing, for example, Landsat 
bands in GRASS, but... who knows, maybe someone needs to respect the original 
naming pattern of old Landsat scenes.)

> From file:
> >>> cat nik.py
> 
> from grass.pygrass.gis import Mapset
> 
> landsat_imagery = dict()
> landsat_imagery['Spectral Bands'] = Mapset().glist('rast',
>                                                    pattern='B[123457]')
> 
> print landsat_imagery
> 
> >>> %run nik.py
> 
> {'Spectral Bands': ['B4', 'B5', 'B1', 'B3', 'B2', 'B7']}

Here too, it should be empty.
> 
> Therefore I think that the problem is not here...
> can you send me or share/publish the whole code somewhere (gist.github,
> dpaste or other).

Grazie, Nikos


More information about the grass-dev mailing list