Skip to content

Added wagner_pruss option for saturation vapour pressure.#43

Open
mariuswinkler wants to merge 18 commits intoobservingClouds:masterfrom
mariuswinkler:PR-1_sat_v_pressure_and_mixing_ratio
Open

Added wagner_pruss option for saturation vapour pressure.#43
mariuswinkler wants to merge 18 commits intoobservingClouds:masterfrom
mariuswinkler:PR-1_sat_v_pressure_and_mixing_ratio

Conversation

@mariuswinkler
Copy link
Copy Markdown
Contributor

With that, the calculation for the mixing ratio has changed throughout pysonde. Although Hardy1998 is used to calibrate the radiosondes from Vaisala side, we decided to go for the Wagner Pruss approach to align with the french MAESTRO Team which.

@mariuswinkler mariuswinkler force-pushed the PR-1_sat_v_pressure_and_mixing_ratio branch from 1af341b to d429efa Compare June 5, 2025 09:53
@mariuswinkler
Copy link
Copy Markdown
Contributor Author

The last test fails because of:

"FAILED test/test_mwx_output.py::test_mwx_file_consistency - AssertionError: difference between old and new dataset is too large for mr
assert <xarray.DataArray 'mr' ()> Size: 4B\narray(0.00014251, dtype=float32)\nAttributes:\n units: dimensionless <= 0.0001"

which must be related to the changes I made in the computation of the saturation vapour pressure whiche affects the mixing ration computation. Since the threshold value is set at 0.0001 and the error is raised for a value slightly larger (0.00014251), would it make sense to raise the threshold value for this test?

Comment thread pysonde/thermodynamics.py Outdated
Comment thread pysonde/thermodynamics.py Outdated
Comment thread pysonde/thermodynamics.py Outdated
Comment thread pysonde/thermodynamics.py Outdated
Comment thread pysonde/thermodynamics.py Outdated
Comment thread pysonde/thermodynamics.py
@observingClouds
Copy link
Copy Markdown
Owner

The last test fails because of:

"FAILED test/test_mwx_output.py::test_mwx_file_consistency - AssertionError: difference between old and new dataset is too large for mr assert <xarray.DataArray 'mr' ()> Size: 4B\narray(0.00014251, dtype=float32)\nAttributes:\n units: dimensionless <= 0.0001"

which must be related to the changes I made in the computation of the saturation vapour pressure whiche affects the mixing ration computation. Since the threshold value is set at 0.0001 and the error is raised for a value slightly larger (0.00014251), would it make sense to raise the threshold value for this test?

The issue is probably that in metpy the molecular weight ratio is given more precisely than 0.622. Could you adjust the calc_wv_mixing_ratio function to use Md and Mv from metpy.constants? I am hopeful that the test will pass after that. Since the test is still covering the Hardy forumlation.

mariuswinkler added a commit to mariuswinkler/pysonde_for_PR that referenced this pull request Jun 10, 2025
@mariuswinkler
Copy link
Copy Markdown
Contributor Author

Won't quite work still... running out of ideas rn

Comment thread pysonde/sounding.py Outdated
td.calc_wv_mixing_ratio(self.profile, e_s)
* self.profile.humidity.values
mixing_ratio = td.calc_wv_mixing_ratio(
self.profile, e_s * self.profile.humidity.values
Copy link
Copy Markdown
Owner

@observingClouds observingClouds Jun 11, 2025

Choose a reason for hiding this comment

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

The brackets are incorrectly set here and in the next occurrence. It is

w = w_s * RH / 100

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the note. Initially the RH scaling was applied after computing the saturated mixing ratio. It should go inside to compute the actual vapor pressure first. I've corrected it so that e = RH * e_s is passed directly into the function.

For the else case when self.profile.humidity.values is in percent the / 100 needs to also go inside the brackets of course.

Comment thread pysonde/_proc_level2.py Outdated
@mariuswinkler
Copy link
Copy Markdown
Contributor Author

mariuswinkler commented Jun 11, 2025

hmmm...

The only explanation I can think of is that the test might use some form of checksum or internal consistency check based on previous test-datasets. By moving the relative humidity inside the brackets of the mixing ratio computation, we might now be slightly overstepping the threshold that causes the test to fail even though the result is actually correct.

@observingClouds
Copy link
Copy Markdown
Owner

So what was wrong with df559b8? You like breaking tests?! ;) Can we not do the scaling afterwards as I did before?

@mariuswinkler
Copy link
Copy Markdown
Contributor Author

Now I've stumbled over my own leg. One more try.

@mariuswinkler
Copy link
Copy Markdown
Contributor Author

I think the scaling by relative humidity (dividing by 100) needs to happen inside the mixing ratio function, since the computation is nonlinear and depends on the actual vapor pressure, not RH in percent, no ?

@observingClouds
Copy link
Copy Markdown
Owner

Well, don't we want to calculate the:

  • saturation mixing ratio (ws) via td.calc_wv_mixing_ratio(self.profile, e_s)
    and than scale it to ambient mixing ratio (w) via saturation_mixing_ratio * RH / 100?

w = w_s * rh / 100

@mariuswinkler
Copy link
Copy Markdown
Contributor Author

Actually, both should work no ?
What I am suggesting is:

e = e_s * RH / 100.0
w = td.calc_wv_mixing_ratio(self.profile, e)

What you are suggesting is:

w_s = td.calc_wv_mixing_ratio(self.profile, e_s)
w = w_s * RH / 100.0

... only, that my version does not pass the test.

@observingClouds
Copy link
Copy Markdown
Owner

Well, to stay simple, let's stay with what works.

@mariuswinkler
Copy link
Copy Markdown
Contributor Author

I'll turn it around in a new push. 1 sec.

@mariuswinkler mariuswinkler force-pushed the PR-1_sat_v_pressure_and_mixing_ratio branch from 411c864 to 69296fb Compare June 11, 2025 11:40
mariuswinkler and others added 12 commits August 16, 2025 20:42
With that, the calculation for the mixing ratio has changed throughout pysonde. Although Hardy1998 is used to calibrate the radiosondes from Vaisala side, we decided to go for the Wagner Pruss approach to align with the french MAESTRO Team which.
Co-authored-by: Hauke Schulz <43613877+observingClouds@users.noreply.github.com>
Co-authored-by: Hauke Schulz <43613877+observingClouds@users.noreply.github.com>
Co-authored-by: Hauke Schulz <43613877+observingClouds@users.noreply.github.com>
Co-authored-by: Hauke Schulz <43613877+observingClouds@users.noreply.github.com>
@mariuswinkler mariuswinkler force-pushed the PR-1_sat_v_pressure_and_mixing_ratio branch from b84bb72 to 5cd1c79 Compare August 16, 2025 18:50
@mariuswinkler mariuswinkler force-pushed the PR-1_sat_v_pressure_and_mixing_ratio branch from d03a79d to cb0ccb2 Compare August 16, 2025 19:03
@mariuswinkler
Copy link
Copy Markdown
Contributor Author

I don't understand why this test won't go through. I took "method=wagner_pruss" out so that the test would pass but without success. I am running out of ideas here. Maybe you can have a look at it, Hauke.

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