title: Calculate the difference in two wind directions in python
body: <p>How can I calculate the difference (WD_Bias) in two wind directions (in degrees) in python so that the results range from -180 to 180? Here is the code I have so far? Does this seem to do what I want or am I missing something else?</p>
  
  <pre><code>WD_Bias = WD_model - WD_obs
  
  WD_Bias[WD_Bias&gt;180.]=360.-WD_Bias[WD_Bias&gt;180.]
  WD_Bias[WD_Bias&lt;-180.]=WD_Bias[WD_Bias&lt;-180.]+360.
  </code></pre>