2

I wanted to able to delete a temporary file, after opening it with rioxarray and start to process the final product.

I followed two ideas:

a)

with rioxarray.open_rasterio(temp_file) as raster:
  # do processing
  # save output
os.remove(file)

b)

raster = rioxarray.open_rasterio(temp_file)
# do processing
# save result somewhere
del raster
gc.collect()
os.remove(file)

Both didn't work because, the file was still opened. How can this temporary file be deleted?

0

1 Answer 1

0

xarray leaves the files open unless you call close. You can read more about it here: http://xarray.pydata.org/en/stable/io.html

The file_cache_maxsize option is also useful to know about: http://xarray.pydata.org/en/stable/generated/xarray.set_options.html

1
  • The docs you link to states using a with statement automatically closes the dataset.
    – user2856
    Feb 16, 2021 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.