Skip to content

Support for Gridded data #3481

@leaver2000

Description

@leaver2000

What should we add?

I've been developing an application that works with gridded data. The metpy.calc.thermo module has been a great guide for my work thus far.

My moist_lapse function differs from metpy.calc.thermo.moist_lapse and is written in Cython, that seemed to be one of the major bottlenecks the vectorizing things for gridded data support.

I currently have implementations of the moist_lapse, wet_bulb_temperature, parcel_profile, ccl, and downdraft_cape that support 2d: (N, Z) array structure.

My implementations don't use pint, everything is assumed si units. Let me know if there is any interest I'm happy to share.

pressure = isobaric_levels()
(temperature, specific_humidity), shape = get_values(["temperatureair", "humidityspecific"])
dewpoint = thermo.dewpoint_from_specific_humidity(pressure[newaxis, :], specific_humidity)

dcape = thermo.downdraft_cape(pressure, temperature, dewpoint)
dcape = dcape.reshape((-1,) + shape[2:])


fig, axes = plt.subplots(1, dcape.shape[0])
fig.tight_layout()
fig.suptitle("dcape", fontsize=16, x=0.5, y=0.65)

for i, ax in enumerate(axes):
    ax.imshow(dcape[i, :, :], cmap="coolwarm")

image

T = temperature[::2500]
Td = dewpoint[::2500]
my_dcape = thermo.downdraft_cape(
    pressure=pressure,
    temperature=T,
    dewpoint=Td,
)
mp_dcape = np.array(
    [
        mpcalc.downdraft_cape(pressure * units.pascal, T[i] * units.kelvin, Td[i] * units.kelvin)[0].m
        for i in range(T.shape[0])
    ]
)

delta = np.abs(my_dcape - mp_dcape)
print(f"{delta.max() = } {delta.mean() = } {delta.std() = }")

delta.max() = 0.6819282354549614 delta.mean() = 0.1615940182263646 delta.std() = 0.13604876693905152

Reference

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions