def test_doesnt_common_metadata_if_not_enabled(self): # Test reading from collection collection = pystac.read_file( TestCases.get_path('data-files/commons/example-collection-without-commons.json')) self.assertFalse(collection.ext.implements(pystac.Extensions.COMMONS)) item = collection.get_item("item-without") self.assertFalse(item.ext.implements(pystac.Extensions.COMMONS)) self.assertTrue(item.ext.implements(pystac.Extensions.EO)) # Should fail since required EO properties weren't inherited. with self.assertRaises(STACValidationError): self.validator.validate_object(item) # Test reading item directly item2 = pystac.read_file( TestCases.get_path('data-files/commons/example-item-without-commons.json')) self.assertFalse(item2.ext.implements(pystac.Extensions.COMMONS)) self.assertTrue(item2.ext.implements(pystac.Extensions.EO)) with self.assertRaises(STACValidationError): self.validator.validate_object(item2)
def merge(source_catalog: str, target_catalog: str, collection_id: Optional[str] = None, move_assets: bool = False, ignore_conflicts: bool = False, as_child: bool = False, child_folder: Optional[str] = None) -> None: source = pystac.read_file(source_catalog) if not isinstance(source, pystac.Catalog): raise click.BadArgumentUsage(f"{source_catalog} is not a STAC Catalog") target = pystac.read_file(target_catalog) if not isinstance(target, pystac.Catalog): raise click.BadArgumentUsage(f"{target_catalog} is not a STAC Catalog") if collection_id is not None: target_new = target.get_child(collection_id, recursive=True) if target_new is None: raise click.BadOptionUsage( 'collection', 'A collection with ID {} does not exist in {}'.format( collection_id, target_catalog)) target = target_new merge_all_items(source, target, move_assets, ignore_conflicts, as_child, child_folder) target.save()
def test_label_overviews(self): # Get label_item = pystac.read_file(self.label_example_1_uri) label_overviews = label_item.ext.label.label_overviews label_item2 = pystac.read_file(self.label_example_2_uri) label_overviews2 = label_item2.ext.label.label_overviews self.assertEqual(len(label_overviews), 2) self.assertEqual(label_overviews[1].property_key, "label-reg") self.assertEqual(label_overviews2[1].property_key, None) # Raster label_counts = label_overviews[0].counts self.assertEqual(label_counts[1].count, 17) label_item.ext.label.label_overviews[0].counts[1].count = 18 self.assertEqual( label_item.properties['label:overviews'][0]['counts'][1]['count'], 18) label_statistics = label_overviews[1].statistics self.assertEqual(label_statistics[0].name, "mean") label_item.ext.label.label_overviews[1].statistics[0].name = "avg" self.assertEqual( label_item.properties['label:overviews'][1]['statistics'][0] ['name'], "avg") # Set new_overviews = [ label.LabelOverview.create(property_key="label2", counts=[ label.LabelCount.create(name="one", count=1), label.LabelCount.create(name="two", count=1), ]), label.LabelOverview.create( property_key="label-reg", statistics=[ label.LabelStatistics.create(name="min", value=0.1), label.LabelStatistics.create(name="max", value=1.0), ]) ] label_item.ext.label.label_overviews = new_overviews self.assertEqual([ (count['name'], count['count']) for count in label_item.properties["label:overviews"][0]['counts'] ], [("one", 1), ("two", 1)]) self.assertEqual([(count['name'], count['value']) for count in label_item.properties["label:overviews"] [1]['statistics']], [("min", 0.1), ("max", 1.0)]) self.validator.validate_object(label_item)
def test_label_properties(self): label_item = pystac.read_file(self.label_example_1_uri) label_item2 = pystac.read_file(self.label_example_2_uri) # Get self.assertIn("label:properties", label_item.properties) label_prop = label_item.ext.label.label_properties self.assertEqual(label_prop, label_item.properties['label:properties']) raster_label_prop = label_item2.ext.label.label_properties self.assertEqual(raster_label_prop, None) # Set label_item.ext.label.label_properties = ["prop1", "prop2"] self.assertEqual(["prop1", "prop2"], label_item.properties['label:properties']) label_item.validate()
def test_validate_current_version(self) -> None: catalog = pystac.read_file( TestCases.get_path("data-files/catalogs/test-case-1/" "catalog.json")) catalog.validate() collection = pystac.read_file( TestCases.get_path("data-files/catalogs/test-case-1/" "/country-1/area-1-1/" "collection.json")) collection.validate() item = pystac.read_file( TestCases.get_path("data-files/item/sample-item.json")) item.validate()
def test_create_single_file_stac(self): cat = TestCases.test_case_1() sfs = create_single_file_stac(TestCases.test_case_1()) with TemporaryDirectory() as tmp_dir: path = os.path.join(tmp_dir, 'single_file_stac.json') pystac.write_file(sfs, include_self_link=False, dest_href=path) sfs_read = pystac.read_file(path) sfs_read.validate() self.assertTrue(sfs_read.ext.implements('single-file-stac')) read_fids = set( [f.id for f in sfs_read.ext['single-file-stac'].features]) expected_fids = set([f.id for f in cat.get_all_items()]) self.assertEqual(read_fids, expected_fids) read_col_ids = set([ col.id for col in sfs_read.ext['single-file-stac'].collections ]) expected_col_ids = set( ['area-1-1', 'area-1-2', 'area-2-1', 'area-2-2']) self.assertEqual(read_col_ids, expected_col_ids)
def fetch_stac_items(stac_path, recursive=False, max_connections=100, timeout=HTTP_REQ_TIMEOUT): """Fetch STAC item from a single item file or items from a catalog. :param stac_path: A STAC object filepath :type filename: str :param recursive: (optional) Browse recursively in child nodes if True :type recursive: bool :param max_connections: Maximum number of connections for HTTP requests :type max_connections: int :param timeout: (optional) Timeout in seconds for each internal HTTP request :type timeout: float :returns: The items found in `stac_path` :rtype: :class:`list` """ # URI opener used by PySTAC internally, instantiated here # to retrieve the timeout. _text_opener = _TextOpener(timeout) pystac.STAC_IO.read_text_method = _text_opener stac_obj = pystac.read_file(stac_path) # Single STAC item if isinstance(stac_obj, pystac.Item): return [stac_obj.to_dict()] # STAC catalog elif isinstance(stac_obj, pystac.Catalog): return _fetch_stac_items_from_catalog(stac_obj, recursive, max_connections, _text_opener) else: raise STACOpenerError( f"{stac_path} must be a STAC catalog or a STAC item")
def __init__(self, old_catalog_path: str = None, new_path: str = None) -> None: if old_catalog_path is None: if new_path is None: new_path = "" self.path: str = new_path self.root_catalog: Catalog = Catalog(id="GisSpot-root-catalog", title="GisSpot-root-catalog", description="Root catalog on GisSpot server") else: old_catalog_path = normalize_stac_path(old_catalog_path) print(old_catalog_path) stac_obj = read_file(old_catalog_path) if type(stac_obj) is Catalog: self.root_catalog: Catalog = stac_obj else: raise TypeError("old_catalog_path must be path to STAC catalog") if new_path is None: self.path: str = self.root_catalog.get_self_href() else: self.path: str = new_path
def test_handles_children_with_same_id(self): # This catalog has the root and child collection share an ID. cat = pystac.read_file( TestCases.get_path('data-files/invalid/shared-id/catalog.json')) items = list(cat.get_all_items()) self.assertEqual(len(items), 1)
def test_migrates_renamed_extension(self): collection = pystac.read_file( TestCases.get_path('data-files/examples/0.9.0/extensions/asset/' 'examples/example-landsat8.json')) self.assertIn('item-assets', collection.stac_extensions) self.assertIn('item_assets', collection.extra_fields)
def test_copy_to_relative(self): cat = TestCases.planet_disaster() with TemporaryDirectory() as tmp_dir: cat.make_all_asset_hrefs_absolute() cat.normalize_hrefs(tmp_dir) cat.save(catalog_type=pystac.CatalogType.ABSOLUTE_PUBLISHED) cat2_dir = os.path.join(tmp_dir, 'second') command = [ 'copy', '-t', 'SELF_CONTAINED', '-a', cat.get_self_href(), cat2_dir ] self.run_command(command) cat2 = pystac.read_file(os.path.join(cat2_dir, 'collection.json')) for item in cat2.get_all_items(): item_href = item.get_self_href() for asset in item.assets.values(): href = asset.href self.assertFalse(is_absolute_href(href)) common_path = os.path.commonpath([ os.path.dirname(item_href), make_absolute_href(href, item_href) ]) self.assertTrue(common_path, os.path.dirname(item_href))
def test_sun_azimuth(self): view_item = pystac.read_file(self.example_uri) # Get self.assertIn("view:sun_azimuth", view_item.properties) view_sun_azimuth = view_item.ext.view.sun_azimuth self.assertEqual(view_sun_azimuth, view_item.properties['view:sun_azimuth']) # Set view_item.ext.view.sun_azimuth = view_sun_azimuth + 100 self.assertEqual(view_sun_azimuth + 100, view_item.properties['view:sun_azimuth']) # Get from Asset asset_no_prop = view_item.assets['blue'] asset_prop = view_item.assets['red'] self.assertEqual(view_item.ext.view.get_sun_azimuth(asset_no_prop), view_item.ext.view.get_sun_azimuth()) self.assertEqual(view_item.ext.view.get_sun_azimuth(asset_prop), 1.0) # Set to Asset asset_value = 11.0 view_item.ext.view.set_sun_azimuth(asset_value, asset_no_prop) self.assertNotEqual(view_item.ext.view.get_sun_azimuth(asset_no_prop), view_item.ext.view.get_sun_azimuth()) self.assertEqual(view_item.ext.view.get_sun_azimuth(asset_no_prop), asset_value) # Validate view_item.validate()
def test_converts(self): test_order_manifest = TestData.get_path( 'data-files/planet-order/manifest.json') with TemporaryDirectory() as tmp_dir: result = self.run_command([ 'planet', 'convert-order', test_order_manifest, tmp_dir, 'test_id', 'A test catalog', '--title', 'test-catalog', '-a', 'copy' ]) self.assertEqual(result.exit_code, 0, msg='\n{}'.format(result.output)) collection = pystac.read_file( os.path.join(tmp_dir, 'collection.json')) item_ids = set([i.id for i in collection.get_all_items()]) self.assertEqual(item_ids, set(['20180119_XXXXXXX_XXXX'])) item = collection.get_item('20180119_XXXXXXX_XXXX') for asset in item.assets.values(): self.assertTrue(os.path.exists(asset.get_absolute_href())) self.assertEqual(os.path.dirname(asset.get_absolute_href()), os.path.dirname(item.get_self_href())) self.assertEqual(item.properties.get('pl:quality_category'), 'standard')
def test_asset_providers(self): item = pystac.read_file( TestCases.get_path( 'data-files/item/sample-item-asset-properties.json')) cm = item.common_metadata item_value = cm.providers a2_known_value = [ pystac.Provider(name="USGS", url="https://landsat.usgs.gov/", roles=["producer", "licensor"]) ] # Get a1_value = cm.get_providers(item.assets['analytic']) a2_value = cm.get_providers(item.assets['thumbnail']) self.assertEqual(a1_value[0].to_dict(), item_value[0].to_dict()) self.assertNotEqual(a2_value[0].to_dict(), item_value[0].to_dict()) self.assertEqual(a2_value[0].to_dict(), a2_known_value[0].to_dict()) # Set set_value = [ pystac.Provider(name="John Snow", url="https://cholera.com/", roles=["producer"]) ] cm.set_providers(set_value, item.assets['analytic']) new_a1_value = cm.get_providers(item.assets['analytic']) self.assertEqual(new_a1_value[0].to_dict(), set_value[0].to_dict()) self.assertEqual(cm.providers[0].to_dict(), item_value[0].to_dict())
def test_epsg(self): proj_item = pystac.read_file(self.example_uri) # Get self.assertIn("proj:epsg", proj_item.properties) proj_epsg = proj_item.ext.projection.epsg self.assertEqual(proj_epsg, proj_item.properties['proj:epsg']) # Set proj_item.ext.projection.epsg = proj_epsg + 100 self.assertEqual(proj_epsg + 100, proj_item.properties['proj:epsg']) # Get from Asset asset_no_prop = proj_item.assets['B1'] asset_prop = proj_item.assets['B8'] self.assertEqual(proj_item.ext.projection.get_epsg(asset_no_prop), proj_item.ext.projection.get_epsg()) self.assertEqual(proj_item.ext.projection.get_epsg(asset_prop), 9999) # Set to Asset proj_item.ext.projection.set_epsg(8888, asset_no_prop) self.assertNotEqual(proj_item.ext.projection.get_epsg(asset_no_prop), proj_item.ext.projection.get_epsg()) self.assertEqual(proj_item.ext.projection.get_epsg(asset_no_prop), 8888) # Validate proj_item.validate
def test_incidence_angle(self): view_item = pystac.read_file(self.example_uri) # Get self.assertIn("view:incidence_angle", view_item.properties) view_incidence_angle = view_item.ext.view.incidence_angle self.assertEqual(view_incidence_angle, view_item.properties['view:incidence_angle']) # Set view_item.ext.view.incidence_angle = view_incidence_angle + 10 self.assertEqual(view_incidence_angle + 10, view_item.properties['view:incidence_angle']) # Get from Asset asset_no_prop = view_item.assets['blue'] asset_prop = view_item.assets['red'] self.assertEqual(view_item.ext.view.get_incidence_angle(asset_no_prop), view_item.ext.view.get_incidence_angle()) self.assertEqual(view_item.ext.view.get_incidence_angle(asset_prop), 4.0) # Set to Asset asset_value = 14.0 view_item.ext.view.set_incidence_angle(asset_value, asset_no_prop) self.assertNotEqual( view_item.ext.view.get_incidence_angle(asset_no_prop), view_item.ext.view.get_incidence_angle()) self.assertEqual(view_item.ext.view.get_incidence_angle(asset_no_prop), asset_value) # Validate view_item.validate()
def test_off_nadir(self): view_item = pystac.read_file(self.example_uri) # Get self.assertIn("view:off_nadir", view_item.properties) view_off_nadir = view_item.ext.view.off_nadir self.assertEqual(view_off_nadir, view_item.properties['view:off_nadir']) # Set view_item.ext.view.off_nadir = view_off_nadir + 10 self.assertEqual(view_off_nadir + 10, view_item.properties['view:off_nadir']) # Get from Asset asset_no_prop = view_item.assets['blue'] asset_prop = view_item.assets['red'] self.assertEqual(view_item.ext.view.get_off_nadir(asset_no_prop), view_item.ext.view.get_off_nadir()) self.assertEqual(view_item.ext.view.get_off_nadir(asset_prop), 3.0) # Set to Asset asset_value = 13.0 view_item.ext.view.set_off_nadir(asset_value, asset_no_prop) self.assertNotEqual(view_item.ext.view.get_off_nadir(asset_no_prop), view_item.ext.view.get_off_nadir()) self.assertEqual(view_item.ext.view.get_off_nadir(asset_no_prop), asset_value) # Validate view_item.validate()
def test_sun_elevation(self): view_item = pystac.read_file(self.example_uri) # Get self.assertIn("view:sun_elevation", view_item.properties) view_sun_elevation = view_item.ext.view.sun_elevation self.assertEqual(view_sun_elevation, view_item.properties['view:sun_elevation']) # Set view_item.ext.view.sun_elevation = view_sun_elevation + 10 self.assertEqual(view_sun_elevation + 10, view_item.properties['view:sun_elevation']) # Get from Asset asset_no_prop = view_item.assets['blue'] asset_prop = view_item.assets['red'] self.assertEqual(view_item.ext.view.get_sun_elevation(asset_no_prop), view_item.ext.view.get_sun_elevation()) self.assertEqual(view_item.ext.view.get_sun_elevation(asset_prop), 2.0) # Set to Asset asset_value = 12.0 view_item.ext.view.set_sun_elevation(asset_value, asset_no_prop) self.assertNotEqual( view_item.ext.view.get_sun_elevation(asset_no_prop), view_item.ext.view.get_sun_elevation()) self.assertEqual(view_item.ext.view.get_sun_elevation(asset_no_prop), asset_value) # Validate view_item.validate()
def copy_command(src, dst, catalog_type, copy_assets): """Copy a STAC Catalog or Collection at SRC to the directory at DST. Note: Copying a catalog will upgrade it to the latest version of STAC.""" source_catalog = pystac.read_file(src) copy_catalog(source_catalog, dst, catalog_type, copy_assets)
def test_read_pre_09_fields_into_common_metadata(self): eo_item = pystac.read_file( TestCases.get_path('data-files/examples/0.8.1/item-spec/examples/' 'landsat8-sample.json')) self.assertEqual(eo_item.common_metadata.platform, "landsat-8") self.assertEqual(eo_item.common_metadata.instruments, ["oli_tirs"])
def test_wkt2(self): proj_item = pystac.read_file(self.example_uri) # Get self.assertIn("proj:wkt2", proj_item.properties) proj_wkt2 = proj_item.ext.projection.wkt2 self.assertEqual(proj_wkt2, proj_item.properties['proj:wkt2']) # Set proj_item.ext.projection.wkt2 = WKT2 self.assertEqual(WKT2, proj_item.properties['proj:wkt2']) # Get from Asset asset_no_prop = proj_item.assets['B1'] asset_prop = proj_item.assets['B8'] self.assertEqual(proj_item.ext.projection.get_wkt2(asset_no_prop), proj_item.ext.projection.get_wkt2()) self.assertTrue( 'TEST_TEXT' in proj_item.ext.projection.get_wkt2(asset_prop)) # Set to Asset asset_value = "TEST TEXT 2" proj_item.ext.projection.set_wkt2(asset_value, asset_no_prop) self.assertNotEqual(proj_item.ext.projection.get_wkt2(asset_no_prop), proj_item.ext.projection.get_wkt2()) self.assertEqual(proj_item.ext.projection.get_wkt2(asset_no_prop), asset_value) # Validate proj_item.validate()
def main(data_dir, input_references, store_username, store_apikey): if store_username is not None: os.environ['STAGEIN_USERNAME'] = store_username os.environ['STAGEIN_PASSWORD'] = store_apikey STAC_IO.read_text_method = my_read_method items = [] for input_reference in input_references: thing = pystac.read_file(input_reference) if isinstance(thing, pystac.item.Item): items.append(thing) elif isinstance(thing, pystac.catalog.Catalog): for item in thing.get_items(): items.append(item) # create catalog catalog = Catalog(id='catalog', description='staged STAC catalog') catalog.add_items(items) catalog.normalize_and_save(root_href=data_dir, catalog_type=CatalogType.RELATIVE_PUBLISHED) catalog.describe()
def test_set_asset_bands(self): eo_item = pystac.read_file( TestCases.get_path('data-files/eo/eo-landsat-example.json')) b1_asset = eo_item.assets['B1'] eo_item.ext.eo.set_asset_bands(b1_asset, ['B2']) eo_item_mod = Item.from_dict(eo_item.to_dict()) b1_asset_mod = eo_item_mod.assets['B1'] asset_bands = eo_item_mod.ext.eo.get_asset_bands(b1_asset_mod) self.assertIsNot(None, asset_bands) self.assertEqual(len(asset_bands), 1) self.assertEqual(asset_bands[0].name, 'B2') self.validator.validate_object(eo_item) # Check setting with invalid keys with self.assertRaises(KeyError): eo_item.ext.eo.set_asset_bands(b1_asset, ['BAD_KEY', 'BAD_KEY_2']) # Check adding a new asset asset = pystac.Asset(href="some/path.tif", media_type=pystac.MediaType.GEOTIFF) eo_item.ext.eo.set_asset_bands(asset, [b.name for b in eo_item.ext.eo.bands]) eo_item.add_asset("test", asset) self.assertEqual(eo_item.assets["test"].properties["eo:bands"], list(range(0, len(eo_item.ext.eo.bands))))
def test_bbox(self): proj_item = pystac.read_file(self.example_uri) # Get self.assertIn("proj:bbox", proj_item.properties) proj_bbox = proj_item.ext.projection.bbox self.assertEqual(proj_bbox, proj_item.properties['proj:bbox']) # Set proj_item.ext.projection.bbox = [1.0, 2.0, 3.0, 4.0] self.assertEqual(proj_item.properties['proj:bbox'], [1.0, 2.0, 3.0, 4.0]) # Get from Asset asset_no_prop = proj_item.assets['B1'] asset_prop = proj_item.assets['B8'] self.assertEqual(proj_item.ext.projection.get_bbox(asset_no_prop), proj_item.ext.projection.get_bbox()) self.assertEqual(proj_item.ext.projection.get_bbox(asset_prop), [1.0, 2.0, 3.0, 4.0]) # Set to Asset asset_value = [10.0, 20.0, 30.0, 40.0] proj_item.ext.projection.set_bbox(asset_value, asset_no_prop) self.assertNotEqual(proj_item.ext.projection.get_bbox(asset_no_prop), proj_item.ext.projection.get_bbox()) self.assertEqual(proj_item.ext.projection.get_bbox(asset_no_prop), asset_value) # Validate proj_item.validate()
def test_shape(self): proj_item = pystac.read_file(self.example_uri) # Get self.assertIn("proj:shape", proj_item.properties) proj_shape = proj_item.ext.projection.shape self.assertEqual(proj_shape, proj_item.properties['proj:shape']) # Set new_val = [100, 200] proj_item.ext.projection.shape = new_val self.assertEqual(proj_item.properties['proj:shape'], new_val) # Get from Asset asset_no_prop = proj_item.assets['B1'] asset_prop = proj_item.assets['B8'] self.assertEqual(proj_item.ext.projection.get_shape(asset_no_prop), proj_item.ext.projection.get_shape()) self.assertEqual(proj_item.ext.projection.get_shape(asset_prop), [16781, 16621]) # Set to Asset asset_value = [1, 2] proj_item.ext.projection.set_shape(asset_value, asset_no_prop) self.assertNotEqual(proj_item.ext.projection.get_shape(asset_no_prop), proj_item.ext.projection.get_shape()) self.assertEqual(proj_item.ext.projection.get_shape(asset_no_prop), asset_value) # Validate proj_item.validate()
def test_transform(self): proj_item = pystac.read_file(self.example_uri) # Get self.assertIn("proj:transform", proj_item.properties) proj_transform = proj_item.ext.projection.transform self.assertEqual(proj_transform, proj_item.properties['proj:transform']) # Set new_val = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] proj_item.ext.projection.transform = new_val self.assertEqual(proj_item.properties['proj:transform'], new_val) # Get from Asset asset_no_prop = proj_item.assets['B1'] asset_prop = proj_item.assets['B8'] self.assertEqual(proj_item.ext.projection.get_transform(asset_no_prop), proj_item.ext.projection.get_transform()) self.assertEqual( proj_item.ext.projection.get_transform(asset_prop), [15.0, 0.0, 224992.5, 0.0, -15.0, 6790207.5, 0.0, 0.0, 1.0]) # Set to Asset asset_value = [2.0, 4.0, 6.0, 8.0, 10.0, 12.0] proj_item.ext.projection.set_transform(asset_value, asset_no_prop) self.assertNotEqual( proj_item.ext.projection.get_transform(asset_no_prop), proj_item.ext.projection.get_transform()) self.assertEqual(proj_item.ext.projection.get_transform(asset_no_prop), asset_value) # Validate proj_item.validate()
def test_cloud_cover(self): item = pystac.read_file(self.LANDSAT_EXAMPLE_URI) # Get self.assertIn("eo:cloud_cover", item.properties) cloud_cover = item.ext.eo.cloud_cover self.assertEqual(cloud_cover, 78) # Set item.ext.eo.cloud_cover = 50 self.assertEqual(item.properties['eo:cloud_cover'], 50) # Get from Asset b2_asset = item.assets['B2'] self.assertEqual(item.ext.eo.get_cloud_cover(b2_asset), item.ext.eo.get_cloud_cover()) b3_asset = item.assets['B3'] self.assertEqual(item.ext.eo.get_cloud_cover(b3_asset), 20) # Set on Asset item.ext.eo.set_cloud_cover(10, b2_asset) self.assertEqual(item.ext.eo.get_cloud_cover(b2_asset), 10) item.validate()
def test_add_item_to_specific_collection(self): catalog = TestCases.test_case_1() subcatalog = list(list(catalog.get_children())[0].get_children())[0] item = list(subcatalog.get_all_items())[0] item_path = item.get_self_href() with TemporaryDirectory() as tmp_dir: target_catalog = create_temp_catalog_copy(tmp_dir) items = list(target_catalog.get_all_items()) self.assertEqual(len(items), 5) cmd = [ "add", item_path, target_catalog.get_self_href(), "--collection", "hurricane-harvey", ] res = self.run_command(cmd) self.assertEqual(res.exit_code, 0) target_col = pystac.read_file(target_catalog.get_self_href()) child_col = target_col.get_child("hurricane-harvey") target_item = child_col.get_item(item.id) self.assertIsNotNone(target_item)
def test_migrates_removed_extension(self): item = pystac.read_file( TestCases.get_path('data-files/examples/0.7.0/extensions/sar/' 'examples/sentinel1.json')) self.assertFalse('dtr' in item.stac_extensions) self.assertEqual(item.common_metadata.start_datetime, str_to_datetime("2018-11-03T23:58:55.121559Z"))
def test_merges_assets(self): item_id = '2017831_195552_SS02' with TemporaryDirectory() as tmp_dir: orig_data = os.path.dirname( TestCases.planet_disaster().get_self_href()) shutil.copytree(orig_data, os.path.join(tmp_dir, '0')) col0 = pystac.read_file(os.path.join(tmp_dir, '0/collection.json')) item = col0.get_item(item_id, recursive=True) new_col1 = col0.clone() new_col1.clear_children() item1 = item.clone() del item1.assets['visual'] new_col1.add_item(item1) new_col1.normalize_hrefs(os.path.join(tmp_dir, 'a')) new_col1.save() new_col2 = col0.clone() new_col2.clear_children() item2 = item.clone() del item2.assets['full-jpg'] new_col2.add_item(item2) new_col2.normalize_hrefs(os.path.join(tmp_dir, 'b')) new_col2.save() cmd = [ 'merge', os.path.join(tmp_dir, 'a/collection.json'), os.path.join(tmp_dir, 'b/collection.json'), '--move-assets', '--ignore-conflicts' ] self.run_command(cmd) target_col = pystac.read_file( os.path.join(tmp_dir, 'b/collection.json')) result_item = target_col.get_item(item_id, recursive=True) self.assertIn('visual', result_item.assets) self.assertIn('full-jpg', result_item.assets)