Skip to content

Upper bc addition for impermeable cloud top - #164

Merged
rcjackson merged 4 commits into
openradar:mainfrom
R0b1et:upper_bc
Aug 20, 2026
Merged

Upper bc addition for impermeable cloud top#164
rcjackson merged 4 commits into
openradar:mainfrom
R0b1et:upper_bc

Conversation

@R0b1et

@R0b1et R0b1et commented Aug 12, 2026

Copy link
Copy Markdown

This PR implements the upper boundary condition modifications discussed for the retrieval workflow. It applies in the scipy option ONLY, this change moves the upper_bc parameter to an integer, making the meanings 0 = no condition, 1 = impermeable at grid top, 2 = impermeable at observation top. It also adds a new parameter "above" which defines a minimum altitude to apply this at.

As in https://doi.org/10.5194/egusphere-2026-4631

@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.45%. Comparing base (c541433) to head (be7c08c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pydda/cost_functions/_cost_functions_numpy.py 42.85% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #164      +/-   ##
==========================================
- Coverage   70.49%   70.45%   -0.05%     
==========================================
  Files          32       32              
  Lines        5355     5361       +6     
==========================================
+ Hits         3775     3777       +2     
- Misses       1580     1584       +4     
Flag Coverage Δ
unittests 70.45% <50.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@rcjackson

Copy link
Copy Markdown
Collaborator

I had Claude add the pre-commit hooks to lint your code for formatting and push those changes to your branch. PyDDA uses pre-commit hooks to ensure consistent style throughout the code, so I would, for future PRs, consider installing pre-commit in your repository so that these checks run automatically.

@R0b1et

R0b1et commented Aug 12, 2026

Copy link
Copy Markdown
Author

Thanks Bobby, looks like it was mostly formatting style things. pre_commit now installed!

@rcjackson

Copy link
Copy Markdown
Collaborator

Another recommendation I have is to add a unit test where we test the upper_bc=2 option so that this code is tested and we know it works. Codecov is failing since the new additions are not unit tested. You can even use the examples here and add a module that will run the TWP-ICE example with upper_bc=2, checking against expected values for your PyDDA upper_bc=2 for the TWP-ICE example. The TWP-ICE code is here in test_twpice_case:
https://github.com/openradar/PyDDA/blob/main/pydda/tests/test_retrieval.py

@rcjackson

Copy link
Copy Markdown
Collaborator

Adding tests + capabilities to Jax/Tensorflow will be another PR. Merging.

@rcjackson
rcjackson merged commit 13dfdb5 into openradar:main Aug 20, 2026
14 of 16 checks passed
rcjackson pushed a commit to rcjackson/PyDDA that referenced this pull request Aug 20, 2026
The PR openradar#164 merge crossed the two sides of the parallel mass continuity
gradient call: it kept main's calculate_mass_continuity_gradient signature,
which has no vrs parameter, alongside the branch's call site, which still
passed parameters.vrs. That sent 12 positional arguments into a function
taking 7 to 11, raising TypeError.

Removing the argument is the right direction rather than restoring the
parameter: the branch's per-gradient vrs/above arguments were consolidated
into calculate_echo_top_mask(vrs, z, above), whose result is threaded
through as the precomputed upper_bc_mask. The matching above= argument had
already been dropped from this call; only vrs survived.

Only the scipy parallel path was affected, which is why the jax and
tensorflow variants passed. parallel=True is the default, so the tests that
do not mention it failed too. The other seven gradient calls in the same
block were checked against their signatures and their arities match.

Fixes the six test_retrieval.py failures.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
rcjackson pushed a commit that referenced this pull request Aug 21, 2026
PR #164 added an integer upper_bc with a new mode 2, which holds w fixed
above the echo top, but only implemented it for the mass continuity term
of the scipy engine. This extends it to every gradient term of the scipy,
jax, tensorflow and auglag engines.

The set of points at which the condition applies is now calculated once
per retrieval by the new calculate_echo_top_mask and stored on
DDParameters.upper_bc_mask, rather than recomputing an
(n_radar, nz, ny, nx) reduction inside the gradient on every iteration.
Each gradient function takes a matching upper_bc_mask keyword and applies
it through a small per-module _apply_upper_bc helper.

Also fixed along the way:

* Every term guarded its upper boundary condition with `upper_bc is True`.
  Since `1 is True` is False, passing upper_bc=1 (as the TWP-ICE tests and
  examples/plot_examples.py already did) silently disabled the grid top
  condition. All terms now compare with ==, so both the integer modes and
  the legacy booleans work.
* The jax vertical vorticity gradient discarded the result of
  `w_grad.at[...].set(0)`, so it never applied the condition at all.
* grad_J passed upper_bc to calculate_point_gradient, which does not accept
  it, raising a TypeError whenever Cpoint > 0. The same applied to
  grad_background_cost in the auglag module. The point term's w gradient is
  identically zero, so the condition is a no-op there and the argument is
  dropped. auglag's grad_smooth_cost was also missing dx, dy and dz.

Documents the three modes and the `above` parameter in the docstrings and
in a new section of the optimizing wind retrieval user guide, and adds
cost function and TWP-ICE retrieval tests for each engine.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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