Code Duplication    Length = 35-36 lines in 2 locations

metpy/calc/thermo.py 2 locations

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