Python API

Import the extension from pystac.extensions.earthquake. Prefer EarthquakeExtension.ext() over constructing the concrete wrappers directly.

pystac.extensions.earthquake

Implementation of the STAC :stac-ext:Earthquake Extension <earthquake>.

MagnitudeType = Literal['0', '2', '4', 'fa', 'H', 'hn', 'lg', 'm', 'ma', 'mb', 'MbLg', 'mb_lg', 'mc', 'md', 'mdl', 'Me', 'mfa', 'mh', 'Mi', 'mint', 'mj', 'ml', 'ml(texnet)', 'mlg', 'mlr', 'mlv', 'Ms', 'ms_20', 'ms_vx', 'Mt', 'muk', 'mun', 'mw', 'mwb', 'mwc', 'mwp', 'mwr', 'mww', 'no', 'uk', 'Unknown'] module-attribute

StatusType = Literal['automatic', 'reviewed', 'deleted'] module-attribute

EARTHQUAKE_EXTENSION_HOOKS: ExtensionHooks = EarthquakeExtensionHooks() module-attribute

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

EarthquakeExtension

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

Implements the STAC Earthquake Extension for Items and also supports reading/writing extension fields on Assets and Collection Item Asset Definitions.

Schema: https://stac-extensions.github.io/earthquake/v1.0.0/schema.json

Source code in pystac/extensions/earthquake.py
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
class EarthquakeExtension(
    Generic[T],
    PropertiesExtension,
    ExtensionManagementMixin[pystac.Item | pystac.Collection],
):
    """
    Implements the STAC Earthquake Extension for Items and also supports reading/writing
    extension fields on Assets and Collection Item Asset Definitions.

    Schema: https://stac-extensions.github.io/earthquake/v1.0.0/schema.json
    """

    name: Literal["eq"] = "eq"

    @classmethod
    def get_schema_uri(cls) -> str:
        """Return the published schema URI for this extension."""
        return SCHEMA_URI

    @classmethod
    def ext(cls, obj: T, add_if_missing: bool = False) -> EarthquakeExtension[T]:
        """
        Extend an Item, Asset, or ItemAssetDefinition with earthquake fields.

        Args:
            obj: The PySTAC object to wrap.
            add_if_missing: If ``True``, add the earthquake schema URI to the owning
                Item or Collection before returning the extension wrapper.
        """
        if isinstance(obj, pystac.Item):
            cls.ensure_has_extension(obj, add_if_missing)
            return cast("EarthquakeExtension[T]", ItemEarthquakeExtension(obj))
        if isinstance(obj, pystac.Asset):
            cls.ensure_owner_has_extension(obj, add_if_missing)
            return cast("EarthquakeExtension[T]", AssetEarthquakeExtension(obj))
        if isinstance(obj, pystac.ItemAssetDefinition):
            cls.ensure_owner_has_extension(obj, add_if_missing)
            return cast("EarthquakeExtension[T]", ItemAssetsEarthquakeExtension(obj))
        raise ExtensionTypeError(cls._ext_error_message(obj))

    def apply(
        self,
        *,
        magnitude: float,
        sources: list[EarthquakeSource],
        magnitude_type: MagnitudeType | None = None,
        felt: int | None = None,
        status: StatusType | None = None,
        tsunami: bool | None = None,
        depth: float | None = None,
    ) -> None:
        """
        Apply earthquake fields to the wrapped object.

        Note: schema marks `eq:magnitude` and `eq:sources` as required.
        """
        self.magnitude = magnitude
        self.sources = sources
        self.magnitude_type = magnitude_type
        self.felt = felt
        self.status = status
        self.tsunami = tsunami
        self.depth = depth

    @property
    def magnitude(self) -> float | None:
        """Magnitude of the earthquake event."""
        return self._get_property(MAGNITUDE_PROP, float)

    @magnitude.setter
    def magnitude(self, v: float | None) -> None:
        self._set_property(MAGNITUDE_PROP, _validate_magnitude(v), pop_if_none=True)

    @property
    def magnitude_type(self) -> MagnitudeType | None:
        """Magnitude scale used to compute :attr:`magnitude`."""
        return cast("MagnitudeType | None", self._get_property(MAGNITUDE_TYPE_PROP, str))

    @magnitude_type.setter
    def magnitude_type(self, v: MagnitudeType | None) -> None:
        self._set_property(MAGNITUDE_TYPE_PROP, v, pop_if_none=True)

    @property
    def felt(self) -> int | None:
        """Reported number of people who felt the event."""
        return self._get_property(FELT_PROP, int)

    @felt.setter
    def felt(self, v: int | None) -> None:
        self._set_property(FELT_PROP, _validate_felt(v), pop_if_none=True)

    @property
    def status(self) -> StatusType | None:
        """Review status of the event metadata."""
        return cast("StatusType | None", self._get_property(STATUS_PROP, str))

    @status.setter
    def status(self, v: StatusType | None) -> None:
        self._set_property(STATUS_PROP, v, pop_if_none=True)

    @property
    def tsunami(self) -> bool | None:
        """Whether the event was associated with a tsunami."""
        return self._get_property(TSUNAMI_PROP, bool)

    @tsunami.setter
    def tsunami(self, v: bool | None) -> None:
        self._set_property(TSUNAMI_PROP, v, pop_if_none=True)

    @property
    def depth(self) -> float | None:
        """Depth of the event in kilometers."""
        return self._get_property(DEPTH_PROP, float)

    @depth.setter
    def depth(self, v: float | None) -> None:
        self._set_property(DEPTH_PROP, None if v is None else float(v), pop_if_none=True)

    @property
    def sources(self) -> list[EarthquakeSource] | None:
        """Provider-specific source records associated with this event."""
        return cast(
            "list[EarthquakeSource] | None",
            self._get_property(SOURCES_PROP, list),
        )

    @sources.setter
    def sources(self, v: list[EarthquakeSource] | None) -> None:
        self._set_property(SOURCES_PROP, _validate_sources(v), pop_if_none=True)

depth: float | None property writable

Depth of the event in kilometers.

felt: int | None property writable

Reported number of people who felt the event.

magnitude: float | None property writable

Magnitude of the earthquake event.

magnitude_type: MagnitudeType | None property writable

Magnitude scale used to compute :attr:magnitude.

sources: list[EarthquakeSource] | None property writable

Provider-specific source records associated with this event.

status: StatusType | None property writable

Review status of the event metadata.

tsunami: bool | None property writable

Whether the event was associated with a tsunami.

apply(*, magnitude: float, sources: list[EarthquakeSource], magnitude_type: MagnitudeType | None = None, felt: int | None = None, status: StatusType | None = None, tsunami: bool | None = None, depth: float | None = None) -> None

Apply earthquake fields to the wrapped object.

Note: schema marks eq:magnitude and eq:sources as required.

Source code in pystac/extensions/earthquake.py
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
def apply(
    self,
    *,
    magnitude: float,
    sources: list[EarthquakeSource],
    magnitude_type: MagnitudeType | None = None,
    felt: int | None = None,
    status: StatusType | None = None,
    tsunami: bool | None = None,
    depth: float | None = None,
) -> None:
    """
    Apply earthquake fields to the wrapped object.

    Note: schema marks `eq:magnitude` and `eq:sources` as required.
    """
    self.magnitude = magnitude
    self.sources = sources
    self.magnitude_type = magnitude_type
    self.felt = felt
    self.status = status
    self.tsunami = tsunami
    self.depth = depth

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

Extend an Item, Asset, or ItemAssetDefinition with earthquake fields.

Parameters:
  • obj (T) –

    The PySTAC object to wrap.

  • add_if_missing (bool, default: False ) –

    If True, add the earthquake schema URI to the owning Item or Collection before returning the extension wrapper.

Source code in pystac/extensions/earthquake.py
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
@classmethod
def ext(cls, obj: T, add_if_missing: bool = False) -> EarthquakeExtension[T]:
    """
    Extend an Item, Asset, or ItemAssetDefinition with earthquake fields.

    Args:
        obj: The PySTAC object to wrap.
        add_if_missing: If ``True``, add the earthquake schema URI to the owning
            Item or Collection before returning the extension wrapper.
    """
    if isinstance(obj, pystac.Item):
        cls.ensure_has_extension(obj, add_if_missing)
        return cast("EarthquakeExtension[T]", ItemEarthquakeExtension(obj))
    if isinstance(obj, pystac.Asset):
        cls.ensure_owner_has_extension(obj, add_if_missing)
        return cast("EarthquakeExtension[T]", AssetEarthquakeExtension(obj))
    if isinstance(obj, pystac.ItemAssetDefinition):
        cls.ensure_owner_has_extension(obj, add_if_missing)
        return cast("EarthquakeExtension[T]", ItemAssetsEarthquakeExtension(obj))
    raise ExtensionTypeError(cls._ext_error_message(obj))

get_schema_uri() -> str classmethod

Return the published schema URI for this extension.

Source code in pystac/extensions/earthquake.py
166
167
168
169
@classmethod
def get_schema_uri(cls) -> str:
    """Return the published schema URI for this extension."""
    return SCHEMA_URI

EarthquakeSource

Bases: TypedDict

A single source entry stored in the eq:sources field.

Source code in pystac/extensions/earthquake.py
86
87
88
89
90
91
class EarthquakeSource(TypedDict, total=False):
    """A single source entry stored in the ``eq:sources`` field."""

    name: str
    code: str
    catalog: str

ItemEarthquakeExtension

Bases: EarthquakeExtension[Item]

Concrete earthquake implementation for :class:~pystac.Item objects.

Source code in pystac/extensions/earthquake.py
283
284
285
286
287
288
289
290
291
292
293
294
class ItemEarthquakeExtension(EarthquakeExtension[pystac.Item]):
    """Concrete earthquake implementation for :class:`~pystac.Item` objects."""

    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"<ItemEarthquakeExtension Item id={self.item.id}>"

AssetEarthquakeExtension

Bases: EarthquakeExtension[Asset]

Concrete earthquake implementation for :class:~pystac.Asset objects.

Source code in pystac/extensions/earthquake.py
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
class AssetEarthquakeExtension(EarthquakeExtension[pystac.Asset]):
    """Concrete earthquake implementation for :class:`~pystac.Asset` objects."""

    asset_href: str
    properties: dict[str, Any]
    additional_read_properties: Iterable[dict[str, Any]] | None = None

    def __init__(self, asset: pystac.Asset) -> None:
        self.asset_href = asset.href
        self.properties = asset.extra_fields
        if asset.owner and isinstance(asset.owner, pystac.Item):
            self.additional_read_properties = [asset.owner.properties]

    def __repr__(self) -> str:
        return f"<AssetEarthquakeExtension Asset href={self.asset_href}>"

ItemAssetsEarthquakeExtension

Bases: EarthquakeExtension[ItemAssetDefinition]

Concrete earthquake implementation for item asset definitions.

Source code in pystac/extensions/earthquake.py
314
315
316
317
318
319
320
321
322
class ItemAssetsEarthquakeExtension(EarthquakeExtension[pystac.ItemAssetDefinition]):
    """Concrete earthquake implementation for item asset definitions."""

    asset_defn: pystac.ItemAssetDefinition
    properties: dict[str, Any]

    def __init__(self, item_asset: pystac.ItemAssetDefinition) -> None:
        self.asset_defn = item_asset
        self.properties = item_asset.properties

EarthquakeExtensionHooks

Bases: ExtensionHooks

Hook registration used when reading or migrating STAC objects.

Source code in pystac/extensions/earthquake.py
325
326
327
328
329
330
331
332
333
class EarthquakeExtensionHooks(ExtensionHooks):
    """Hook registration used when reading or migrating STAC objects."""

    schema_uri: str = SCHEMA_URI
    prev_extension_ids: ClassVar[set[str]] = {"earthquake", "eq"}
    stac_object_types: ClassVar[set[pystac.STACObjectType]] = {
        pystac.STACObjectType.COLLECTION,
        pystac.STACObjectType.ITEM,
    }