Adding a suffix for output raster map names

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding a suffix for output raster map names

NikosAlexandris
Using the following in a python script's header

#%option
#% key: outputsuffix
#% key_desc: suffix string
#% type: string
#% description: Suffix for the Pan-Sharpened image(s)
#% required: yes
#% answer: hpf
#%end

and somewhere in the script the following

run("g.rename", rast=(tmp_msx_hpf,"%s.%s" % (msx, outputsuffix)))

works fine in the command line. Testing the modules wx-GUI (G70),
doesn't play nice. For exampe,
the following WARNING (error) appears:

WARNING: Illegal filename <[hidden email]>.
Character <@> not allowed.
WARNING: <[hidden email]> is an illegal file
name

The "suffix" is added after the Mapset's name(string). Is there no
option to "fix" this? Should I "fix" this in my code directly, i.e. take
the string, split-off the Mapset-part, put in the suffix and add the
Mapset's name in the end?

Thank you, Nikos
_______________________________________________
grass-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-dev
Reply | Threaded
Open this post in threaded view
|

Re: Adding a suffix for output raster map names

Anna Petrášová


On Fri, Nov 14, 2014 at 9:40 AM, Nikos Alexandris <[hidden email]> wrote:
Using the following in a python script's header

#%option
#% key: outputsuffix
#% key_desc: suffix string
#% type: string
#% description: Suffix for the Pan-Sharpened image(s)
#% required: yes
#% answer: hpf
#%end

and somewhere in the script the following

run("g.rename", rast=(tmp_msx_hpf,"%s.%s" % (msx, outputsuffix)))

works fine in the command line. Testing the modules wx-GUI (G70), doesn't play nice. For exampe,
the following WARNING (error) appears:

WARNING: Illegal filename <12DEC02053035.blue@python_scripting.hpf>. Character <@> not allowed.
WARNING: <12DEC02053035.blue@python_scripting.hpf> is an illegal file name

The "suffix" is added after the Mapset's name(string). Is there no option to "fix" this? Should I "fix" this in my code directly, i.e. take the string, split-off the Mapset-part, put in the suffix and add the Mapset's name in the end?

I would say you have to expect that your input map may have mapset, test it, split if necessary and add suffix to the map name, but you might not need to add the mapset again to the name.

Anna

Thank you, Nikos
_______________________________________________
grass-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-dev


_______________________________________________
grass-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-dev
Reply | Threaded
Open this post in threaded view
|

Re: Adding a suffix for output raster map names

NikosAlexandris
Nikos Alexandris wrote:

>> Using the following in a python script's header:
>> #%option
>> #% key: outputsuffix
>> #% key_desc: suffix string
>> #% type: string
>> #% description: Suffix for the Pan-Sharpened image(s)
>> #% required: yes
>> #% answer: hpf
>> #%end

>> and somewhere in the script the following:
>> run("g.rename", rast=(tmp_msx_hpf,"%s.%s" % (msx, outputsuffix)))
>> works fine in the command line. Testing the modules wx-GUI (G70),
>> doesn't
>> play nice. For exampe, the following WARNING (error) appears:
>> WARNING: Illegal filename <[hidden email]>.
>> Character <@> not allowed.
>> WARNING: <[hidden email]> is an illegal
>> file name

>> The "suffix" is added after the Mapset's name(string). Is there no
>> option
>> to "fix" this? Should I "fix" this in my code directly, i.e. take
>> the
>> string, split-off the Mapset-part, put in the suffix and add the
>> Mapset's
>> name in the end?

Anna Petrášová wrote:

> I would say you have to expect that your input map may have mapset,
> test
> it, split if necessary and add suffix to the map name, but you might
> not
> need to add the mapset again to the name.

Thanks Anna.

Is there a pygrass function to isolate the a raster map's basename from
the Mapset part? Looking for it...

Nikos
_______________________________________________
grass-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-dev
Reply | Threaded
Open this post in threaded view
|

Re: Adding a suffix for output raster map names

Helmut Kudrnovsky
NikosAlexandris wrote
Is there a pygrass function to isolate the a raster map's basename from
the Mapset part? Looking for it...

Nikos
_______________________________________________
grass-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-dev
this should work:

def main():
    vectorforcalculations = options['vector'].split('@')[0]
best regards
Helmut
Reply | Threaded
Open this post in threaded view
|

Re: Adding a suffix for output raster map names

NikosAlexandris
Nikos Alexandris wrote:

>> Is there a pygrass function to isolate the a raster map's basename
>> from
>> the Mapset part? Looking for it...

Helmut Kudrnovsky wrote:

> this should work:

> def main():
>     vectorforcalculations = options['vector'].split('@')[0]

Danke Helmut :-)

Since I already do:

from grass.pygrass.raster.abstract import Info
..
images = {}
     for img in imglst:  # Retrieving Image Info
         images[img] = Info(img, mapset)
         images[img].read()

I would prefer to do something like:

msx_nam = ("%s.%s" % (images[msx].name, outputsuffix))

and use the "msx_name" where-ever it is needed.  But, the ".name"
attribute of the Info class does add the @Mapset too. So, no luck :-/

Nikos

ps- Just a reminder/idea @Pietro: make the Info class independent, it
might prove to be very useful.
_______________________________________________
grass-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-dev