From c7a83f8133b3a08f1e7694d0150a5e5ad86519b2 Mon Sep 17 00:00:00 2001 From: Sharon Fitzpatrick Date: Mon, 24 Jun 2024 13:46:31 -0700 Subject: [PATCH] update filters.py to save the kmeans classifer scores to model_settings.json --- src/coastseg/filters.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/coastseg/filters.py b/src/coastseg/filters.py index f7ff46b4..070566a9 100644 --- a/src/coastseg/filters.py +++ b/src/coastseg/filters.py @@ -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