Code Duplication    Length = 44-44 lines in 2 locations

metpy/calc/thermo.py 2 locations

@@ 246-289 (lines=44) @@
243
        return x[0], y[0]
244
245
246
@exporter.export
247
@check_units('[pressure]', '[temperature]', '[temperature]')
248
def el(pressure, temperature, dewpt):
249
    r"""Calculate the equilibrium level.
250
251
    This works by finding the last intersection of the ideal parcel path and
252
    the measured environmental temperature. If there is one or fewer intersections, there is
253
    no equilibrium level.
254
255
    Parameters
256
    ----------
257
    pressure : `pint.Quantity`
258
        The atmospheric pressure
259
    temperature : `pint.Quantity`
260
        The temperature at the levels given by `pressure`
261
    dewpt : `pint.Quantity`
262
        The dew point at the levels given by `pressure`
263
264
    Returns
265
    -------
266
    `pint.Quantity, pint.Quantity`
267
        The EL pressure and temperature
268
269
    See Also
270
    --------
271
    parcel_profile
272
273
    """
274
    ideal_profile = parcel_profile(pressure, temperature[0], dewpt[0]).to('degC')
275
    x, y = find_intersections(pressure[1:], ideal_profile[1:], temperature[1:])
276
277
    # If there is only one intersection, there are two possibilities:
278
    # the dataset does not contain the EL, or the LFC = LCL.
279
    if len(x) <= 1:
280
        if (ideal_profile[-1] < temperature[-1]) and (len(x) == 1):
281
            # Profile top colder than environment with one
282
            # intersection, EL exists and LFC = LCL
283
            return x[-1], y[-1]
284
        else:
285
            # The EL does not exist, either due to incomplete data
286
            # or no intersection occurring.
287
            return np.nan * pressure.units, np.nan * temperature.units
288
    else:
289
        return x[-1], y[-1]
290
291
292
@exporter.export
@@ 200-243 (lines=44) @@
197
    return lcl_p, dewpoint(vapor_pressure(lcl_p, w))
198
199
200
@exporter.export
201
@check_units('[pressure]', '[temperature]', '[temperature]')
202
def lfc(pressure, temperature, dewpt):
203
    r"""Calculate the level of free convection (LFC).
204
205
    This works by finding the first intersection of the ideal parcel path and
206
    the measured parcel temperature.
207
208
    Parameters
209
    ----------
210
    pressure : `pint.Quantity`
211
        The atmospheric pressure
212
    temperature : `pint.Quantity`
213
        The temperature at the levels given by `pressure`
214
    dewpt : `pint.Quantity`
215
        The dew point at the levels given by `pressure`
216
217
    Returns
218
    -------
219
    `pint.Quantity`
220
        The LFC pressure and temperature
221
222
    See Also
223
    --------
224
    parcel_profile
225
226
    """
227
    ideal_profile = parcel_profile(pressure, temperature[0], dewpt[0]).to('degC')
228
229
    # The parcel profile and data have the same first data point, so we ignore
230
    # that point to get the real first intersection for the LFC calculation.
231
    x, y = find_intersections(pressure[1:], ideal_profile[1:], temperature[1:],
232
                              direction='increasing')
233
    # Two possible cases here: LFC = LCL, or LFC doesn't exist
234
    if len(x) == 0:
235
        if np.any(ideal_profile > temperature):
236
            # LFC = LCL
237
            x, y = lcl(pressure[0], temperature[0], dewpt[0])
238
            return x, y
239
        # LFC doesn't exist
240
        else:
241
            return np.nan * pressure.units, np.nan * temperature.units
242
    else:
243
        return x[0], y[0]
244
245
246
@exporter.export