[GRASS-dev] [GRASS-user] temporary files of grass.script.array

Glynn Clements glynn at gclements.plus.com
Tue Feb 3 07:23:41 PST 2015


Johannes Radinger wrote:

> In GRASS 7 (RC1) python it is possible to export a raster map to an array
> which can be used e.g. by Numpy.
> 
> For example:
> 
> import grass.script.array as garray
> x1 = garray.array()
> x1.read("my_raster")
> 
> It seems that this creates a temporary file in the .tmp folder of the
> respective
> location. I am not sure if this has been existing before, but these
> temporary
> files are not deleted after e.g. x1 is not used anymore (i.e. the
> calculation of
> the script finished). So do I need to manually (in the python script) close
> that x1 so
> that the associated temporary file gets deleted (and if yes how?)? Otherwise
> when using this procedure to do numpy calculations in loops the tmp-files
> pile up quite fast.
> 
> Of course I can empty the tmp folder after every loop, but I am not sure
> if this is really the right way.

The temporary files were supposed to be deleted when the array object
was destroyed. However, this relied upon the ._close() method, which
is no longer used. r64426 (trunk) should fix this.

Apart from that, you can manually delete the temporary file for an
array object with e.g. grass.script.try_remove(x1.filename).

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


More information about the grass-dev mailing list