Skip to content
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

Workflow for ZPPY- PCMDI for E3SM diagnostics #624

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9e2488c
Modify time series processing to include 3D model variables
zhangshixuan1987 Sep 16, 2024
692ceaa
Modifications to run zppy with PCMDI diagnostics
zhangshixuan1987 Sep 16, 2024
fc70d92
Changes in pcmdi module to allow parallel calculation
zhangshixuan1987 Sep 19, 2024
6311655
Future refine the worflow for E3SM-PCMDI diagnostics
zhangshixuan1987 Sep 23, 2024
534a942
Default setup for zppy-pcmdi
zhangshixuan1987 Sep 23, 2024
b15b993
conda environment for zppy at Chrisalis
zhangshixuan1987 Sep 23, 2024
72c862a
Add a python script to convert the observations/reanalysis data
zhangshixuan1987 Sep 23, 2024
a34c833
Add pcmdi-diags into the main workflow
zhangshixuan1987 Sep 23, 2024
e62188b
Change nco to be the default to process the climatology data
zhangshixuan1987 Sep 23, 2024
4937d9a
assign case_id for climo generated by pcmdi
zhangshixuan1987 Sep 23, 2024
482ac68
Refine workflow and add mean climate metrics plot
zhangshixuan1987 Oct 2, 2024
c7c4d8b
Clean up the redundent setups
zhangshixuan1987 Oct 3, 2024
a122380
small bug fix to add default grid information for model data
zhangshixuan1987 Oct 3, 2024
8546e63
Bug fix for mean climate metrics plot function
zhangshixuan1987 Oct 30, 2024
82e7afd
Changes made to improve the plotting function for mean climate metrics
zhangshixuan1987 Oct 31, 2024
dbb6b23
Bug fix in the mean climate metrics plot
zhangshixuan1987 Oct 31, 2024
0cce5a4
Bug fix for mean climate plots
zhangshixuan1987 Nov 1, 2024
ebbe9b5
Improve input validation and testing (#628)
forsyth2 Oct 12, 2024
af277d4
Update supported python versions (#620)
altheaden Oct 14, 2024
557b721
Tweak behaviors of build and release CI workflows (#621)
altheaden Oct 14, 2024
75da18c
Update python version in `setup.py` (#630)
altheaden Oct 14, 2024
5be8805
Update pre-commit dependencies (#627)
altheaden Oct 14, 2024
3b60b4f
Make TC Analysis parallel (#631)
forsyth2 Oct 15, 2024
233a294
Improve carryover dependency handling (#623)
forsyth2 Oct 16, 2024
e2dc984
Fix dir issues in comparing images (#638)
forsyth2 Oct 28, 2024
ee26c00
Updates to diags handling (#633)
forsyth2 Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions conda/chrisalis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: zppy_dev
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need a new file here. https://github.com/E3SM-Project/zppy/blob/main/conda/dev.yml (dev environment) and https://github.com/E3SM-Project/zppy/blob/main/conda/meta.yaml (production environment) can be modified

channels:
- conda-forge
- defaults
dependencies:
# Base
# =================
- python=3.9.13
- pip=22.2.2
- configobj=5.0.6
- jinja2=3.1.2
- mache>=1.5.0
- mpas_tools>=0.15.0
- pillow=9.2.0
# Developer Tools
# =================
# If versions are updated, also update 'rev' in `.pre-commit-config.yaml`
- black=22.8.0 # version from https://anaconda.org/conda-forge/black
- flake8=5.0.4 # version from https://anaconda.org/conda-forge/flake8
# This line also implicitly installs isort
- flake8-isort=4.2.0 # version from https://anaconda.org/conda-forge/flake8-isort
- mypy=0.982 # version from https://anaconda.org/conda-forge/mypy
- pre-commit=2.20.0 # version from https://anaconda.org/conda-forge/pre-commit
- tbump=6.9.0
# Documentation
# If versions are updated, also update in `.github/workflows/build_workflow.yml`
# =================
- sphinx=5.2.3
- sphinx-multiversion=0.2.4
- sphinx_rtd_theme=1.0.0
# Need to pin docutils because 0.17 has a bug with unordered lists
# https://github.com/readthedocs/sphinx_rtd_theme/issues/1115
- docutils=0.16
prefix: /home/ac.szhang/.conda/envs/zppy_dev
4 changes: 4 additions & 0 deletions zppy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from zppy.global_time_series import global_time_series
from zppy.ilamb import ilamb
from zppy.mpas_analysis import mpas_analysis
from zppy.pcmdi_diags import pcmdi_diags
from zppy.tc_analysis import tc_analysis
from zppy.ts import ts
from zppy.utils import checkStatus, submitScript
Expand Down Expand Up @@ -209,6 +210,9 @@ def main(): # noqa: C901
# ilamb tasks
existing_bundles = ilamb(config, scriptDir, existing_bundles, job_ids_file)

# pcmdi_diags tasks
existing_bundles = pcmdi_diags(config, scriptDir, existing_bundles, job_ids_file)

# zppy external plugins
for plugin in plugins:
# Get plugin module function
Expand Down
158 changes: 158 additions & 0 deletions zppy/pcmdi_diags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import os
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file looks more or less adjusted from another .py file, so from visual inspection alone this seems ok.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is adapted from the e3sm_diag.py.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhangshixuan1987 As part of #628, I did modularizing refactoring of zppy that greatly improves code readability/understandability + testing quality. We'll probably want to update this file to more closely match the other post-#628 .py files. I'm happy to help with that.

import pprint
from typing import List

import jinja2

from zppy.bundle import handle_bundles
from zppy.utils import (
add_dependencies,
checkStatus,
getTasks,
getYears,
makeExecutable,
print_url,
submitScript,
)


# -----------------------------------------------------------------------------
def pcmdi_diags(config, scriptDir, existing_bundles, job_ids_file):

# Initialize jinja2 template engine
templateLoader = jinja2.FileSystemLoader(
searchpath=config["default"]["templateDir"]
)
templateEnv = jinja2.Environment(loader=templateLoader)
template = templateEnv.get_template("pcmdi_diags.bash")

# --- List of pcmdi_diags tasks ---
tasks = getTasks(config, "pcmdi_diags")
if len(tasks) == 0:
return existing_bundles

# --- Generate and submit pcmdi_diags scripts ---
dependencies: List[str] = []

for c in tasks:

c["scriptDir"] = scriptDir

if "ts_num_years" in c.keys():
c["ts_num_years"] = int(c["ts_num_years"])

# procedure type for e3sm_to_cmip
c["cmor_tables_prefix"] = c["diagnostics_base_path"]

# Loop over year sets
year_sets = getYears(c["ts_years"])
if ("ref_years" in c.keys()) and (c["ref_years"] != [""]):
ref_year_sets = getYears(c["ref_years"])
else:
ref_year_sets = year_sets
for s, rs in zip(year_sets, ref_year_sets):
c["year1"] = s[0]
c["year2"] = s[1]
if ("last_year" in c.keys()) and (c["year2"] > c["last_year"]):
continue # Skip this year set
c["ref_year1"] = rs[0]
c["ref_year2"] = rs[1]
if c["subsection"]:
c["sub"] = c["subsection"]
else:
c["sub"] = c["grid"]
# Make a guess for observation paths, if need be
if ("ts_num_years" in c.keys()) and (c["obs_ts"] == ""):
c[
"obs_ts"
] = f"{c['diagnostics_base_path']}/observations/Atm/time-series/"
if c["run_type"] == "model_vs_obs":
prefix = "pcmdi_diags_%s_%s_%04d-%04d" % (
c["sub"],
c["tag"],
c["year1"],
c["year2"],
)
elif c["run_type"] == "model_vs_model":
prefix = "pcmdi_diags_%s_%s_%04d-%04d_vs_%04d-%04d" % (
c["sub"],
c["tag"],
c["year1"],
c["year2"],
c["ref_year1"],
c["ref_year2"],
)
reference_data_path = (
c["reference_data_path"].split("/post")[0] + "/post"
)
if ("ts_num_years" in c.keys()) and (c["reference_data_path_ts"] == ""):
c[
"reference_data_path_ts"
] = f"{reference_data_path}/atm/{c['grid']}/cmip_ts/monthly"
else:
raise ValueError("Invalid run_type={}".format(c["run_type"]))
print(prefix)
c["prefix"] = prefix
scriptFile = os.path.join(scriptDir, "%s.bash" % (prefix))
statusFile = os.path.join(scriptDir, "%s.status" % (prefix))
settingsFile = os.path.join(scriptDir, "%s.settings" % (prefix))
skip = checkStatus(statusFile)
if skip:
continue

# Create script
with open(scriptFile, "w") as f:
f.write(template.render(**c))
makeExecutable(scriptFile)

# Iterate from year1 to year2 incrementing by the number of years per time series file.
if "ts_num_years" in c.keys():
for yr in range(c["year1"], c["year2"], c["ts_num_years"]):
start_yr = yr
end_yr = yr + c["ts_num_years"] - 1
if (
("mean_climate" in c["sets"])
or ("variability_mode_atm" in c["sets"])
or ("variability_mode_cpl" in c["sets"])
or ("enso" in c["sets"])
):
add_dependencies(
dependencies,
scriptDir,
"ts",
"atm_monthly_180x360_aave",
start_yr,
end_yr,
c["ts_num_years"],
)
with open(settingsFile, "w") as sf:
p = pprint.PrettyPrinter(indent=2, stream=sf)
p.pprint(c)
p.pprint(s)

export = "ALL"
existing_bundles = handle_bundles(
c,
scriptFile,
export,
dependFiles=dependencies,
existing_bundles=existing_bundles,
)
if not c["dry_run"]:
if c["bundle"] == "":
# Submit job
submitScript(
scriptFile,
statusFile,
export,
job_ids_file,
dependFiles=dependencies,
)

else:
print("...adding to bundle '%s'" % (c["bundle"]))

print(f" environment_commands={c['environment_commands']}")
print_url(c, "pcmdi_diags")

return existing_bundles
Loading
Loading