Python API

Use OscExtension.ext() for Catalogs, Collections, and Items.

pystac.extensions.osc

Implements the :stac-ext:Open Science Catalog Extension <osc>.

OSC_EXTENSION_HOOKS: ExtensionHooks = OscExtensionHooks() module-attribute

SCHEMA_URI: str = 'https://stac-extensions.github.io/osc/v1.0.0/schema.json' module-attribute

OscType

Bases: StringEnum

The supported Open Science Catalog resource types.

Source code in pystac/extensions/osc.py
44
45
46
47
48
class OscType(StringEnum):
    """The supported Open Science Catalog resource types."""

    PROJECT = "project"
    PRODUCT = "product"

OscStatus

Bases: StringEnum

The supported lifecycle states for OSC projects and products.

Source code in pystac/extensions/osc.py
51
52
53
54
55
56
class OscStatus(StringEnum):
    """The supported lifecycle states for OSC projects and products."""

    PLANNED = "planned"
    ONGOING = "ongoing"
    COMPLETED = "completed"

OscExtension

Bases: Generic[T], PropertiesExtension, ExtensionManagementMixin[Catalog | Collection | Item]

The Open Science Catalog Extension for Catalogs, Collections, and Items.

Source code in pystac/extensions/osc.py
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
class OscExtension(
    Generic[T],
    PropertiesExtension,
    ExtensionManagementMixin[pystac.Catalog | pystac.Collection | pystac.Item],
):
    """The Open Science Catalog Extension for Catalogs, Collections, and Items."""

    name: Literal["osc"] = "osc"

    def apply_project(
        self,
        *,
        status: OscStatus,
        workflows: list[str] | None = None,
    ) -> None:
        """Apply the OSC project fields and remove product-only fields."""
        self.osc_type = OscType.PROJECT
        self.status = status
        self.workflows = workflows

        self.project = None
        self.region = None
        self.variables = None
        self.missions = None
        self.experiment = None

    def apply_product(
        self,
        *,
        status: OscStatus,
        project: str,
        region: str | None = None,
        variables: list[str] | None = None,
        missions: list[str] | None = None,
        experiment: str | None = None,
    ) -> None:
        """Apply the OSC product fields and remove project-only fields."""
        self.osc_type = OscType.PRODUCT
        self.status = status
        self.project = project
        self.region = region
        self.variables = variables
        self.missions = missions
        self.experiment = experiment

        self.workflows = None

    @property
    def osc_type(self) -> OscType | None:
        """The OSC resource type."""
        value = self._get_property(TYPE_PROP, str)
        return OscType(value) if value is not None else None

    @osc_type.setter
    def osc_type(self, value: OscType | None) -> None:
        self._set_property(TYPE_PROP, value.value if value is not None else None)

    @property
    def status(self) -> OscStatus | None:
        """The OSC lifecycle status."""
        value = self._get_property(STATUS_PROP, str)
        return OscStatus(value) if value is not None else None

    @status.setter
    def status(self, value: OscStatus | None) -> None:
        self._set_property(STATUS_PROP, value.value if value is not None else None)

    @property
    def workflows(self) -> list[str] | None:
        """The workflows created by an OSC project."""
        return self._get_property(WORKFLOWS_PROP, list[str])

    @workflows.setter
    def workflows(self, value: list[str] | None) -> None:
        self._set_property(WORKFLOWS_PROP, value)

    @property
    def project(self) -> str | None:
        """The project associated with an OSC product."""
        return self._get_property(PROJECT_PROP, str)

    @project.setter
    def project(self, value: str | None) -> None:
        self._set_property(PROJECT_PROP, value)

    @property
    def region(self) -> str | None:
        """The geographic region associated with an OSC product."""
        return self._get_property(REGION_PROP, str)

    @region.setter
    def region(self, value: str | None) -> None:
        self._set_property(REGION_PROP, value)

    @property
    def variables(self) -> list[str] | None:
        """The variables observed by an OSC product."""
        return self._get_property(VARIABLES_PROP, list[str])

    @variables.setter
    def variables(self, value: list[str] | None) -> None:
        self._set_property(VARIABLES_PROP, value)

    @property
    def missions(self) -> list[str] | None:
        """The missions providing input to an OSC product."""
        return self._get_property(MISSIONS_PROP, list[str])

    @missions.setter
    def missions(self, value: list[str] | None) -> None:
        self._set_property(MISSIONS_PROP, value)

    @property
    def experiment(self) -> str | None:
        """The experiment that created an OSC product."""
        return self._get_property(EXPERIMENT_PROP, str)

    @experiment.setter
    def experiment(self, value: str | None) -> None:
        self._set_property(EXPERIMENT_PROP, value)

    @classmethod
    def get_schema_uri(cls) -> str:
        """Return the supported OSC extension schema identifier."""
        return SCHEMA_URI

    @classmethod
    def ext(cls, obj: T, add_if_missing: bool = False) -> OscExtension[T]:
        """Wrap a Catalog, Collection, or Item with live OSC accessors.

        Args:
            obj: Object whose OSC fields will be read or modified.
            add_if_missing: Add the schema declaration when absent.

        Raises:
            pystac.ExtensionNotImplemented: If the declaration is missing and
                adding it was not requested.
            pystac.ExtensionTypeError: If the object type is unsupported.
        """
        if isinstance(obj, pystac.Collection):
            cls.ensure_has_extension(obj, add_if_missing)
            return cast("OscExtension[T]", CollectionOscExtension(obj))
        if isinstance(obj, pystac.Catalog):
            cls.ensure_has_extension(obj, add_if_missing)
            return cast("OscExtension[T]", CatalogOscExtension(obj))
        if isinstance(obj, pystac.Item):
            cls.ensure_has_extension(obj, add_if_missing)
            return cast("OscExtension[T]", ItemOscExtension(obj))
        raise pystac.ExtensionTypeError(cls._ext_error_message(obj))

experiment: str | None property writable

The experiment that created an OSC product.

missions: list[str] | None property writable

The missions providing input to an OSC product.

osc_type: OscType | None property writable

The OSC resource type.

project: str | None property writable

The project associated with an OSC product.

region: str | None property writable

The geographic region associated with an OSC product.

status: OscStatus | None property writable

The OSC lifecycle status.

variables: list[str] | None property writable

The variables observed by an OSC product.

workflows: list[str] | None property writable

The workflows created by an OSC project.

apply_product(*, status: OscStatus, project: str, region: str | None = None, variables: list[str] | None = None, missions: list[str] | None = None, experiment: str | None = None) -> None

Apply the OSC product fields and remove project-only fields.

Source code in pystac/extensions/osc.py
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def apply_product(
    self,
    *,
    status: OscStatus,
    project: str,
    region: str | None = None,
    variables: list[str] | None = None,
    missions: list[str] | None = None,
    experiment: str | None = None,
) -> None:
    """Apply the OSC product fields and remove project-only fields."""
    self.osc_type = OscType.PRODUCT
    self.status = status
    self.project = project
    self.region = region
    self.variables = variables
    self.missions = missions
    self.experiment = experiment

    self.workflows = None

apply_project(*, status: OscStatus, workflows: list[str] | None = None) -> None

Apply the OSC project fields and remove product-only fields.

Source code in pystac/extensions/osc.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def apply_project(
    self,
    *,
    status: OscStatus,
    workflows: list[str] | None = None,
) -> None:
    """Apply the OSC project fields and remove product-only fields."""
    self.osc_type = OscType.PROJECT
    self.status = status
    self.workflows = workflows

    self.project = None
    self.region = None
    self.variables = None
    self.missions = None
    self.experiment = None

ext(obj: T, add_if_missing: bool = False) -> OscExtension[T] classmethod

Wrap a Catalog, Collection, or Item with live OSC accessors.

Parameters:
  • obj (T) –

    Object whose OSC fields will be read or modified.

  • add_if_missing (bool, default: False ) –

    Add the schema declaration when absent.

Raises:
  • ExtensionNotImplemented –

    If the declaration is missing and adding it was not requested.

  • ExtensionTypeError –

    If the object type is unsupported.

Source code in pystac/extensions/osc.py
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
@classmethod
def ext(cls, obj: T, add_if_missing: bool = False) -> OscExtension[T]:
    """Wrap a Catalog, Collection, or Item with live OSC accessors.

    Args:
        obj: Object whose OSC fields will be read or modified.
        add_if_missing: Add the schema declaration when absent.

    Raises:
        pystac.ExtensionNotImplemented: If the declaration is missing and
            adding it was not requested.
        pystac.ExtensionTypeError: If the object type is unsupported.
    """
    if isinstance(obj, pystac.Collection):
        cls.ensure_has_extension(obj, add_if_missing)
        return cast("OscExtension[T]", CollectionOscExtension(obj))
    if isinstance(obj, pystac.Catalog):
        cls.ensure_has_extension(obj, add_if_missing)
        return cast("OscExtension[T]", CatalogOscExtension(obj))
    if isinstance(obj, pystac.Item):
        cls.ensure_has_extension(obj, add_if_missing)
        return cast("OscExtension[T]", ItemOscExtension(obj))
    raise pystac.ExtensionTypeError(cls._ext_error_message(obj))

get_schema_uri() -> str classmethod

Return the supported OSC extension schema identifier.

Source code in pystac/extensions/osc.py
180
181
182
183
@classmethod
def get_schema_uri(cls) -> str:
    """Return the supported OSC extension schema identifier."""
    return SCHEMA_URI

CatalogOscExtension

Bases: OscExtension[Catalog]

Expose OSC fields on a PySTAC catalog.

Source code in pystac/extensions/osc.py
210
211
212
213
214
215
216
217
218
219
220
221
class CatalogOscExtension(OscExtension[pystac.Catalog]):
    """Expose OSC fields on a PySTAC catalog."""

    catalog: pystac.Catalog
    properties: dict[str, Any]

    def __init__(self, catalog: pystac.Catalog) -> None:
        self.catalog = catalog
        self.properties = catalog.extra_fields

    def __repr__(self) -> str:
        return f"<CatalogOscExtension Catalog id={self.catalog.id}>"

CollectionOscExtension

Bases: OscExtension[Collection]

Expose OSC fields on a PySTAC collection.

Source code in pystac/extensions/osc.py
224
225
226
227
228
229
230
231
232
233
234
235
class CollectionOscExtension(OscExtension[pystac.Collection]):
    """Expose OSC fields on a PySTAC collection."""

    collection: pystac.Collection
    properties: dict[str, Any]

    def __init__(self, collection: pystac.Collection) -> None:
        self.collection = collection
        self.properties = collection.extra_fields

    def __repr__(self) -> str:
        return f"<CollectionOscExtension Collection id={self.collection.id}>"

ItemOscExtension

Bases: OscExtension[Item]

Expose OSC fields on a PySTAC item.

Source code in pystac/extensions/osc.py
238
239
240
241
242
243
244
245
246
247
248
249
class ItemOscExtension(OscExtension[pystac.Item]):
    """Expose OSC fields on a PySTAC item."""

    item: pystac.Item
    properties: dict[str, Any]

    def __init__(self, item: pystac.Item) -> None:
        self.item = item
        self.properties = item.properties

    def __repr__(self) -> str:
        return f"<ItemOscExtension Item id={self.item.id}>"

OscExtensionHooks

Bases: ExtensionHooks

Describe OSC schema membership for PySTAC migration hooks.

Source code in pystac/extensions/osc.py
252
253
254
255
256
257
258
259
260
261
class OscExtensionHooks(ExtensionHooks):
    """Describe OSC schema membership for PySTAC migration hooks."""

    schema_uri: str = SCHEMA_URI
    prev_extension_ids: ClassVar[set[str]] = set()
    stac_object_types: ClassVar[set[pystac.STACObjectType]] = {
        pystac.STACObjectType.CATALOG,
        pystac.STACObjectType.COLLECTION,
        pystac.STACObjectType.ITEM,
    }