| Conditions | 1 |
| Total Lines | 73 |
| 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. |
||
| 106 | @exporter.export |
||
| 107 | @check_units('[pressure]', '[speed]', '[speed]', '[length]') |
||
| 108 | def bunkers_storm_motion(pressure, u, v, heights): |
||
| 109 | r"""Calculate the Bunkers right-mover and left-mover storm motions and sfc-6km mean flow. |
||
| 110 | |||
| 111 | Uses the storm motion calculation from [Bunkers et al, 2000]_. |
||
| 112 | |||
| 113 | Parameters |
||
| 114 | ---------- |
||
| 115 | pressure : array-like |
||
| 116 | Pressure from sounding |
||
| 117 | u : array-like |
||
| 118 | U component of the wind |
||
| 119 | v : array-like |
||
| 120 | V component of the wind |
||
| 121 | heights : array-like |
||
| 122 | Heights from sounding |
||
| 123 | |||
| 124 | Returns |
||
| 125 | ------- |
||
| 126 | RM_vector |
||
| 127 | U and v component of Bunkers RM storm motion |
||
| 128 | LM_vector |
||
| 129 | U and v component of Bunkers LM storm motion |
||
| 130 | mean_vector |
||
| 131 | U and v component of sfc-6km mean flow |
||
| 132 | |||
| 133 | """ |
||
| 134 | ums = u.to('m/s') |
||
| 135 | vms = v.to('m/s') |
||
| 136 | |||
| 137 | # mean wind from sfc-6km |
||
| 138 | u6m, v6m = mean_pressure_weighted(pressure, ums, vms, heights=heights, |
||
| 139 | depth=6000 * units('meter')) |
||
| 140 | |||
| 141 | # mean wind from sfc-500m |
||
| 142 | u5m, v5m = mean_pressure_weighted(pressure, ums, vms, heights=heights, |
||
| 143 | depth=500 * units('meter')) |
||
| 144 | |||
| 145 | # mean wind from 5.5-6km |
||
| 146 | u55m, v55m = mean_pressure_weighted(pressure, ums, vms, heights=heights, |
||
| 147 | depth=500 * units('meter'), |
||
| 148 | bottom=heights[0] + 5500 * units('meter')) |
||
| 149 | |||
| 150 | # Calculate the shear vector from sfc-500m to 5.5-6km |
||
| 151 | u6shr = u55m - u5m |
||
| 152 | v6shr = v55m - v5m |
||
| 153 | |||
| 154 | # making the shear vector |
||
| 155 | vl = [u6shr.magnitude, v6shr.magnitude, 0] |
||
| 156 | |||
| 157 | # Create a k hat vector |
||
| 158 | vk = [0, 0, 1] |
||
| 159 | |||
| 160 | # Take the cross product of the wind shear and k, and divide by the vector magnitude and |
||
| 161 | # multiply by the deviaton empirically calculated in Bunkers (2000) (7.5 m/s) |
||
| 162 | rdev = np.cross(vl, vk) * (7.5 / (np.sqrt(u6shr.magnitude ** 2 + v6shr.magnitude ** 2))) |
||
| 163 | |||
| 164 | # Add the deviations to the layer average wind to get the RM motion |
||
| 165 | urm = u6m.magnitude + rdev[0] |
||
| 166 | vrm = v6m.magnitude + rdev[1] |
||
| 167 | |||
| 168 | # Subtract the deviations to get the LM motion |
||
| 169 | ulm = u6m.magnitude - rdev[0] |
||
| 170 | vlm = v6m.magnitude - rdev[1] |
||
| 171 | |||
| 172 | rm_vector = np.asarray([urm, vrm]) * units('m/s').to(u.units) |
||
| 173 | |||
| 174 | lm_vector = np.asarray([ulm, vlm]) * units('m/s').to(u.units) |
||
| 175 | |||
| 176 | mean_vector = np.asarray([u6m.magnitude, v6m.magnitude]) * units('m/s').to(u.units) |
||
| 177 | |||
| 178 | return rm_vector, lm_vector, mean_vector |
||
| 179 | |||
| 233 |