3030from 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.
0 commit comments