Skip to content

Commit d5388ba

Browse files
committed
Pass-through search kwargs to earthaccess.search_data.
1 parent 2ac7055 commit d5388ba

File tree

7 files changed

+43
-38
lines changed

7 files changed

+43
-38
lines changed

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
Generate an Elevation Timeseries" notebook.
88
- Filter for cloud-hosted data, avoiding duplicate granule results from
99
`fetch.find_iceflow_data`
10-
- Make "bounding box" construct consistent with `icepyx` and `earthaccess`. This
11-
simplifies the api, and means the user no longer needs to import `BoundingBox`
12-
to query for data.
10+
- Pass through search kwargs to `earthaccess` without any type validation. This
11+
allows earthaccess to do watever validation it needs to, and then it passes
12+
those on to CMR. This provides much greater flexibility over data search and
13+
makes the interface more consistent with `icepyx` and `earthaccess`.
14+
https://github.com/nsidc/iceflow/issues/51.
1315

1416
# v0.3.0
1517

docs/getting-started.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@ search_results = find_iceflow_data(
3535
)
3636
```
3737

38+
By default, all iceflow-supported datasets are searched. To search for a
39+
specific subset of iceflow-supported datasets, use the `datasets` kwarg:
40+
41+
```
42+
from nsidc.iceflow import ILATM1BDataset
43+
44+
45+
search_results = find_iceflow_data(
46+
datasets=[ILATM1BDataset(version="1")],
47+
# Lower_left_lon, lower_left_lat, upper_right_lon, upper_right_lat
48+
bounding_box=(-103.125559, -75.180563, -102.677327, -74.798063),
49+
temporal=(dt.date(2009, 11, 1), dt.date(2009, 12, 31)),
50+
)
51+
```
52+
53+
All other keyword arguments to this function (e.g,. `bounding_box`, `temporal`)
54+
map to [CMR](https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html)
55+
search parameters, and are passed un-modified to
56+
[earthaccess.search_data](https://earthaccess.readthedocs.io/en/latest/user-reference/api/api/#earthaccess.api.search_data)
57+
to perform the search.
58+
3859
### Downloading data
3960

4061
Once search results have been found, download data with

docs/notebooks/iceflow-example.ipynb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"import matplotlib.pyplot as plt\n",
4444
"\n",
4545
"from nsidc.iceflow import (\n",
46-
" DatasetSearchParameters,\n",
4746
" ILATM1BDataset,\n",
4847
" download_iceflow_results,\n",
4948
" find_iceflow_data,\n",
@@ -121,11 +120,9 @@
121120
],
122121
"source": [
123122
"search_results = find_iceflow_data(\n",
124-
" dataset_search_params=DatasetSearchParameters(\n",
125-
" datasets=[atm1b_v1_dataset],\n",
126-
" bounding_box=BBOX,\n",
127-
" temporal=date_range,\n",
128-
" ),\n",
123+
" datasets=[atm1b_v1_dataset],\n",
124+
" bounding_box=BBOX,\n",
125+
" temporal=date_range,\n",
129126
")\n",
130127
"len(search_results)"
131128
]

docs/notebooks/iceflow-with-icepyx.ipynb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,6 @@
763763
"import xarray as xr\n",
764764
"\n",
765765
"from nsidc.iceflow import (\n",
766-
" DatasetSearchParameters,\n",
767766
" IceflowDataFrame,\n",
768767
" download_iceflow_results,\n",
769768
" find_iceflow_data,\n",
@@ -821,7 +820,7 @@
821820
"source": [
822821
"Next we will use the `find_iceflow_data` function from the `iceflow` API to find data matching our area of interest.\n",
823822
"\n",
824-
"By default, `DatasetSearchParameters` will include all `iceflow` supported datasets, unless one or more are specified as a filter with the `datasets` kwarg. There may be warnings raised about there not being search results for specific datasets supported by `iceflow`."
823+
"By default, `find_iceflow_data` will include all `iceflow` supported datasets, unless one or more are specified as a filter with the `datasets` kwarg. There may be warnings raised about there not being search results for specific datasets supported by `iceflow`."
825824
]
826825
},
827826
{
@@ -850,10 +849,8 @@
850849
],
851850
"source": [
852851
"search_results = find_iceflow_data(\n",
853-
" dataset_search_params=DatasetSearchParameters(\n",
854-
" bounding_box=BBOX,\n",
855-
" temporal=DATE_RANGE,\n",
856-
" ),\n",
852+
" bounding_box=BBOX,\n",
853+
" temporal=DATE_RANGE,\n",
857854
")\n",
858855
"len(search_results)"
859856
]

src/nsidc/iceflow/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from nsidc.iceflow.data.models import (
2323
ALL_DATASETS,
2424
BLATM1BDataset,
25-
DatasetSearchParameters,
2625
GLAH06Dataset,
2726
IceflowDataFrame,
2827
ILATM1BDataset,
@@ -37,7 +36,6 @@
3736
__all__ = [
3837
"ALL_DATASETS",
3938
"BLATM1BDataset",
40-
"DatasetSearchParameters",
4139
"GLAH06Dataset",
4240
"ILATM1BDataset",
4341
"ILVIS2Dataset",

src/nsidc/iceflow/data/fetch.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
11
from __future__ import annotations
22

3-
import datetime as dt
43
from pathlib import Path
54

65
import earthaccess
76
from loguru import logger
87

98
from nsidc.iceflow.data.models import (
109
ALL_DATASETS,
11-
BoundingBoxLike,
1210
Dataset,
1311
IceflowSearchResult,
1412
IceflowSearchResults,
15-
TemporalRange,
1613
)
1714

1815

1916
def _find_iceflow_data_for_dataset(
2017
*,
2118
dataset: Dataset,
22-
bounding_box: BoundingBoxLike,
23-
temporal: tuple[dt.datetime | dt.date, dt.datetime | dt.date],
19+
**search_kwargs,
2420
) -> IceflowSearchResult:
2521
earthaccess.login()
2622

27-
ctx_string = (
28-
f"{dataset.short_name=} {dataset.version=} with {bounding_box=} {temporal=}"
29-
)
23+
ctx_string = f"{dataset.short_name=} {dataset.version=} with {search_kwargs=}"
3024

3125
try:
3226
granules_list = earthaccess.search_data(
@@ -36,8 +30,7 @@ def _find_iceflow_data_for_dataset(
3630
# non-cloud, we may get duplicate granules as long as the ECS copy
3731
# remains.
3832
cloud_hosted=True,
39-
bounding_box=bounding_box,
40-
temporal=temporal,
33+
**search_kwargs,
4134
)
4235
except IndexError:
4336
# There's no data matching the given parameters.
@@ -84,17 +77,20 @@ def _download_iceflow_search_result(
8477

8578
def find_iceflow_data(
8679
*,
87-
bounding_box: BoundingBoxLike,
88-
temporal: TemporalRange,
8980
datasets: list[Dataset] = ALL_DATASETS,
81+
**search_kwargs,
9082
) -> IceflowSearchResults:
91-
"""Find iceflow-compatible data using spatial and temporal constraints."""
83+
"""Find iceflow-compatible data using search kwargs.
84+
85+
`search_kwargs` are passed to `earthaccess.search_data`, allowing for
86+
CMR-supported filters (see
87+
https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html)
88+
"""
9289
iceflow_search_results = []
9390
for dataset in datasets:
9491
iceflow_search_result = _find_iceflow_data_for_dataset(
9592
dataset=dataset,
96-
bounding_box=bounding_box,
97-
temporal=temporal,
93+
**search_kwargs,
9894
)
9995
iceflow_search_results.append(iceflow_search_result)
10096

src/nsidc/iceflow/data/models.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,6 @@ class GLAH06Dataset(Dataset):
248248
TemporalRange = tuple[dt.datetime | dt.date, dt.datetime | dt.date]
249249

250250

251-
class DatasetSearchParameters(pydantic.BaseModel):
252-
datasets: list[Dataset] = ALL_DATASETS
253-
bounding_box: BoundingBoxLike
254-
temporal: TemporalRange
255-
256-
257251
class IceflowSearchResult(pydantic.BaseModel):
258252
dataset: Dataset
259253
granules: list[DataGranule]

0 commit comments

Comments
 (0)