Skip to content

Commit 4e93ab6

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 65d365a commit 4e93ab6

File tree

5 files changed

+44
-26
lines changed

5 files changed

+44
-26
lines changed

icepyx/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from _icepyx_version import version as __version__
2+
23
from icepyx.core.base_query import BaseQuery, GenQuery
34
from icepyx.core.query import Query
45
from icepyx.core.read import Read

icepyx/core/harmony.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _place_order(
6767
spatial=spatial, # type: ignore[arg-type]
6868
temporal=temporal, # type: ignore[arg-type]
6969
# shape=shape, # type: ignore[arg-type]
70-
granule_name=granule_name
70+
granule_name=granule_name,
7171
)
7272

7373
if not request.is_valid():
@@ -116,7 +116,7 @@ def place_order(
116116
spatial=spatial,
117117
temporal=temporal,
118118
shape=shape,
119-
granule_name=granule_name
119+
granule_name=granule_name,
120120
)
121121

122122
# Append this job to the list of job ids.

icepyx/core/query.py

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@
3030
from icepyx.core.variables import Variables
3131

3232

33-
class DataOrder():
34-
33+
class DataOrder:
3534
HARMONY_BASE_URL = "https://harmony.earthdata.nasa.gov/workflow-ui/"
3635

3736
def __init__(self, job_id, type, granules, harmony_client):
38-
"""Initialize a DataOrder object. This object represents an order for Harmony.
39-
"""
37+
"""Initialize a DataOrder object. This object represents an order for Harmony."""
4038
self.job_id = job_id
4139
self.harmony_api = harmony_client
4240
self.granules = granules
@@ -85,7 +83,9 @@ def status(self):
8583

8684
def download(self, path, overwrite=False):
8785
if self.type == "subset":
88-
return self.harmony_api.download_granules(download_dir=path, overwrite=overwrite)
86+
return self.harmony_api.download_granules(
87+
download_dir=path, overwrite=overwrite
88+
)
8989
else:
9090
return earthaccess.download(self.granules, local_path=path)
9191

@@ -165,9 +165,10 @@ def _get_concept_id(self, product, version) -> Union[str, None]:
165165
return collections[0].concept_id()
166166
else:
167167
return None
168+
168169
@property
169170
def order_vars(self) -> list[str]:
170-
"""This used to print the list of vasriables for subsetting, Harmony doesn't provide that
171+
"""This used to print the list of vasriables for subsetting, Harmony doesn't provide that
171172
we do need to implement a class that gets the variables even if it'sm only for listing.
172173
"""
173174
if self.product:
@@ -328,7 +329,6 @@ def _order_subset_granules(self) -> str:
328329
version=self._version,
329330
)
330331

331-
332332
if concept_id is None:
333333
raise ValueError(
334334
f"Could not find concept ID for {self._prod} v{self._version}"
@@ -364,13 +364,14 @@ def _order_subset_granules(self) -> str:
364364
# Polygons must be passed to `harmony-py` as a path to a valid
365365
# shapefile (json, geojson, kml, shz, or zip). Create a temporary
366366
# directory to store this file for the harmony order.
367-
else:
368-
raise NotImplementedError("Only bounding box and polygon spatial subsetting is supported.")
367+
else:
368+
raise NotImplementedError(
369+
"Only bounding box and polygon spatial subsetting is supported."
370+
)
369371
else:
370372
if harmony_temporal is None:
371373
raise ValueError("No temporal or spatial parameters provided.")
372374

373-
374375
job_id = self.harmony_api.place_order(
375376
concept_id=concept_id,
376377
temporal=harmony_temporal,
@@ -383,13 +384,21 @@ def get_granule_links(self, cloud_hosted=False) -> list[str]:
383384
links = []
384385
for granule in self.granules.avail:
385386
for link in granule["links"]:
386-
if cloud_hosted and link["rel"] == "http://esipfed.org/ns/fedsearch/1.1/s3#" or ((link["rel"] == "http://esipfed.org/ns/fedsearch/1.1/data#") and
387-
("type" in link and link["type"] in ["application/x-hdf5",
388-
"application/x-hdfeos"])):
387+
if (
388+
cloud_hosted
389+
and link["rel"] == "http://esipfed.org/ns/fedsearch/1.1/s3#"
390+
or (
391+
(link["rel"] == "http://esipfed.org/ns/fedsearch/1.1/data#")
392+
and (
393+
"type" in link
394+
and link["type"]
395+
in ["application/x-hdf5", "application/x-hdfeos"]
396+
)
397+
)
398+
):
389399
links.append(link["href"])
390400
return links
391401

392-
393402
def _order_whole_granules(self, cloud_hosted=False, path="./") -> list[str]:
394403
"""
395404
Downloads the whole granules for the query object. This is not an asnc operation
@@ -409,7 +418,6 @@ def _order_whole_granules(self, cloud_hosted=False, path="./") -> list[str]:
409418
files = earthaccess.download(links, local_path=path)
410419
return files
411420

412-
413421
def order_granules(self, subset=True) -> DataOrder:
414422
"""
415423
Place an order for the available granules for the query object.
@@ -438,8 +446,10 @@ def order_granules(self, subset=True) -> DataOrder:
438446
Your harmony order is: complete
439447
"""
440448
if subset:
441-
job_id =self._order_subset_granules()
442-
self.last_order = DataOrder(job_id, "subset", self.granules, self.harmony_api)
449+
job_id = self._order_subset_granules()
450+
self.last_order = DataOrder(
451+
job_id, "subset", self.granules, self.harmony_api
452+
)
443453
return self.last_order
444454
else:
445455
files = self._order_whole_granules()
@@ -465,12 +475,14 @@ def download_granules(
465475
status = self.last_order.status()
466476
if status["status"] == "running" or status["status"] == "accepted":
467477
print(
468-
(
469-
"Your harmony job status is still "
470-
f"{status['status']}. Please continue waiting... this may take a few moments."
471-
)
478+
(
479+
"Your harmony job status is still "
480+
f"{status['status']}. Please continue waiting... this may take a few moments."
481+
)
472482
)
473-
while status["status"].startswith("running") or status["status"] == "accepted":
483+
while (
484+
status["status"].startswith("running") or status["status"] == "accepted"
485+
):
474486
sys.stdout.write(".")
475487
sys.stdout.flush()
476488
# Requesting the status too often can result in a 500 error.

icepyx/tests/unit/test_orders.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def test_status_subset():
2626
assert result == {"status": "processing"}
2727
mock_harmony_client.check_order_status.assert_called_once_with(123)
2828

29+
2930
def test_status_non_subset():
3031
# Mock the harmony_client (not used in this case)
3132
mock_harmony_client = Mock()
@@ -45,6 +46,7 @@ def test_status_non_subset():
4546
assert result == {"status": "complete"}
4647
mock_harmony_client.check_order_status.assert_not_called()
4748

49+
4850
def test_download_subset():
4951
# Mock the harmony_client
5052
mock_harmony_client = Mock()
@@ -74,7 +76,10 @@ def test_download_non_subset(mock_earthaccess_download):
7476
mock_harmony_client = Mock()
7577

7678
# Mock the earthaccess.download method to return specific file paths
77-
mock_earthaccess_download.return_value = ["/fake/path/granule1.nc", "/fake/path/granule2.nc"]
79+
mock_earthaccess_download.return_value = [
80+
"/fake/path/granule1.nc",
81+
"/fake/path/granule2.nc",
82+
]
7883

7984
# Create a DataOrder instance with type="download"
8085
order = DataOrder(
@@ -93,4 +98,3 @@ def test_download_non_subset(mock_earthaccess_download):
9398
["granule1", "granule2"], local_path="/fake/path"
9499
)
95100
mock_harmony_client.download_granules.assert_not_called()
96-

icepyx/tests/unit/test_spatial.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,7 @@ def poly():
14471447
]
14481448
return spat.Spatial(coords)
14491449

1450+
14501451
@pytest.mark.skip(reason="Skipping this test for now, it fails with current polygons")
14511452
def test_polygon_fmt(poly):
14521453
obs = poly.fmt_for_CMR()

0 commit comments

Comments
 (0)