[GRASS-user] ERROR 1: TIFFOpen: No error Using GDAL data type <Byte>

I am using "r.out.gdal" function within a Python script through the command
console of grass7.
I am calling it by doing:

{{{
from grass.script.core import run_command

run_command("r.out.gdal",
        flags="c",
        type="Byte",
        input="prova"+ str(m+1),
        output=outFolder+ "\prova"+ str(m+1)+ ".tif",
        nodata=255)
}}}

I am getting this error:

{{{
ERROR 1: TIFFOpen:D:\UMBE\PhD\Nepal\khumbu_article\shadow
_sun_hourly\prova_hourly_shadow\prova1.tif: No error
Using GDAL data type <Byte>
ERROR: Impossibile creare il dataset
<D:\UMBE\PhD\Nepal\khumbu_article\shadow
_sun_hourly\prova_hourly_shadow\prova1.tif> usando il driver <GTiff>
Traceback (most recent call last):
  File "D:\UMBE\PhD\Nepal\khumbu_article\shadow\r_sun_hourly
\prova_r-sun-hourly.py", line 39, in <module>
    nodata=255)
  File "C:\OSGeo4W\apps\grass\grass-7.0.0\etc\python\grass\s
cript\core.py", line 375, in run_command
    return handle_errors(returncode, returncode, args,
kwargs)
  File "C:\OSGeo4W\apps\grass\grass-7.0.0\etc\python\grass\s
cript\core.py", line 310, in handle_errors
    returncode=returncode)
grass.exceptions.CalledModuleError: Module run None
['r.out.gdal', '-c', 'output=D:\\UMBE\\PhD\\Nepal\\khumbu_ar
ticle\\shadow\r_sun_hourly\\prova_hourly_shadow\\prova1.tif'
, 'nodata=255', 'type=Byte', 'input=prova1'] ended with
error
Process ended with non-zero return code 1. See errors in the
(error) output.
}}}

Anyway, if I use the same call from the command line (not calling the Python
script) I have my "prova1.tif" written correctly in the folder I chose. Why?
Any guess?

--
View this message in context: http://osgeo-org.1560.x6.nabble.com/ERROR-1-TIFFOpen-No-error-Using-GDAL-data-type-Byte-tp5200187.html
Sent from the Grass - Users mailing list archive at Nabble.com.

Maybe ...

outFolder is not correctly defined, python wants slash (/) in path definition

Il 07/04/2015 11.00, umberto.minora ha scritto:

I am using "r.out.gdal" function within a Python script through the command
console of grass7.
I am calling it by doing:

{{{
from grass.script.core import run_command

run_command("r.out.gdal",
        flags="c",
        type="Byte",
        input="prova"+ str(m+1),
        output=outFolder+ "\prova"+ str(m+1)+ ".tif",
        nodata=255)
}}}

I am getting this error:

{{{
ERROR 1: TIFFOpen:D:\UMBE\PhD\Nepal\khumbu_article\shadow
_sun_hourly\prova_hourly_shadow\prova1.tif: No error
Using GDAL data type <Byte>
ERROR: Impossibile creare il dataset
<D:\UMBE\PhD\Nepal\khumbu_article\shadow
_sun_hourly\prova_hourly_shadow\prova1.tif> usando il driver <GTiff>
Traceback (most recent call last):
   File "D:\UMBE\PhD\Nepal\khumbu_article\shadow\r_sun_hourly
\prova_r-sun-hourly.py", line 39, in <module>
     nodata=255)
   File "C:\OSGeo4W\apps\grass\grass-7.0.0\etc\python\grass\s
cript\core.py", line 375, in run_command
     return handle_errors(returncode, returncode, args,
kwargs)
   File "C:\OSGeo4W\apps\grass\grass-7.0.0\etc\python\grass\s
cript\core.py", line 310, in handle_errors
     returncode=returncode)
grass.exceptions.CalledModuleError: Module run None
['r.out.gdal', '-c', 'output=D:\\UMBE\\PhD\\Nepal\\khumbu_ar
ticle\\shadow\r_sun_hourly\\prova_hourly_shadow\\prova1.tif'
, 'nodata=255', 'type=Byte', 'input=prova1'] ended with
error
Process ended with non-zero return code 1. See errors in the
(error) output.
}}}

Anyway, if I use the same call from the command line (not calling the Python
script) I have my "prova1.tif" written correctly in the folder I chose. Why?
Any guess?

--
View this message in context: http://osgeo-org.1560.x6.nabble.com/ERROR-1-TIFFOpen-No-error-Using-GDAL-data-type-Byte-tp5200187.html
Sent from the Grass - Users mailing list archive at Nabble.com.
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

I think you're somehow getting a newline character into the output path. See below.
Try using the native python os.path.join(...) to create an output variable and avoid any use of string concatenation within the run_command statement (including the input varialbe)

On 04/07/2015 12:00 PM, umberto.minora wrote:

I am using "r.out.gdal" function within a Python script through the command
console of grass7.
I am calling it by doing:

{{{
from grass.script.core import run_command

run_command("r.out.gdal",
        flags="c",
        type="Byte",
        input="prova"+ str(m+1),
        output=outFolder+ "\prova"+ str(m+1)+ ".tif",
        nodata=255)
}}}

I am getting this error:

{{{
ERROR 1: TIFFOpen:D:\UMBE\PhD\Nepal\khumbu_article\shadow
_sun_hourly\prova_hourly_shadow\prova1.tif: No error
Using GDAL data type <Byte>
ERROR: Impossibile creare il dataset
<D:\UMBE\PhD\Nepal\khumbu_article\shadow
_sun_hourly\prova_hourly_shadow\prova1.tif> usando il driver <GTiff>
Traceback (most recent call last):
   File "D:\UMBE\PhD\Nepal\khumbu_article\shadow\r_sun_hourly
\prova_r-sun-hourly.py", line 39, in <module>
     nodata=255)
   File "C:\OSGeo4W\apps\grass\grass-7.0.0\etc\python\grass\s
cript\core.py", line 375, in run_command
     return handle_errors(returncode, returncode, args,
kwargs)
   File "C:\OSGeo4W\apps\grass\grass-7.0.0\etc\python\grass\s
cript\core.py", line 310, in handle_errors
     returncode=returncode)
grass.exceptions.CalledModuleError: Module run None
['r.out.gdal', '-c', 'output=D:\\UMBE\\PhD\\Nepal\\khumbu_ar
ticle\\shadow\r_sun_hourly\\prova_hourly_shadow\\prova1.tif'

------------------^^^--------------------------------------------
Note the '\r' between shadow and _sun

, 'nodata=255', 'type=Byte', 'input=prova1'] ended with
error
Process ended with non-zero return code 1. See errors in the
(error) output.
}}}

Anyway, if I use the same call from the command line (not calling the Python
script) I have my "prova1.tif" written correctly in the folder I chose. Why?
Any guess?

--
View this message in context: http://osgeo-org.1560.x6.nabble.com/ERROR-1-TIFFOpen-No-error-Using-GDAL-data-type-Byte-tp5200187.html
Sent from the Grass - Users mailing list archive at Nabble.com.
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

This mail was received via Mail-SeCure System.

Thank you so much. Indeed, the problem were those slashes.
Now I am using this line of code as suggested (with a slight addition
("os.sep") to make it work on a Windows machine):

{{{
outFolder=
os.path.join("D:",os.sep,"UMBE","PhD","Nepal","khumbu_article","shadow","r_sun_hourly","prova_hourly_shadow")

run_command("r.out.gdal",
        flags="c",
        type="Byte",
        input="prova"+ str(m+1),
        output=os.path.join(outFolder,"prova"+ str(m+1)+ ".tif"),
        nodata=255)
}}}

--
View this message in context: http://osgeo-org.1560.x6.nabble.com/ERROR-1-TIFFOpen-No-error-Using-GDAL-data-type-Byte-tp5200187p5200218.html
Sent from the Grass - Users mailing list archive at Nabble.com.

yes, mutch better :slight_smile:

Il 07/04/2015 14.05, umberto.minora ha scritto:

Thank you so much. Indeed, the problem were those slashes.
Now I am using this line of code as suggested (with a slight addition
("os.sep") to make it work on a Windows machine):

{{{
outFolder=
os.path.join("D:",os.sep,"UMBE","PhD","Nepal","khumbu_article","shadow","r_sun_hourly","prova_hourly_shadow")

run_command("r.out.gdal",
        flags="c",
        type="Byte",
        input="prova"+ str(m+1),
        output=os.path.join(outFolder,"prova"+ str(m+1)+ ".tif"),
        nodata=255)
}}}

--
View this message in context: http://osgeo-org.1560.x6.nabble.com/ERROR-1-TIFFOpen-No-error-Using-GDAL-data-type-Byte-tp5200187p5200218.html
Sent from the Grass - Users mailing list archive at Nabble.com.
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user