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

Fix to make GIS scripts work in production environment #321

Merged
merged 3 commits into from
Oct 31, 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: 1 addition & 1 deletion docker/.env
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ES_DISCOVERY_TYPE=single-node
# --------------------------------------------------------------------

# Docker image of the Registry API
REG_API_IMAGE=nasapds/registry-api-service:latest
REG_API_IMAGE=nasapds/registry-api-service:1.5.0

# Absolute path of the application.properties file to be used for the Registry API
REG_API_APP_PROPERTIES_FILE=./default-config/application.properties
Expand Down
27 changes: 19 additions & 8 deletions src/pds/registry/utils/geostac/create_lola_pds4.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
"""Script to scrape GeoSTAC for Lola point clouds and make pds4 xml."""
import argparse
import importlib
import logging
import os
from datetime import date
from pathlib import Path

import requests
from jinja2 import Environment
from pds.registry.utils.geostac import templates

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def check_for_overlap(bbox1, bbox2):
"""Checks if bounding boxes overlap anywhere.
Expand Down Expand Up @@ -53,7 +57,7 @@ def create_reference_list(item):
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"
url = "http://pds.nasa.gov/api/search/1/products/urn:nasa:pds:lro_lola_rdr:data_gridded::1.0/members"
response = requests.get(url, timeout=30)
json_data = response.json()

Expand Down Expand Up @@ -82,15 +86,16 @@ def create_product_external(item):
"""
# create env
env = Environment()

with importlib.resources.open_text(templates, "product-external-template.xml") as io:
template_text = io.read()
template = env.from_string(template_text)

item_title = item["assets"]["data"]["title"]

last_slash_i = item["assets"]["data"]["href"].rfind("/")
file = item["assets"]["data"]["href"][last_slash_i + 1:]
file = "data/" +item["assets"]["data"]["href"][last_slash_i + 1:]
logger.info(f'file is on {item["assets"]["data"]["href"]},fake file is on {file}')
open("lola_xml/product_external/" + file, 'a').close()

# fill out template params
lid = "urn:nasa:pds:geostac:external:" + item_title.lower()
Expand Down Expand Up @@ -147,7 +152,10 @@ def create_product_browse(item):
item_title = item["assets"]["data"]["title"]

last_slash_i = item["assets"]["thumbnail"]["href"].rfind("/")
file = item["assets"]["thumbnail"]["href"][last_slash_i + 1:]
file = "data/" + item["assets"]["thumbnail"]["href"][last_slash_i + 1:]
logger.info(f'file is on {item["assets"]["thumbnail"]["href"]},fake file is on {file}')
open("lola_xml/product_browse/" + file, 'a').close()

data_type = item["assets"]["thumbnail"]["type"]
encoding_map = {"image/jpeg": "JPEG"}

Expand Down Expand Up @@ -210,15 +218,18 @@ def main():
json_data = response.json()
features = json_data["features"]

if save_xml:
# create destination directoru if they don't exist
Path(dest + "/product_external").mkdir(parents=True, exist_ok=True)
Path(dest + "/product_external/data").mkdir(parents=True, exist_ok=True)
Path(dest + "/product_browse").mkdir(parents=True, exist_ok=True)
Path(dest + "/product_browse/data").mkdir(parents=True, exist_ok=True)

for item in features:
external_pds4 = create_product_external(item)
browse_pds4 = create_product_browse(item)

if save_xml:
# create destination directoru if they don't exist
Path(dest + "/product_external").mkdir(parents=True, exist_ok=True)
Path(dest + "/product_browse").mkdir(parents=True, exist_ok=True)

ex_path = dest + "/product_external/" + item["assets"]["data"]["title"] + "_product_external.xml"
with open(ex_path, "w") as f:
f.write(external_pds4)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?xml-model
href="https://pds.nasa.gov/pds4/pds/v1/PDS4_PDS_1L00.sch" schematypens="http://purl.oclc.org/dsdl/schematron"
?>
<Product_Browse>
<Product_Browse
xmlns="http://pds.nasa.gov/pds4/pds/v1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pds.nasa.gov/pds4/pds/v1 https://pds.nasa.gov/pds4/pds/v1/PDS4_PDS_1M00.xsd">
<Identification_Area>
<logical_identifier>
{{lid|e}}
Expand Down
Loading