Skip to content

Commit 9351385

Browse files
Add MLM extension (#1542)
* added missing Classification parameter title * added changes to changelog * added missing parameters to test_classification_object: title, nodata, percentage, count * added ml extension * added stac:mlm extension tests * added collection and asset extension * removed TODO * added documentation * added docstring to classes * renamed asset extension classes * added mlm extension classes * added mlm extension * removed todos * added extension migration * removed useless code * fixed docstrings * fixed __eq__ NotImplemented * fixed repr strings * improved test coverage * improved test coverage * changed exceptions * fixed docstring * Update CHANGELOG.md Co-authored-by: Pete Gadomski <[email protected]> * fixed typo Co-authored-by: Pete Gadomski <[email protected]> * fixed typo Co-authored-by: Pete Gadomski <[email protected]> * fixed typo Co-authored-by: Pete Gadomski <[email protected]> * fixed typo Co-authored-by: Pete Gadomski <[email protected]> * fixed typo Co-authored-by: Pete Gadomski <[email protected]> * line break to satisfy line length requirement * fixed typo in ENTRYPOINT_ASSET_PROP * fixed typo in COMPILE_METHOD_ASSET_PROP * removed dummy docstring * fixed Enum tuples * added mlm to CollectionExt * added mlm to Asset and ItemAssetDefinition mlm accessor * Update CHANGELOG.md --------- Co-authored-by: Pete Gadomski <[email protected]>
1 parent e713adf commit 9351385

File tree

12 files changed

+5580
-0
lines changed

12 files changed

+5580
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Added
66

77
- `Collection.from_items` for creating a `pystac.Collection` from an `ItemCollection` ([#1522](https://github.com/stac-utils/pystac/pull/1522))
8+
- `extensions.mlm` for supporting the [MLM](https://github.com/stac-extensions/mlm) extension ([#1542](https://github.com/stac-utils/pystac/pull/1542))
89

910
### Fixed
1011

docs/api/extensions.rst

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ pystac.extensions
2020
grid.GridExtension
2121
item_assets.ItemAssetsExtension
2222
mgrs.MgrsExtension
23+
mlm.MLMExtension
24+
mlm.AssetGeneralMLMExtension
25+
mlm.AssetDetailedMLMExtension
2326
pointcloud.PointcloudExtension
2427
projection.ProjectionExtension
2528
raster.RasterExtension

docs/api/extensions/mlm.rst

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pystac.extensions.mlm
2+
============================
3+
4+
.. automodule:: pystac.extensions.mlm
5+
:members:
6+
:inherited-members: StringEnum, Generic, PropertiesExtension, ExtensionManagementMixin
7+
:undoc-members:
8+

pystac/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
warnings.filterwarnings("ignore", category=DeprecationWarning)
101101
import pystac.extensions.label
102102
import pystac.extensions.mgrs
103+
import pystac.extensions.mlm
103104
import pystac.extensions.pointcloud
104105
import pystac.extensions.projection
105106
import pystac.extensions.raster
@@ -123,6 +124,7 @@
123124
pystac.extensions.item_assets.ITEM_ASSETS_EXTENSION_HOOKS,
124125
pystac.extensions.label.LABEL_EXTENSION_HOOKS,
125126
pystac.extensions.mgrs.MGRS_EXTENSION_HOOKS,
127+
pystac.extensions.mlm.MLM_EXTENSION_HOOKS,
126128
pystac.extensions.pointcloud.POINTCLOUD_EXTENSION_HOOKS,
127129
pystac.extensions.projection.PROJECTION_EXTENSION_HOOKS,
128130
pystac.extensions.raster.RASTER_EXTENSION_HOOKS,

pystac/extensions/ext.py

+26
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
from pystac.extensions.grid import GridExtension
2020
from pystac.extensions.item_assets import ItemAssetsExtension
2121
from pystac.extensions.mgrs import MgrsExtension
22+
from pystac.extensions.mlm import (
23+
AssetDetailedMLMExtension,
24+
AssetGeneralMLMExtension,
25+
MLMExtension,
26+
)
2227
from pystac.extensions.pointcloud import PointcloudExtension
2328
from pystac.extensions.projection import ProjectionExtension
2429
from pystac.extensions.raster import RasterExtension
@@ -48,6 +53,7 @@
4853
"grid",
4954
"item_assets",
5055
"mgrs",
56+
"mlm",
5157
"pc",
5258
"proj",
5359
"raster",
@@ -71,6 +77,7 @@
7177
GridExtension.name: GridExtension,
7278
ItemAssetsExtension.name: ItemAssetsExtension,
7379
MgrsExtension.name: MgrsExtension,
80+
MLMExtension.name: MLMExtension,
7481
PointcloudExtension.name: PointcloudExtension,
7582
ProjectionExtension.name: ProjectionExtension,
7683
RasterExtension.name: RasterExtension,
@@ -153,6 +160,10 @@ def cube(self) -> DatacubeExtension[Collection]:
153160
def item_assets(self) -> dict[str, ItemAssetDefinition]:
154161
return ItemAssetsExtension.ext(self.stac_object).item_assets
155162

163+
@property
164+
def mlm(self) -> MLMExtension[Collection]:
165+
return MLMExtension.ext(self.stac_object)
166+
156167
@property
157168
def render(self) -> dict[str, Render]:
158169
return RenderExtension.ext(self.stac_object).renders
@@ -225,6 +236,10 @@ def grid(self) -> GridExtension:
225236
def mgrs(self) -> MgrsExtension:
226237
return MgrsExtension.ext(self.stac_object)
227238

239+
@property
240+
def mlm(self) -> MLMExtension[Item]:
241+
return MLMExtension.ext(self.stac_object)
242+
228243
@property
229244
def pc(self) -> PointcloudExtension[Item]:
230245
return PointcloudExtension.ext(self.stac_object)
@@ -389,6 +404,13 @@ class AssetExt(_AssetExt[Asset]):
389404
def file(self) -> FileExtension[Asset]:
390405
return FileExtension.ext(self.stac_object)
391406

407+
@property
408+
def mlm(self) -> AssetGeneralMLMExtension[Asset] | AssetDetailedMLMExtension:
409+
if "mlm:name" in self.stac_object.extra_fields:
410+
return AssetDetailedMLMExtension.ext(self.stac_object)
411+
else:
412+
return AssetGeneralMLMExtension.ext(self.stac_object)
413+
392414
@property
393415
def timestamps(self) -> TimestampsExtension[Asset]:
394416
return TimestampsExtension.ext(self.stac_object)
@@ -406,6 +428,10 @@ class ItemAssetExt(_AssetExt[ItemAssetDefinition]):
406428

407429
stac_object: ItemAssetDefinition
408430

431+
@property
432+
def mlm(self) -> MLMExtension[ItemAssetDefinition]:
433+
return MLMExtension.ext(self.stac_object)
434+
409435

410436
@dataclass
411437
class LinkExt(_AssetsExt[Link]):

0 commit comments

Comments
 (0)