-
Notifications
You must be signed in to change notification settings - Fork 198
Add fetch job and update stage_ic to work with fetched ICs #3141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
WalterKolczynski-NOAA
merged 47 commits into
NOAA-EMC:develop
from
DavidGrumm-NOAA:stage_ic_2988
Jan 27, 2025
Merged
Changes from 13 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
fdb996d
Stage_ic updates: GH2988
DavidGrumm-NOAA a1f03ec
Removed white space
DavidGrumm-NOAA 17f7e6c
remove more whitespace
DavidGrumm-NOAA a9bd3e2
Incorporate fetch into GW
DavidGrumm-NOAA ba1a017
Merge branch 'develop' into stage_ic_2988
DavidGrumm-NOAA e624872
Fix whitespace
DavidGrumm-NOAA fa35c61
Reconcile divergent branches. Merge branch 'stage_ic_2988' of github.…
DavidGrumm-NOAA f21f96b
Move the fetch options to the run_options dict
DavidGrumm-NOAA 20f2862
Additonal code to incorporate fetch, including modifying some of the …
DavidGrumm-NOAA 5ca1531
Updated fetch code to use fetch directory FETCHDIR instead of ATARDIR…
DavidGrumm-NOAA 09ce49c
Deleted ci/cases/pr/ATM_cold.yaml
DavidGrumm-NOAA c71b340
modifying stage_ic and fetch code to ensure that both function compat…
DavidGrumm-NOAA a6dade0
Moved setting of cycle_YMDH
DavidGrumm-NOAA a6a84d4
Updates for the fetch and yaml code, and keys.
DavidGrumm-NOAA 8aead59
Corrected typo
DavidGrumm-NOAA ecc1b48
Add specification of fetch directory, corrrected name of yaml file.
DavidGrumm-NOAA dd645eb
Add DO_FETCH_HPSS setting to all non-hera files in workflow/hosts
DavidGrumm-NOAA 4ca9d49
Change pass to raise an error
DavidGrumm-NOAA df88c29
whitespace repair
DavidGrumm-NOAA dd2b726
Merge branch 'develop' into stage_ic_2988
DavidGrumm-NOAA 89c42ef
Add S2SW_cold fetch template
DavidHuber-NOAA d0e6f9b
Update ATM_cold.yaml.j2
DavidHuber-NOAA 701093c
Add YMDH to fetch_yamls
DavidHuber-NOAA 9433473
Add previous_cycle to fetch dict
DavidHuber-NOAA 04f8da9
Check for missing files after untarring, add logging
DavidHuber-NOAA d1f2a00
Renamed fetch configs
DavidHuber-NOAA 34ae4a8
Replace gefs config.fetch with link to gfs
DavidHuber-NOAA 5c25f26
Update fetch directory
DavidHuber-NOAA 35f2454
Restrict fetch cases to C48_S2SW and C48_ATM
DavidHuber-NOAA 57d01ea
Merge pull request #1 from DavidHuber-NOAA/new_fetch_yaml
DavidGrumm-NOAA b929200
Cleanup of env files
DavidGrumm-NOAA 8e3be40
Merge branch 'develop' into stage_ic_2988
DavidGrumm-NOAA 23b2057
Renamed variable, removed unused code
DavidGrumm-NOAA bab00e5
need to pull changes from remote. Merge branch 'stage_ic_2988' of git…
DavidGrumm-NOAA ac86509
Merged in develop
DavidGrumm-NOAA 60241bd
Merged in develop
DavidGrumm-NOAA 00e3d62
Undo merge mangling
DavidGrumm-NOAA e7396bc
Adding higher resolutions back
DavidGrumm-NOAA eba7841
Removing higher resolutions (they will be added in a different PR)
DavidGrumm-NOAA 8644449
Address additional reviewer comments
DavidGrumm-NOAA b7c919e
Remove some fetch options for now
DavidGrumm-NOAA aae3e6e
Address reviewer comments(.venv) [David.Grumm@hfe10 G_WF_2988]$ git a…
DavidGrumm-NOAA 2eec8da
Remove extraneous new lines
DavidGrumm-NOAA 939ce24
Merge branch 'develop' into stage_ic_2988
DavidHuber-NOAA 7afe68c
Delete updated submodules to placate git pull. Merge branch 'stage_ic…
DavidGrumm-NOAA 0984012
Add newline to end of yaml files
DavidGrumm-NOAA 78e1bea
Merge branch 'develop' into stage_ic_2988
DavidHuber-NOAA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#! /usr/bin/env bash | ||
|
||
source "${HOMEgfs}/ush/preamble.sh" | ||
source "${HOMEgfs}/ush/jjob_header.sh" -e "fetch" -c "base fetch" | ||
|
||
# Execute fetching | ||
"${SCRgfs}/exglobal_fetch.py" | ||
err=$? | ||
|
||
############################################################### | ||
# Check for errors and exit if any of the above failed | ||
if [[ "${err}" -ne 0 ]]; then | ||
echo "FATAL ERROR: Unable to fetch ICs to ${ROTDIR}; ABORT!" | ||
exit "${err}" | ||
fi | ||
|
||
########################################## | ||
# Remove the Temporary working directory | ||
########################################## | ||
cd "${DATAROOT}" || (echo "${DATAROOT} does not exist. ABORT!"; exit 1) | ||
[[ ${KEEPDATA} = "NO" ]] && rm -rf "${DATA}" | ||
|
||
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#! /usr/bin/env bash | ||
|
||
source "${HOMEgfs}/ush/preamble.sh" | ||
|
||
# Source FV3GFS workflow modules | ||
. "${HOMEgfs}/ush/load_fv3gfs_modules.sh" | ||
status=$? | ||
[[ "${status}" -ne 0 ]] && exit "${status}" | ||
|
||
export job="fetch" | ||
export jobid="${job}.$$" | ||
|
||
# Execute the JJOB | ||
"${HOMEgfs}/jobs/JGLOBAL_FETCH" | ||
status=$? | ||
|
||
|
||
exit "${status}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#! /usr/bin/env bash | ||
|
||
########## config.fetch ########## | ||
|
||
echo "BEGIN: config.fetch" | ||
|
||
export FETCH_YAML_TMPL="${PARMgfs}/fetch/C48_cold.yaml.j2" | ||
|
||
# Get task specific resources | ||
source "${EXPDIR}/config.resources" fetch | ||
|
||
echo "END: config.fetch" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#! /usr/bin/env bash | ||
|
||
########## config.fetch ########## | ||
|
||
echo "BEGIN: config.fetch" | ||
|
||
export FETCH_YAML_TMPL="${PARMgfs}/fetch/C48_cold.yaml.j2" | ||
DavidHuber-NOAA marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Get task specific resources | ||
source "${EXPDIR}/config.resources" fetch | ||
WalterKolczynski-NOAA marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
echo "END: config.fetch" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{% set cycle_YMDH = current_cycle | to_YMDH %} | ||
untar: | ||
DavidHuber-NOAA marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tarball : "{{ FETCHDIR }}/{{ cycle_YMDH }}/atm_cold.tar" | ||
on_hpss: True | ||
contents: | ||
- gfs_ctrl.nc | ||
{% for ftype in ["gfs_data", "sfc_data"] %} | ||
{% for ntile in range(1, ntiles + 1) %} | ||
- {{ ftype }}.tile{{ ntile }}.nc | ||
{% endfor %} # ntile | ||
{% endfor %} # ftype | ||
destination: "{{ DATAROOT }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
|
||
from pygfs.task.fetch import Fetch | ||
from wxflow import AttrDict, Logger, cast_strdict_as_dtypedict, logit | ||
|
||
# initialize root logger | ||
logger = Logger(level=os.environ.get("LOGGING_LEVEL", "DEBUG"), colored_log=True) | ||
|
||
|
||
@logit(logger) | ||
def main(): | ||
|
||
config = cast_strdict_as_dtypedict(os.environ) | ||
|
||
# Instantiate the Fetch object | ||
fetch = Fetch(config) | ||
|
||
# Pull out all the configuration keys needed to run the fetch step | ||
keys = ['current_cycle', 'RUN', 'PDY', 'PARMgfs', 'PSLOT', 'ROTDIR', 'fetch_yaml', 'FETCHDIR', 'ntiles', 'DATAROOT'] | ||
DavidHuber-NOAA marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fetch_dict = AttrDict() | ||
for key in keys: | ||
fetch_dict[key] = fetch.task_config.get(key) | ||
if fetch_dict[key] is None: | ||
print(f"Warning: key ({key}) not found in task_config!") | ||
|
||
# Also import all COMOUT* directory and template variables | ||
for key in fetch.task_config.keys(): | ||
if key.startswith("COMOUT_"): | ||
fetch_dict[key] = fetch.task_config.get(key) | ||
if fetch_dict[key] is None: | ||
print(f"Warning: key ({key}) not found in task_config!") | ||
|
||
DavidHuber-NOAA marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Determine which archives to retrieve from HPSS | ||
# Read the input YAML file to get the list of tarballs on tape | ||
fetchdir_set = fetch.configure(fetch_dict) | ||
|
||
# Pull the data from tape or locally and store the specified destination | ||
fetch.execute_pull_data(fetchdir_set) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
from logging import getLogger | ||
from typing import Any, Dict, List | ||
|
||
from wxflow import (AttrDict, FileHandler, Hsi, Task, | ||
logit, parse_j2yaml, chdir) | ||
from wxflow import htar as Htar | ||
import tarfile | ||
|
||
|
||
logger = getLogger(__name__.split('.')[-1]) | ||
|
||
|
||
class Fetch(Task): | ||
"""Task to pull ROTDIR data from HPSS (or locally) | ||
""" | ||
|
||
@logit(logger, name="Fetch") | ||
def __init__(self, config: Dict[str, Any]) -> None: | ||
"""Constructor for the Fetch task | ||
The constructor is responsible for collecting necessary yamls based on | ||
the runtime options and RUN. | ||
|
||
Parameters | ||
---------- | ||
config : Dict[str, Any] | ||
Incoming configuration for the task from the environment | ||
|
||
Returns | ||
------- | ||
None | ||
""" | ||
super().__init__(config) | ||
# Perhaps add other stuff to self. | ||
DavidHuber-NOAA marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@logit(logger) | ||
def configure(self, fetch_dict: Dict[str, Any]): | ||
"""Determine which tarballs will need to be extracted | ||
|
||
Parameters | ||
---------- | ||
fetch_dict : Dict[str, Any] | ||
Task specific keys, e.g. COM directories, etc | ||
|
||
Return | ||
------ | ||
parsed_fetch: Dict[str, Any] | ||
Dictionary derived from the yaml file with necessary HPSS info. | ||
""" | ||
self.hsi = Hsi() | ||
|
||
fetch_yaml = fetch_dict.fetch_yaml | ||
DavidHuber-NOAA marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fetch_parm = os.path.join(fetch_dict.PARMgfs, "fetch") | ||
|
||
parsed_fetch = parse_j2yaml(os.path.join(fetch_parm, fetch_yaml), | ||
fetch_dict) | ||
return parsed_fetch | ||
|
||
@logit(logger) | ||
def execute_pull_data(self, fetchdir_set: Dict[str, Any]) -> None: | ||
"""Pull data from HPSS based on a yaml dictionary and store at the | ||
specified destination. | ||
|
||
Parameters | ||
---------- | ||
fetchdir_set: Dict[str, Any], | ||
Dict defining set of tarballs to pull and where to put them. | ||
|
||
Return | ||
None | ||
""" | ||
|
||
f_names = fetchdir_set.untar.contents | ||
if len(f_names) <= 0: # Abort if no files | ||
raise FileNotFoundError("FATAL ERROR: The tar ball has no files") | ||
|
||
on_hpss = fetchdir_set.untar.on_hpss | ||
dest = fetchdir_set.untar.destination | ||
tarball = fetchdir_set.untar.tarball | ||
|
||
# Select action whether no_hpss is True or not, and pull these | ||
# data from tape or locally and place where it needs to go | ||
# DG - these need testing | ||
with chdir(dest): | ||
if on_hpss is True: # htar all files in fnames | ||
htar_obj = Htar.Htar() | ||
htar_obj.xvf(tarball, f_names) | ||
|
||
else: # tar all files in fnames | ||
pass # TODO | ||
DavidHuber-NOAA marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# with tarfile.open(dest, "w") as tar: | ||
# for filename in f_names: | ||
# tar.add(filename) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.