Skip to content

Commit

Permalink
#197 fix bug if sat has no shorelines
Browse files Browse the repository at this point in the history
  • Loading branch information
2320sharon committed Oct 24, 2023
1 parent 44a9b2b commit ceb379a
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/coastseg/extracted_shoreline.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ def combine_satellite_data(satellite_data: dict) -> dict:

# Fill the satellite_data dict
for satname, sat_data in satellite_data.items():
satellite_data[satname].setdefault("dates", [])
satellite_data[satname].setdefault("geoaccuracy", [])
satellite_data[satname].setdefault("shorelines", [])
satellite_data[satname].setdefault("cloud_cover", [])
satellite_data[satname].setdefault("filename", [])
satellite_data[satname].setdefault("idx", [])
# For each key in the nested dictionary
for key, value in sat_data.items():
# Wrap non-list values in a list and concatenate to merged_satellite_data
Expand All @@ -293,9 +299,10 @@ def combine_satellite_data(satellite_data: dict) -> dict:
else:
merged_satellite_data[key] += value
# Add the satellite name to the satellite name list
merged_satellite_data["satname"] += [
_ for _ in np.tile(satname, len(satellite_data[satname]["dates"]))
]
if "dates" in satellite_data[satname].keys():
merged_satellite_data["satname"] += [
_ for _ in np.tile(satname, len(satellite_data[satname]["dates"]))
]
# Sort dates chronologically
if "dates" in merged_satellite_data.keys():
idx_sorted = sorted(
Expand Down Expand Up @@ -361,6 +368,14 @@ def process_satellite(
# filenames of tifs (ms) for this satellite
filenames = metadata[satname]["filenames"]
output = {}
output.setdefault(satname, {})
output[satname].setdefault("dates", [])
output[satname].setdefault("geoaccuracy", [])
output[satname].setdefault("shorelines", [])
output[satname].setdefault("cloud_cover", [])
output[satname].setdefault("filename", [])
output[satname].setdefault("idx", [])

if len(filenames) == 0:
logger.warning(f"Satellite {satname} had no imagery")
return output
Expand Down Expand Up @@ -1290,7 +1305,12 @@ def extract_shorelines_with_dask(

logger.info(f"satellite_dict : {satellite_dict}")
logger.info(f"before result_dict : {result_dict}")
result_dict[satname] = satellite_dict[satname]
if not satellite_dict:
result_dict[satname] = {}
elif not satname in satellite_dict.keys():
result_dict[satname] = {}
else:
result_dict[satname] = satellite_dict[satname]
logger.info(f"result_dict.keys() : {result_dict.keys()}")
logger.info(f" after result_dict : {result_dict}")

Expand Down

0 comments on commit ceb379a

Please sign in to comment.