[GRASS-dev] Avoid the addition of @mymapset in output map name

Stefan Blumentrath Stefan.Blumentrath at nina.no
Tue May 29 04:36:28 PDT 2018

Hi Roberta,

You can try:
b1 = b1.split(‘@’)[0]


From: grass-dev <grass-dev-bounces at lists.osgeo.org> On Behalf Of Roberta Fagandini
Sent: tirsdag 29. mai 2018 13:17
To: GRASS developers list <grass-dev at lists.osgeo.org>
Subject: [GRASS-dev] Avoid the addition of @mymapset in output map name

Hi all!
I'm working on the GUI of my module for clouds and shadows detection in Sentinel 2 images  (GSoC 2018 project) and I have some trouble with the automatic addition of the mapset name in the output maps.
I have several input bands imported in GRASS that I convert into float value and rescale using r.mapcalc, each output map should be automatically named with the inputs band name and a suffix (e.g. input: nir - output: nir_float).
When I run the script using the GUI I have an error due to the @mapset automatically added to the output map name (e.g. nir at mymapset_float).

At the moment, I solved the problem with a replace() function but I'm not sure this can be the best solution, do you have any hint?

Following you can find the code:

              mapset = gscript.gisenv()['MAPSET']
              mapset2 = '@%s' % mapset
              b1 = options['blu']
              b1 = b1.replace(mapset2, "")
              b2 = options['green']
              b2 = b2.replace(mapset2, "")
              b3 = options['red']
              b3 = b3.replace(mapset2, "")
              b4 = options['nir']
              b4 = b4.replace(mapset2, "")
              b5 = options['nir8a']
              b5 = b5.replace(mapset2, "")
              b7 = options['swir11']
              b7 = b7.replace(mapset2, "")
              b8 = options['swir12']
              b8 = b8.replace(mapset2, "")
              f = 'float'
              bands = [b1, b2, b3, b4, b5, b7, b8]

              for b in bands:
                            gscript.mapcalc('{r} = 1.0 * ({a})/{c}'.format(r="%s_%s" % (b, f), a=b, c=scale_fac), overwrite=True)
                            f_bands.append ("%s_%s" % (b, f))

Thanks in advance,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20180529/562887c1/attachment-0001.html>

More information about the grass-dev mailing list