Skip to content

Commit

Permalink
refactored treks and added data links to lola script
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Anikiej committed Aug 15, 2024
1 parent a6f7076 commit 6f7695f
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 169 deletions.
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 @@ -31,6 +31,10 @@
<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>
Expand Down Expand Up @@ -90,10 +94,12 @@
</File_Area_External>

<Reference_List>
{% for reference in reference_list %}
<Internal_Reference>
<lid_reference>urn:nasa:pds:context:target:satellite.earth.moon</lid_reference>
<reference_type>data_to_target</reference_type>
<lid_reference>{{reference}}</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

0 comments on commit 6f7695f

Please sign in to comment.