Code Duplication    Length = 35-36 lines in 2 locations

metpy/calc/thermo.py 2 locations

@@ 202-237 (lines=36) @@
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
    if len(x) == 0:
234
        return np.nan * pressure.units, np.nan * temperature.units
235
    else:
236
        return x[0], y[0]
237
238
239
@exporter.export
240
@check_units('[pressure]', '[temperature]', '[temperature]')
@@ 240-274 (lines=35) @@
237
238
239
@exporter.export
240
@check_units('[pressure]', '[temperature]', '[temperature]')
241
def el(pressure, temperature, dewpt):
242
    r"""Calculate the equilibrium level.
243
244
    This works by finding the last intersection of the ideal parcel path and
245
    the measured environmental temperature. If there is one or fewer intersections, there is
246
    no equilibrium level.
247
248
    Parameters
249
    ----------
250
    pressure : `pint.Quantity`
251
        The atmospheric pressure
252
    temperature : `pint.Quantity`
253
        The temperature at the levels given by `pressure`
254
    dewpt : `pint.Quantity`
255
        The dew point at the levels given by `pressure`
256
257
    Returns
258
    -------
259
    `pint.Quantity, pint.Quantity`
260
        The EL pressure and temperature
261
262
    See Also
263
    --------
264
    parcel_profile
265
266
    """
267
    ideal_profile = parcel_profile(pressure, temperature[0], dewpt[0]).to('degC')
268
    x, y = find_intersections(pressure[1:], ideal_profile[1:], temperature[1:])
269
270
    # If there is only one intersection, it's the LFC and we return None.
271
    if len(x) <= 1:
272
        return np.nan * pressure.units, np.nan * temperature.units
273
    else:
274
        return x[-1], y[-1]
275
276
277
@exporter.export