Skip to content

Commit

Permalink
FIX: Fix management of numpy temporary files saved on disk
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-braun committed Jan 10, 2025
1 parent 04fa7cb commit df69796
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- FIX: Fix the computation of parametric spectral indices [#193](https://github.com/sertit/eoreader/issues/193)
- FIX: Fix retrieval of quicklook path for SAOCOM when already computed
- FIX: Write data using `windowed=True` for very big rasters (> 50 Go) to avoid core dumps
- FIX: Fix management of numpy temporary files saved on disk
- OPTIM: Cache the access to any archived file list, as this operation is expensive when done with large archives stored on the cloud (and thus better done only once).
- CI: Remove useless verbosity in CI
- CI: GDAL performance tuning by tweaking `rasterio`'s env
Expand Down
6 changes: 3 additions & 3 deletions eoreader/products/optical/dimap_v2_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def _manage_invalid_pixels(

np.save(str(mask_path), nodata)
else:
nodata = utils.load_np(mask_path, self._tmp_output)
nodata = utils.load_np(mask_path, self._tmp_process)
except InvalidProductError:
pass

Expand Down Expand Up @@ -922,7 +922,7 @@ def _open_clouds(
)
np.save(str(cld_path), cld_arr)
else:
cld_arr = utils.load_np(cld_path, self._tmp_output)
cld_arr = utils.load_np(cld_path, self._tmp_process)

# Rasterize gives a 2D array, we want a 3D array
cld_arr = np.expand_dims(cld_arr, axis=0)
Expand Down Expand Up @@ -1128,7 +1128,7 @@ def _load_nodata(
)
np.save(str(nodata_path), nodata)
else:
nodata = utils.load_np(nodata_path, self._tmp_output)
nodata = utils.load_np(nodata_path, self._tmp_process)

return nodata

Expand Down
2 changes: 1 addition & 1 deletion eoreader/products/optical/s3_olci_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ def _rad_2_refl(

else:
# Open rad_2_refl_coeff (resampled to band_arr size)
rad_2_refl_coeff = utils.load_np(rad_2_refl_path, self._tmp_output)
rad_2_refl_coeff = utils.load_np(rad_2_refl_path, self._tmp_process)

return band_arr * rad_2_refl_coeff

Expand Down
4 changes: 2 additions & 2 deletions eoreader/products/optical/s3_slstr_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ def _rad_2_refl(

else:
# Open rad_2_refl_coeff (resampled to band_arr size)
rad_2_refl_coeff = utils.load_np(rad_2_refl_path, self._tmp_output)
rad_2_refl_coeff = utils.load_np(rad_2_refl_path, self._tmp_process)

return band_arr * rad_2_refl_coeff

Expand Down Expand Up @@ -892,7 +892,7 @@ def _compute_sza_img_grid(self, suffix) -> np.ndarray:

else:
# Open sza_img (resampled to band_arr size)
sza_img = utils.load_np(sza_img_path, self._tmp_output)
sza_img = utils.load_np(sza_img_path, self._tmp_process)

return sza_img

Expand Down
8 changes: 4 additions & 4 deletions eoreader/products/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ def __init__(
self._tmp_output = tempfile.TemporaryDirectory()
self._output = AnyPath(self._tmp_output.name)

# Temporary file path (private)
self._tmp_process = self._output.joinpath(f"tmp_{self.condensed_name}")
os.makedirs(self._tmp_process, exist_ok=True)

# Pre initialization
self._pre_init(**kwargs)

Expand Down Expand Up @@ -297,10 +301,6 @@ def __init__(
# Condensed name
self.condensed_name = self._get_condensed_name()

# Temporary file path (private)
self._tmp_process = self._output.joinpath(f"tmp_{self.condensed_name}")
os.makedirs(self._tmp_process, exist_ok=True)

def __del__(self):
"""Cleaning up _tmp directory"""
self.clear()
Expand Down

0 comments on commit df69796

Please sign in to comment.