diff --git a/src/swell/suites/compare/flow.cylc b/src/swell/suites/compare/flow.cylc index 7df94f8c8..8e030f405 100644 --- a/src/swell/suites/compare/flow.cylc +++ b/src/swell/suites/compare/flow.cylc @@ -26,6 +26,11 @@ runahead limit = {{runahead_limit}} [[graph]] + R1 = """ + {% for model_component in model_components %} + JediLogComparison-{{model_component}}? + {% endfor %} + """ {% for cycle_time in cycle_times %} {{cycle_time.cycle_time}} = """ {% for model_component in model_components %} @@ -33,10 +38,9 @@ {% for path in comparison_experiment_paths %} JediOopsLogParser-{{model_component}}-{{ loop.index0 }} {% endfor %} - JediLogComparison-{{model_component}}? - JediLogComparison-{{model_component}}:fail? => EvaComparisonIncrement-{{model_component}} - JediLogComparison-{{model_component}}:fail? => EvaComparisonJediLog-{{model_component}} - JediLogComparison-{{model_component}}:fail? => EvaComparisonObservations-{{model_component}} => comparison_fail + JediLogComparison-{{model_component}}[^]:fail? => EvaComparisonIncrement-{{model_component}} => PublishComparisons => comparison_fail + JediLogComparison-{{model_component}}[^]:fail? => EvaComparisonJediLog-{{model_component}} => PublishComparisons => comparison_fail + JediLogComparison-{{model_component}}[^]:fail? => EvaComparisonObservations-{{model_component}} => PublishComparisons => comparison_fail {% endif %} {% endfor %} """ @@ -77,6 +81,9 @@ --{{key}} = {{value}} {%- endfor %} + [[PublishComparisons]] + script = "swell task PublishComparisons $config -d $datetime -m {{model_component}}" + {% if comparison_experiment_paths is mapping %} {% for path in comparison_experiment_paths.values() %} [[JediOopsLogParser-{{model_component}}-{{ loop.index0 }}]] diff --git a/src/swell/tasks/publish_comparisons.py b/src/swell/tasks/publish_comparisons.py new file mode 100644 index 000000000..63d97c1d0 --- /dev/null +++ b/src/swell/tasks/publish_comparisons.py @@ -0,0 +1,66 @@ +# (C) Copyright 2021- United States Government as represented by the Administrator of the +# National Aeronautics and Space Administration. All Rights Reserved. +# +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. + + +# -------------------------------------------------------------------------------------------------- + + +import os +import glob +import shutil + +from swell.tasks.base.task_base import taskBase + +# -------------------------------------------------------------------------------------------------- + + +class PublishComparisons(taskBase): + + '''Copies releveant text files and plots to a specified "publish location". + + If 'publish_directory' is None, the files will not be copied. + ''' + + def execute(self) -> None: + + # Output path base to copy files to + publish_directory = self.config.publish_directory(None) + + # Skip this task if there is no publish directory + if publish_directory is None: + print('Skipping') + return + + print('Not skipped') + # For CI tests - contain results under the run ID + github_run_id = os.environ.get('GITHUB_RUN_ID') + experiment_id = self.experiment_id() + if github_run_id is not None: + experiment_id = os.path.join(github_run_id, experiment_id) + + # Name the location after the experiment ID + publish_location = os.path.join(self.config.publish_directory(), experiment_id) + + os.makedirs(publish_location, exist_ok=True) + + # Copy the JEDI log file comparison + log_file = os.path.join(self.experiment_path(), 'jedi_log_comparison.txt') + shutil.copy(log_file, publish_location) + + if os.path.isdir(os.path.join(self.cycle_dir(), 'eva')): + + # Copy eva png files + files = glob.glob(os.path.join(self.cycle_dir(), 'eva', '**', '*.png'), recursive=True) + + out_path = os.path.join(publish_location, self.__datetime__.string_directory(), + self.get_model()) + + os.makedirs(out_path, exist_ok=True) + + for file in files: + shutil.copy(file, out_path) + +# -------------------------------------------------------------------------------------------------- diff --git a/src/swell/tasks/task_questions.py b/src/swell/tasks/task_questions.py index 1e9707c9f..7a7dd5a6c 100644 --- a/src/swell/tasks/task_questions.py +++ b/src/swell/tasks/task_questions.py @@ -502,6 +502,16 @@ class TaskQuestions(QuestionContainer, Enum): # -------------------------------------------------------------------------------------------------- + PublishComparisons = QuestionList( + list_name="PublishComparisons", + questions=[ + qd.model_components(), + qd.publish_directory() + ] + ) + + # -------------------------------------------------------------------------------------------------- + PrepareAnalysis = QuestionList( list_name="PrepareAnalysis", questions=[ diff --git a/src/swell/utilities/question_defaults.py b/src/swell/utilities/question_defaults.py index df01ae2cf..ae8619313 100644 --- a/src/swell/utilities/question_defaults.py +++ b/src/swell/utilities/question_defaults.py @@ -1219,6 +1219,16 @@ class produce_geovals(TaskQuestion): # -------------------------------------------------------------------------------------------------- + @dataclass + class publish_directory(TaskQuestion): + default_value: str = None + question_name: str = "publish_directory" + ask_question: bool = False + prompt: str = "Provide an external directory to publish relevant results to." + widget_type: WType = WType.STRING + + # -------------------------------------------------------------------------------------------------- + @dataclass class r2d2_local_path(TaskQuestion): default_value: str = "defer_to_platform"