Skip to content

Commit 1f80121

Browse files
Merge pull request #72 from nsidc/other-api-improvements
Improvements to code organization & api/docs
2 parents 6c679c3 + 80e43b0 commit 1f80121

File tree

11 files changed

+526
-428
lines changed

11 files changed

+526
-428
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
those on to CMR. This provides much greater flexibility over data search and
1313
makes the interface more consistent with `icepyx` and `earthaccess`.
1414
https://github.com/nsidc/iceflow/issues/51.
15+
- Remove restrictive `fetch_iceflow_df` function from public API. Users should
16+
utilize the search, download, and read functions described in
17+
`doc/getting-started.md` instead.
1518

1619
# v0.3.0
1720

docs/getting-started.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,32 @@ By default, all iceflow-supported datasets are searched. To search for a
3939
specific subset of iceflow-supported datasets, use the `datasets` kwarg:
4040

4141
```
42-
from nsidc.iceflow import ILATM1BDataset
42+
from nsidc.iceflow import Dataset
4343
4444
4545
search_results = find_iceflow_data(
46-
datasets=[ILATM1BDataset(version="1")],
46+
datasets=[Dataset(short_name="ILATM1B", version="1")],
4747
# Lower_left_lon, lower_left_lat, upper_right_lon, upper_right_lat
4848
bounding_box=(-103.125559, -75.180563, -102.677327, -74.798063),
4949
temporal=(dt.date(2009, 11, 1), dt.date(2009, 12, 31)),
5050
)
5151
```
5252

53+
```{include} ../supported_datasets
54+
55+
```
56+
57+
`iceflow` currently supports the following datasets:
58+
59+
| Dataset | Temporal Coverage |
60+
| -------------------------------------------------------- | ----------------------------- |
61+
| [ILATM1B v1](https://nsidc.org/data/ilatm1b/versions/1) | 2009-03-31 through 2012-11-08 |
62+
| [ILATM1B v2](https://nsidc.org/data/ilatm1b/versions/2) | 2013-03-20 through 2019-11-20 |
63+
| [BLATM1B v1](https://nsidc.org/data/blatm1b/versions/1) | 1993-06-23 through 2008-10-30 |
64+
| [ILVIS2 v1](https://nsidc.org/data/ilvis2/versions/1) | 2009-04-14 through 2015-10-31 |
65+
| [ILVIS2 v2](https://nsidc.org/data/ilvis2/versions/2) | 2017-08-25 through 2017-09-20 |
66+
| [GLAH06 v034](https://nsidc.org/data/glah06/versions/34) | 2003-02-20 through 2009-10-11 |
67+
5368
All other keyword arguments to this function (e.g,. `bounding_box`, `temporal`)
5469
map to [CMR](https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html)
5570
search parameters, and are passed un-modified to

docs/notebooks/iceflow-example.ipynb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"import matplotlib.pyplot as plt\n",
4444
"\n",
4545
"from nsidc.iceflow import (\n",
46-
" ILATM1BDataset,\n",
46+
" Dataset,\n",
4747
" download_iceflow_results,\n",
4848
" find_iceflow_data,\n",
4949
" read_iceflow_datafiles,\n",
@@ -77,10 +77,8 @@
7777
"data_path.mkdir(exist_ok=True)\n",
7878
"\n",
7979
"# Define the dataset that we want to search for.\n",
80-
"atm1b_v1_dataset = ILATM1BDataset(version=\"1\")\n",
80+
"atm1b_v1_dataset = Dataset(short_name=\"ILATM1B\", version=\"1\")\n",
8181
"\n",
82-
"# Define the dataset that we want to search for.\n",
83-
"atm1b_v1_dataset = ILATM1BDataset(version=\"1\")\n",
8482
"# Define a bounding box for our area of interest.\n",
8583
"BBOX = (\n",
8684
" -103.125559,\n",
@@ -145,13 +143,13 @@
145143
"name": "stderr",
146144
"output_type": "stream",
147145
"text": [
148-
"\u001b[32m2025-06-10 11:00:52.469\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mnsidc.iceflow.data.fetch\u001b[0m:\u001b[36m_download_iceflow_search_result\u001b[0m:\u001b[36m72\u001b[0m - \u001b[1mDownloading 1 granules to downloaded-data/ILATM1B_1.\u001b[0m\n"
146+
"\u001b[32m2025-06-12 17:43:41.316\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mnsidc.iceflow.data.fetch\u001b[0m:\u001b[36m_download_iceflow_search_result\u001b[0m:\u001b[36m62\u001b[0m - \u001b[1mDownloading 1 granules to downloaded-data/ILATM1B_1.\u001b[0m\n"
149147
]
150148
},
151149
{
152150
"data": {
153151
"application/vnd.jupyter.widget-view+json": {
154-
"model_id": "28d39c1f197042658119f2853eb69670",
152+
"model_id": "f23a8e430d9e4a8db9a654bbbb9e86b8",
155153
"version_major": 2,
156154
"version_minor": 0
157155
},
@@ -165,7 +163,7 @@
165163
{
166164
"data": {
167165
"application/vnd.jupyter.widget-view+json": {
168-
"model_id": "1e4341335843469e8757c8ebe0c3ca3a",
166+
"model_id": "11cf2a6ec02c404d81dc3a9635f6ed90",
169167
"version_major": 2,
170168
"version_minor": 0
171169
},
@@ -179,7 +177,7 @@
179177
{
180178
"data": {
181179
"application/vnd.jupyter.widget-view+json": {
182-
"model_id": "b43146c391224e4494a864e6c3f0f364",
180+
"model_id": "baaff268fc2c413e9606ccb33c431c38",
183181
"version_major": 2,
184182
"version_minor": 0
185183
},

docs/notebooks/iceflow-with-icepyx.ipynb

Lines changed: 379 additions & 311 deletions
Large diffs are not rendered by default.

src/nsidc/iceflow/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,26 @@
2020
from nsidc.iceflow.api import make_iceflow_parquet
2121
from nsidc.iceflow.data.fetch import download_iceflow_results, find_iceflow_data
2222
from nsidc.iceflow.data.models import (
23-
ALL_DATASETS,
23+
Dataset,
24+
IceflowDataFrame,
25+
)
26+
from nsidc.iceflow.data.read import read_iceflow_datafiles
27+
from nsidc.iceflow.data.supported_datasets import (
28+
ALL_SUPPORTED_DATASETS,
2429
BLATM1BDataset,
2530
GLAH06Dataset,
26-
IceflowDataFrame,
2731
ILATM1BDataset,
2832
ILVIS2Dataset,
2933
)
30-
from nsidc.iceflow.data.read import read_iceflow_datafiles
3134
from nsidc.iceflow.itrf.converter import transform_itrf
3235

3336
__version__ = "v1.0.0"
3437

3538

3639
__all__ = [
37-
"ALL_DATASETS",
40+
"ALL_SUPPORTED_DATASETS",
3841
"BLATM1BDataset",
42+
"Dataset",
3943
"GLAH06Dataset",
4044
"ILATM1BDataset",
4145
"ILVIS2Dataset",

src/nsidc/iceflow/api.py

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,11 @@
88
import dask.dataframe as dd
99
from loguru import logger
1010

11-
from nsidc.iceflow.data.fetch import download_iceflow_results, find_iceflow_data
12-
from nsidc.iceflow.data.models import (
13-
ALL_DATASETS,
14-
BoundingBoxLike,
15-
Dataset,
16-
IceflowDataFrame,
17-
TemporalRange,
18-
)
1911
from nsidc.iceflow.data.read import read_iceflow_datafiles
12+
from nsidc.iceflow.data.supported_datasets import ALL_SUPPORTED_DATASETS
2013
from nsidc.iceflow.itrf.converter import transform_itrf
2114

2215

23-
def fetch_iceflow_df(
24-
*,
25-
bounding_box: BoundingBoxLike,
26-
temporal: TemporalRange,
27-
datasets: list[Dataset] = ALL_DATASETS,
28-
output_dir: Path,
29-
# TODO: also add option for target epoch!!
30-
output_itrf: str | None = None,
31-
) -> IceflowDataFrame:
32-
"""Search for data matching parameters and return an IceflowDataframe.
33-
34-
Optionally transform data to the given ITRF for consistency.
35-
36-
Note: a potentially large amount of data may be returned, especially if the
37-
user requests a large spatial/temporal area across multiple datasets. The
38-
result may not even fit in memory!
39-
40-
Consider using `make_iceflow_parquet` to store downloaded data in parquet
41-
format.
42-
"""
43-
44-
iceflow_search_reuslts = find_iceflow_data(
45-
bounding_box=bounding_box,
46-
temporal=temporal,
47-
datasets=datasets,
48-
)
49-
50-
downloaded_files = download_iceflow_results(
51-
iceflow_search_results=iceflow_search_reuslts,
52-
output_dir=output_dir,
53-
)
54-
55-
iceflow_df = read_iceflow_datafiles(downloaded_files)
56-
57-
if output_itrf is not None:
58-
iceflow_df = transform_itrf(
59-
data=iceflow_df,
60-
target_itrf=output_itrf,
61-
)
62-
63-
return iceflow_df
64-
65-
6616
def make_iceflow_parquet(
6717
*,
6818
data_dir: Path,
@@ -97,7 +47,7 @@ def make_iceflow_parquet(
9747

9848
all_subdirs = [
9949
data_dir / ds.subdir_name
100-
for ds in ALL_DATASETS
50+
for ds in ALL_SUPPORTED_DATASETS
10151
if (data_dir / ds.subdir_name).is_dir()
10252
]
10353
for subdir in all_subdirs:

src/nsidc/iceflow/data/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
from __future__ import annotations
22

33
from nsidc.iceflow.data.models import (
4-
ALL_DATASETS,
5-
BLATM1BDataset,
64
Dataset,
5+
)
6+
from nsidc.iceflow.data.supported_datasets import (
7+
ALL_SUPPORTED_DATASETS,
8+
BLATM1BDataset,
79
GLAH06Dataset,
810
ILATM1BDataset,
911
ILVIS2Dataset,
1012
)
1113

1214
__all__ = [
13-
"ALL_DATASETS",
15+
"ALL_SUPPORTED_DATASETS",
1416
"BLATM1BDataset",
1517
"Dataset",
1618
"GLAH06Dataset",

src/nsidc/iceflow/data/fetch.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
from pathlib import Path
44

55
import earthaccess
6+
import pydantic
67
from loguru import logger
78

89
from nsidc.iceflow.data.models import (
9-
ALL_DATASETS,
1010
Dataset,
1111
IceflowSearchResult,
1212
IceflowSearchResults,
1313
)
14+
from nsidc.iceflow.data.supported_datasets import ALL_SUPPORTED_DATASETS
1415

1516

1617
def _find_iceflow_data_for_dataset(
@@ -75,9 +76,10 @@ def _download_iceflow_search_result(
7576
return downloaded_filepaths
7677

7778

79+
@pydantic.validate_call()
7880
def find_iceflow_data(
7981
*,
80-
datasets: list[Dataset] = ALL_DATASETS,
82+
datasets: list[Dataset] = ALL_SUPPORTED_DATASETS,
8183
**search_kwargs,
8284
) -> IceflowSearchResults:
8385
"""Find iceflow-compatible data using search kwargs.

src/nsidc/iceflow/data/models.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -205,46 +205,12 @@ class ATM1BDataset(Dataset):
205205
short_name: ATM1BShortName
206206

207207

208-
class ILATM1BDataset(ATM1BDataset):
209-
short_name: ATM1BShortName = "ILATM1B"
210-
version: Literal["1", "2"]
211-
212-
213-
class BLATM1BDataset(ATM1BDataset):
214-
short_name: ATM1BShortName = "BLATM1B"
215-
# There is only 1 version of BLATM1B
216-
version: Literal["1"] = "1"
217-
218-
219-
class ILVIS2Dataset(Dataset):
220-
short_name: DatasetShortName = "ILVIS2"
221-
version: Literal["1", "2"]
222-
223-
224-
class GLAH06Dataset(Dataset):
225-
short_name: DatasetShortName = "GLAH06"
226-
# Note: some dataset versions are padded with zeros like GLAH06. NSIDC
227-
# documentation refers to "version 34", but CMR only recognizes "034". As a
228-
# rule-of-thumb, ICESat-2, SMAP, and GLAH/GLA datasets have zero padding.
229-
version: Literal["034"] = "034"
230-
231-
232208
# This mirrors the bounding box construct in `earthaccess` and `icepyx`: a
233209
# list/float of len 4:
234210
# (lower_left_lon, lower_left_lat, upper_right_lon, upper_right_lat)
235211
BoundingBoxLike = list[float] | tuple[float, float, float, float]
236212

237213

238-
ALL_DATASETS: list[Dataset] = [
239-
ILATM1BDataset(version="1"),
240-
ILATM1BDataset(version="2"),
241-
BLATM1BDataset(version="1"),
242-
ILVIS2Dataset(version="1"),
243-
ILVIS2Dataset(version="2"),
244-
GLAH06Dataset(),
245-
]
246-
247-
248214
TemporalRange = tuple[dt.datetime | dt.date, dt.datetime | dt.date]
249215

250216

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from __future__ import annotations
2+
3+
from typing import Literal
4+
5+
from nsidc.iceflow.data.models import (
6+
ATM1BDataset,
7+
ATM1BShortName,
8+
Dataset,
9+
DatasetShortName,
10+
)
11+
12+
13+
class ILATM1BDataset(ATM1BDataset):
14+
short_name: ATM1BShortName = "ILATM1B"
15+
version: Literal["1", "2"]
16+
17+
18+
class BLATM1BDataset(ATM1BDataset):
19+
short_name: ATM1BShortName = "BLATM1B"
20+
# There is only 1 version of BLATM1B
21+
version: Literal["1"] = "1"
22+
23+
24+
class ILVIS2Dataset(Dataset):
25+
short_name: DatasetShortName = "ILVIS2"
26+
version: Literal["1", "2"]
27+
28+
29+
class GLAH06Dataset(Dataset):
30+
short_name: DatasetShortName = "GLAH06"
31+
# Note: some dataset versions are padded with zeros like GLAH06. NSIDC
32+
# documentation refers to "version 34", but CMR only recognizes "034". As a
33+
# rule-of-thumb, ICESat-2, SMAP, and GLAH/GLA datasets have zero padding.
34+
version: Literal["034"] = "034"
35+
36+
37+
ALL_SUPPORTED_DATASETS: list[Dataset] = [
38+
ILATM1BDataset(version="1"),
39+
ILATM1BDataset(version="2"),
40+
BLATM1BDataset(version="1"),
41+
ILVIS2Dataset(version="1"),
42+
ILVIS2Dataset(version="2"),
43+
GLAH06Dataset(),
44+
]

0 commit comments

Comments
 (0)