Skip to content

Add tempo_diagnose_refl to diagnose 10-cm reflectivity from a given state - #72

Open
ywangwof wants to merge 1 commit into
NCAR:tempo_v3.3.0from
ywangwof:feature/tempo-diagnose-refl-v3.2.4
Open

ywangwof wants to merge 1 commit into
NCAR:tempo_v3.3.0from
ywangwof:feature/tempo-diagnose-refl-v3.2.4

Conversation

@ywangwof

@ywangwof ywangwof commented Nov 20, 2026 •

Copy link
Copy Markdown

Description

Adds tempo_diagnose_refl (3D driver wrapper) and tempo_diagnose_refl_1d (column routine). Together they diagnose 10-cm reflectivity (refl10cm) from a given model state without applying any microphysical tendency.

Motivation: in cycled ensemble reflectivity DA (WoFS / RRFS with MPAS-JEDI), refl10cm at model initialization (t=0) must match the analyzed hydrometeors. Without a diagnosis it is just whatever was read from the input file. The MPAS-side change that calls this routine at initialization is ufs-community/MPAS-Model#299.

tempo_diagnose_refl_1d reproduces the end-of-step reflectivity path of tempo_main:

  • rain and snow *_check_and_update plus snow_moments;
  • graupel_init on the first step when hail-aware and the column ng/qb sums are zero, as tempo_main does;
  • the graupel check and, when hailhyperaware_flag is set, thermo_vars and compute_hail_fraction. Hail is split from graupel (via hail_check_and_update, then the graupel re-check), and reflectivity_10cm receives the hail category, exactly as tempo_main does.

tempo_diagnose_refl follows the tempo_run conventions:

  • arrays are dimensioned with memory bounds (ims:ime, kms:kme, jms:jme); only the tile (its:ite, kts:kte, jts:jte) is computed;
  • refl is intent(inout); points outside the tile are left unchanged;
  • temperature comes from either t, or th and pii (all optional). If neither is given, it returns errflg = 1 with an errmsg;
  • ng/qb are optional (hail-aware).

Input arrays are not modified. The routines are new public entry points; no existing code path changes.

Testing

gfortran 12.4, full debug (-O0 -g -fcheck=all -ffpe-trap=invalid,zero,overflow -finit-real=snan -finit-integer=-999999 -Wall -Wextra), both double (-fdefault-real-8 -fdefault-double-8) and single precision (-DSINGLE_PREC):

  • The library and run_tempo_tests build with no warnings in the new code.
  • A standalone driver uses memory bounds wider than the tile (halo in i and j). Results:
    • refl outside the tile is untouched, and all inputs are unchanged.
    • The t and th+pii forms give the same result.
    • The missing-temperature case returns errflg /= 0.
    • Compared with tempo_run refl10cm (turn_off_micro_flag, dt = 1e-4 s): max |dBZ diff| < 3e-4 for hailhyperaware on/off × with/without graupel_init, in both DP and SP.
  • run_tempo_tests: all pass in DP. In SP, test_water_conservation fails its 1e-6 tolerance (|R/P| = 1.54e-5). Pristine tempo_v3.3.0 fails identically (byte-identical test output), so this is unrelated to this PR.

In MPAS-Model (noaa/develop + ufs-community/MPAS-Model#299, CMake, Intel, Ursa), the code builds and a 3 km WoFS forecast (96 MPI tasks, mp_tempo hail-aware) runs. The t=0 refl10cm ranges from −35 to 72.9 dBZ and matches the observed convective structure.

This branch is based on tempo_v3.3.0 (4df316e).

Credits: original implementation by Chengsi Liu (v3.0.3); ported to v3.2.4/v3.3.0 by Yunheng Wang.

@ywangwof

ywangwof commented Dec 3, 2026

Copy link
Copy Markdown
Author

@AndersJensen-NOAA @dustinswales Gentle ping on this PR. It is a prerequisite for ufs-community/MPAS-Model#299 (t=0 reflectivity for MPAS-WoFS/RRFS reflectivity DA). I noticed recent merges are going into tempo_v3.3.0. Should this target tempo_v3.3.0 instead of main? I'm happy to retarget it and re-verify against tempo_main there. Thanks!

@AndersJensen-NOAA AndersJensen-NOAA left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this contribution. I let Claude do the review (Opus 5.5) and it had one main suggestion.

Comment thread src/module_mp_tempo_driver.F90 Outdated
Comment on lines +754 to +762
subroutine tempo_diagnose_refl(tempo_cfgs, th, pii, pres, qv, qc, qr, nr, qs, qg, refl, ng, qb, &
is_first_step, its, ite, jts, jte, kts, kte)
!! 10-cm reflectivity from the current hydrometeor state.
!! Does not update the hydrometeor profiles.
type(ty_tempo_cfgs), intent(in) :: tempo_cfgs
integer, intent(in) :: its, ite, jts, jte, kts, kte
real(wp), dimension(its:ite, kts:kte, jts:jte), intent(in) :: th, pii, pres, qv, qc, qr, nr, qs, qg
real(wp), dimension(its:ite, kts:kte, jts:jte), intent(out) :: refl
real(wp), dimension(its:ite, kts:kte, jts:jte), intent(in), optional :: ng, qb

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I let Claude do the review: here's them main comment:

Array bounds don't match tempo_run. These are declared over the tile range its:ite, kts:kte, jts:jte. tempo_run takes memory bounds (ims:ime, kms:kme, jms:jme) plus tile bounds and loops over the tile. If a host model with halos (WRF, or any host where ims /= its) passes its full arrays, every index shifts silently. It may happen to be fine for the MPAS call, but this is a public API, so it should follow the same convention as tempo_run.

It would also be good to accept either t or th + pii, the way tempo_run does. Rough sketch:

  subroutine tempo_diagnose_refl(tempo_cfgs, pres, qv, qc, qr, nr, qs, qg, refl, &
      t, th, pii, ng, qb, is_first_step, &
      ims, ime, jms, jme, kms, kme, &
      its, ite, jts, jte, kts, kte)
    !! 10-cm reflectivity [dBZ] diagnosed from the current hydrometeor state.
    !! Hydrometeor fields are not modified. Array conventions follow tempo_run.
    type(ty_tempo_cfgs), intent(in) :: tempo_cfgs
    integer, intent(in) :: ims, ime, jms, jme, kms, kme
    integer, intent(in) :: its, ite, jts, jte, kts, kte
    real(wp), dimension(ims:ime, kms:kme, jms:jme), intent(in) :: pres, qv, qc, qr, nr, qs, qg
    real(wp), dimension(ims:ime, kms:kme, jms:jme), intent(inout) :: refl
    real(wp), dimension(ims:ime, kms:kme, jms:jme), intent(in), optional :: t, th, pii, ng, qb
    logical, intent(in), optional :: is_first_step

    real(wp), dimension(kts:kte) :: t1d, p1d, qv1d, qc1d, qr1d, nr1d, qs1d, qg1d, ng1d, qb1d, dbz
    integer :: i, j, k
    logical :: hail_aware, use_temperature

    if (present(t)) then
      use_temperature = .true.
    elseif (present(th) .and. present(pii)) then
      use_temperature = .false.
    else
      ! error stop "tempo_diagnose_refl() --- requires either t, or th and pii"
    endif
    hail_aware = present(ng) .and. present(qb)

    do j = jts, jte
      do i = its, ite
        do k = kts, kte
          if (use_temperature) then
            t1d(k) = t(i,k,j)
          else
            t1d(k) = th(i,k,j) * pii(i,k,j)
          endif
          ! ... rest unchanged

(refl is intent(inout) so that points outside the tile keep their values. With intent(out) they become undefined.) This changes the argument list, so ufs-community/MPAS-Model#299 would need a matching update.

@AndersJensen-NOAA

AndersJensen-NOAA commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

@AndersJensen-NOAA @dustinswales Gentle ping on this PR. It is a prerequisite for ufs-community/MPAS-Model#299 (t=0 reflectivity for MPAS-WoFS/RRFS reflectivity DA). I noticed recent merges are going into tempo_v3.3.0. Should this target tempo_v3.3.0 instead of main? I'm happy to retarget it and re-verify against tempo_main there. Thanks!

@ywangwof Yes, please change the base to v3.3.0. There shouldn't be any merge conflicts doing so.

@AndersJensen-NOAA

Copy link
Copy Markdown
Collaborator

One last comment. Can you test compilation with gfortran in full debug. That should catch uninitialized variables and precision issues.

…n state

- module_mp_tempo_main: add tempo_diagnose_refl_1d, which reproduces the
  end-of-step refl10cm diagnostic of tempo_main without applying any
  microphysical tendency. It takes cloud water (qc), splits hail from
  graupel via compute_hail_fraction when hailhyperaware_flag is set (as
  tempo_main does), and optionally applies graupel_init on the first step.
- module_mp_tempo_driver: add the 3D wrapper tempo_diagnose_refl, following
  the tempo_run conventions:
  * arrays dimensioned with memory bounds (ims:ime, kms:kme, jms:jme);
    only the tile (its:ite, kts:kte, jts:jte) is computed,
  * refl is intent(inout); points outside the tile are left unchanged,
  * temperature from either t, or th and pii (all optional); if neither is
    given, errflg=1 / errmsg are returned,
  * ng/qb optional (hail-aware).

Tested with gfortran 12.4 full debug (-O0 -fcheck=all
-ffpe-trap=invalid,zero,overflow -finit-real=snan -Wall -Wextra), DP and SP,
no warnings in new code. A standalone driver with halo memory bounds checks
that refl outside the tile is untouched, inputs are unchanged, t and th*pii
give the same result, the missing-temperature error path, and agreement with
tempo_run refl10cm (turn_off_micro_flag, dt=1e-4 s): max |dBZ diff| < 3e-4
with hailhyperaware on/off and with/without graupel_init.

Co-authored-by: chengsiliu <61298443+chengsiliu@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ywangwof
ywangwof force-pushed the feature/tempo-diagnose-refl-v3.2.4 branch from b721655 to eed2f33 Compare December 3, 2026 19:56
@ywangwof
ywangwof changed the base branch from main to tempo_v3.3.0 December 3, 2026 19:56
ywangwof added a commit to ywangwof/frdd-MPAS-Model that referenced this pull request Dec 3, 2026
…-style interface

- TEMPO submodule -> ywangwof/TEMPO@eed2f33 (tempo_diagnose_refl on top of
  NCAR/TEMPO tempo_v3.3.0, see NCAR/TEMPO#72).
- init_reflectivity_diagnostic: allocate work arrays with memory bounds
  (ims:ime,kms:kme,jms:jme) as for tempo_run, pass memory and tile bounds
  with keyword arguments, and abort via physics_error_fatal on errflg.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ywangwof

ywangwof commented Dec 3, 2026

Copy link
Copy Markdown
Author

Thanks @AndersJensen-NOAA. Changes pushed:

  • Retargeted to tempo_v3.3.0 and rebased (one commit, no conflicts).
  • tempo_diagnose_refl now follows the tempo_run conventions:
    • memory bounds (ims:ime, kms:kme, jms:jme) with only the tile computed;
    • refl is intent(inout) and untouched outside the tile;
    • optional t or th+pii, with an errflg/errmsg return if neither is given;
    • optional ng/qb.
  • Tested with gfortran 12.4 in full debug (-O0 -fcheck=all -ffpe-trap=invalid,zero,overflow -finit-real=snan -Wall -Wextra), in both DP and SP. There are no warnings in the new code. A halo-bounds test driver matches tempo_run refl10cm within 3e-4 dBZ.
  • FYI: in SP, test_water_conservation fails its 1e-6 tolerance (1.54e-5) on pristine tempo_v3.3.0 as well, so this is unrelated to this PR.

Details are in the updated PR description.

This branch has not been deployed

No deployments
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