Skip to content

Commit 346fca4

Browse files
authored
Merge branch 'main' into update-search-user-guide
2 parents 303d1c0 + f08b89c commit 346fca4

31 files changed

+2838
-2674
lines changed

.github/workflows/test-mindeps.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
uses: actions/[email protected]
2525

2626
- name: Install uv
27-
uses: astral-sh/setup-uv@v6.0.1
27+
uses: astral-sh/setup-uv@v6.1.0
2828
with:
2929
enable-cache: true
3030

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ repos:
1010
# Validate format
1111
- id: check-yaml
1212
args: ["--unsafe"]
13+
exclude: ".*/vcr_cassettes/.*\\.yaml"
1314
- id: check-toml
1415
- id: check-json
1516
# Check for common mistakes

CHANGELOG.md

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,58 +7,69 @@ and this project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- By default, _disable_ progress bars during downloading.
13+
([#612](https://github.com/nsidc/earthaccess/issues/612))
14+
([@Sherwin-14](https://github.com/Sherwin-14))
15+
- Updated bug and triage label names in bug Issue template.
16+
([#998](https://github.com/nsidc/earthaccess/pull/998))
17+
([@asteiker](https://github.com/asteiker))
18+
- `download` now raises `DownloadFailure` exception on failure.
19+
([#612](https://github.com/nsidc/earthaccess/issues/612))
20+
([@Sherwin-14](https://github.com/Sherwin-14))
21+
- `GESDISC` should be `GES_DISC` in docstrings.
22+
([#1037](https://github.com/nsidc/earthaccess/issues/1037))
23+
([@abarciauskas-bgse](https://github.com/abarciauskas-bgse))
1024

1125
### Added
1226

27+
- Add notebook demonstrating workflow with TEMPO Level 3 data as a virtual dataset
28+
([#924](https://github.com/nsidc/earthaccess/pull/924))
29+
([@danielfromearth](https://github.com/danielfromearth))
30+
- `get_s3_filesystem` now accepts an `endpoint` argument for specifying a credentials url.
31+
([#602](https://github.com/nsidc/earthaccess/issues/602))
32+
([@rwegener2](https://github.com/rwegener2))
33+
- s3 `download` now checks for existing files.
34+
([#807](https://github.com/nsidc/earthaccess/issues/807))
35+
([@Sherwin-14](https://github.com/Sherwin-14))
1336
- Added triaging guide ([#754](https://github.com/nsidc/earthaccess/issues/754))
1437
([@Sherwin-14](https://github.com/Sherwin-14))
1538
([@mfisher87](https://github.com/mfisher87))
39+
- `download` now returns Path consistently.
40+
([#595])(https://github.com/nsidc/earthaccess/issues/595)
41+
([@Sherwin-14](https://github.com/Sherwin-14))
42+
- Users may now authenticate with an existing Earthdata login token with
43+
environment variable `EARTHDATA_TOKEN`
44+
([#484](https://github.com/nsidc/earthaccess/issues/484))
45+
([@kgrimes2](https://github.com/kgrimes2))
1646

1747
### Removed
1848

49+
- **Breaking:** Removed `has_granules=true` and `include_granule_counts=true`
50+
as default parameters upon creation of a `DataCollections` instance.
51+
([#884](https://github.com/nsidc/earthaccess/issues/884))
52+
([@Sherwin-14](https://github.com/Sherwin-14))
1953
- Python 3.10 is no longer supported.
2054
([#966](https://github.com/nsidc/earthaccess/pull/966))
2155
([@weiji14](https://github.com/weiji14))
2256

23-
### Added
24-
- Add notebook demonstrating workflow with TEMPO Level 3 data as a virtual dataset ([#924](https://github.com/nsidc/earthaccess/pull/924))
25-
([@danielfromearth](https://github.com/danielfromearth))
26-
- `get_s3_filesystem` now accepts an `endpoint` argument for specifying a credentials url.
27-
([#602](https://github.com/nsidc/earthaccess/issues/602))
28-
([@rwegener2](https://github.com/rwegener2))
29-
30-
- s3 `download` now checks for existing files.
31-
([#807](https://github.com/nsidc/earthaccess/issues/807))
32-
([@Sherwin-14](https://github.com/Sherwin-14))
33-
34-
35-
### Changed
36-
37-
- By default, _disable_ progress bars during downloading.
38-
([#612](https://github.com/nsidc/earthaccess/issues/612))
39-
([@Sherwin-14](https://github.com/Sherwin-14))
40-
41-
- Updated bug and triage label names in bug Issue template.
42-
([#998](https://github.com/nsidc/earthaccess/pull/998))
43-
([@asteiker](https://github.com/asteiker))
44-
45-
- `download` now raises `DownloadFailure` exception on failure.
46-
([#612](https://github.com/nsidc/earthaccess/issues/612))
47-
([@Sherwin-14](https://github.com/Sherwin-14))
48-
4957
### Fixed
58+
5059
- Corrected Harmony typo in notebooks/Demo.ipynb([#995](https://github.com/nsidc/earthaccess/issues/995))([stelios-c](https://github.com/stelios-c))
5160

5261
## [v0.14.0] - 2025-02-11
5362

5463
### Added
64+
5565
- `search_datasets` now accepts a `has_granules` keyword argument. Use
5666
`has_granules=False` to search for metadata about collections with no
5767
associated granules. The default value set in `DataCollections` remains `True`.
5868
([#939](https://github.com/nsidc/earthaccess/issues/939))
5969
([**@juliacollins**](https://github.com/juliacollins))
6070

6171
### Changed
72+
6273
- **Breaking**: earthaccess will now raise an exception when login credentials are
6374
rejected. If you need the old behavior, please use a `try` block.
6475
([#946](https://github.com/nsidc/earthaccess/pull/946))
@@ -68,6 +79,7 @@ and this project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
6879
## [v0.13.0] - 2025-01-28
6980

7081
### Added
82+
7183
- VirtualiZarr: earthaccess can open archival formats (NetCDF, HDF5) as if they were Zarr by leveraging VirtualiZarr
7284
In order to use this capability the collection needs to be supported by OPeNDAP and have dmrpp files.
7385
See [example notebooks](https://github.com/nsidc/earthaccess/blob/main/docs/tutorials/dmrpp-virtualizarr.ipynb)!
@@ -83,7 +95,6 @@ and this project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
8395
([#913](https://github.com/nsidc/earthaccess/issues/913))
8496
([**@hailiangzhang**](https://github.com/hailiangzhang))
8597

86-
8798
## [v0.12.0] - 2024-11-13
8899

89100
### Changed

docs/howto/authenticate.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ use:
3131
auth = earthaccess.login(strategy="environment")
3232
```
3333

34+
Alternatively, you can use an existing Earthdata Login token by setting the environment
35+
variable `EARTHDATA_TOKEN` to it and using the same "environment" strategy, above.
36+
3437
If you wish to enter your Earthdata Login credentials when prompted, with
3538
optional persistence to your `.netrc` file (see below), specify the interactive
3639
strategy:
@@ -54,7 +57,8 @@ credentials in two locations:
5457
used throughout documentation primarily for convenience. The only
5558
requirement is that the *contents* of the file adhere to the
5659
[`.netrc` file format](https://www.gnu.org/software/inetutils/manual/html_node/The-_002enetrc-file.html).
57-
2. `EARTHDATA_USERNAME` and `EARTHDATA_PASSWORD` environment variables
60+
2. `EARTHDATA_USERNAME` and `EARTHDATA_PASSWORD` environment variables (or, optionally, `EARTHDATA_TOKEN`
61+
to use an existing Earthdata Login token)
5862

5963
If neither of these options are configured, you can authenticate by calling the
6064
`earthaccess.login()` method and manually entering your EDL account credentials.

earthaccess/api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ def login(
184184
* **"all"**: (default) try all methods until one works
185185
* **"interactive"**: enter username and password.
186186
* **"netrc"**: retrieve username and password from ~/.netrc.
187-
* **"environment"**: retrieve username and password from `$EARTHDATA_USERNAME` and `$EARTHDATA_PASSWORD`.
187+
* **"environment"**: retrieve either a username and password pair from
188+
the `EARTHDATA_USERNAME` and `EARTHDATA_PASSWORD` environment variables,
189+
or an Earthdata login token from the `EARTHDATA_TOKEN` environment variable.
188190
persist: will persist credentials in a .netrc file
189191
system: the Earthdata system to access, defaults to PROD
190192
@@ -233,7 +235,7 @@ def download(
233235
threads: int = 8,
234236
*,
235237
pqdm_kwargs: Optional[Mapping[str, Any]] = None,
236-
) -> List[str]:
238+
) -> List[Path]:
237239
"""Retrieves data granules from a remote storage system. Provide the optional `local_path` argument to prevent repeated downloads.
238240
239241
* If we run this in the cloud, we will be using S3 to move data to `local_path`.

earthaccess/auth.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ def login(
110110
* **"interactive"**: Enter a username and password.
111111
* **"netrc"**: (default) Retrieve a username and password from ~/.netrc.
112112
* **"environment"**:
113-
Retrieve a username and password from $EARTHDATA_USERNAME and $EARTHDATA_PASSWORD.
114-
persist: Will persist credentials in a `.netrc` file.
113+
Retrieve either a username and password pair from the
114+
`EARTHDATA_USERNAME` and `EARTHDATA_PASSWORD` environment variables,
115+
or an Earthdata login token from the `EARTHDATA_TOKEN` environment
116+
variable.
117+
persist: Will persist username and password credentials in a `.netrc` file.
115118
system: the EDL endpoint to log in to Earthdata, defaults to PROD
116119
117120
Returns:
@@ -245,7 +248,7 @@ def _interactive(
245248
) -> bool:
246249
username = input("Enter your Earthdata Login username: ")
247250
password = getpass.getpass(prompt="Enter your Earthdata password: ")
248-
authenticated = self._get_credentials(username, password)
251+
authenticated = self._get_credentials(username, password, None)
249252
if authenticated:
250253
logger.debug("Using user provided credentials for EDL")
251254
if persist_credentials:
@@ -282,7 +285,7 @@ def _netrc(self) -> bool:
282285
f"Password not found in .netrc file {netrc_loc}"
283286
)
284287

285-
authenticated = self._get_credentials(username, password)
288+
authenticated = self._get_credentials(username, password, None)
286289

287290
if authenticated:
288291
logger.debug("Using .netrc file for EDL")
@@ -292,21 +295,27 @@ def _netrc(self) -> bool:
292295
def _environment(self) -> bool:
293296
username = os.getenv("EARTHDATA_USERNAME")
294297
password = os.getenv("EARTHDATA_PASSWORD")
298+
token = os.getenv("EARTHDATA_TOKEN")
295299

296-
if not username or not password:
300+
if (not username or not password) and not token:
297301
raise LoginStrategyUnavailable(
298-
"EARTHDATA_USERNAME and EARTHDATA_PASSWORD are not set in the current environment, try "
299-
"setting them or use a different strategy (netrc, interactive)"
302+
"Either the environment variables EARTHDATA_USERNAME and "
303+
"EARTHDATA_PASSWORD must both be set, or EARTHDATA_TOKEN must be set for "
304+
"the 'environment' login strategy."
300305
)
301306

302307
logger.debug("Using environment variables for EDL")
303-
return self._get_credentials(username, password)
308+
return self._get_credentials(username, password, token)
304309

305310
def _get_credentials(
306311
self,
307312
username: Optional[str],
308313
password: Optional[str],
314+
user_token: Optional[str],
309315
) -> bool:
316+
if user_token is not None:
317+
self.token = {"access_token": user_token}
318+
self.authenticated = True
310319
if username is not None and password is not None:
311320
token_resp = self._find_or_create_token(username, password)
312321

earthaccess/search.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ def __init__(self, auth: Optional[Auth] = None, *args: Any, **kwargs: Any) -> No
6262

6363
self._debug = False
6464

65-
self.params["has_granules"] = True
66-
self.params["include_granule_counts"] = True
67-
6865
@override
6966
def hits(self) -> int:
7067
"""Returns the number of hits the current query will return.
@@ -306,10 +303,10 @@ def has_granules(self, has_granules: bool | None = True) -> Self:
306303
if has_granules is not None and not isinstance(has_granules, bool):
307304
raise TypeError("has_granules must be of type bool or None")
308305

309-
if has_granules is None and "has_granules" in self.params:
310-
del self.params["has_granules"]
311-
else:
306+
if has_granules is not None:
312307
self.params["has_granules"] = has_granules
308+
elif "has_granules" in self.params:
309+
del self.params["has_granules"]
313310

314311
return self
315312

@@ -360,7 +357,7 @@ def data_center(self, data_center_name: str) -> Self:
360357
"""An alias for the `daac` method.
361358
362359
Parameters:
363-
data_center_name: DAAC shortname, e.g. NSIDC, PODAAC, GESDISC
360+
data_center_name: DAAC shortname, e.g. NSIDC, PODAAC, GES_DISC
364361
365362
Returns:
366363
self
@@ -372,7 +369,7 @@ def daac(self, daac_short_name: str) -> Self:
372369
for the DAAC.
373370
374371
Parameters:
375-
daac_short_name: a DAAC shortname, e.g. NSIDC, PODAAC, GESDISC
372+
daac_short_name: a DAAC shortname, e.g. NSIDC, PODAAC, GES_DISC
376373
377374
Returns:
378375
self
@@ -556,7 +553,7 @@ def data_center(self, data_center_name: str) -> Self:
556553
"""An alias for the `daac` method.
557554
558555
Parameters:
559-
data_center_name (String): DAAC shortname, e.g. NSIDC, PODAAC, GESDISC
556+
data_center_name (String): DAAC shortname, e.g. NSIDC, PODAAC, GES_DISC
560557
561558
Returns:
562559
self
@@ -568,7 +565,7 @@ def daac(self, daac_short_name: str) -> Self:
568565
the DAAC.
569566
570567
Parameters:
571-
daac_short_name: a DAAC shortname, e.g. NSIDC, PODAAC, GESDISC
568+
daac_short_name: a DAAC shortname, e.g. NSIDC, PODAAC, GES_DISC
572569
573570
Returns:
574571
self

earthaccess/store.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def get(
494494
threads: int = 8,
495495
*,
496496
pqdm_kwargs: Optional[Mapping[str, Any]] = None,
497-
) -> List[str]:
497+
) -> List[Path]:
498498
"""Retrieves data granules from a remote storage system.
499499
500500
* If we run this in the cloud,
@@ -545,7 +545,7 @@ def _get(
545545
provider: Optional[str] = None,
546546
*,
547547
pqdm_kwargs: Optional[Mapping[str, Any]] = None,
548-
) -> List[str]:
548+
) -> List[Path]:
549549
"""Retrieves data granules from a remote storage system.
550550
551551
* If we run this in the cloud,
@@ -576,7 +576,7 @@ def _get_urls(
576576
provider: Optional[str] = None,
577577
*,
578578
pqdm_kwargs: Optional[Mapping[str, Any]] = None,
579-
) -> List[str]:
579+
) -> List[Path]:
580580
data_links = granules
581581
downloaded_files: List = []
582582
if provider is None and self.in_region and "cumulus" in data_links[0]:
@@ -616,7 +616,7 @@ def _get_granules(
616616
provider: Optional[str] = None,
617617
*,
618618
pqdm_kwargs: Optional[Mapping[str, Any]] = None,
619-
) -> List[str]:
619+
) -> List[Path]:
620620
data_links: List = []
621621
downloaded_files: List = []
622622
provider = granules[0]["meta"]["provider-id"]
@@ -687,7 +687,7 @@ def _clone_session_in_local_thread(
687687
local_thread_session.auth = original_session.auth
688688
self.thread_locals.local_thread_session = local_thread_session
689689

690-
def _download_file(self, url: str, directory: Path) -> str:
690+
def _download_file(self, url: str, directory: Path) -> Path:
691691
"""Download a single file from an on-prem location, a DAAC data center.
692692
693693
Parameters:
@@ -722,7 +722,7 @@ def _download_file(self, url: str, directory: Path) -> str:
722722
raise DownloadFailure(msg)
723723
else:
724724
logger.info(f"File {local_filename} already downloaded")
725-
return str(path)
725+
return path
726726

727727
def _download_onprem_granules(
728728
self,

tests/integration/fixtures/vcr_cassettes/TestServices.test_services.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ interactions:
297297
User-Agent:
298298
- earthaccess v0.9.0
299299
method: GET
300-
uri: https://cmr.earthdata.nasa.gov/search/collections.umm_json?has_granules=true&include_granule_counts=true&short_name=MUR-JPL-L4-GLOB-v4.1&cloud_hosted=true&temporal%5B%5D=2024-02-27T00:00:00Z,2024-02-29T00:00:00Z&page_size=0
300+
uri: https://cmr.earthdata.nasa.gov/search/collections.umm_json?short_name=MUR-JPL-L4-GLOB-v4.1&cloud_hosted=true&temporal%5B%5D=2024-02-27T00:00:00Z,2024-02-29T00:00:00Z&page_size=0
301301
response:
302302
body:
303303
string: '{"hits":1,"took":730,"items":[]}'
@@ -364,7 +364,7 @@ interactions:
364364
User-Agent:
365365
- earthaccess v0.9.0
366366
method: GET
367-
uri: https://cmr.earthdata.nasa.gov/search/collections.umm_json?has_granules=true&include_granule_counts=true&short_name=MUR-JPL-L4-GLOB-v4.1&cloud_hosted=true&temporal%5B%5D=2024-02-27T00:00:00Z,2024-02-29T00:00:00Z&page_size=0
367+
uri: https://cmr.earthdata.nasa.gov/search/collections.umm_json?short_name=MUR-JPL-L4-GLOB-v4.1&cloud_hosted=true&temporal%5B%5D=2024-02-27T00:00:00Z,2024-02-29T00:00:00Z&page_size=0
368368
response:
369369
body:
370370
string: '{"hits":1,"took":213,"items":[]}'
@@ -431,7 +431,7 @@ interactions:
431431
User-Agent:
432432
- earthaccess v0.9.0
433433
method: GET
434-
uri: https://cmr.earthdata.nasa.gov/search/collections.umm_json?has_granules=true&include_granule_counts=true&short_name=MUR-JPL-L4-GLOB-v4.1&cloud_hosted=true&temporal%5B%5D=2024-02-27T00:00:00Z,2024-02-29T00:00:00Z&page_size=1
434+
uri: https://cmr.earthdata.nasa.gov/search/collections.umm_json?short_name=MUR-JPL-L4-GLOB-v4.1&cloud_hosted=true&temporal%5B%5D=2024-02-27T00:00:00Z,2024-02-29T00:00:00Z&page_size=1
435435
response:
436436
body:
437437
string: "{\"hits\":1,\"took\":271,\"items\":[{\"meta\":{\"revision-id\":38,\"deleted\":false,\"format\":\"application/vnd.nasa.cmr.umm+json\",\"provider-id\":\"POCLOUD\",\"has-combine\":true,\"user-id\":\"wenhaoli\",\"has-formats\":true,\"associations\":{\"variables\":[\"V2262655973-POCLOUD\",\"V2112015425-POCLOUD\",\"V2028632047-POCLOUD\",\"V2112015422-POCLOUD\",\"V2028668049-POCLOUD\",\"V2028632042-POCLOUD\",\"V2112015420-POCLOUD\",\"V2028632044-POCLOUD\"],\"services\":[\"S2839491596-XYZ_PROV\",\"S2164732315-XYZ_PROV\",\"S2004184019-POCLOUD\",\"S2874702816-XYZ_PROV\",\"S2606110201-XYZ_PROV\"],\"tools\":[\"TL2108419875-POCLOUD\",\"TL2245207664-POCLOUD\"]},\"s3-links\":[\"podaac-ops-cumulus-public/MUR-JPL-L4-GLOB-v4.1/\",\"podaac-ops-cumulus-protected/MUR-JPL-L4-GLOB-v4.1/\"],\"has-spatial-subsetting\":true,\"native-id\":\"GHRSST+Level+4+MUR+Global+Foundation+Sea+Surface+Temperature+Analysis+(v4.1)\",\"has-transforms\":false,\"association-details\":{\"variables\":[{\"concept-id\":\"V2262655973-POCLOUD\"},{\"concept-id\":\"V2112015425-POCLOUD\"},{\"concept-id\":\"V2028632047-POCLOUD\"},{\"concept-id\":\"V2112015422-POCLOUD\"},{\"concept-id\":\"V2028668049-POCLOUD\"},{\"concept-id\":\"V2028632042-POCLOUD\"},{\"concept-id\":\"V2112015420-POCLOUD\"},{\"concept-id\":\"V2028632044-POCLOUD\"}],\"services\":[{\"concept-id\":\"S2839491596-XYZ_PROV\"},{\"concept-id\":\"S2164732315-XYZ_PROV\"},{\"concept-id\":\"S2004184019-POCLOUD\"},{\"concept-id\":\"S2874702816-XYZ_PROV\"},{\"concept-id\":\"S2606110201-XYZ_PROV\"}],\"tools\":[{\"concept-id\":\"TL2108419875-POCLOUD\"},{\"concept-id\":\"TL2245207664-POCLOUD\"}]},\"has-variables\":true,\"concept-id\":\"C1996881146-POCLOUD\",\"revision-date\":\"2023-05-30T16:42:26.806Z\",\"granule-count\":3,\"has-temporal-subsetting\":true,\"concept-type\":\"collection\"},\"umm\":{\"DataLanguage\":\"eng\",\"AncillaryKeywords\":[\"GHRSST\",\"sea

0 commit comments

Comments
 (0)