Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LID Reference to LOLA GDR in GeoSTAC script #317

Merged
merged 7 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ All users and developers of the NASA-PDS software are expected to abide by our [
* This package is also hosted on the "cheeseshop" and can be installed with
```pip install pds.registry```
* The GeoSTAC utilities can be used to create pds4 labels for the Lola point clouds they host
* This command needs LOLA GDR data to be loaded in the registry in order to connect the lid references
* This data can be found here: [https://pds-geosciences.wustl.edu/lro/lro-l-lola-3-rdr-v1/lrolol_1xxx/data/lola_gdr/cylindrical/float_img/](https://pds-geosciences.wustl.edu/lro/lro-l-lola-3-rdr-v1/lrolol_1xxx/data/lola_gdr/cylindrical/float_img/)
* Run the command:
```create-lola-pds4```

Expand Down
68 changes: 67 additions & 1 deletion src/pds/registry/utils/geostac/create_lola_pds4.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,70 @@
from pds.registry.utils.geostac import templates


def check_for_overlap(bbox1, bbox2):
"""Checks if bounding boxes overlap anywhere.

:param item: item to fill out pds4 xml information with

:return: reference list
"""
# unpack bounding boxes
b1_west, b1_south, b1_east, b1_north = bbox1
b2_west, b2_south, b2_east, b2_north = bbox2

# check lat overlap
lat_overlap = False
if b1_east >= b2_west and b2_east >= b1_west:
lat_overlap = True

# check lon overlap
lon_overlap = False
if b1_north >= b2_south and b2_north >= b1_south:
lon_overlap = True

if lat_overlap and lon_overlap:
return True

return False


def create_reference_list(item):
"""Finds relevant references for given item.

:param item: item to fill out pds4 xml information with

:return: reference list
"""
reference_list = []

bb_west = float(item["bbox"][0])
bb_south = float(item["bbox"][1])
bb_east = float(item["bbox"][2])
bb_north = float(item["bbox"][3])

bbox1 = [bb_west, bb_south, bb_east, bb_north]

# needs to be updated with the collection we want to check for overlapping bounding boxes with
url = "http://localhost:8080/products/urn:nasa:pds:lro_lola_rdr:data_gridded::1.0/members"
response = requests.get(url, timeout=30)
json_data = response.json()

for gdr in json_data["data"]:

gdr_lid = gdr["properties"]["lid"][0]
gdr_bb_west = float(gdr["properties"]["cart:Bounding_Coordinates.cart:west_bounding_coordinate"][0])
gdr_bb_south = float(gdr["properties"]["cart:Bounding_Coordinates.cart:south_bounding_coordinate"][0])
gdr_bb_east = float(gdr["properties"]["cart:Bounding_Coordinates.cart:east_bounding_coordinate"][0])
gdr_bb_north = float(gdr["properties"]["cart:Bounding_Coordinates.cart:north_bounding_coordinate"][0])

bbox2 = [gdr_bb_west, gdr_bb_south, gdr_bb_east, gdr_bb_north]

if check_for_overlap(bbox1, bbox2):
reference_list.append(gdr_lid)

return reference_list


def create_product_external(item):
"""Creates Product_External for given item.

Expand Down Expand Up @@ -43,6 +107,7 @@ def create_product_external(item):
file_url = item["assets"]["data"]["href"]
# file_size not in api, but also not required by pds
encoding_standard = item["properties"]["pc:encoding"]
reference_list = create_reference_list(item)

context = {
"lid": lid,
Expand All @@ -58,7 +123,8 @@ def create_product_external(item):
"file_date": file_date,
"file_url": file_url,
# file_size
"encoding_standard": encoding_standard
"encoding_standard": encoding_standard,
"reference_list": reference_list
}

return template.render(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ href="https://pds.nasa.gov/pds4/pds/v1/PDS4_PDS_1L00.sch" schematypens="http://p
<Product_Browse>
<Identification_Area>
<logical_identifier>
{{lid}}
{{lid|e}}
</logical_identifier>
<version_id>1.0</version_id>
<title>
{{title}}
{{title|e}}
</title>
<information_model_version>1.21.0.0</information_model_version>
<product_class>Product_Browse</product_class>
Expand All @@ -17,7 +17,7 @@ href="https://pds.nasa.gov/pds4/pds/v1/PDS4_PDS_1L00.sch" schematypens="http://p
<Internal_Reference>
<!-->lid_reference is incorrect, used as filler right now</-->
<lid_reference>
{{lid_ref}}
{{lid_ref|e}}
</lid_reference>
<reference_type>browse_to_data</reference_type>
<comment>
Expand All @@ -27,15 +27,15 @@ href="https://pds.nasa.gov/pds4/pds/v1/PDS4_PDS_1L00.sch" schematypens="http://p
</Reference_List>
<File_Area_Browse>
<File>
<file_name>{{file_name}}</file_name>
<file_name>{{file_name|e}}</file_name>
<local_identifier>BROWSE_FILE</local_identifier>
<creation_date_time>{{file_date}}</creation_date_time>
<file_URL>{{file_url}}</file_URL>
<creation_date_time>{{file_date|e}}</creation_date_time>
<file_URL>{{file_url|e}}</file_URL>
</File>
<Encoded_Image>
<local_identifier>BROWSE_IMAGE</local_identifier>
<offset unit="byte">0</offset>
<encoding_standard_id>{{encoding}}</encoding_standard_id>
<encoding_standard_id>{{encoding|e}}</encoding_standard_id>
</Encoded_Image>
</File_Area_Browse>
</Product_Browse>
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
http://pds.nasa.gov/pds4/cart/v1 https://pds.nasa.gov/pds4/cart/v1/PDS4_CART_1L00_1970.xsd">

<Identification_Area>
<logical_identifier>{{lid}}</logical_identifier>
<logical_identifier>{{lid|e}}</logical_identifier>
<version_id>1.0</version_id>
<title>{{title}}</title>
<title>{{title|e}}</title>
<information_model_version>1.21.0.0</information_model_version>
<product_class>Product_External</product_class>
<Modification_History>
<Modification_Detail>
<modification_date>{{modification_date}}</modification_date>
<modification_date>{{modification_date|e}}</modification_date>
<version_id>1.0</version_id>
<description>
Derived release of the LOLA LIDAR shots in a stretched LAZ/COPC format for streaming services
Expand All @@ -31,19 +31,23 @@
<Target_Identification>
<name>Moon</name>
<type>Satellite</type>
<Internal_Reference>
<lid_reference>urn:nasa:pds:context:target:satellite.earth.moon</lid_reference>
<reference_type>data_to_target</reference_type>
</Internal_Reference>
</Target_Identification>
<Discipline_Area>
<cart:Cartography>
<Local_Internal_Reference>
<local_identifier_reference>{{lid_ref}}</local_identifier_reference>
<local_identifier_reference>{{lid_ref|e}}</local_identifier_reference>
<local_reference_type>cartography_parameters_to_service</local_reference_type>
</Local_Internal_Reference>
<cart:Spatial_Domain>
<cart:Bounding_Coordinates>
<cart:west_bounding_coordinate unit="deg">{{bb_west}}</cart:west_bounding_coordinate>
<cart:east_bounding_coordinate unit="deg">{{bb_east}}</cart:east_bounding_coordinate>
<cart:north_bounding_coordinate unit="deg">{{bb_north}}</cart:north_bounding_coordinate>
<cart:south_bounding_coordinate unit="deg">{{bb_south}}</cart:south_bounding_coordinate>
<cart:west_bounding_coordinate unit="deg">{{bb_west|e}}</cart:west_bounding_coordinate>
<cart:east_bounding_coordinate unit="deg">{{bb_east|e}}</cart:east_bounding_coordinate>
<cart:north_bounding_coordinate unit="deg">{{bb_north|e}}</cart:north_bounding_coordinate>
<cart:south_bounding_coordinate unit="deg">{{bb_south|e}}</cart:south_bounding_coordinate>
</cart:Bounding_Coordinates>
</cart:Spatial_Domain>
<cart:Spatial_Reference_Information>
Expand Down Expand Up @@ -72,9 +76,9 @@
</Context_Area>
<File_Area_External>
<File>
<file_name>{{file_name}}</file_name>
<local_identifier>{{lid_file}}</local_identifier>
<creation_date_time>{{file_date}}</creation_date_time>
<file_name>{{file_name|e}}</file_name>
<local_identifier>{{lid_file|e}}</local_identifier>
<creation_date_time>{{file_date|e}}</creation_date_time>
<file_URL>{{file_url}}</file_URL>
<!-- <file_size unit="byte">{{file_size}}</file_size> -->
<comment>
Expand All @@ -88,4 +92,14 @@
<encoding_standard_id>{{encoding_standard}}</encoding_standard_id>
</Encoded_External>
</File_Area_External>

<Reference_List>
{% for reference in reference_list %}
<Internal_Reference>
<lid_reference>{{reference|e}}</lid_reference>
<reference_type>external_used_to_derive_gridded_data</reference_type>
</Internal_Reference>
{% endfor %}
</Reference_List>

</Product_External>
8 changes: 7 additions & 1 deletion src/pds/registry/utils/treks/create_treks_pds4.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ def main():
dest=target_dest,
verbose=verbose)

_, lidvid = psb.create_pds4_xml()
service_pds4, lidvid = psb.create_pds4_xml()

if save_xml:
save_path = target_dest + "/" + data["productLabel"].lower() + ".xml"
with open(save_path, "w") as f:
f.write(service_pds4)

entry = "P," + lidvid + "\n"
inventory_entries.append(entry)

Expand Down
Loading