Skip to content

Zppy pcmdi enhancement#815

Draft
zhangshixuan1987 wants to merge 18 commits into
mainfrom
zppy_pcmdi_enhancement
Draft

Zppy pcmdi enhancement#815
zhangshixuan1987 wants to merge 18 commits into
mainfrom
zppy_pcmdi_enhancement

Conversation

@zhangshixuan1987
Copy link
Copy Markdown
Collaborator

Summary

Objectives:

  • Enhance robustness of the PCMDI diagnostics workflow.
  • Add adaptive num_workers safeguard for resource-intensive diagnostics.
  • Improve extraction and handling of observations.
  • Bug fixes to NCO processing and general workflow reliability.

Issue resolution:

This pull request is to:

  • a bug fix: increment the patch version
  • a small improvement: increment the minor version
  • a new feature: increment the minor version
  • an incompatible (non-backwards compatible) API change: increment the major version
  • Please fill out either the "Small Change" or "Big Change" section (the latter includes the numbered subsections), and delete the other.

Small Change

  • To merge, I will use "Squash and merge". That is, this change should be a single commit.
  • Logic: I have visually inspected the entire pull request myself.
  • Pre-commit checks: All the pre-commits checks have passed.

1. Does this do what we want it to do?

  • I have added or modified at least one "min-case" configuration file to test this change. Every objective above is represented in at least one cfg. Note: I have tested the changes, but did not add a new or modified "min-case" config file. Please advise if this is required.

2. Are the implementation details accurate & efficient?

  • I have visually inspected the entire pull request myself.
  • I have left comments highlighting important pieces of code logic in the commit messages. I have had these code blocks reviewed by at least one other team member.

3. Is this well documented?

  • Documentation: Key usage notes and explanations are included in the commit messages. The code changes are also commented for clarity. Please advise if further documentation updates are needed.

4. Is this code clean?

-Pre-commit checks: All the pre-commits checks have passed.

@zhangshixuan1987 zhangshixuan1987 requested a review from forsyth2 May 5, 2026 23:18
@zhangshixuan1987 zhangshixuan1987 self-assigned this May 5, 2026
@zhangshixuan1987 zhangshixuan1987 marked this pull request as draft May 5, 2026 23:18
@zhangshixuan1987
Copy link
Copy Markdown
Collaborator Author

@forsyth2: I submit this pull request for some changes I made based on my observations during the testing I did when I try to resolve the reported issues for #807. I noticed in my log file for the mean climate metrics calculation:

  • /compyfs/zhan391/e3sm_project/E3SMv3_testings/v3.LR.historical_0051/post/scripts/fix2/pcmdi_diags_mean_climate_model_vs_obs_1985-1994.o755476

ncra: WARNING nco_fl_lst_stdin() tried and failed to get input filename(s) from stdin ncra: ERROR received 1 positional filename(s); need at least two ncra Command line options cheatsheet (full details at http://nco.sf.net/nco.html#ncra): ncra [-3] [-4] [-5] [-6] [-7] [-A] [--bfr byt] [-C] [-c] [--cb ...] [--cmp sng] [--cnk_byt byt] [--cnk_csh byt] [--cnk_dmn nm,lmn] [--cnk_map map] [--cnk_min byt] [--cnk_plc plc] [--cnk_scl sz] [-D dbg_lvl] [-d ...] [--dbl|flt] [-F] [--fl_fmt fmt] [-G grp:lvl] [-g ...] [--gaa ...] [--gad ...] [-H] [-h] [--hdf] [--hdr_pad nbr] [--hpss] [-L lvl] [-l path] [--mro] [--msa] [-N] [-n ...] [--no_cll_msr] [--no_cll_mth] [--no_frm_trm] [--no_tmp_fl] [-O] [-o out.nc] [-p path] [--prm_ints] [--prw] [--qnt ...] [--qnt_alg alg_nm] [-R] [-r] [--ram_all] [--rec_apn] [-t thr_nbr] [--uio] [--unn] [-w wgt] [-v ...] [-X box] [-x] [-y op_typ] [-Y prg_nm] in1.nc in2.nc [...] [out.nc]

I did some debugging and found that there is a missing condition that is not fully handled in https://github.com/E3SM-Project/zppy/pull/815/changes#diff-47eb0fa6e3e0e191a714b640eddb33424a2516b9dab2c7ec57e46193d8e160bdL238-R301

Specifically, for the mean climate metrics calculation of radiative flux variables such as rsut, when CERES-EBAF is used as the observational reference, the observational dataset only covers 2001–2018. If the target model output period is, for example, 1985–1994, which is completely outside the observational coverage period, then the current code path is not able to correctly perform the observational subselection and can lead to unexpected behavior in the downstream metrics calculation. Although the metrics processing will still proceed and produce outputs, this is not the expected behavior. Instead, when this situation occurs, we would expect the workflow to fall back to using the full available observational period (2001–2018 in this case) to calculate the observational climatology for comparison, rather than attempting an invalid temporal subselection.

@chengzhuzhang chengzhuzhang requested a review from Copilot May 6, 2026 17:01
@chengzhuzhang chengzhuzhang marked this pull request as ready for review May 6, 2026 17:02
@zhangshixuan1987 zhangshixuan1987 force-pushed the zppy_pcmdi_enhancement branch from ace60e0 to f50333f Compare May 11, 2026 05:24
@chengzhuzhang
Copy link
Copy Markdown
Collaborator

@zhangshixuan1987 Should we convert this PR back to draft? From another thread, we decided that the pcmdi feature will remain as beta version until enso set is being finalized and integrated. We are at the end of e3sm-unified testing period, if you'd like to make more changes, we can choose to review and merge this PR after this e3sm-unified release.

@zhangshixuan1987
Copy link
Copy Markdown
Collaborator Author

@chengzhuzhang : Sure, I converted this to a draft. Please take any necessary actions and let me know if you need any help from me.

@zhangshixuan1987 zhangshixuan1987 marked this pull request as draft May 11, 2026 16:35
@chengzhuzhang
Copy link
Copy Markdown
Collaborator

Thank you @zhangshixuan1987. Let's plan to keep this PR open and integrate in the next release. Thanks for the testing and keeping enhance this feature.

@zhangshixuan1987 zhangshixuan1987 force-pushed the zppy_pcmdi_enhancement branch from 17f1022 to 23dedd1 Compare May 13, 2026 20:06
zppy/pcmdi_diags.py:
- Replace print() with logger.debug() for prefix logging
- Fix break -> continue in commented-out enso skip block
- Add missing else branch with ValueError in add_pcmdi_dependencies
  to prevent UnboundLocalError on invalid run_type

zppy/templates/pcmdi_diags.bash:
- Move $? check before rm in create_links_acyc_climo so ncap2
  failures are caught instead of silently swallowed
- Fix .nc file filter from regex =~ ".nc" to glob != *.nc in
  create_links_acyc_climo_obs and create_links_ts_obs
- Remove unused dofm variable from create_links_acyc_climo and
  create_links_acyc_climo_obs
- Fix double space before --enso_groups in zi-pcmdi-enso command
- Fix Jinja2 spacing: {{var}} -> {{ var }} for model_tableID,
  save_all_data, enso_viewer, enso_vars, enso_years

zppy/defaults/default.ini:
- Fix enso_vars default: hflx -> hfls (correct CMIP variable name)
…rnings

zppy/templates/pcmdi_diags.bash:
- Normalize time and time_bnds to the nearest second after ncrcat
  subsetting in create_links_ts and create_links_ts_obs to prevent
  floating-point precision artifacts causing cftime to decode boundary
  values as second=60 (e.g. 2015-12-31 23:59:60 instead of 2016-01-01)
- Guard defdim("bnds",2) with if(!exists("bnds")) in all three ncap2
  call sites to suppress spurious warnings when the bnds dimension is
  already present in the input file
Here we set default interp_vars to be empty so that it will be a user
decideded input parameter to trigger the vertical interpolation code
block instead of blindly activate it with file names
This commit contains the changes made to the pcmdi.py so that it will
allow users to pass the dependencies of the pcmdi section on the
subsection of ts and e3sm_to_cmip
Use a non-interactive Matplotlib backend for batch diagnostics.
Safe for workflows that save figures to files and avoids GUI/Tkinter errors
on systems without a display.
Split MPAS-Ocean and MPAS-Seaice time-series processing into native
ncclimo generation followed by explicit ncremap regridding. This allows
the workflow to restore MPAS-native time metadata, construct a CF-style
numeric time coordinate from timeMonthly_avg_daysSinceStartOfSim, and
preserve missing_value metadata after regridding.

For MPAS-Seaice, construct spatial-only SGS helper variables from
timeMonthly_avg_iceAreaCell before regridding. This avoids failures when
ncremap attempts to use the time-dependent timeMonthly_avg_iceAreaCell
field directly as the SGS fraction. Temporary helper variables are removed
from final output, and timeMonthly_avg_iceAreaCell is retained only when it
is the requested output variable.
@zhangshixuan1987 zhangshixuan1987 force-pushed the zppy_pcmdi_enhancement branch from 1057e0f to cd718e4 Compare May 16, 2026 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants