Skip to content

Commit

Permalink
Use sertit 1.43.2
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-braun committed Nov 27, 2024
1 parent a0b6217 commit 0451c0b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
16 changes: 12 additions & 4 deletions eoreader/products/optical/s3_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
from rasterio.errors import NotGeoreferencedWarning
from sertit import path, types, vectors, xml
from sertit.misc import ListEnum
from sertit.rasters import MAX_CORES
from sertit.types import AnyPathStrType, AnyPathType
from shapely.geometry import Polygon, box

Expand Down Expand Up @@ -674,7 +673,7 @@ def _geocode(
resampler.load_resampling_info(cache_file)

band_arr_resampled = resampler.resample(
band_arr.squeeze(), nprocs=MAX_CORES, fill_value=nodata
band_arr.squeeze(), nprocs=utils.get_max_cores(), fill_value=nodata
)

# Save resampling info if needed
Expand Down Expand Up @@ -858,8 +857,17 @@ def _read_nc(

nc.load()
else:
# No need to load here
nc = xr.open_dataset(nc_path, mask_and_scale=True, engine="h5netcdf")
with warnings.catch_warnings():
# Ignore UserWarning: Duplicate dimension names present: dimensions {'bands'} appear more than once in dims=('bands', 'bands').
# We do not yet support duplicate dimension names, but we do allow initial construction of the object.
# We recommend you rename the dims immediately to become distinct, as most xarray functionality is likely to fail silently if you do not.
# To rename the dimensions you will need to set the ``.dims`` attribute of each variable, ``e.g. var.dims=('x0', 'x1')``.
warnings.simplefilter("ignore", category=UserWarning)

# No need to load here
nc = xr.open_dataset(
nc_path, mask_and_scale=True, engine="h5netcdf"
)

if subdataset:
nc = nc[subdataset]
Expand Down
5 changes: 2 additions & 3 deletions eoreader/products/optical/vhr_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from rasterio.enums import Resampling
from rasterio.vrt import WarpedVRT
from sertit import AnyPath, path, rasters, rasters_rio
from sertit.snap import MAX_CORES
from sertit.types import AnyPathStrType, AnyPathType

from eoreader import EOREADER_NAME, utils
Expand Down Expand Up @@ -305,7 +304,7 @@ def _reproject(
dst_crs=self.crs(),
dst_resolution=self.pixel_size,
dst_nodata=self._raw_nodata, # input data should be in integer
num_threads=MAX_CORES,
num_threads=utils.get_max_cores(),
resampling=Resampling.bilinear,
**kwargs,
)
Expand Down Expand Up @@ -596,7 +595,7 @@ def _warp_band(
* int(os.getenv(TILE_SIZE, DEFAULT_TILE_SIZE)) ** 2
/ 1e6,
"dtype": src.meta["dtype"],
"num_threads": MAX_CORES,
"num_threads": utils.get_max_cores(),
}
with rasterio.Env(
**{"GDAL_NUM_THREADS": "ALL_CPUS", "NUM_THREADS": "ALL_CPUS"}
Expand Down
5 changes: 5 additions & 0 deletions eoreader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from rasterio.errors import NotGeoreferencedWarning
from rasterio.rpc import RPC
from sertit import AnyPath, geometry, logs, path, rasters
from sertit.snap import SU_MAX_CORE
from sertit.types import AnyPathStrType, AnyPathType

from eoreader import EOREADER_NAME
Expand Down Expand Up @@ -508,3 +509,7 @@ def load_np(path_to_load: AnyPathStrType, output: AnyPathStrType) -> np.ndarray:
if path.is_cloud_path(path_to_load):
path_to_load = path_to_load.download_to(output)
return np.load(str(path_to_load))


def get_max_cores():
return int(os.getenv(SU_MAX_CORE, os.cpu_count() - 2))
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ shapely>=2.0.0
spyndex>=0.3.0

# SERTIT libs
sertit[full]>=1.42.1
sertit[full]>=1.42.2

# Optimizations
dask[complete]>=2024.5.1 # numpy >= 2
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"rioxarray>=0.10.0",
"odc-geo>=0.4.6",
"geopandas>=0.14.4",
"sertit[full]>=1.42.1",
"sertit[full]>=1.42.2",
"spyndex>=0.3.0",
"pyresample",
"zarr",
Expand Down

0 comments on commit 0451c0b

Please sign in to comment.