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
Wet Bulb Sounding Computation fails to converge after 50 iterations, value is nan #1705
Comments
I was able to reproduce this on latest master branch with the following copy/pasteable example derived from @jsillin's example: import numpy as np
from metpy.units import units
import metpy.calc as mpcalc
pressure = [
1000.0, 975.0, 950.0, 925.0, 900.0,
850.0, 800.0, 750.0, 700.0, 650.0,
600.0, 550.0, 500.0, 450.0, 400.0,
350.0, 300.0, 250.0, 200.0, 150.0,
100.0, 70.0, 50.0, 40.0, 30.0,
20.0, 15.0, 10.0, 7.0, 5.0,
3.0, 2.0, 1.0, 0.4
] * units.hPa
dewpoint = [
18.26819029083491, 17.461145433226555, 16.336553308346822, 13.115820973342743, 6.143452735189838,
-0.2623966010678873, -3.3370926082535926, -6.550658968811679, -9.53219938820244, -14.238884651017894,
-22.66240089860936, -30.84751911458423, -33.68444429930677, -33.758997581695766, -44.84378577284087,
-43.464276398501696, -60.91091595765517, -59.34560239336541, -77.78116414272493, -77.3133221938806,
-82.27649829610058, -83.63567550304444, -84.52241968178798, np.nan, -90.08663879090643,
-88.4437696852317, np.nan, -89.92561301616831, np.nan, np.nan,
np.nan, np.nan, np.nan, np.nan
] * units.degC
temperature = [
21.38790283, 19.25753174, 17.29430542, 16.52999878,
16.88999023, 15.28999634, 12.13189697, 8.73193359,
5.1416748 , 1.52350464, -2.15553589, -6.14998169,
-11.08999634, -17.96802979, -25.26040649, -32.41000061,
-41.09917908, -45.71267395, -48.46999512, -59.97120056,
-74.6106781 , -79.78999329, -74.53684082, -63.49831848,
-58.1831604 , -53.39454041, -48.2122467 , -39.66942444,
-34.30999451, -33.35002747, -23.31001892, -14.55002441,
-11.74678955, -25.58999634
] * units.degC
mpcalc.wet_bulb_temperature(pressure, temperature, dewpoint) I'm pretty sure this is a case of For a temporary workaround, the NaN values can be removed, and then those positions replaced with NaNs in the output with the following nan_mask = np.isnan(pressure) | np.isnan(temperature) | np.isnan(dewpoint)
idx = np.arange(pressure.size)[~nan_mask]
wetbulb_valid_only = mpcalc.wet_bulb_temperature(pressure[idx], temperature[idx], dewpoint[idx])
wetbulb_full = np.full(pressure.size, np.nan) * wetbulb_valid_only.units
wetbulb_full[idx] = wetbulb_valid_only returning
(there's probably a cleaner way to do this, but this is the first workaround that came to mind) |
hi @jthielen I've been using this workaround for a bit but started to have some troubles today. I'm feeding it many many sounding arrays and lots will work until all of the sudden I get hit with:
where the first two arrays are the inputs dewpoint and temperature |
update: this also happens when I just use the normal mpcalc.wet_bulb_temperature function with data that contains no NaN values... Works 20 or 30 times in a for loop then all of the sudden doesn't. Input data for a time when things worked:
input for the one that failed:
|
This most recent error looks awfully similar to #1332, which was fixed in MetPy 1.0 (which I noticed you aren't using based on the code in the traceback). Does it only/always occur when you have perfectly saturated layer(s) in your profile? Is it feasible for you to try these same profiles in MetPy 1.0? |
hmm I have made a new conda environment with 1.0 and so far not so good:
takes >20min for that to pop up (usually <1min to read in data) |
Ooh, now that's a strange one. I can't know for sure without playing around with the exact data and process your using, but I think there are two things going on:
In the meantime, you could try adding the CRS manually with |
The exact data in question is NOMADS 18z GFS and is working fine on several other scripts using 0.12.1. I think your idea of a bug in parse_cf is a good one. Will give the manual CRS a try. Thanks for the suggestion! |
This required fixing lcl and moist_lapse to work with nans, or at least work better.
This required fixing lcl and moist_lapse to work with nans, or at least work better.
I have arrays with temperature, pressure, and relative humidity corresponding to each mandatory pressure level off the GFS from NOMADS, and am trying to produce profiles of wet bulb temperature with these data.
The particular arrays with which I am working at the moment are:
when I attempt to combine these into wet bulb using the mpcalc.wet_bulb_temperature method
sound_wb = mpcalc.wet_bulb_temperature(sound_pres.values*units.hPa,sound_temps.values*units.degC,sound_dp)
I get hit with
The expected output should be an array of wet bulb temperature values.
I am running metpy 0.12.2 and python 3.8.5 on windows with conda
I was chatting with @jthielen about this over on the discussion board earlier today, and perhaps that thread may have more information that would be helpful #1702
The text was updated successfully, but these errors were encountered: