Skip to content

Commit

Permalink
Set max time series length to 500
Browse files Browse the repository at this point in the history
  • Loading branch information
hrodmn committed Dec 16, 2024
1 parent ca6521e commit 94d6d50
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 26 deletions.
14 changes: 14 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,17 @@ def test_unbounded_start(app, xarray_query_params) -> None:
)

assert response.status_code == 400


def test_too_long(app, xarray_query_params) -> None:
"""Make sure a request for a time series that is too long returns a 400"""
response = app.get(
"/timeseries",
params={
**xarray_query_params,
"datetime": "2010-01-01T00:00:00Z/2024-10-12T23:59:59Z",
"step": "P1D",
},
)

assert response.status_code == 400
15 changes: 13 additions & 2 deletions tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ def test_timeseries_query(
@freeze_time("2024-10-01T00:00:00Z")
def test_timeseries_query_unbounded_intervals(
xarray_query_params: Dict[str, str],
arctic_bounds: Tuple[float, float, float, float],
) -> None:
"""Test unbounded intervals"""
# expect an error if an interval is provided with an unbounded start datetime
Expand All @@ -259,7 +258,6 @@ def test_timeseries_query_unbounded_intervals(

def test_timeseries_mixed_datetime(
xarray_query_params: Dict[str, str],
arctic_bounds: Tuple[float, float, float, float],
) -> None:
"""Test comma-separated mixed points and intervals"""
mixed_query = timeseries_cmr_query(
Expand All @@ -271,3 +269,16 @@ def test_timeseries_mixed_datetime(
),
)
assert len(mixed_query) == 6


def test_timeseries_max_interval(xarray_query_params: Dict[str, str]) -> None:
"""Make sure a request for a very long time series results in an error"""
with pytest.raises(HTTPException):
timeseries_cmr_query(
concept_id=xarray_query_params["concept_id"],
timeseries_params=TimeseriesParams(
datetime="2010-01-01T00:00:00Z/2020-01-01T00:00:00Z",
step="P1D",
temporal_mode="point",
),
)
71 changes: 47 additions & 24 deletions tests/test_timeseries_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,35 @@ class ConceptConfig:
warmup=False,
)
@pytest.mark.parametrize(
["concept_config_id", "bbox_dims"],
["concept_config_id", "bbox_dims", "num_timepoints"],
[
(id, f"{bbox_dims[0]}x{bbox_dims[1]}")
for id in CONCEPT_CONFIGS.keys()
("GAMSSA", f"{bbox_dims[0]}x{bbox_dims[1]}", num_timepoints)
for bbox_dims in [
(64, 64),
(128, 128),
(360, 180),
]
],
)
@pytest.mark.parametrize(
"num_timepoints",
[
10,
500,
1000,
for num_timepoints in [
10,
50,
100,
300,
500,
]
]
+ [
("MUR-SST", f"{bbox_dims[0]}x{bbox_dims[1]}", num_timepoints)
for bbox_dims in [
(64, 64),
(128, 128),
]
for num_timepoints in [
10,
50,
100,
300,
500,
]
],
)
@pytest.mark.parametrize(
Expand Down Expand Up @@ -177,24 +189,35 @@ def run_gif_request():
warmup=False,
)
@pytest.mark.parametrize(
["concept_config_id", "bbox_dims"],
["concept_config_id", "bbox_dims", "num_timepoints"],
[
(id, f"{bbox_dims[0]}x{bbox_dims[1]}")
for id in CONCEPT_CONFIGS.keys()
("GAMSSA", f"{bbox_dims[0]}x{bbox_dims[1]}", num_timepoints)
for bbox_dims in [
(64, 64),
(128, 128),
(360, 180),
]
],
)
@pytest.mark.parametrize(
"num_timepoints",
[
10,
100,
500,
1000,
1500,
for num_timepoints in [
10,
50,
100,
300,
500,
]
]
+ [
("MUR-SST", f"{bbox_dims[0]}x{bbox_dims[1]}", num_timepoints)
for bbox_dims in [
(64, 64),
(128, 128),
]
for num_timepoints in [
10,
50,
100,
300,
500,
]
],
)
def test_statistics(
Expand Down
9 changes: 9 additions & 0 deletions titiler/cmr/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
from titiler.core.resources.enums import ImageType
from titiler.core.resources.responses import GeoJSONResponse

MAX_DATETIMES = 500

# this section should eventually get moved to titiler.extensions.timeseries
timeseries_img_endpoint_params: Dict[str, Any] = {
"responses": {
Expand Down Expand Up @@ -338,6 +340,13 @@ def timeseries_cmr_query(
"list of comma-separated datetime strings",
)

if len(datetime_params) > MAX_DATETIMES:
raise HTTPException(
status_code=400,
detail=f"this request ({len(datetime_params)}) exceeds the maximum number of distinct "
f"time series points/intervals of {MAX_DATETIMES}",
)

return [
CMRQueryParameters(
concept_id=concept_id,
Expand Down

0 comments on commit 94d6d50

Please sign in to comment.