Skip to content

Commit

Permalink
Client: v3.0.0 cleanup - remove metadata v1, scenes, and derived band…
Browse files Browse the repository at this point in the history
…s (#12382)

GitOrigin-RevId: 507e680b898050110d25f5e37f05a75fad3e5968
  • Loading branch information
stephencpope authored and Descartes Labs Build committed Jan 4, 2024
1 parent b008440 commit b55ba5e
Show file tree
Hide file tree
Showing 37 changed files with 22 additions and 4,983 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ Changelog

- The `tags` attributes on Catalog objects can now contain up to 32 elements, each up to 1000 characters long.
But why would you even want to go there?
- *Breaking Change*: Derived bands, never supported in the AWS environment and catalog products, have been
removed.

### Compute

- `Function` and `Job` objects now have a new `environment` attribute which can be used to define environment
variables for the jobs when they are run.
- Breaking Change: The `Function.map` method previously had no bound on how many jobs could be created at one time.
- *Breaking Change*: The `Function.map` method previously had no bound on how many jobs could be created at one time.
This led to operational problems with very large numbers of jobs. Now it submits jobs in batches (up to 1000
jobs per batch) to avoid request timeouts, and is more robust on retryable errors so that duplicate jobs are not
submitted accidently. There is still no bound on how many jobs you may create with a single call to `Function.map`.
Expand All @@ -40,9 +42,11 @@ Changelog

### General

- The minimum required version of `urllib3` has been bumped to 1.26.18 to address a security vulnerability.
- The old client version v1.12.1 is reaching end of life and will no longer be supported as of February 2024.
- The old client version v1.12.1 is reaching end of life and will longer be supported as of February 2024.
You can expect the version to stop working at any point after that as legacy backend support is turned off.
- *Breaking Change*: The deprecated `Scenes` client API has been removed.
- *Breaking Change*: The deprecated `Metadata` client API has been removed.
- The minimum required version of `urllib3` has been bumped to 1.26.18 to address a security vulnerability.

## [2.1.2] - 2023-10-31

Expand Down
2 changes: 0 additions & 2 deletions descarteslabs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
from descarteslabs import geo
from descarteslabs import utils
from descarteslabs import catalog
from descarteslabs import scenes

select_env = config.select_env
get_settings = config.get_settings
Expand All @@ -65,7 +64,6 @@
"exceptions",
"geo",
"get_settings",
"scenes",
"select_env",
"utils",
]
4 changes: 0 additions & 4 deletions descarteslabs/core/catalog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
ClassBand,
Colormap,
DataType,
DerivedBand,
DerivedBandCollection,
DerivedParamsAttribute,
GenericBand,
MaskBand,
Expand Down Expand Up @@ -98,8 +96,6 @@
"DataType",
"DeletedObjectError",
"DeletionTaskStatus",
"DerivedBand",
"DerivedBandCollection",
"DerivedParamsAttribute",
"DocumentState",
"DownloadFileFormat",
Expand Down
115 changes: 1 addition & 114 deletions descarteslabs/core/catalog/band.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@

from strenum import StrEnum

from ..client.deprecation import deprecate
from ..common.collection import Collection
from ..common.property_filtering import Properties
from .catalog_base import CatalogObject, _new_abstract_class
from .catalog_base import _new_abstract_class
from .named_catalog_base import NamedCatalogObject
from .attributes import (
Attribute,
Expand Down Expand Up @@ -900,115 +899,3 @@ class GenericBand(Band):
physical_range_unit = Attribute(doc="str, optional: Unit of the physical range.")
colormap_name = EnumAttribute(Colormap, doc=Band._DOC_COLORMAPNAME)
colormap = Attribute(doc=Band._DOC_COLORMAP)


class DerivedBand(CatalogObject):
"""A band with pixel values computed from the data in other bands.
A type of band that is the result of a pixel function applied to one or more
existing bands. This object type only supports read operations;
they cannot be created, updated, or deleted using this client.
Instantiating a derived band can only be done through `Band.get()
<descarteslabs.catalog.Band.get>`, or `Band.search()
<descarteslabs.catalog.Band.search>`.
Parameters
----------
client : CatalogClient, optional
A `CatalogClient` instance to use for requests to the Descartes Labs catalog.
The :py:meth:`~descarteslabs.catalog.CatalogClient.get_default_client` will
be used if not set.
kwargs : dict, optional
You cannot set any additional keyword arguments as a derived band is readonly.
"""

_doc_type = "derived_band"
_url = "/derived_bands"
# _collection_type set below due to circular problems

name = Attribute(
readonly=True,
doc="""str, readonly: The name of the derived band, globally unique.
*Filterable, sortable*.
""",
)
description = Attribute(
readonly=True, doc="str, readonly: " + Band._DOC_DESCRIPTION
)
data_type = EnumAttribute(
DataType, readonly=True, doc="str or DataType, readonly: " + Band._DOC_DATATYPE
)
data_range = Attribute(
readonly=True, doc="tuple(float, float), readonly: " + Band._DOC_DATARANGE
)
physical_range = TupleAttribute(
readonly=True,
min_length=2,
max_length=2,
coerce=True,
attribute_type=float,
doc=Band._DOC_PHYSICALRANGE,
)
bands = Attribute(
readonly=True,
doc="""list(str), readonly: List of bands used in the derived band pixel function.
*Filterable*
""",
)
function_name = Attribute(
readonly=True,
doc="str, readonly: Name of the function applied to create this derived band.",
)

def update(self, **kwargs):
"""You cannot update a derived band.
Raises
------
NotImplementedError
This method is not supported for DerivedBands.
"""
raise NotImplementedError("Updating DerivedBands is not permitted")

@deprecate(renamed={"extra_attributes": "request_params"})
def save(self, request_params=None):
"""You cannot save a derived band.
Raises
------
NotImplementedError
This method is not supported for DerivedBands.
"""
raise NotImplementedError("Saving DerivedBands is not permitted")

@classmethod
def delete(cls, id, client=None):
"""You cannot delete a derived band.
Raises
------
NotImplementedError
This method is not supported for DerivedBands.
"""
raise NotImplementedError("Deleting DerivedBands is not permitted")

def _instance_delete(self):
"""You cannot delete a derived band.
Raises
------
NotImplementedError
This method is not supported for DerivedBands.
"""
raise NotImplementedError("Deleting DerivedBands is not permitted")


class DerivedBandCollection(Collection):
_item_type = DerivedBand


# set here due to circular references
DerivedBand._collection_type = DerivedBandCollection
14 changes: 1 addition & 13 deletions descarteslabs/core/catalog/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
from ..client.services.raster import Raster
from ..common.property_filtering import Properties

from .band import Band, DerivedBand
from .search import Search
from .band import Band
from .image_types import DownloadFileFormat, ResampleAlgorithm


Expand All @@ -36,17 +35,6 @@ def cached_bands_by_product(product_id, client):
Properties().product_id == product_id
)
}
bands.update(
{
band.id: band
for band in Search(
DerivedBand,
url="/products/{}/relationships/derived_bands".format(product_id),
client=client,
includes=False,
)
}
)
return bands


Expand Down
8 changes: 4 additions & 4 deletions descarteslabs/core/catalog/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,8 +1000,8 @@ def ndarray(
----------
bands : str or Sequence[str]
Band names to load. Can be a single string of band names
separated by spaces (``"red green blue derived:ndvi"``),
or a sequence of band names (``["red", "green", "blue", "derived:ndvi"]``).
separated by spaces (``"red green blue"``),
or a sequence of band names (``["red", "green", "blue"]``).
Names must be keys in ``self.properties.bands``.
If the alpha band is requested, it must be last in the list
to reduce rasterization errors.
Expand Down Expand Up @@ -1249,8 +1249,8 @@ def download(
----------
bands : str or Sequence[str]
Band names to load. Can be a single string of band names
separated by spaces (``"red green blue derived:ndvi"``),
or a sequence of band names (``["red", "green", "blue", "derived:ndvi"]``).
separated by spaces (``"red green blue"``),
or a sequence of band names (``["red", "green", "blue"]``).
Names must be keys in ``self.properties.bands``.
geocontext : :class:`~descarteslabs.common.geo.geocontext.GeoContext`, default None
A :class:`~descarteslabs.common.geo.geocontext.GeoContext` to use when loading this image.
Expand Down
5 changes: 1 addition & 4 deletions descarteslabs/core/catalog/image_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from ..client.services.raster import Raster

from .attributes import ResolutionUnit
from .band import DerivedBand
from .image_types import ResampleAlgorithm, DownloadFileFormat
from .helpers import bands_to_list, cached_bands_by_product, download, is_path_like
from .scaling import multiproduct_scaling_parameters, append_alpha_scaling
Expand Down Expand Up @@ -75,9 +74,7 @@ def __init__(self, iterable=None, geocontext=None):
band.resolution
for product_id in product_bands
for band in product_bands[product_id].values()
if not isinstance(band, DerivedBand)
and band.resolution is not None
and band.resolution.value
if band.resolution is not None and band.resolution.value
]

if resolutions:
Expand Down
27 changes: 0 additions & 27 deletions descarteslabs/core/catalog/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
_new_abstract_class,
check_deleted,
)
from .search import Search


properties = Properties()
Expand Down Expand Up @@ -395,32 +394,6 @@ def bands(self, request_params=None):
.sort("sort_order")
)

@check_deleted
def derived_bands(self, request_params=None):
"""A search query for all derived bands associated with this product.
Returns
-------
:py:class:`~descarteslabs.catalog.Search`
A :py:class:`~descarteslabs.catalog.Search` instance configured to
find all derived bands for this product.
Raises
------
DeletedObjectError
If this product was deleted.
"""
from .band import DerivedBand

return Search(
DerivedBand,
url="{}/{}/relationships/{}".format(self._url, self.id, "derived_bands"),
client=self._client,
includes=False,
request_params=request_params,
)

@check_deleted
def images(self, request_params=None):
"""A search query for all images in this product.
Expand Down
7 changes: 1 addition & 6 deletions descarteslabs/core/catalog/scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,7 @@ def properties_for_band(name, band, processing_level):
"""
Gather up relevant properties for the band, applying processing level and defaults.
"""
# DerivedBand has no type field but treat as generic
band_type = getattr(band, "type", BandType.GENERIC)
band_type = band.type

# defaults on band base properties are real legacy
data_type = band.data_type or "UInt16"
Expand Down Expand Up @@ -552,8 +551,6 @@ def scaling_parameters(properties, bands, processing_level, scaling, data_type):
for band in bands:
if band not in properties:
message = "Invalid bands: band '{}' is not available".format(band)
if "derived:{}".format(band) in properties:
message += ", did you mean 'derived:{}'?".format(band)
raise ValueError(message)
band_properties[band] = properties_for_band(
band, properties[band], processing_level
Expand Down Expand Up @@ -642,8 +639,6 @@ def multiproduct_scaling_parameters(
band, product
)
)
if "derived:{}".format(band) in properties[product]:
message += ", did you mean 'derived:{}'?".format(band)
raise ValueError(message)
product_band_properties.setdefault(product, {})[band] = properties_for_band(
band, properties[product][band], processing_level
Expand Down
6 changes: 1 addition & 5 deletions descarteslabs/core/catalog/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
from .attributes import serialize_datetime


V1_COMPATIBILITY = "v1_compatibility"


class Search(object):
"""A search request that iterates over its search results.
Expand Down Expand Up @@ -227,10 +224,9 @@ def _to_request(self):

def _require_product_ids(self, filters):
from .product import Product
from .band import DerivedBand
from .blob import Blob

if self._model_cls in (Product, DerivedBand, Blob):
if self._model_cls in (Product, Blob):
return
if filters:
for filter in filters:
Expand Down
Loading

0 comments on commit b55ba5e

Please sign in to comment.