Skip to content

ValueError: zero-size array to reduction operation minimum which has no identity #3795

@leaver2000

Description

@leaver2000

What went wrong?

Example

Given this example in calculating the most_unstable_cape_cin...

P = [
    101300.0,
    100000.0,
    97500.0,
    95000.0,
    92500.0,
    90000.0,
    87500.0,
    85000.0,
    82500.0,
    80000.0,
    77500.0,
    75000.0,
    72500.0,
    70000.0,
    65000.0,
    60000.0,
    55000.0,
    50000.0,
    45000.0,
    40000.0,
    35000.0,
    30000.0,
    25000.0,
    20000.0,
]
T = [
    297.54987283445246,
    296.88002814889177,
    295.7800726652342,
    294.78940763027333,
    292.9596739891891,
    293.0196074610551,
    291.93022847243265,
    290.53941937530794,
    288.93002938078973,
    287.759563930231,
    287.01920927776916,
    286.03030699198086,
    284.6906176208595,
    283.3897087315337,
    281.5599750904495,
    276.50969871115626,
    272.8995884058186,
    267.7999550496946,
    261.2795458605129,
    255.03060004390053,
    248.24049023132204,
    239.7704804573242,
    229.55006075500586,
    217.17027331634054,
]
Td = [
    295.903247655174,
    295.69122116536846,
    295.0838908693815,
    293.5371919545537,
    292.24457112007633,
    288.04982069988165,
    285.37780607791353,
    284.17380677750697,
    282.68806839907216,
    276.70189149107654,
    269.4555485732638,
    263.42704064619716,
    258.0106646774842,
    249.26453828772148,
    239.24704466847052,
    244.3324971464268,
    238.1753929086274,
    234.09412244735233,
    231.72751436757792,
    232.84305312811804,
    241.34976858460612,
    236.3692283618347,
    225.98551449499607,
    213.61268518282787,
]
P *= units.Pa
T *= units.K
Td *= units.K
assert np.all(T >= Td)

mpcalc.most_unstable_cape_cin(P, T, Td)

An error is triggered when evaluating the LFC https://github.com/Unidata/MetPy/blob/main/src/metpy/calc/thermo.py#L976

if np.min(el_pressure) > this_lcl[0]:

Seemingly because the profile contains no EL . This can be solved with a size check on el_pressure as such.

if el_pressure.size and np.min(el_pressure) > this_lcl[0]: # the LFC is this_lcl

or

if not el_pressure.size or np.min(el_pressure) > this_lcl[0]: # the LFC is nan

Operating System

Windows

Version

MetPy==1.6.3

Python Version

3.12

Code to Reproduce

P = [
    101300.0,
    100000.0,
    97500.0,
    95000.0,
    92500.0,
    90000.0,
    87500.0,
    85000.0,
    82500.0,
    80000.0,
    77500.0,
    75000.0,
    72500.0,
    70000.0,
    65000.0,
    60000.0,
    55000.0,
    50000.0,
    45000.0,
    40000.0,
    35000.0,
    30000.0,
    25000.0,
    20000.0,
]
T = [
    297.54987283445246,
    296.88002814889177,
    295.7800726652342,
    294.78940763027333,
    292.9596739891891,
    293.0196074610551,
    291.93022847243265,
    290.53941937530794,
    288.93002938078973,
    287.759563930231,
    287.01920927776916,
    286.03030699198086,
    284.6906176208595,
    283.3897087315337,
    281.5599750904495,
    276.50969871115626,
    272.8995884058186,
    267.7999550496946,
    261.2795458605129,
    255.03060004390053,
    248.24049023132204,
    239.7704804573242,
    229.55006075500586,
    217.17027331634054,
]
Td = [
    295.903247655174,
    295.69122116536846,
    295.0838908693815,
    293.5371919545537,
    292.24457112007633,
    288.04982069988165,
    285.37780607791353,
    284.17380677750697,
    282.68806839907216,
    276.70189149107654,
    269.4555485732638,
    263.42704064619716,
    258.0106646774842,
    249.26453828772148,
    239.24704466847052,
    244.3324971464268,
    238.1753929086274,
    234.09412244735233,
    231.72751436757792,
    232.84305312811804,
    241.34976858460612,
    236.3692283618347,
    225.98551449499607,
    213.61268518282787,
]
P *= units.Pa
T *= units.K
Td *= units.K
assert np.all(T >= Td)

mpcalc.most_unstable_cape_cin(P, T, Td)

Errors, Traceback, and Logs

728 el_pressure, _ = find_intersections(pressure[1:], parcel_temperature_profile[1:],
    729                                     temperature[1:], direction='decreasing',
    730                                     log_x=True)
    731 # if not el_pressure.size or np.min(el_pressure) > this_lcl[0]:
    732 # if el_pressure.size and np.min(el_pressure) > this_lcl[0]:
--> 733 if np.min(el_pressure) > this_lcl[0]:
    734     x = units.Quantity(np.nan, pressure.units)
    735     y = units.Quantity(np.nan, temperature.units)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: CalcPertains to calculationsType: BugSomething is not working like it should

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions