Skip to content

Commit 7fc157b

Browse files
committed
release prep
1 parent 1f48cdf commit 7fc157b

1 file changed

Lines changed: 38 additions & 27 deletions

File tree

xcube_multistore/accessors/stac.py

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
from xcube_multistore.accessor import Accessor
2929
from xcube_multistore.visualization import GeneratorState
3030

31-
_NB_PIXELS = int(2e4 * 2e4) * 5 * 4
31+
_NB_PIXELS = int(2e4 * 2e4) * 50
3232
_MAX_DAYS = {
3333
"sentinel-2-l1c": 100,
3434
"sentinel-2-l2a": 100,
35-
"sentinel-3-syn-2-syn-ntc": 7,
36-
"sentinel-3-sl-2-lst-ntc": 7,
37-
"sentinel-3-synergy-syn-l2-netcdf": 7,
38-
"sentinel-3-slstr-lst-l2-netcdf": 7,
35+
"sentinel-3-syn-2-syn-ntc": 2,
36+
"sentinel-3-sl-2-lst-ntc": 2,
37+
"sentinel-3-synergy-syn-l2-netcdf": 2,
38+
"sentinel-3-slstr-lst-l2-netcdf": 2,
3939
}
4040

4141
_NUM_BANDS = {
@@ -82,15 +82,13 @@ def open_data(self, data_id: str, **open_params) -> xr.Dataset:
8282

8383
@staticmethod
8484
def _split_time_range(data_id: str, open_params: dict):
85-
if "asset_names" in open_params:
86-
nb_vars = len(open_params["asset_names"])
87-
else:
88-
nb_vars = _NUM_BANDS[data_id]
85+
# get number days
8986
start, end = open_params["time_range"]
9087
start = datetime.date.fromisoformat(start)
9188
end = datetime.date.fromisoformat(end)
92-
total_days = (end - start).days
93-
nb_ts = total_days // 2
89+
nb_days = (end - start).days
90+
91+
# get number spatial pixel
9492
spatial_res = open_params["spatial_res"]
9593
if not isinstance(spatial_res, Iterable):
9694
spatial_res = (spatial_res, spatial_res)
@@ -104,25 +102,38 @@ def _split_time_range(data_id: str, open_params: dict):
104102
nb_pixels_spatial = int(bbox_width / spatial_res[0]) * int(
105103
bbox_width / spatial_res[1]
106104
)
107-
nb_pixels = nb_pixels_spatial * nb_ts * nb_vars
105+
106+
# get number variables
107+
if "asset_names" in open_params:
108+
nb_vars = len(open_params["asset_names"])
109+
else:
110+
nb_vars = _NUM_BANDS[data_id]
111+
112+
nb_pixels = nb_pixels_spatial * nb_days * nb_vars
108113
nb_splits = nb_pixels // _NB_PIXELS
109114
if nb_splits == 0:
110115
nb_splits = 1
111116

112-
base = total_days // nb_splits
117+
step = nb_days // nb_splits
113118
max_days = _MAX_DAYS[data_id]
114-
if base > max_days:
115-
base = _MAX_DAYS[data_id]
116-
nb_splits = total_days // max_days
117-
remainder = total_days % nb_splits
118-
time_ranges = []
119-
current = start
120-
for i in range(nb_splits):
121-
length = base + (1 if i < remainder else 0)
122-
sub_start = current
123-
sub_end = current + datetime.timedelta(days=length)
124-
time_ranges.append(
125-
(sub_start.strftime("%Y-%m-%d"), sub_end.strftime("%Y-%m-%d"))
126-
)
127-
current = sub_end + datetime.timedelta(days=1)
119+
if step > max_days:
120+
step = max_days
121+
nb_splits = nb_days // step
122+
123+
if nb_splits == 1:
124+
time_ranges = [(start.strftime("%Y-%m-%d"), end.strftime("%Y-%m-%d"))]
125+
else:
126+
time_ranges = []
127+
current = start
128+
step -= 1
129+
for i in range(nb_splits + 1):
130+
sub_start = current
131+
if i == nb_splits:
132+
sub_end = end
133+
else:
134+
sub_end = current + datetime.timedelta(days=step)
135+
time_ranges.append(
136+
(sub_start.strftime("%Y-%m-%d"), sub_end.strftime("%Y-%m-%d"))
137+
)
138+
current = sub_end + datetime.timedelta(days=1)
128139
return time_ranges

0 commit comments

Comments
 (0)