def test_from_file(self): label_example_1 = Item.from_file(self.label_example_1_uri) self.assertEqual(len(label_example_1.ext.label.label_overviews[0].counts), 2) label_example_1.validate() label_example_2 = Item.from_file(self.label_example_2_uri) self.assertEqual(len(label_example_2.ext.label.label_overviews[0].counts), 2) label_example_2.validate()
def test_from_file(self) -> None: label_example_1 = Item.from_file(self.label_example_1_uri) overviews = get_opt( LabelExtension.ext(label_example_1).label_overviews) self.assertEqual(len(get_opt(overviews[0].counts)), 2) label_example_1.validate() label_example_2 = Item.from_file(self.label_example_2_uri) overviews2 = get_opt( LabelExtension.ext(label_example_2).label_overviews) self.assertEqual(len(get_opt(overviews2[0].counts)), 2) label_example_2.validate()
def stac_api_to_stac(uri: str) -> dict: """ Takes in a URI and uses that to feed the STAC transform """ item = Item.from_file(uri) return transform_stac_to_stac(item, source_link=uri, enable_proj=False)
def test_from_item(self): i = Item.from_file(self.URI_1) with self.assertRaises(AttributeError): getattr(i, 'bands') self.assertTrue('eo:bands' in i.properties.keys()) eo_ext = i.ext.eo self.assertIsNotNone(getattr(eo_ext, 'bands'))
def test_from_item(self): i = Item.from_file(self.URI_1) with self.assertRaises(AttributeError): getattr(i, 'bands') self.assertTrue('eo:bands' in i.properties.keys()) eoi = EOItem.from_item(i) self.assertIsNotNone(getattr(eoi, 'bands')) with self.assertRaises(KeyError): eoi.properties['eo:bands']
def setUp(self): self.validator = SchemaValidator() self.maxDiff = None self.URI_1 = TestCases.get_path( 'data-files/eo/eo-landsat-example.json') self.URI_2 = TestCases.get_path( 'data-files/eo/eo-landsat-example-INVALID.json') self.eoi = Item.from_file(self.URI_1) with open(self.URI_1) as f: self.eo_dict = json.load(f)
def setUp(self): self.URI_1 = TestCases.get_path( 'data-files/examples/0.9.0/item-spec/examples/datetimerange.json') self.ITEM_1 = Item.from_file(self.URI_1) self.URI_2 = TestCases.get_path( 'data-files/examples/0.9.0/item-spec/examples/sample-full.json') self.ITEM_2 = Item.from_file(self.URI_2) self.EXAMPLE_CM_DICT = { 'start_datetime': '2020-05-21T16:42:24.896Z', 'platform': 'example platform', 'providers': [{ 'name': 'example provider', 'roles': ['example roll'], 'url': 'https://example-provider.com/' }] }
def test_migration(self) -> None: with open(self.item_0_8_path) as src: item_dict = json.load(src) self.assertIn("eo:epsg", item_dict["properties"]) item = Item.from_file(self.item_0_8_path) self.assertNotIn("eo:epsg", item.properties) self.assertIn("proj:epsg", item.properties) self.assertIn(ProjectionExtension.get_schema_uri(), item.stac_extensions)
def setUp(self) -> None: self.URI_1 = TestCases.get_path( "data-files/examples/1.0.0-beta.2/item-spec/examples/datetimerange.json" ) self.ITEM_1 = Item.from_file(self.URI_1) self.URI_2 = TestCases.get_path( "data-files/examples/1.0.0-beta.2/item-spec/examples/sample-full.json" ) self.ITEM_2 = Item.from_file(self.URI_2) self.EXAMPLE_CM_DICT: Dict[str, Any] = { "start_datetime": "2020-05-21T16:42:24.896Z", "platform": "example platform", "providers": [{ "name": "example provider", "roles": ["example roll"], "url": "https://example-provider.com/", }], }
def test_add_to(self) -> None: item = Item.from_file(self.PLAIN_ITEM) self.assertNotIn(EOExtension.get_schema_uri(), item.stac_extensions) # Check that the URI gets added to stac_extensions EOExtension.add_to(item) self.assertIn(EOExtension.get_schema_uri(), item.stac_extensions) # Check that the URI only gets added once, regardless of how many times add_to # is called. EOExtension.add_to(item) EOExtension.add_to(item) eo_uris = [ uri for uri in item.stac_extensions if uri == EOExtension.get_schema_uri() ] self.assertEqual(len(eo_uris), 1)
def landsat_command(mtl, stac, enable_proj, dst): if mtl and stac or (not mtl and not stac): print("Please choose one of either MTL or STAC, not both") sys.exit(1) item = None if mtl: # Transform not implemented, so tell folks print("MTL transform not yet implemented.") sys.exit(1) with open(mtl) as f: item = transform_mtl_to_stac(json.load(f)) elif stac: in_item = Item.from_file(stac) item = transform_stac_to_stac(in_item, enable_proj=enable_proj) item_path = os.path.join(dst, '{}.json'.format(item.id)) item.set_self_href(item_path) item.save_object()
def test_read_eo_item_owns_asset(self): item = Item.from_file(self.URI_1) assert len(item.assets) > 0 for asset_key in item.assets: self.assertEqual(item.assets[asset_key].owner, item)
def setUp(self) -> None: self.maxDiff = None self.naip_item = Item.from_file(self.NAIP_EXAMPLE_URI) self.plain_item = Item.from_file(self.PLAIN_ITEM_URI) self.naip_collection = Collection.from_file(self.NAIP_COLLECTION_URI)
def setUp(self) -> None: self.maxDiff = None self.item = Item.from_file( TestCases.get_path( "data-files/item/sample-item-asset-properties.json"))