[GRASS-dev] Unable to rename cell/null file - NULL file messed up

When running a script (r.biodiversity) in GRASS 7.0 for Windows, I am getting the warning:

WARNING: Unable to rename cell file ‘C:\GIS\GrassJvdS/latlong/YLD_NUT/.tmp/unknown/3988.0’ to ‘C:\GIS\GrassJvdS/latlong/YLD_NUT/fcell/Shan3_CA_Renyi_0_0’: File exists
WARNING: Unable to rename null file ‘C:\GIS\GrassJvdS/latlong_2005/YLD_NUT/.tmp/unknown/4100.1’ to ‘C:\GIS\GrassJvdS/latlong_2005/YLD_NUT/cell_misc/Shan3_CA_Renyi_1_0/null’: File exists

The script does create the output files, but the NULL file seems to be messed up, as large parts of the map are rendered as no-data. Removing and then recreating the null file seems to solve the problem.

However, there still is another issue: r.info shows that the range of values is e.g., min = -0 max = 2.98928848941905. This is as expected. Yet, when clicking on the map with the query button, the query results show negative values.

I thought this was related to g.rename, but that function runs without problems. Perhaps something with permission: to run the script I just copied it to the script folder (c:/users/user1/appdata/roaming/grass7/addons/bin) (I did not install with g.extension because that does not seem to work for GRASS at the moment).

Running the same on Linux results in the correct map, with none of the problems listed above. Any idea what I am doing wrong / how this can be solved?

Paulo

(I did not install with g.extension because that does not seem to work for

GRASS at the moment).

testedt here with

System Info
GRASS version: 7.0.2
GRASS SVN Revision: 66861
Build Date: 2015-11-19
Build Platform: i686-pc-mingw32
GDAL/OGR: 1.11.3
PROJ.4: 4.8.0
GEOS: 3.5.0
SQLite: 3.7.17
Python: 2.7.4
wxPython: 2.8.12.1
Platform: Windows-7-6.1.7601-SP1 (OSGeo4W)

g.extension extension=r.biodiversity
svnurl=http://svn.osgeo.org/grass/grass-addons/grass7
Downloading precompiled GRASS Addons <r.biodiversity>...
Updating addons metadata file...
Installation of <r.biodiversity> successfully finished

-----
best regards
Helmut
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Unable-to-rename-cell-null-file-NULL-file-messed-up-tp5239350p5239352.html
Sent from the Grass - Dev mailing list archive at Nabble.com.

pvanbosgeo wrote

When running a script (r.biodiversity) in GRASS 7.0 for Windows, I am
getting the warning:

WARNING: Unable to rename cell file
'C:\GIS\GrassJvdS/latlong/YLD_NUT/.tmp/unknown/3988.0' to
'C:\GIS\GrassJvdS/latlong/YLD_NUT/fcell/Shan3_CA_Renyi_0_0': File exists
WARNING: Unable to rename null file
'C:\GIS\GrassJvdS/latlong_2005/YLD_NUT/.tmp/unknown/4100.1' to
'C:\GIS\GrassJvdS/latlong_2005/YLD_NUT/cell_misc/Shan3_CA_Renyi_1_0/null':
File exists

tested here:

r.biodiversity -r --verbose
input=spec1@data,spec2@data,spec3@data,spec4@data,spec5@data output=renyi
alpha=0,1,2
WARNING: Unable to rename null file
'C:\grassdata/test3035/data/.tmp/unknown/1680.1' to
'C:\grassdata/test3035/data/cell_misc/renyi_Renyi_0_0/null': File exists
WARNING: Unable to rename cell file
'C:\grassdata/test3035/data/.tmp/unknown/1680.0' to
'C:\grassdata/test3035/data/fcell/renyi_Renyi_0_0': File exists
WARNING: Unable to rename null file
'C:\grassdata/test3035/data/.tmp/unknown/8936.1' to
'C:\grassdata/test3035/data/cell_misc/renyi_Renyi_1_0/null': File exists
WARNING: Unable to rename cell file
'C:\grassdata/test3035/data/.tmp/unknown/8936.0' to
'C:\grassdata/test3035/data/fcell/renyi_Renyi_1_0': File exists
WARNING: Unable to rename null file
'C:\grassdata/test3035/data/.tmp/unknown/9328.1' to
'C:\grassdata/test3035/data/cell_misc/renyi_Renyi_2_0/null': File exists
WARNING: Unable to rename cell file
'C:\grassdata/test3035/data/.tmp/unknown/9328.0' to
'C:\grassdata/test3035/data/fcell/renyi_Renyi_2_0': File exists

is there some overwriting of existing files in the script? AFAIR there may
be some issues with overwriting existing files in windows os.

-----
best regards
Helmut
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Unable-to-rename-cell-null-file-NULL-file-messed-up-tp5239350p5239357.html
Sent from the Grass - Dev mailing list archive at Nabble.com.

On Tue, Dec 1, 2015 at 2:04 PM, Helmut Kudrnovsky <hellik@web.de> wrote:

pvanbosgeo wrote
> When running a script (r.biodiversity) in GRASS 7.0 for Windows, I am
> getting the warning:
>
> WARNING: Unable to rename cell file
> 'C:\GIS\GrassJvdS/latlong/YLD_NUT/.tmp/unknown/3988.0' to
> 'C:\GIS\GrassJvdS/latlong/YLD_NUT/fcell/Shan3_CA_Renyi_0_0': File exists
> WARNING: Unable to rename null file
> 'C:\GIS\GrassJvdS/latlong_2005/YLD_NUT/.tmp/unknown/4100.1' to
>
'C:\GIS\GrassJvdS/latlong_2005/YLD_NUT/cell_misc/Shan3_CA_Renyi_1_0/null':
> File exists

tested here:

r.biodiversity -r --verbose
input=spec1@data,spec2@data,spec3@data,spec4@data,spec5@data output=renyi
alpha=0,1,2
WARNING: Unable to rename null file
'C:\grassdata/test3035/data/.tmp/unknown/1680.1' to
'C:\grassdata/test3035/data/cell_misc/renyi_Renyi_0_0/null': File exists
WARNING: Unable to rename cell file
'C:\grassdata/test3035/data/.tmp/unknown/1680.0' to
'C:\grassdata/test3035/data/fcell/renyi_Renyi_0_0': File exists
WARNING: Unable to rename null file
'C:\grassdata/test3035/data/.tmp/unknown/8936.1' to
'C:\grassdata/test3035/data/cell_misc/renyi_Renyi_1_0/null': File exists
WARNING: Unable to rename cell file
'C:\grassdata/test3035/data/.tmp/unknown/8936.0' to
'C:\grassdata/test3035/data/fcell/renyi_Renyi_1_0': File exists
WARNING: Unable to rename null file
'C:\grassdata/test3035/data/.tmp/unknown/9328.1' to
'C:\grassdata/test3035/data/cell_misc/renyi_Renyi_2_0/null': File exists
WARNING: Unable to rename cell file
'C:\grassdata/test3035/data/.tmp/unknown/9328.0' to
'C:\grassdata/test3035/data/fcell/renyi_Renyi_2_0': File exists

is there some overwriting of existing files in the script? AFAIR there may
be some issues with overwriting existing files in windows os.

Thanks Helmut. Yes, the script does also overwrite some intermediate files

(with r.mapcalc). I will look into that and see how to change that.

I wonder though, if I use overwrite on the command line, there is no
problem. So than that would be a problem specific to grass.script.mapcalc ?

-----
best regards
Helmut
--
View this message in context:
http://osgeo-org.1560.x6.nabble.com/Unable-to-rename-cell-null-file-NULL-file-messed-up-tp5239350p5239357.html
Sent from the Grass - Dev mailing list archive at Nabble.com.
_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

On Tue, Dec 1, 2015 at 1:44 PM, Paulo van Breugel
<p.vanbreugel@gmail.com> wrote:

When running a script (r.biodiversity) in GRASS 7.0 for Windows, I am
getting the warning:

WARNING: Unable to rename cell file
'C:\GIS\GrassJvdS/latlong/YLD_NUT/.tmp/unknown/3988.0' to
'C:\GIS\GrassJvdS/latlong/YLD_NUT/fcell/Shan3_CA_Renyi_0_0': File exists
WARNING: Unable to rename null file
'C:\GIS\GrassJvdS/latlong_2005/YLD_NUT/.tmp/unknown/4100.1' to
'C:\GIS\GrassJvdS/latlong_2005/YLD_NUT/cell_misc/Shan3_CA_Renyi_1_0/null':
File exists

The script does create the output files, but the NULL file seems to be
messed up, as large parts of the map are rendered as no-data. Removing and
then recreating the null file seems to solve the problem.

Looks like:
https://trac.osgeo.org/grass/ticket/2712

Was the fix backported? According to a local diff, r65775 was not
backported but the ticket closed.

?

Markus

On Tue, Dec 1, 2015 at 3:28 PM, Markus Neteler <neteler@osgeo.org> wrote:

On Tue, Dec 1, 2015 at 1:44 PM, Paulo van Breugel
<p.vanbreugel@gmail.com> wrote:
> When running a script (r.biodiversity) in GRASS 7.0 for Windows, I am
> getting the warning:
>
> WARNING: Unable to rename cell file
> 'C:\GIS\GrassJvdS/latlong/YLD_NUT/.tmp/unknown/3988.0' to
> 'C:\GIS\GrassJvdS/latlong/YLD_NUT/fcell/Shan3_CA_Renyi_0_0': File exists
> WARNING: Unable to rename null file
> 'C:\GIS\GrassJvdS/latlong_2005/YLD_NUT/.tmp/unknown/4100.1' to
>
'C:\GIS\GrassJvdS/latlong_2005/YLD_NUT/cell_misc/Shan3_CA_Renyi_1_0/null':
> File exists
>
> The script does create the output files, but the NULL file seems to be
> messed up, as large parts of the map are rendered as no-data. Removing
and
> then recreating the null file seems to solve the problem.

Looks like:
https://trac.osgeo.org/grass/ticket/2712

Was the fix backported? According to a local diff, r65775 was not
backported but the ticket closed.

?

Can't answer that, but I see that a related (?) ticket
https://trac.osgeo.org/grass/ticket/2434 was retargeted to 7.03? From the
description that issue seems to be very similar to the problem described
above?

Markus

Hi Helmut, you were absolutely right, the problem was with r.mapcalc overwriting some intermediate files, so I changed that. I don’t have Windows myself, but had a quick try on my colleagues computer, and it seems to work now. Thanks for your help.

···

On 01-12-15 14:51, Paulo van Breugel wrote:

On Tue, Dec 1, 2015 at 2:04 PM, Helmut Kudrnovsky <hellik@web.de> wrote:

pvanbosgeo wrote

When running a script (r.biodiversity) in GRASS 7.0 for Windows, I am
getting the warning:

WARNING: Unable to rename cell file
‘C:\GIS\GrassJvdS/latlong/YLD_NUT/.tmp/unknown/3988.0’ to
‘C:\GIS\GrassJvdS/latlong/YLD_NUT/fcell/Shan3_CA_Renyi_0_0’: File exists
WARNING: Unable to rename null file
‘C:\GIS\GrassJvdS/latlong_2005/YLD_NUT/.tmp/unknown/4100.1’ to
‘C:\GIS\GrassJvdS/latlong_2005/YLD_NUT/cell_misc/Shan3_CA_Renyi_1_0/null’:
File exists

tested here:

r.biodiversity -r --verbose
input=spec1@data,spec2@data,spec3@data,spec4@data,spec5@data output=renyi
alpha=0,1,2
WARNING: Unable to rename null file
‘C:\grassdata/test3035/data/.tmp/unknown/1680.1’ to
‘C:\grassdata/test3035/data/cell_misc/renyi_Renyi_0_0/null’: File exists
WARNING: Unable to rename cell file
‘C:\grassdata/test3035/data/.tmp/unknown/1680.0’ to
‘C:\grassdata/test3035/data/fcell/renyi_Renyi_0_0’: File exists
WARNING: Unable to rename null file
‘C:\grassdata/test3035/data/.tmp/unknown/8936.1’ to
‘C:\grassdata/test3035/data/cell_misc/renyi_Renyi_1_0/null’: File exists
WARNING: Unable to rename cell file
‘C:\grassdata/test3035/data/.tmp/unknown/8936.0’ to
‘C:\grassdata/test3035/data/fcell/renyi_Renyi_1_0’: File exists
WARNING: Unable to rename null file
‘C:\grassdata/test3035/data/.tmp/unknown/9328.1’ to
‘C:\grassdata/test3035/data/cell_misc/renyi_Renyi_2_0/null’: File exists
WARNING: Unable to rename cell file
‘C:\grassdata/test3035/data/.tmp/unknown/9328.0’ to
‘C:\grassdata/test3035/data/fcell/renyi_Renyi_2_0’: File exists

is there some overwriting of existing files in the script? AFAIR there may
be some issues with overwriting existing files in windows os.

Thanks Helmut. Yes, the script does also overwrite some intermediate files (with r.mapcalc). I will look into that and see how to change that.

I wonder though, if I use overwrite on the command line, there is no problem. So than that would be a problem specific to grass.script.mapcalc ?


best regards
Helmut

View this message in context: http://osgeo-org.1560.x6.nabble.com/Unable-to-rename-cell-null-file-NULL-file-messed-up-tp5239350p5239357.html

Sent from the Grass - Dev mailing list archive at Nabble.com.


grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Paulo van Breugel wrote:

Can't answer that, but I see that a related (?) ticket

#2434 isn't related to #2712. #2712 relates specifically to the null
file compression changes. #2434 was opened a year before those changes
were started.

https://trac.osgeo.org/grass/ticket/2434 was retargeted to 7.03? From the
description that issue seems to be very similar to the problem described
above?

The problem described above:

> > WARNING: Unable to rename cell file
> > 'C:\GIS\GrassJvdS/latlong/YLD_NUT/.tmp/unknown/3988.0' to
> > 'C:\GIS\GrassJvdS/latlong/YLD_NUT/fcell/Shan3_CA_Renyi_0_0': File exists
> > WARNING: Unable to rename null file
> > 'C:\GIS\GrassJvdS/latlong_2005/YLD_NUT/.tmp/unknown/4100.1' to
> > 'C:\GIS\GrassJvdS/latlong_2005/YLD_NUT/cell_misc/Shan3_CA_Renyi_1_0/null':
> > File exists

doesn't match the symptoms of either #2434 or #2712. In both of those
cases, the rename() fails with EACCESS ("Permission denied"), which is
symptomatic of the file being open.

This case fails with EEXIST ("File exists"), which suggests that the
destination file wasn't deleted first. On Unix, deleting the original
isn't required (or even desired); rename() will atomically remove any
existing file. Windows generates an error if the destination exists.
So we (try to) remove it first (on all platforms).

  remove(path);
  if (rename(fcb->temp_name, path)) {
      G_warning(_("Unable to rename cell file '%s' to '%s': %s"),
          fcb->temp_name, path, strerror(errno));
      stat = -1;
  }

(close_new() in lib/raster/close.c).

The warning suggests that the file exists and remove() failed to
remove it. On Windows, that can happen if the file is open.

And looking at r.biodiversity.py, I notice:

            grass.mapcalc("$outl = -1 * $outl",
                              outl=out_renyi,
                              overwrite=True,
                              quiet=True)

I.e. it's running r.mapcalc with the same map as both input and
output. That isn't guaranteed to work. And in fact it doesn't, because
the close_maps() function (which closes all of the input maps) is
never actually called.

So when it tries to close the output maps, which involves renaming the
new cell/fcell/null files into place, the original cell/fcell/null
files are still open for reading, meaning that the remove() will fail,
as will the subsequent rename().

Having r.mapcalc close the input maps would avoid that, and should be
done, but ultimately that's fixing the symptoms. r.biodiversity
shouldn't be trying to modify out_renyi "in-place". It should create a
new map then, if necessary, replace the original using g.remove and
g.rename.

One problem with in-place modification is that closing an output map
writes a number of support files (history, range, quant, cats,
histogram). But after closing the output maps, r.mapcalc will
sometimes copy some of the metadata (cats, colors, history) from the
input map. Currently, it only does this if the entire expression is
just a map with optional modifiers, but it may get more "intelligent"
in the future. Clearly, that's a problem if the input map has already
been replaced.

--
Glynn Clements <glynn@gclements.plus.com>

On 03-12-15 05:15, Glynn Clements wrote:

Paulo van Breugel wrote:

Can't answer that, but I see that a related (?) ticket

#2434 isn't related to #2712. #2712 relates specifically to the null
file compression changes. #2434 was opened a year before those changes
were started.

https://trac.osgeo.org/grass/ticket/2434 was retargeted to 7.03? From the
description that issue seems to be very similar to the problem described
above?

The problem described above:

WARNING: Unable to rename cell file
'C:\GIS\GrassJvdS/latlong/YLD_NUT/.tmp/unknown/3988.0' to
'C:\GIS\GrassJvdS/latlong/YLD_NUT/fcell/Shan3_CA_Renyi_0_0': File exists
WARNING: Unable to rename null file
'C:\GIS\GrassJvdS/latlong_2005/YLD_NUT/.tmp/unknown/4100.1' to
'C:\GIS\GrassJvdS/latlong_2005/YLD_NUT/cell_misc/Shan3_CA_Renyi_1_0/null':
File exists

doesn't match the symptoms of either #2434 or #2712. In both of those
cases, the rename() fails with EACCESS ("Permission denied"), which is
symptomatic of the file being open.

This case fails with EEXIST ("File exists"), which suggests that the
destination file wasn't deleted first. On Unix, deleting the original
isn't required (or even desired); rename() will atomically remove any
existing file. Windows generates an error if the destination exists.
So we (try to) remove it first (on all platforms).

  remove(path);
  if (rename(fcb->temp_name, path)) {
      G_warning(_("Unable to rename cell file '%s' to '%s': %s"),
          fcb->temp_name, path, strerror(errno));
      stat = -1;
  }

(close_new() in lib/raster/close.c).

The warning suggests that the file exists and remove() failed to
remove it. On Windows, that can happen if the file is open.

And looking at r.biodiversity.py, I notice:

             grass.mapcalc("$outl = -1 * $outl",
                               outl=out_renyi,
                               overwrite=True,
                               quiet=True)

I changed that already, now output is different from any of the input layers

I.e. it's running r.mapcalc with the same map as both input and
output. That isn't guaranteed to work. And in fact it doesn't, because
the close_maps() function (which closes all of the input maps) is
never actually called.

So when it tries to close the output maps, which involves renaming the
new cell/fcell/null files into place, the original cell/fcell/null
files are still open for reading, meaning that the remove() will fail,
as will the subsequent rename().

Having r.mapcalc close the input maps would avoid that, and should be
done, but ultimately that's fixing the symptoms. r.biodiversity
shouldn't be trying to modify out_renyi "in-place". It should create a
new map then, if necessary, replace the original using g.remove and
g.rename.

Thanks for the detailed explanation. After I changed the r.mapcalc statement the script also works on Windows, but it is good to know better the underlying problem.

One problem with in-place modification is that closing an output map
writes a number of support files (history, range, quant, cats,
histogram). But after closing the output maps, r.mapcalc will
sometimes copy some of the metadata (cats, colors, history) from the
input map. Currently, it only does this if the entire expression is
just a map with optional modifiers, but it may get more "intelligent"
in the future. Clearly, that's a problem if the input map has already
been replaced.

On Dec 2, 2015 11:17 PM, “Glynn Clements” <glynn@gclements.plus.com> wrote:

Paulo van Breugel wrote:

Can’t answer that, but I see that a related (?) ticket

#2434 isn’t related to #2712. #2712 relates specifically to the null
file compression changes. #2434 was opened a year before those changes
were started.

https://trac.osgeo.org/grass/ticket/2434 was retargeted to 7.03? From the
description that issue seems to be very similar to the problem described
above?

The problem described above:

WARNING: Unable to rename cell file
‘C:\GIS\GrassJvdS/latlong/YLD_NUT/.tmp/unknown/3988.0’ to
‘C:\GIS\GrassJvdS/latlong/YLD_NUT/fcell/Shan3_CA_Renyi_0_0’: File exists
WARNING: Unable to rename null file
‘C:\GIS\GrassJvdS/latlong_2005/YLD_NUT/.tmp/unknown/4100.1’ to
‘C:\GIS\GrassJvdS/latlong_2005/YLD_NUT/cell_misc/Shan3_CA_Renyi_1_0/null’:
File exists

doesn’t match the symptoms of either #2434 or #2712. In both of those
cases, the rename() fails with EACCESS (“Permission denied”), which is
symptomatic of the file being open.

This case fails with EEXIST (“File exists”), which suggests that the
destination file wasn’t deleted first. On Unix, deleting the original
isn’t required (or even desired); rename() will atomically remove any
existing file. Windows generates an error if the destination exists.
So we (try to) remove it first (on all platforms).

remove(path);
if (rename(fcb->temp_name, path)) {
G_warning(_(“Unable to rename cell file ‘%s’ to ‘%s’: %s”),
fcb->temp_name, path, strerror(errno));
stat = -1;
}

(close_new() in lib/raster/close.c).

The warning suggests that the file exists and remove() failed to
remove it. On Windows, that can happen if the file is open.

Glynn, any insights about #2434? I remember looking at the code of v.surf.bspline but I haven’t found any obvious differences between it and other modules which use segment library.

Thanks,

Anna

And looking at r.biodiversity.py, I notice:

grass.mapcalc(“$outl = -1 * $outl”,
outl=out_renyi,
overwrite=True,
quiet=True)

I.e. it’s running r.mapcalc with the same map as both input and
output. That isn’t guaranteed to work. And in fact it doesn’t, because
the close_maps() function (which closes all of the input maps) is
never actually called.

So when it tries to close the output maps, which involves renaming the
new cell/fcell/null files into place, the original cell/fcell/null
files are still open for reading, meaning that the remove() will fail,
as will the subsequent rename().

Having r.mapcalc close the input maps would avoid that, and should be
done, but ultimately that’s fixing the symptoms. r.biodiversity
shouldn’t be trying to modify out_renyi “in-place”. It should create a
new map then, if necessary, replace the original using g.remove and
g.rename.

One problem with in-place modification is that closing an output map
writes a number of support files (history, range, quant, cats,
histogram). But after closing the output maps, r.mapcalc will
sometimes copy some of the metadata (cats, colors, history) from the
input map. Currently, it only does this if the entire expression is
just a map with optional modifiers, but it may get more “intelligent”
in the future. Clearly, that’s a problem if the input map has already
been replaced.


Glynn Clements <glynn@gclements.plus.com>


grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev