Code Duplication    Length = 14-18 lines in 2 locations

metpy/calc/tools.py 2 locations

@@ 407-424 (lines=18) @@
404
    #
405
406
    # Depth is in pressure
407
    if depth.dimensionality == {'[length]': -1.0, '[mass]': 1.0, '[time]': -2.0}:
408
        top_pressure = bottom_pressure - depth
409
        if heights is not None:
410
            top_height = log_interp(top_pressure, p, heights)
411
        else:
412
            top_height = pressure_to_height_std(top_pressure)
413
414
    # Depth is in height
415
    elif depth.dimensionality == {'[length]': 1.0}:
416
        top_height = bottom_height + depth
417
        if heights is not None:
418
            top_pressure = np.interp(np.array([top_height.m]), heights, p)[0] * p.units
419
        else:
420
            top_pressure = height_to_pressure_std(top_height)
421
422
    # Depth is in invalid units
423
    else:
424
        raise ValueError('Depth must be in units of length or pressure.')
425
426
    # Handle top or bottom values that are invalid
427
    if bottom_pressure > p[0]:
@@ 387-400 (lines=14) @@
384
    # If the bottom pressure is specified
385
    else:
386
        # in pressure units, assign it
387
        if bottom.dimensionality == {'[length]': -1.0, '[mass]': 1.0, '[time]': -2.0}:
388
            bottom_pressure = bottom
389
            if heights is not None:
390
                bottom_height = log_interp(bottom_pressure, p, heights)
391
            else:
392
                bottom_height = pressure_to_height_std(bottom_pressure)
393
        # in height units
394
        elif bottom.dimensionality == {'[length]': 1.0}:
395
            bottom_height = bottom
396
            if heights is not None:
397
                bottom_pressure = np.interp(np.array([bottom_height.m]), heights,
398
                                            p)[0] * p.units
399
            else:
400
                bottom_pressure = height_to_pressure_std(bottom_height)
401
402
    #
403
    # Top of layer calculations