44from unittest import TestCase
55
66import pystac
7+ from pystac import Item
78
89from mdps_ds_lib .lib .cumulus_stac .granules_catalog import GranulesCatalog
910from mdps_ds_lib .lib .utils .file_utils import FileUtils
@@ -134,20 +135,32 @@ def test_get_granules_item(self):
134135 "bbox" : [
135136 0.0 ,
136137 0.0 ,
137- 0 .0 ,
138- 0 .0
138+ 10 .0 ,
139+ 10 .0
139140 ],
140141 "stac_extensions" : [],
141142 "collection" : "SNDR_SNPP_ATMS_L1A___1"
142143 }
144+ with tempfile .TemporaryDirectory () as tmp_dir_name :
145+ granules_catalog_path = os .path .join (tmp_dir_name , 'sample_granules.json' )
146+ FileUtils .write_json (granules_catalog_path , sample_granules )
147+ pystac_catalog = GranulesCatalog ().get_granules_item (granules_catalog_path )
148+ self .assertEqual (pystac_catalog .id , 'SNDR.SNPP.ATMS.L1A.nominal2.12' )
149+ sample_granules ['bbox' ] = [10 , 10 , 0 , 0 ]
150+ with tempfile .TemporaryDirectory () as tmp_dir_name :
151+ granules_catalog_path = os .path .join (tmp_dir_name , 'sample_granules.json' )
152+ FileUtils .write_json (granules_catalog_path , sample_granules )
153+ pystac_catalog = GranulesCatalog ().get_granules_item (granules_catalog_path )
154+ self .assertEqual (pystac_catalog .id , 'SNDR.SNPP.ATMS.L1A.nominal2.12' )
155+ sample_granules ['bbox' ] = [0 , 10 , 10 , 0 ]
143156 with tempfile .TemporaryDirectory () as tmp_dir_name :
144157 granules_catalog_path = os .path .join (tmp_dir_name , 'sample_granules.json' )
145158 FileUtils .write_json (granules_catalog_path , sample_granules )
146159 pystac_catalog = GranulesCatalog ().get_granules_item (granules_catalog_path )
147160 self .assertEqual (pystac_catalog .id , 'SNDR.SNPP.ATMS.L1A.nominal2.12' )
148161 return
149162
150- def test_extract_assets_href (self ):
163+ def test_get_granules_item_invalid_bbox (self ):
151164 sample_granules = {
152165 "type" : "Feature" ,
153166 "stac_version" : "1.0.0" ,
@@ -179,6 +192,12 @@ def test_extract_assets_href(self):
179192 "description" : "SNDR.SNPP.ATMS.L1A.nominal2.12.nc" ,
180193 "roles" : ["data" ],
181194 },
195+ "SNDR.SNPP.ATMS.L1A.nominal2.12.1.nc" : {
196+ "href" : "s3://uds-test-cumulus-protected/SNDR_SNPP_ATMS_L1A___1/SNDR.SNPP.ATMS.L1A.nominal2.12.1.nc" ,
197+ "title" : "SNDR.SNPP.ATMS.L1A.nominal2.12.1.nc" ,
198+ "description" : "SNDR.SNPP.ATMS.L1A.nominal2.12.1.nc" ,
199+ "roles" : ["data" ],
200+ },
182201 "SNDR.SNPP.ATMS.L1A.nominal2.12.nc.cas" : {
183202 "href" : "s3://uds-test-cumulus-protected/SNDR_SNPP_ATMS_L1A___1/SNDR.SNPP.ATMS.L1A.nominal2.12.nc.cas" ,
184203 "title" : "SNDR.SNPP.ATMS.L1A.nominal2.12.nc.cas" ,
@@ -201,6 +220,82 @@ def test_extract_assets_href(self):
201220 "stac_extensions" : [],
202221 "collection" : "SNDR_SNPP_ATMS_L1A___1"
203222 }
223+ with tempfile .TemporaryDirectory () as tmp_dir_name :
224+ granules_catalog_path = os .path .join (tmp_dir_name , 'sample_granules.json' )
225+ FileUtils .write_json (granules_catalog_path , sample_granules )
226+ with self .assertRaises (ValueError ) as context :
227+ GranulesCatalog ().get_granules_item (granules_catalog_path )
228+ self .assertTrue (str (context .exception ).startswith ('invalid BBOX. It may be a point or a line' ))
229+ sample_granules ['bbox' ] = [0 , 1 , 0 , 1 ]
230+ with tempfile .TemporaryDirectory () as tmp_dir_name :
231+ granules_catalog_path = os .path .join (tmp_dir_name , 'sample_granules.json' )
232+ FileUtils .write_json (granules_catalog_path , sample_granules )
233+ with self .assertRaises (ValueError ) as context :
234+ GranulesCatalog ().get_granules_item (granules_catalog_path )
235+ self .assertTrue (str (context .exception ).startswith ('invalid BBOX. It may be a point or a line' ))
236+ sample_granules ['bbox' ] = [1 , 0 , 1 , 0 ]
237+ with tempfile .TemporaryDirectory () as tmp_dir_name :
238+ granules_catalog_path = os .path .join (tmp_dir_name , 'sample_granules.json' )
239+ FileUtils .write_json (granules_catalog_path , sample_granules )
240+ with self .assertRaises (ValueError ) as context :
241+ GranulesCatalog ().get_granules_item (granules_catalog_path )
242+ self .assertTrue (str (context .exception ).startswith ('invalid BBOX. It may be a point or a line' ))
243+ return
244+
245+ def test_extract_assets_href (self ):
246+ sample_granules = {
247+ "type" : "Feature" ,
248+ "stac_version" : "1.0.0" ,
249+ "id" : "SNDR.SNPP.ATMS.L1A.nominal2.12" ,
250+ "properties" : {
251+ "start_datetime" : "2016-01-14T11:00:00Z" ,
252+ "end_datetime" : "2016-01-14T11:06:00Z" ,
253+ "created" : "2020-12-14T13:50:00Z" ,
254+ "updated" : "2022-08-15T06:26:25.344000Z" ,
255+ "datetime" : "2022-08-15T06:26:17.938000Z"
256+ },
257+ "geometry" : {
258+ "type" : "Point" ,
259+ "coordinates" : [
260+ 0.0 ,
261+ 0.0
262+ ]
263+ },
264+ "links" : [
265+ {
266+ "rel" : "collection" ,
267+ "href" : "."
268+ }
269+ ],
270+ "assets" : {
271+ "SNDR.SNPP.ATMS.L1A.nominal2.12.nc" : {
272+ "href" : "s3://uds-test-cumulus-protected/SNDR_SNPP_ATMS_L1A___1/SNDR.SNPP.ATMS.L1A.nominal2.12.nc" ,
273+ "title" : "SNDR.SNPP.ATMS.L1A.nominal2.12.nc" ,
274+ "description" : "SNDR.SNPP.ATMS.L1A.nominal2.12.nc" ,
275+ "roles" : ["data" ],
276+ },
277+ "SNDR.SNPP.ATMS.L1A.nominal2.12.nc.cas" : {
278+ "href" : "s3://uds-test-cumulus-protected/SNDR_SNPP_ATMS_L1A___1/SNDR.SNPP.ATMS.L1A.nominal2.12.nc.cas" ,
279+ "title" : "SNDR.SNPP.ATMS.L1A.nominal2.12.nc.cas" ,
280+ "description" : "SNDR.SNPP.ATMS.L1A.nominal2.12.nc.cas" ,
281+ "roles" : ["metadata__data" ],
282+ },
283+ "SNDR.SNPP.ATMS.L1A.nominal2.12.cmr.xml" : {
284+ "href" : "s3://uds-test-cumulus-private/SNDR_SNPP_ATMS_L1A___1/SNDR.SNPP.ATMS.L1A.nominal2.12.cmr.xml" ,
285+ "title" : "SNDR.SNPP.ATMS.L1A.nominal2.12.cmr.xml" ,
286+ "description" : "SNDR.SNPP.ATMS.L1A.nominal2.12.cmr.xml" ,
287+ "roles" : ["metadata__cmr" ],
288+ }
289+ },
290+ "bbox" : [
291+ 0.0 ,
292+ 0.0 ,
293+ 10.0 ,
294+ 10.0
295+ ],
296+ "stac_extensions" : [],
297+ "collection" : "SNDR_SNPP_ATMS_L1A___1"
298+ }
204299 with tempfile .TemporaryDirectory () as tmp_dir_name :
205300 granules_catalog_path = os .path .join (tmp_dir_name , 'sample_granules.json' )
206301 FileUtils .write_json (granules_catalog_path , sample_granules )
@@ -263,8 +358,8 @@ def test_extract_assets_relative_href_01(self):
263358 "bbox" : [
264359 0.0 ,
265360 0.0 ,
266- 0 .0 ,
267- 0 .0
361+ 10 .0 ,
362+ 10 .0
268363 ],
269364 "stac_extensions" : [],
270365 "collection" : "SNDR_SNPP_ATMS_L1A___1"
@@ -337,8 +432,8 @@ def test_extract_assets_relative_href_02(self):
337432 "bbox" : [
338433 0.0 ,
339434 0.0 ,
340- 0 .0 ,
341- 0 .0
435+ 10 .0 ,
436+ 10 .0
342437 ],
343438 "stac_extensions" : [],
344439 "collection" : "SNDR_SNPP_ATMS_L1A___1"
@@ -416,8 +511,8 @@ def test_extract_assets_relative_href_03(self):
416511 "bbox" : [
417512 0.0 ,
418513 0.0 ,
419- 0 .0 ,
420- 0 .0
514+ 10 .0 ,
515+ 10 .0
421516 ],
422517 "stac_extensions" : [],
423518 "collection" : "SNDR_SNPP_ATMS_L1A___1"
@@ -485,8 +580,8 @@ def test_update_assets_href(self):
485580 "bbox" : [
486581 0.0 ,
487582 0.0 ,
488- 0 .0 ,
489- 0 .0
583+ 10 .0 ,
584+ 10 .0
490585 ],
491586 "stac_extensions" : [],
492587 "collection" : "SNDR_SNPP_ATMS_L1A___1"
@@ -570,8 +665,8 @@ def test_update_assets_href_02(self):
570665 "bbox" : [
571666 0.0 ,
572667 0.0 ,
573- 0 .0 ,
574- 0 .0
668+ 10 .0 ,
669+ 10 .0
575670 ],
576671 "stac_extensions" : [],
577672 "collection" : "SNDR_SNPP_ATMS_L1A___1"
@@ -721,6 +816,8 @@ def test_manual_validdate_stac(self):
721816 "collection": "URN:NASA:UNITY:UDS_BLACK:DEV:UDS_UNIT_COLLECTION___2410010608"
722817 }'''
723818 raw_json = json .loads (raw_json )
819+ granules_stac = Item .from_dict (raw_json )
820+ print (granules_stac .bbox )
724821 schema1 = {
725822 "$schema" : "http://json-schema.org/draft-07/schema#" ,
726823 "$id" : "https://stac-extensions.github.io/file/v2.1.0/schema.json#" ,
0 commit comments