Using python Basemap.pcolormesh with non-monotonic longitude jumps
<p>I have satellite sweep data that I am attempting to plot on a basemap using pcolormesh.</p>

<p>The data is organized as a 2d matrix, (bTemp), with two corresponding 2D arrays lat and lon, that give the corresponding latitude and longitude at each point. So my plotting code looks like</p>

<pre><code>m = Basemap()
m.drawcoastlines()
m.pcolormesh(lon, lat, bTemp)
</code></pre>

<p>However, this doesn't quite give me the result I am looking for. A large stripe runs across the map.
<a href="https://i.stack.imgur.com/S9unj.png" rel="nofollow"><img src="https://i.stack.imgur.com/S9unj.png" alt="enter image description here"></a></p>

<p>I think the cause of this is that my longitude increases non-monotonically along a given ray, at the wrap-around point.</p>

<p>Here is a plot of on ray in my longitude array</p>

<pre><code>plot(lon[100,:])
</code></pre>

<p><a href="https://i.stack.imgur.com/Sv1Yq.png" rel="nofollow"><img src="https://i.stack.imgur.com/Sv1Yq.png" alt="enter image description here"></a></p>

<p>What would the best way to fix this be, so that the pcolormesh plot just jumps to the other side of the map without connecting the two points with a filled in area?</p>

<p>You could try using <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.unwrap.html" rel="nofollow"><code>numpy.unwrap</code></a> to unwrap your data. It was designed exactly for this: to unwrap angular jumps (in radians) that are artifacts due to the way how we use single-valued functions.</p>

<p>You need to convert your longitudes back and forth between degrees and radians for this to work, but the gist is this:</p>

<pre><code>import numpy as np
lon_unwrapped = np.rad2deg(np.unwrap(np.deg2rad(lon)))
</code></pre>

<p>This will find those jumps in your data that are larger than 180 degrees, and take their 360-degree complement. Example:</p>

<pre><code>np.rad2deg(np.unwrap(np.deg2rad([150,-150])))
# array([ 150.,  210.])
</code></pre>

<p>Additionally, <code>unwrap</code> accepts ndarray data, and you can tell it along which axes to perform the unravelling. By default this is the last dimension, which seems to be fine for your case, where you want to unwrap <code>lon[i,:]</code>.</p>

python matplotlib-basemap