Skip to content

Create valid temporal ranges when updating collection extents #590

@anayeaye

Description

@anayeaye

Note I initially drafted this issue thinking that the temporal ranges were causing stac-browser incompatibility for the dev disasters instance but it turns out there is also a cloudfront behavior problem. If the cloudfront behavior resolution makes the root stac api compatible with stac-browser, we can close this issue. Related issue: https://github.com/NASA-IMPACT/veda-architecture/issues/754

What

Automated updates to stac collection temporal extent is creating invalid stac metadata. This is currently happening in a custom SQL function which should be improved or replaced with a different technique for updating the temporal range of a collection to agree with the true range of item dates.

    "temporal": {
      "interval": [
        [
          "2023-01-15 00:00:00+00",
          "2024-08-08 23:59:59+00"
        ]
      ]
    }

should be

    "temporal": {
      "interval": [
        [
          "2023-01-15T00:00:00Z",
          "2024-08-08T23:59:59Z"
        ]
      ]
    }

update extents current SQL

def create_collection_extents_functions(cursor) -> None:
"""
Functions to update spatial and temporal extents off all items in a collection
This is slightly different from the inbuilt pgstac.update_collection_extents function which describes the range of nominal datetimes,
here we capture the maximum range which must include max end datetime.
"""
collection_temporal_extent_max_sql = """
CREATE OR REPLACE FUNCTION dashboard.collection_temporal_extent_max(id text) RETURNS jsonb
LANGUAGE sql
IMMUTABLE PARALLEL SAFE
SET search_path TO 'pgstac', 'public'
AS $function$
SELECT to_jsonb(array[array[min(datetime)::text, max(end_datetime)::text]])
FROM items WHERE collection=$1;
$function$
;
"""
cursor.execute(sql.SQL(collection_temporal_extent_max_sql))
update_collection_extents_max_sql = """
CREATE OR REPLACE FUNCTION dashboard.update_collection_extents_max(id text)
RETURNS void
LANGUAGE sql
SET search_path TO 'pgstac', 'public'
AS $function$
UPDATE collections SET
content = content ||
jsonb_build_object(
'extent', jsonb_build_object(
'spatial', jsonb_build_object(
'bbox', collection_bbox(collections.id)
),
'temporal', jsonb_build_object(
'interval', dashboard.collection_temporal_extent_max(collections.id)
)
)
)
WHERE collections.id=$1;
$function$
;
"""
cursor.execute(sql.SQL(update_collection_extents_max_sql))

datetime formatting in datetime summries

SELECT to_jsonb(
array[
to_char(min(datetime) at time zone 'Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"'),
to_char(max(end_datetime) at time zone 'Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')
])​

ingest-api extent update event

Collection temporal and spatial extents are updated when the ingestions api is used to enqueue and publish items to an existing collection

# First update the spatial and temporal extents for all item records for the collection
logger.info(f"Updating extents for collection: {collection_id}.")
cur.execute(
"SELECT dashboard.update_collection_extents_max(%s)",
(collection_id,),
)
# Next update default summaries which use the collection temporal extent for summaries of periodic items
logger.info(
f"Updating dashboard summaries for collection: {collection_id}."
)
cur.execute(
"SELECT dashboard.update_collection_default_summaries(%s)",
(collection_id,),

AC

  • first check to see if upgrading pgstac version will resolve this problem!
  • when ingestions/ endpoint enqueued veda data load completes, the temporal extent update produces valid RFC3339 dates
  • propose and ticket solution for identifying and correcting existing invalid collection temporal ranges

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions