| Conditions | 3 |
| Total Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # Copyright (c) 2008-2017 MetPy Developers. |
||
| 57 | @exporter.export |
||
| 58 | @check_units('[speed]', '[speed]', '[pressure]', '[length]', '[length]', '[length]') |
||
| 59 | def mean_wind_pressure_weighted(u, v, p, hgt, top, bottom=None, interp=False): |
||
| 60 | r"""Calculate pressure-weighted mean wind through a layer. |
||
| 61 | |||
| 62 | Layer top and bottom specified in meters AGL. Options are included to use only |
||
| 63 | observed winds or interpolate through the layer to match NSHARP/SharpPy's output. |
||
| 64 | |||
| 65 | Parameters |
||
| 66 | ---------- |
||
| 67 | u : array-like |
||
| 68 | U-component of wind. |
||
| 69 | v : array-like |
||
| 70 | V-component of wind. |
||
| 71 | p : array-like |
||
| 72 | Atmospheric pressure profile |
||
| 73 | hgt : array-like |
||
| 74 | Heights from sounding |
||
| 75 | top: `pint.Quantity` |
||
| 76 | The top of the layer in meters AGL |
||
| 77 | bottom: `pint.Quantity`, optional |
||
| 78 | The bottom of the layer in meters AGL. |
||
| 79 | Default is the surface. |
||
| 80 | interp: boolean, optional |
||
| 81 | Determines whether to use only observations or interpolate. |
||
| 82 | Default is only observations. |
||
| 83 | |||
| 84 | Returns |
||
| 85 | ------- |
||
| 86 | `pint.Quantity` |
||
| 87 | u_mean: u-component of layer mean wind, in m/s |
||
| 88 | `pint.Quantity` |
||
| 89 | v_mean: v-component of layer mean wind, in m/s |
||
| 90 | |||
| 91 | """ |
||
| 92 | if bottom: |
||
| 93 | depth_s = top - bottom |
||
| 94 | bottom = bottom + hgt[0] |
||
| 95 | else: |
||
| 96 | depth_s = top |
||
| 97 | |||
| 98 | if interp: |
||
| 99 | dp = -1 |
||
| 100 | pressure_top = np.interp(top.magnitude, hgt.magnitude - hgt[0].magnitude, |
||
| 101 | np.log(p.magnitude)) |
||
| 102 | pressure_top = np.exp(pressure_top) |
||
| 103 | interp_levels = (np.arange(p[0].magnitude, pressure_top + dp, dp)) * units('hPa') |
||
| 104 | u_int = log_interp(interp_levels, p, u) |
||
| 105 | v_int = log_interp(interp_levels, p, v) |
||
| 106 | h_int = log_interp(interp_levels, p, hgt) |
||
| 107 | w_int = get_layer(interp_levels, u_int, v_int, heights=h_int, |
||
| 108 | bottom=bottom, depth=depth_s) |
||
| 109 | else: |
||
| 110 | w_int = get_layer(p, u, v, heights=hgt, bottom=bottom, depth=depth_s) |
||
| 111 | |||
| 112 | u_mean = ma.average(w_int[1], weights=w_int[0]) * u.units |
||
| 113 | v_mean = ma.average(w_int[2], weights=w_int[0]) * v.units |
||
| 114 | |||
| 115 | return u_mean, v_mean |
||
| 116 |