Skip to content

Commit

Permalink
update filters.py to save the kmeans classifer scores to model_settin…
Browse files Browse the repository at this point in the history
…gs.json
  • Loading branch information
2320sharon committed Jun 24, 2024
1 parent b3c5fa4 commit c7a83f8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/coastseg/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,19 @@ def filter_model_outputs(

rmse, input_rmse = measure_rmse(da, times, timeav)
labels, scores = get_kmeans_clusters(input_rmse, rmse)

# get the parent directory of good dir
parent_dir = os.path.abspath(pathlib.Path(dest_folder_good).parent)
# check if a file called model_settings.json exists in the parent directory
settings_file = os.path.join(parent_dir, "model_settings.json")
if os.path.exists(settings_file):
import json
with open(settings_file) as f:
settings = json.load(f)
# add the model score to the settings
# drop any NaN values from the scores
settings["model_scores"] = scores[~np.isnan(scores)].tolist()

files_bad, files_good = get_good_bad_files(valid_files, labels, scores)
handle_files_and_directories(
files_bad, files_good, dest_folder_bad, dest_folder_good
Expand Down

0 comments on commit c7a83f8

Please sign in to comment.