title: Quickly Plotting Polar Radar Data using Python?
body: <p>I've got an interesting application that requires transforming 3D polar data (angle, distance, and value at that point) into images representing the data. It's NOAA NEXRAD radar data that I'm using in a custom application.</p>
  
  <p>The data is stored in 3 arrays, range_data (the distance from the radar in meters, 1800 points), azimuth_data (the angle in 0.5 degree steps, 720 points), and radar_data (a 720x1800 array containing a data value for each combination of range and azimuth). This is the format I get the data in from NOAA so there's not much I can do to change things on that front.</p>
  
  <p>Right now, I'm plotting it using a matplotlib pcolormesh in the following way (basically <a href="https://unidata.github.io/siphon/latest/examples/Radar_Server_Level_3.html#sphx-glr-examples-radar-server-level-3-py" rel="nofollow noreferrer">this example from the library I'm using</a>):</p>
  
  <pre><code>x = range_data * np.sin(np.deg2rad(azimuth_data))[:,None]
  y = range_data * np.cos(np.deg2rad(azimuth_data))[:,None]
  
  fig, ax = plt.subplots(1,1,figsize=(4,4))
  ax.pcolormesh(x,y,radar_data,cmap=ref_cmap,norm=ref_norm)
  ax.set_aspect('equal','datalim')
  ax.set_xlim(-460, 460)
  ax.set_ylim(-460, 460)
  ax.set_axis_off()
  plt.axis('off')
  
  plt.savefig(imgpath, bbox_inches='tight', transparent=True, dpi=dpiCalc)
  </code></pre>
  
  <p>The major hangup right now is in the actual rendering and saving of the plot using the savefig() command. It takes around 7 seconds per image and with 20 or so sets of data to process it takes far too long for the application I have in mind.</p>
  
  <p>Since I just need the colormapped data as an image, I don't really need the majority of matplotlib's tools and features. I'm thinking there must be a quicker way to generate this image from my raw data.</p>
  
  <p>I tried stepping through the data and populating an x-y array piece-by-piece, then saving the array with PIL, but iterating through the data manually took way longer than even matplotlib. Doing array operations with numpy would be way faster but I can't really think of any operations to convert the data between coordinate systems.</p>
  
  <p>To breakdown the question even simpler, I've got polar data stored in a 720x1800 radar_data array in the format value[angle,distance], and I want to generate a <a href="https://unidata.github.io/siphon/latest/_images/sphx_glr_Radar_Server_Level_3_001.png" rel="nofollow noreferrer">colormapped radar image like this one</a> (without the axes or frame) in the quickest way possible. Since I'm not a programmer nor a mathematician by trade, there might be something simple I'm overlooking.</p>
  
  <p>Any and all recommendations are appreciated!</p>