Skip to content

Commit dea2038

Browse files
authored
Merge pull request #861 from singhd789/847.pp-an-switch-default
Update logic where `postprocess_on` and `analysis_on` is used
2 parents fae6172 + 4792f03 commit dea2038

File tree

20 files changed

+110
-117
lines changed

20 files changed

+110
-117
lines changed

docs/tools/listtools.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
-----------------
33

44
``fre list exps [options]``
5-
- Purpose: Lists available post-processing experiments included in the yaml configurations
5+
- Purpose: List available post-processing experiments included in the yaml configurations
66
- Options:
77
- ``-y, --yamlfile [experiment yaml]``
88

99
``platforms``
1010
-----------------
1111

1212
``fre list platforms [options]``
13-
- Purpose: Lists available platforms included in the yaml configurations
13+
- Purpose: List available platforms included in the yaml configurations
1414
- Options:
1515
- ``-y, --yamlfile [experiment yaml]``
1616

1717
``pp-components``
1818
-----------------
1919

2020
``fre list pp-components [options]``
21-
- Purpose: Lists components that have the `postprocess_on` key set to `True` in the postprocessing yaml configurations
21+
- Purpose: List components in the postprocessing yaml that will be post-processed. All components will be post-processed unless ``postprocess_on: False`` is specified
2222
- Options:
2323
- ``-y, --yamlfile [experiment yaml]``
2424
- ``-e, --experiment [experiment to be post-processed]``

docs/usage/postprocess.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ Required configuration
7979
8080
postprocess:
8181
settings:
82-
pp_start: 1979-01-01T0000Z
82+
pp_start: "1979-01-01T0000Z"
8383
84-
pp_stop: 2020-01-01T0000Z
84+
pp_stop: "2020-01-01T0000Z"
8585
8686
Postprocess components
8787
----------------------

docs/usage/yaml_dev/pp_yaml.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Required keys include:
2727

2828
- type
2929
- sources
30-
- postprocess_on
3130

3231
**Settings yaml**
3332

@@ -52,11 +51,8 @@ This file can follow the format below:
5251
pp_chunks: "array of ISO8601 datetime durations, specifying the interval of simulated time per postprocessed file" (string)
5352
pp_grid_spec: "path to FMS grid definition tarfile" (string)
5453
switches:
55-
do_timeavgs: "switch to turn on/off time-average file generation" (boolean)
5654
clean_work: "switch to remove intermediate data files when they are no longer needed" (boolean)
5755
do_atmos_plevel_masking: "switch to mask atmos pressure-level output above/below surface pressure/atmos top" (boolean)
58-
do_analysis: "switch to launch analysis scripts" (boolean)
59-
do_analysis_only: "switch to only launch analysis scripts" (boolean)
6056
6157
Required keys include:
6258

@@ -72,5 +68,3 @@ Required keys include:
7268
- clean_work
7369
- do_timeavgs
7470
- do_atmos_plevel_masking
75-
- do_analysis
76-
- do_analysis_only

fre/app/regrid_xy/regrid_xy.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,14 @@ def regrid_xy(yamlfile: str,
342342

343343
# submit fregrid job for each component
344344
for component in components:
345-
346-
# skip component if postprocess_on = False
347-
if not component["postprocess_on"]:
348-
fre_logger.warning(f"postprocess_on=False for {source} in component {component['type']}." \
349-
"Skipping {source}")
350-
continue
345+
# If postprocess_on is not defined, it should have the default value of True
346+
# If postprocess_on is defined, check for a True or False value
347+
if "postprocess_on" in component:
348+
# skip component if postprocess_on = False
349+
if not component["postprocess_on"]:
350+
fre_logger.warning(f"postprocess_on=False for {source} in component {component['type']}." \
351+
"Skipping {source}")
352+
continue
351353

352354
# skip component if xyInterp is not set
353355
if 'xyInterp' not in component:

fre/gfdl_msd_schemas

fre/list_/list_pp_components_script.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ def list_ppcomps_subtool(yamlfile: str, experiment: str):
4444
# log the experiment names, which should show up on screen for sure
4545
fre_logger.info("Components to be post-processed:")
4646
for i in yml_dict["postprocess"]["components"]:
47-
if i.get("postprocess_on"):
47+
if "postprocess_on" in i:
48+
if i.get("postprocess_on") is True:
49+
fre_logger.info(' - %s', i.get("type"))
50+
else:
4851
fre_logger.info(' - %s', i.get("type"))
4952
fre_logger.info("\n")
5053

fre/list_/tests/test_list_pp_components_script.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22
Test fre list pp-comps
33
"""
44
from pathlib import Path
5-
6-
import pytest
7-
import yaml
8-
95
from fre.list_ import list_pp_components_script
10-
from fre.yamltools import combine_yamls_script as cy
11-
from fre.yamltools import helpers
126

137

148
# SET-UP
@@ -37,13 +31,18 @@ def test_ppyamls_exist():
3731
assert Path(f"{TEST_DIR}/{AM5_EXAMPLE}/{pp_yaml}").exists()
3832

3933
# Test whole tool
40-
def test_exp_list(caplog):
34+
def test_pp_comp_list(caplog):
4135
''' Test fre list pp-components subtool '''
4236
list_pp_components_script.list_ppcomps_subtool(f"{TEST_DIR}/{AM5_EXAMPLE}/{MODEL_YAMLFILE}", EXP_NAME)
4337

4438
# check the logging output
4539
check_out = [ 'Components to be post-processed:',
40+
' - atmos_cmip',
4641
' - atmos',
42+
' - atmos_level_cmip',
43+
' - atmos_level',
44+
' - atmos_month_aer',
45+
' - atmos_diurnal',
4746
' - atmos_scalar']
4847

4948
for i in check_out:
@@ -66,4 +65,4 @@ def test_yamlvalidate(caplog):
6665
assert i in caplog.text
6766

6867
for record in caplog.records:
69-
record.levelname == "INFO"
68+
assert record.levelname == "INFO"

fre/make/tests/null_example/settings.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,3 @@ postprocess:
99
site: "ppan"
1010
switches:
1111
clean_work: True
12-
do_refinediag: False
13-
do_analysis: True

fre/make/tests/null_example/wrong_model/wrong_null_model.yaml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,3 @@ fre_properties:
1010
build:
1111
compileYaml: "../compile.yaml"
1212
platformYaml: "empty_platforms.yaml"
13-
14-
shared: # directories shared across tools
15-
directories: &shared_directories
16-
history_dir: !join [/archive/$USER/, *FRE_STEM, /, *name, /, *platform, -, *target, /, history]
17-
pp_dir: !join [/archive/$USER/, *FRE_STEM, /, *name, /, *platform, -, *target, /, pp]
18-
analysis_dir: !join [/nbhome/$USER/, *FRE_STEM, /, *name]
19-
20-
# shared pp settings
21-
postprocess:
22-
settings: &shared_settings
23-
site: "ppan"
24-
switches: &shared_switches
25-
clean_work: True
26-
do_refinediag: False
27-
do_analysis: True
28-
29-
experiments:
30-
- name: "null_model_full"
31-
pp:
32-
- name: "null_model_0"
33-
pp:
34-
- name: "null_model_1"
35-
pp:
36-
- name: "null_model_2"
37-
pp:

fre/pp/configure_script_yaml.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def set_rose_suite(yamlfile: dict, rose_suite: metomi.rose.config.ConfigNode) ->
122122
"""
123123
pp=yamlfile.get("postprocess")
124124
dirs=yamlfile.get("directories")
125+
analysis=yamlfile.get("analysis")
125126

126127
# set rose-suite items
127128
pa_scripts = ""
@@ -186,6 +187,34 @@ def set_rose_suite(yamlfile: dict, rose_suite: metomi.rose.config.ConfigNode) ->
186187
rose_suite.set( keys = ['template variables', 'DO_PREANALYSIS'],
187188
value = 'False' )
188189

190+
# Set DO_ANALYSIS switch
191+
# analysis_on is optional key for each component in the analysis yaml and
192+
# defaults to True if not specified.
193+
# In the rose_suite.conf:
194+
# - if 'analysis_on: False' for all analysis components, set DO_ANALYSIS=False
195+
# - if 'analysis_on: True' for any analysis components, set DO_ANALYSIS=True
196+
do_analysis_switch = []
197+
if not analysis:
198+
return
199+
200+
for an_key, an_value in analysis.items():
201+
an_workflow_info = an_value["workflow"]
202+
# if analysis_on key is actually set, evaluate and save its value in a list
203+
if "analysis_on" in an_workflow_info:
204+
do_analysis_switch.append(an_workflow_info["analysis_on"])
205+
#if analysis_on key is NOT set, save its value as True in the list
206+
else:
207+
do_analysis_switch.append("True")
208+
209+
# if ANY of the analysis components do not set analysis_on or set analysis_on: True,
210+
# set DO_ANALYSIS=True in the rose_suite.conf
211+
if any(do_analysis_switch):
212+
rose_suite.set( keys = ['template variables', 'DO_ANALYSIS'],
213+
value = 'True' )
214+
else:
215+
rose_suite.set( keys = ['template variables', 'DO_ANALYSIS'],
216+
value = 'False' )
217+
189218
if dirs is not None:
190219
for key,value in dirs.items():
191220
rose_suite.set(keys=['template variables', key.upper()], value=quote_rose_values(value))

0 commit comments

Comments
 (0)