Code Duplication    Length = 35-36 lines in 2 locations

metpy/calc/thermo.py 2 locations

@@ 202-237 (lines=36) @@
199
    return lcl_p, dewpoint(vapor_pressure(lcl_p, w))
200
201
202
@exporter.export
203
@check_units('[pressure]', '[temperature]', '[temperature]')
204
def lfc(pressure, temperature, dewpt):
205
    r"""Calculate the level of free convection (LFC).
206
207
    This works by finding the first intersection of the ideal parcel path and
208
    the measured parcel temperature.
209
210
    Parameters
211
    ----------
212
    pressure : `pint.Quantity`
213
        The atmospheric pressure
214
    temperature : `pint.Quantity`
215
        The temperature at the levels given by `pressure`
216
    dewpt : `pint.Quantity`
217
        The dew point at the levels given by `pressure`
218
219
    Returns
220
    -------
221
    `pint.Quantity`
222
        The LFC pressure and temperature
223
224
    See Also
225
    --------
226
    parcel_profile
227
228
    """
229
    ideal_profile = parcel_profile(pressure, temperature[0], dewpt[0]).to('degC')
230
231
    # The parcel profile and data have the same first data point, so we ignore
232
    # that point to get the real first intersection for the LFC calculation.
233
    x, y = find_intersections(pressure[1:], ideal_profile[1:], temperature[1:],
234
                              direction='increasing')
235
    if len(x) == 0:
236
        return np.nan * pressure.units, np.nan * temperature.units
237
    else:
238
        return x[0], y[0]
239
240
@@ 240-274 (lines=35) @@
237
    else:
238
        return x[0], y[0]
239
240
241
@exporter.export
242
@check_units('[pressure]', '[temperature]', '[temperature]')
243
def el(pressure, temperature, dewpt):
244
    r"""Calculate the equilibrium level.
245
246
    This works by finding the last intersection of the ideal parcel path and
247
    the measured environmental temperature. If there is one or fewer intersections, there is
248
    no equilibrium level.
249
250
    Parameters
251
    ----------
252
    pressure : `pint.Quantity`
253
        The atmospheric pressure
254
    temperature : `pint.Quantity`
255
        The temperature at the levels given by `pressure`
256
    dewpt : `pint.Quantity`
257
        The dew point at the levels given by `pressure`
258
259
    Returns
260
    -------
261
    `pint.Quantity, pint.Quantity`
262
        The EL pressure and temperature
263
264
    See Also
265
    --------
266
    parcel_profile
267
268
    """
269
    ideal_profile = parcel_profile(pressure, temperature[0], dewpt[0]).to('degC')
270
    x, y = find_intersections(pressure[1:], ideal_profile[1:], temperature[1:])
271
272
    # If there is only one intersection, it's the LFC and we return None.
273
    if len(x) <= 1:
274
        return np.nan * pressure.units, np.nan * temperature.units
275
    else:
276
        return x[-1], y[-1]
277