How to use the descarteslabs.catalog.attributes.Attribute function in descarteslabs

To help you get started, we’ve selected a few descarteslabs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github descarteslabs / descarteslabs-python / descarteslabs / catalog / attributes.py View on Github external
def __init__(self, item_cls, validate=True, items=None, _mutable=True):
        super(ListAttribute, self).__init__(_mutable=_mutable)

        self._model_objects = {}

        # ensure we can deserilize data correctly
        if not issubclass(item_cls, Attribute):
            raise AttributeValidationError("expected an Attribute type")

        self._item_cls = item_cls
        self._item_type = item_cls(_mutable=_mutable)

        if items is None:
            items = []
        self._items = [
            self._instantiate_item(item, validate=validate) for item in items
        ]
github descarteslabs / descarteslabs-python / descarteslabs / catalog / image.py View on Github external
acquired = Timestamp()
    acquired_end = Timestamp()
    published = Timestamp()

    # Stored files
    storage_state = EnumAttribute(StorageState)
    files = ListAttribute(File)

    # Image properties
    area = Attribute()
    azimuth_angle = Attribute()
    bits_per_pixel = ListAttribute(Attribute)
    bright_fraction = Attribute()
    cloud_fraction = Attribute()
    alt_cloud_fraction = Attribute()
    processing_pipeline_id = Attribute()
    fill_fraction = Attribute()
    incidence_angle = Attribute()
    reflectance_scale = ListAttribute(Attribute)
    roll_angle = Attribute()
    solar_azimuth_angle = Attribute()
    solar_elevation_angle = Attribute()
    view_angle = Attribute()
    satellite_id = Attribute()

    # Provider info
    provider_id = Attribute()
    provider_url = Attribute()
    preview_url = Attribute()
    preview_file = Attribute()

    @classmethod
github descarteslabs / descarteslabs-python / descarteslabs / catalog / attributes.py View on Github external
Objects with resolution values can be filtered by a unitless number in which
    case the value is always in meters. For example, retrieving all bands with
    a resolution of 60 meters per pixel:

    >>> Band.search().filter(p.resolution == 60)

    Attributes
    ----------
    value : float
        Required: The value of the resolution.
    unit : str
        Required: The unit the resolution is measured in.
    """

    value = Attribute()
    unit = EnumAttribute(ResolutionUnit)

    def serialize(self, value, jsonapi_format=False):
        # Serialize a single number as is - this supports filtering resolution
        # attributes by meters.
        if isinstance(value, numbers.Number):
            return value
        else:
            return super(Resolution, self).serialize(
                value, jsonapi_format=jsonapi_format
            )


class File(MappingAttribute):
    """
    File definition for an Image.
github descarteslabs / descarteslabs-python / descarteslabs / catalog / band.py View on Github external
Raises
        ------
        NotImplementedError
            This method is not supported for DerivedBands.

    """

    _doc_type = "derived_band"
    _url = "/derived_bands"

    name = Attribute()
    description = Attribute()
    data_type = EnumAttribute(DataType)
    data_range = Attribute()
    physical_range = Attribute()
    bands = Attribute()
    function_name = Attribute()

    def save(self):
        """You cannot save a derived band.

        Raises
        ------
        NotImplementedError
            This method is not supported for DerivedBands.
        """
        raise NotImplementedError("Saving and updating DerivedBands is not permitted")

    @classmethod
    def delete(cls, id, client=None, ignore_missing=False):
        """You cannot delete a derived band.
github descarteslabs / descarteslabs-python / descarteslabs / catalog / band.py View on Github external
You cannot delete a derived band.

        Raises
        ------
        NotImplementedError
            This method is not supported for DerivedBands.

    """

    _doc_type = "derived_band"
    _url = "/derived_bands"

    name = Attribute()
    description = Attribute()
    data_type = EnumAttribute(DataType)
    data_range = Attribute()
    physical_range = Attribute()
    bands = Attribute()
    function_name = Attribute()

    def save(self):
        """You cannot save a derived band.

        Raises
        ------
        NotImplementedError
            This method is not supported for DerivedBands.
        """
        raise NotImplementedError("Saving and updating DerivedBands is not permitted")

    @classmethod
    def delete(cls, id, client=None, ignore_missing=False):
github descarteslabs / descarteslabs-python / descarteslabs / catalog / band.py View on Github external
is a 4-tuple of RGBA values to map pixels whose value is the index of the
        tuple. E.g. the colormap ``[[100, 20, 200, 255]]`` would map pixels
        whose value is 0 in the original band to the RGBA color defined by
        ``[100, 20, 200, 255]``. The number of 4-tuples provided can be up
        to the maximum of this band's data range. Omitted values will map to black
        by default.
    class_labels : list(str or None)
        A list of labels where each element is a name for the class with the value at
        that index. Elements can be null if there is no label at that value.
    """

    _derived_type = BandType.CLASS.value

    colormap_name = EnumAttribute(Colormap)
    colormap = Attribute()
    class_labels = Attribute()


class GenericBand(Band):
    """A generic kind of band not fitting any other type.

    For example mapping physical values like temperature or angles.

    Parameters
    ----------
    kwargs : dict
        With the exception of readonly attributes
        (:py:attr:`~descarteslabs.catalog.CatalogObject.created`,
        :py:attr:`~descarteslabs.catalog.CatalogObject.modified`), any
        (inherited) attribute listed below can also be used as a keyword argument.

    Inheritance
github descarteslabs / descarteslabs-python / descarteslabs / catalog / band.py View on Github external
Weighted center of min/max responsiveness of the band, in nm.
        *Filterable, sortable*.
    wavelength_nm_min : float
        Minimum wavelength this band is sensitive to, in nm.
        *Filterable, sortable*.
    wavelength_nm_max : float
        Maximum wavelength this band is sensitive to, in nm.
        *Filterable, sortable*.
    wavelength_nm_fwhm : float
        Full width at half maximum value of the wavelength spread, in nm.
        *Filterable, sortable*.
    """

    _derived_type = BandType.SPECTRAL.value

    wavelength_nm_center = Attribute()
    wavelength_nm_min = Attribute()
    wavelength_nm_max = Attribute()
    wavelength_nm_fwhm = Attribute()


class MicrowaveBand(Band):
    """A band that lies in the microwave spectrum, often from SAR or passive radar sensors.

    Parameters
    ----------
    kwargs : dict
        With the exception of readonly attributes
        (:py:attr:`~descarteslabs.catalog.CatalogObject.created`,
        :py:attr:`~descarteslabs.catalog.CatalogObject.modified`), any
        (inherited) attribute listed below can also be used as a keyword argument.
github descarteslabs / descarteslabs-python / descarteslabs / catalog / band.py View on Github external
Defaults to 0 (first file).
    jpx_layer_index : int
        The 0-based layer index if the source data is JPEG2000 with layers.
        Defaults to 0.
    """

    _doc_type = "band"
    _url = "/bands"
    _derived_type_switch = "type"
    _default_includes = ["product"]

    description = Attribute()
    type = EnumAttribute(BandType)
    sort_order = Attribute()
    data_type = EnumAttribute(DataType)
    nodata = Attribute()
    data_range = Attribute()
    display_range = Attribute()
    resolution = Resolution()
    band_index = Attribute()
    file_index = Attribute()
    jpx_layer_index = Attribute()

    def __new__(cls, *args, **kwargs):
        return _new_abstract_class(cls, Band)

    def __init__(self, **kwargs):
        if self._derived_type_switch not in kwargs:
            kwargs[self._derived_type_switch] = self._derived_type

        super(Band, self).__init__(**kwargs)
github descarteslabs / descarteslabs-python / descarteslabs / catalog / product.py View on Github external
*Filterable, sortable*.
    resolution_min : Resolution
        Minimum resolution of the bands for this product. If applying a filter with a
        plain unitless number the value is assumed to be in meters.
        *Filterable, sortable*.
    resolution_max : Resolution
        Maximum resolution of the bands for this product. If applying a filter with a
        plain unitless number the value is assumed to be in meters.
        *Filterable, sortable*.
    """

    _doc_type = "product"
    _url = "/products"

    # Product Attributes
    name = Attribute()
    description = Attribute()
    is_core = BooleanAttribute()
    revisit_period_minutes_min = Attribute()
    revisit_period_minutes_max = Attribute()
    start_datetime = Timestamp()
    end_datetime = Timestamp()
    resolution_min = Resolution()
    resolution_max = Resolution()

    @check_deleted
    def delete_related_objects(self):
        """Delete all related bands and images for this product.

        Starts an asynchronous operation that deletes all bands and images associated
        with this product. If the product has a large number of associated images, this
        operation could take several minutes, or even hours.
github descarteslabs / descarteslabs-python / descarteslabs / catalog / band.py View on Github external
is_alpha : bool
        Whether this band should be useable as an alpha band during rastering.
        This enables special behavior for this band during rastering. If this
        is ``True`` and the band appears as the last band in a raster operation
        (such as :meth:`descarteslabs.scenes.scenecollection.SceneCollection.mosaic`
        or :meth:`descarteslabs.scenes.scenecollection.SceneCollection.stack`)
        pixels with a value of 0 in this band will be treated as transparent.
    data_range : tuple(float, float)
        Readonly: [0, 1].
    display_range : tuple(float, float)
        Readonly: [0, 1].
    """

    _derived_type = BandType.MASK.value

    is_alpha = Attribute()


class ClassBand(Band):
    """A band that maps a finite set of values that may not be continuous.

    For example land use classification.  A visualization with straight pixel values
    is typically not useful, so commonly a colormap is used.

    Parameters
    ----------
    kwargs : dict
        With the exception of readonly attributes
        (:py:attr:`~descarteslabs.catalog.CatalogObject.created`,
        :py:attr:`~descarteslabs.catalog.CatalogObject.modified`), any
        (inherited) attribute listed below can also be used as a keyword argument.