Skip to content

Commit

Permalink
fix: fix and rename util function to get product id from filename
Browse files Browse the repository at this point in the history
  • Loading branch information
jkgeo committed Dec 20, 2024
1 parent cf02a5e commit 0c91d4b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions glam_api/glam/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
AnomalyBaselineRaster,
)

from glam.utils import extract_datetime_from_filename, match_filename_to_product_id
from glam.utils import extract_datetime_from_filename, get_product_id_from_filename

from config.storage import RasterStorage

Expand Down Expand Up @@ -167,7 +167,7 @@ def add_product_rasters_from_storage():
else:
prelim = False
ds_date = extract_datetime_from_filename(filename)
product_id = match_filename_to_product_id(filename)
product_id = get_product_id_from_filename(filename)
dataset_directory = os.path.join(
settings.PRODUCT_DATASET_LOCAL_PATH, product_id
)
Expand All @@ -177,6 +177,7 @@ def add_product_rasters_from_storage():
valid_product = Product.objects.get(product_id=slugify(product_id))
try:
ds = ProductRaster.objects.get(product=valid_product, date=ds_date)
logging.info(f"{filename} exists")
except ProductRaster.DoesNotExist:
# if it doesn't exist, make it
new_dataset = ProductRaster(
Expand All @@ -187,7 +188,7 @@ def add_product_rasters_from_storage():
file_object=f"product-rasters/{filename}",
)
logging.info(f"saving {filename}")
new_dataset.save() # prevent re-upload to S3
new_dataset.save()
logging.info(f"saved {new_dataset}")


Expand Down
6 changes: 3 additions & 3 deletions glam_api/glam/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def extract_datetime_from_filename(filename):
return None


def match_filename_to_product_id(filename):
def get_product_id_from_filename(filename):
"""
Matches a filename to its corresponding ID from a given list.
Expand All @@ -126,9 +126,9 @@ def match_filename_to_product_id(filename):
return "chirps-precip"
elif "swi" in filename:
return "copernicus-swi"
elif "DFPPM_4_WK" in filename:
elif "DFPPM_4WK" in filename:
return "servir-4wk-esi"
elif "DFPPM_12_WK" in filename:
elif "DFPPM_12WK" in filename:
return "servir-12wk-esi"
elif "VNP09H1.ndvi" in filename:
return "vnp09h1-ndvi"
Expand Down

0 comments on commit 0c91d4b

Please sign in to comment.