Interpolates and plots ungridded model outputs from SAS_NG solution

def xyzinterp(self, x, y, z, titletext):
    """
    Interpolates and plots ungridded model outputs from SAS_NG solution
    """
    # Help from http://wiki.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data
    
    if self.Verbose:
      print("Starting to interpolate grid for plotting -- can be a slow process!")
    
    from scipy.interpolate import griddata
    import numpy.ma as ma
    
    # define grid.
    xmin = np.min(self.xw)
    xmean = np.mean(self.xw) # not used right now
    xmax = np.max(self.xw)
    ymin = np.min(self.yw)
    ymean = np.mean(self.yw) # not used right now
    ymax = np.max(self.yw)
    x_range = xmax - xmin
    y_range = ymax - ymin
    
    # x and y grids
    # 100 cells on each side -- just for plotting, not so important
    # to optimize with how many points are plotted
    #xi = np.linspace(xmin-.05*x_range, xmax+.05*x_range, 200)
    #yi = np.linspace(ymin-.05*y_range, ymax+.05*y_range, 200)
    xi = np.linspace(xmin, xmax, 200)
    yi = np.linspace(ymin, ymax, 200)
    # grid the z-axis
    zi = griddata((x, y), z, (xi[None,:], yi[:,None]), method='cubic')
    # turn nan into 0 -- this will just be outside computation area for q
    zi[np.isnan(zi)] = 0
    # contour the gridded outputs, plotting dots at the randomly spaced data points.
    #CS = plt.contour(xi,yi,zi,15,linewidths=0.5,colors='k') -- don't need lines
    if self.latlon:
      CS = plt.contourf(xi, yi, zi, 100, cmap=plt.cm.jet)
    else:
      CS = plt.contourf(xi/1000., yi/1000., zi, 100, cmap=plt.cm.jet)
    plt.colorbar() # draw colorbar
    # plot model points.
    # Computed at
    if self.latlon:
      plt.plot(x, y, 'o', markerfacecolor='.6', markeredgecolor='.6', markersize=1)
      plt.plot(self.x, self.y, 'o', markerfacecolor='.2', markeredgecolor='.2', markersize=1)
    else:
      plt.plot(x/1000., y/1000., 'o', markerfacecolor='.6', markeredgecolor='.6', markersize=1)
      # Load sources (overlay computed at)
      plt.plot(self.x/1000., self.y/1000., 'o', markerfacecolor='.2', markeredgecolor='.2', markersize=1)
      #plt.hexbin(self.x, self.y, C=self.w) -- show colors on points -- harder to see
    if self.latlon:
      plt.xlabel('longitude [deg E]', fontsize=12, fontweight='bold')
      plt.ylabel('latitude [deg N]', fontsize=12, fontweight='bold')
    else:
      plt.xlabel('x [km]', fontsize=12, fontweight='bold')
      plt.ylabel('y [km]', fontsize=12, fontweight='bold')
    # Limits -- to not get messed up by points (view wants to be wider so whole point visible)
    if self.latlon:
      plt.xlim( (xi[0], xi[-1]) )
      plt.ylim( (yi[0], yi[-1]) )
    else:
      plt.xlim( (xi[0]/1000., xi[-1]/1000.) )
      plt.ylim( (yi[0]/1000., yi[-1]/1000.) )
    # Title
    plt.title(titletext, fontsize=16)