예제 #1
0
    def test_can_add_custom_extension(self):
        prev_extensions = pystac.STAC_EXTENSIONS.get_registered_extensions()

        pystac.STAC_EXTENSIONS.add_extension(
            ExtensionDefinition("test", [
                ExtendedObject(Catalog, TestCatalogExt),
                ExtendedObject(Collection, TestCollectionExt),
                ExtendedObject(Item, TestItemExt)
            ]))

        try:
            cat = TestCases.test_case_2()
            col = cat.get_child('1a8c1632-fa91-4a62-b33e-3a87c2ebdf16')
            item = next(cat.get_all_items())

            cat.ext.enable("test")
            col.ext.enable("test")
            item.ext.enable("test")

            self.assertEqual(cat.ext.test.test_id, cat.id)
            self.assertEqual(col.ext.test.xmin,
                             col.extent.spatial.bboxes[0][0])
            self.assertEqual(item.ext.test.asset_keys, set(item.assets))

        finally:
            pystac.STAC_EXTENSIONS.remove_extension("test")

        self.assertFalse(
            pystac.STAC_EXTENSIONS.is_registered_extension("test"))
        self.assertEqual(pystac.STAC_EXTENSIONS.get_registered_extensions(),
                         prev_extensions)
예제 #2
0
        return self.properties.get('name')

    @name.setter
    def name(self, v):
        self.properties['name'] = v

    @property
    def value(self):
        """Get or sets the value of the statistic

        Returns:
            [int or float]
        """
        return self.properties.get('value')

    @value.setter
    def value(self, v):
        self.properties['value'] = v

    def to_dict(self):
        """Returns the dictionary representing the JSON of this LabelStatistics.

        Returns:
            dict: The wrapped dict of the LabelStatistics that can be written out as JSON.
        """
        return {'name': self.name, 'value': self.value}


LABEL_EXTENSION_DEFINITION = ExtensionDefinition(
    Extensions.LABEL, [ExtendedObject(Item, LabelItemExt)])
예제 #3
0
    @wrs_path.setter
    def wrs_path(self, val):
        self.item.properties['landsat:wrs_path'] = val

    @property
    def wrs_row(self):
        """ Landsat WRS_ROW """
        return self.item.properties.get('landsat:wrs_row')

    @wrs_row.setter
    def wrs_row(self, val):
        self.item.properties['landsat:wrs_row'] = val


landsat_def = ExtensionDefinition('landsat',
                                  [ExtendedObject(pystac.Item, LandsatExt)])
pystac.STAC_EXTENSIONS.add_extension(landsat_def)

band_info = {
    'B1': {
        'band':
        Band.create(name="B1",
                    common_name="coastal",
                    center_wavelength=0.48,
                    full_width_half_max=0.02),
        'gsd':
        30.0
    },
    'B2': {
        'band':
        Band.create(name="B2",
예제 #4
0
    Examples
    --------
    Returns ``True`` if the API landing page contains any of the
    :class:`~pystac_api.conformance.STAC_API_ITEM_SEARCH_CONTEXT_EXT` conformance URIs in its ``"conformsTo"``
    attribute.

    >>> from pystac_api import API, ConformanceClasses
    >>> api = API.from_file(...)
    >>> api.api_ext.implements(ConformanceClasses.STAC_API_ITEM_SEARCH_CONTEXT_EXT)
    True
    """

    conformance = ConformanceClasses.STAC_API_ITEM_SEARCH_CONTEXT_EXT
    """See the :class:`~pystac_api.conformance.STAC_API_ITEM_SEARCH_CONTEXT_EXT` for valid conformance URIs."""
    def __init__(self, api: API):
        self.api = api

    @classmethod
    def from_api(cls, api: API):
        return cls(api)

    @classmethod
    def _object_links(cls):
        return []


CONTEXT_EXTENSION_DEFINITION = ExtensionDefinition(APIExtensions.CONTEXT, [
    base.ExtendedObject(API, ContextAPIExtension),
    base.ExtendedObject(ItemCollection, ContextItemCollectionExtension)
])
예제 #5
0
    @unpublished.setter
    def unpublished(self, v):
        self.set_unpublished(v)

    def get_unpublished(self, asset=None):
        """Get an Item or Asset unpublished datetime

        If an Asset is supplied and the unpublished property exists on the Asset,
        return the Asset's value. Otherwise return the Item's value. 'Unpublished'
        has a different meaning depending on where it is used. If available in
        the asset properties, it refers to the timestamps valid for the actual data linked
        to the Asset Object. If it comes from the Item properties, it's referencing to
        the timestamp valid for the metadata.

        Returns:
            datetime
        """
        return self._timestamp_getter('unpublished', asset)

    def set_unpublished(self, unpublished, asset=None):
        """Set an Item or asset unpublished datetime

        If an Asset is supplied, sets the property on the Asset.
        Otherwise sets the Item's value.
        """
        self._timestamp_setter(unpublished, 'unpublished', asset)


TIMESTAMPS_EXTENSION_DEFINITION = ExtensionDefinition(
    Extensions.TIMESTAMPS, [ExtendedObject(Item, TimestampsItemExt)])
예제 #6
0
        Returns:
            List[float]
        """
        if asset is None or 'proj:transform' not in asset.properties:
            return self.item.properties.get('proj:transform')
        else:
            return asset.properties.get('proj:transform')

    def set_transform(self, transform, asset=None):
        """Set an Item or an Asset transform.

        If an Asset is supplied, sets the property on the Asset.
        Otherwise sets the Item's value.
        """
        if asset is None:
            self.item.properties['proj:transform'] = transform
        else:
            asset.properties['proj:transform'] = transform

    @classmethod
    def _object_links(cls):
        return []

    @classmethod
    def from_item(cls, item):
        return cls(item)


PROJECTION_EXTENSION_DEFINITION = ExtensionDefinition(
    Extensions.PROJECTION, [ExtendedObject(Item, ProjectionItemExt)])
예제 #7
0
파일: view.py 프로젝트: whatnick/pystac
    @sun_azimuth.setter
    def sun_azimuth(self, v):
        self.item.properties['view:sun_azimuth'] = v

    @property
    def sun_elevation(self):
        """Get or sets the sun elevation angle. The angle from the tangent of the scene
        center point to the sun. Measured from the horizon in degrees (0-90).

        Returns:
            [float]
        """
        return self.item.properties.get('view:sun_elevation')

    @sun_elevation.setter
    def sun_elevation(self, v):
        self.item.properties['view:sun_elevation'] = v

    @classmethod
    def _object_links(cls):
        return []

    @classmethod
    def from_item(cls, item):
        return cls(item)


VIEW_EXTENSION_DEFINITION = ExtensionDefinition(Extensions.VIEW,
                                                [ExtendedObject(Item, ViewItemExt)])
예제 #8
0
    This class does not provide any additional functionality; the functionality for merging
    commons metadata is part of the serialization code in PySTAC.

    Args:
        collection (Collection): The collection to be extended.

    Attributes:
        collection (Collection): The Collection that is being extended.
    """
    def __init__(self, collection):
        if collection.stac_extensions is None:
            collection.stac_extensions = [Extensions.COMMONS]
        elif Extensions.COMMONS not in collection.stac_extensions:
            collection.stac_extensions.append(Extensions.COMMONS)

        self.collection = collection

    @classmethod
    def _object_links(cls):
        return []

    @classmethod
    def from_collection(cls, collection):
        return cls(collection)


COMMONS_EXTENSION_DEFINITION = ExtensionDefinition(Extensions.COMMONS, [
    ExtendedObject(Item, CommonsItemExt),
    ExtendedObject(Collection, CommonsCollectionExt)
])
예제 #9
0
            'cirrus': (1.35, 1.40),
            'swir16': (1.55, 1.75),
            'swir22': (2.10, 2.30),
            'lwir': (10.5, 12.5),
            'lwir11': (10.5, 11.5),
            'lwir12': (11.5, 12.5)
        }

        return name_to_range.get(common_name)

    @staticmethod
    def band_description(common_name):
        """Returns a description of the band for one with a common name.

        Args:
            common_name (str): The common band name. Must be one of the `list of accepted common names <https://github.com/radiantearth/stac-spec/tree/v0.8.1/extensions/eo#common-band-names>`_.

        Returns:
            str or None: If a recognized common name, returns a description including the
            band range. Otherwise returns None.
        """ # noqa E501
        r = Band.band_range(common_name)
        if r is not None:
            r = "Common name: {}, Range: {} to {}".format(
                common_name, r[0], r[1])
        return r


EO_EXTENSION_DEFINITION = ExtensionDefinition(
    Extensions.EO, [ExtendedObject(Item, EOItemExt)])
예제 #10
0
        """Get or sets a list of :class:`~pystac.Collection` objects contained
        in this Single File STAC.

        Returns:
            List[Band]
        """
        collections = self.catalog.extra_fields.get('collections')

        if collections is not None:
            collections = [pystac.read_dict(col) for col in collections]
        return collections

    @collections.setter
    def collections(self, v):
        if v is not None:
            self.catalog.extra_fields['collections'] = [col.to_dict() for col in v]
        else:
            self.catalog.extra_fields.pop('collections', None)

    @classmethod
    def _object_links(cls):
        return []

    @classmethod
    def from_catalog(cls, catalog):
        return SingleFileSTACCatalogExt(catalog)


SFS_EXTENSION_DEFINITION = ExtensionDefinition(Extensions.SINGLE_FILE_STAC,
                                               [ExtendedObject(Catalog, SingleFileSTACCatalogExt)])