Skip to content

Commit

Permalink
Unify setup_expt.py and setup_expt_fcstonly.py (#537)
Browse files Browse the repository at this point in the history
`setup_expt.py` and `setup_expt_fcstonly.py` are unified under the former name.

The user is now required to provide a `mode` as the first positional argument to `setup.py`.  Valid options are `cycled` and `forecast-only`.  

```
❯ python3 setup_expt.py -h
usage: setup_expt.py [-h] {cycled,forecast-only} ...

Setup files and directories to start a GFS parallel. Create EXPDIR, copy config files. Create COMROT experiment directory structure, link
initial condition files from $ICSDIR to $COMROT

positional arguments:
  {cycled,forecast-only}
    cycled              arguments for cycled mode
    forecast-only       arguments for forecast-only mode

optional arguments:
  -h, --help            show this help message and exit
```

Upon choosing one of these modes, options specific to the mode can be realized as follows for the `forecast-only` and `cycled` modes respectively.

```
❯ python3 setup_expt.py forecast-only -h                                                                  feature/unify-setups
usage: setup_expt.py forecast-only [-h] [--pslot PSLOT] [--resdet RESDET] [--comrot COMROT] [--expdir EXPDIR] --idate IDATE --edate EDATE
                                   [--icsdir ICSDIR] [--configdir CONFIGDIR] [--cdump CDUMP] [--gfs_cyc {0,1,2,4}] [--start {warm,cold}]
                                   [--app {ATM,ATMW,S2S,S2SW}]

optional arguments:
  -h, --help            show this help message and exit
  --pslot PSLOT         parallel experiment name
  --resdet RESDET       resolution of the deterministic model forecast
  --comrot COMROT       full path to COMROT
  --expdir EXPDIR       full path to EXPDIR
  --idate IDATE         starting date of experiment, initial conditions must exist!
  --edate EDATE         end date experiment
  --icsdir ICSDIR       full path to initial condition directory
  --configdir CONFIGDIR
                        full path to directory containing the config files
  --cdump CDUMP         CDUMP to start the experiment
  --gfs_cyc {0,1,2,4}   GFS cycles to run
  --start {warm,cold}   restart mode: warm or cold
  --app {ATM,ATMW,S2S,S2SW}
                        UFS application
```

```
❯ python3 setup_expt.py cycled -h                                                                         feature/unify-setups
usage: setup_expt.py cycled [-h] [--pslot PSLOT] [--resdet RESDET] [--comrot COMROT] [--expdir EXPDIR] --idate IDATE --edate EDATE
                            [--icsdir ICSDIR] [--configdir CONFIGDIR] [--cdump CDUMP] [--gfs_cyc {0,1,2,4}] [--start {warm,cold}]
                            [--resens RESENS] [--nens NENS] [--app {ATM,ATMW}]

optional arguments:
  -h, --help            show this help message and exit
  --pslot PSLOT         parallel experiment name
  --resdet RESDET       resolution of the deterministic model forecast
  --comrot COMROT       full path to COMROT
  --expdir EXPDIR       full path to EXPDIR
  --idate IDATE         starting date of experiment, initial conditions must exist!
  --edate EDATE         end date experiment
  --icsdir ICSDIR       full path to initial condition directory
  --configdir CONFIGDIR
                        full path to directory containing the config files
  --cdump CDUMP         CDUMP to start the experiment
  --gfs_cyc {0,1,2,4}   GFS cycles to run
  --start {warm,cold}   restart mode: warm or cold
  --resens RESENS       resolution of the ensemble model forecast
  --nens NENS           number of ensemble members
  --app {ATM,ATMW}      UFS application
```

Note, `cycled` mode presents some extra options e.g. `nens` as well as a reduced list of the UFS weather model applications.

The functionality of `--icsdir` had been broken for cycled and was hard-coded in free forecast. The functionality has now been repaired for cycled. If you provide one, $COMROT will be populated with appropriate links. If none is specified, no links will be created in $COMROT. In coupled mode free-forecast, ICs are copied *to* icsdir from the central maintained prototype location. Coupled users will now need to set this explicitly. For non-coupled forecast-only, this setting currently does nothing.

The default value for `--configdir` has been updated to the appropriate location in the workflow. Most users will no longer need to set it unless they want to point to a different config source.

The default values for `--comrot` and `--expdir` are updated from None to $HOME to facilitate offline testing of workflow creation.

There are some irrelevant sections such as `gfs_cyc` in forecast-only that is still preserved in this PR.   It will be cleaned up in subsequent PR's.

Another unnecessary complication is the argument of `--start`.  The logic presented here would ideally be selected at runtime based on the type of IC's populated in comrot.  It is left unchanged.
  • Loading branch information
aerorahul authored Feb 3, 2022
1 parent d7319f1 commit 97ebc4d
Show file tree
Hide file tree
Showing 4 changed files with 409 additions and 542 deletions.
48 changes: 42 additions & 6 deletions ush/rocoto/rocoto.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
ABOUT:
Helper module to create tasks, metatasks, and dependencies
AUTHOR:
Rahul.Mahajan
rahul.mahajan@noaa.gov
Brian Curtis (2021): Port to python 3.6.3+
brian.curtis@noaa.gov
'''

def create_metatask(task_dict, metatask_dict):
Expand Down Expand Up @@ -341,3 +335,45 @@ def create_envar(name=None,value=None):
string += '</envar>'

return string


def create_cycledef(group=None, start=None, stop=None, step=None):
'''
create an Rocoto cycle definition
returns the environment variable as a string
:param group: cycle definition group name
:type group: str
:param start: cycle start datetime
:type start: str
:param end: cycle end datetime
:type stop: str
:param step: cycle interval (timedelta)
:type interval: str
:param value: value of the environment variable
:type value: str or float or int or unicode
:return: Rocoto cycledef variable string
:rtype: str
'''

string = ''
string += f'<cycledef group="{group}">'
string += f'{start} {stop} {step}'
string += '</cycledef>'

return string


def create_entity(name=None, value=None):
'''
create an XML ENTITY variable given name and value
returns the variable as a string
:param name: name of the variable
:type name: str
:param value: value of the variable
:type value: str or float or int or unicode
:return: XML entity variable key-value pair
:rtype: str
'''

return f'<!ENTITY {name} "{value}">'

Loading

0 comments on commit 97ebc4d

Please sign in to comment.