Skip to content

Commit

Permalink
fix missing import
Browse files Browse the repository at this point in the history
  • Loading branch information
2320sharon committed Sep 27, 2023
1 parent af175ee commit 44c172e
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/coastsat/SDS_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import numpy as np
import matplotlib.pyplot as plt
import pdb
from typing import List, Dict
from typing import List, Dict, Union
import time
from functools import wraps

Expand Down Expand Up @@ -702,40 +702,40 @@ def read_metadata_file(filepath: str) -> Dict[str, Union[str, int, float]]:
"im_width",
"im_height",
]

# Mapping of actual file keys to metadata keys
key_mapping = {"image_quality": "im_quality"}

# Initialize the metadata dictionary with default values.
metadata = {
"filename": "",
"epsg": "",
"acc_georef": -1,
"im_quality": -1,
"im_width": -1,
"im_height": -1,
"im_height": -1
}

with open(filepath, "r") as f:
for line in f:
line = line.strip()
if not line:
continue # Skip empty lines

parts = line.split("\t")
if len(parts) < 2:
continue # Skip lines without a tab character

key = parts[0].strip()
value = parts[1].strip()

# Map the actual key in the file to the metadata key
key = key_mapping.get(key, key)

# If the mapped key is not in metadata_keys, then skip it.
if key not in metadata_keys:
continue

# Convert value to the appropriate type based on the key
if key in ["epsg", "im_width", "im_height"]:
try:
Expand All @@ -744,21 +744,20 @@ def read_metadata_file(filepath: str) -> Dict[str, Union[str, int, float]]:
try:
value = float(value)
except ValueError:
print(
f"Error: Unable to convert {key} {value} to a numeric value."
)
print(f"Error: Unable to convert {key} {value} to a numeric value.")
elif key in ["acc_georef", "im_quality"]:
try:
value = float(value)
except ValueError:
pass # Keep the value as a string if conversion to float fails

# Update the metadata dictionary with the extracted key-value pair.
metadata[key] = value

return metadata



def get_metadata(inputs):
"""
Gets the metadata from the downloaded images by parsing .txt files located
Expand All @@ -782,7 +781,6 @@ def get_metadata(inputs):
date, filename, georeferencing accuracy and image coordinate reference system
"""
print(f"Getting metadata")
# Construct the directory path containing the images
filepath = os.path.join(inputs["filepath"], inputs["sitename"])
if not os.path.exists(filepath):
Expand Down

0 comments on commit 44c172e

Please sign in to comment.