Source code for pycaps.interp.setup_subdomain

#!/usr/bin/python

#Code: setup_subdomain.py (Python Module)
#Author: Nate Snook (CAPS)
#---------------------------------------------------------------------------------#

# List of contents:

# setup_subdomain(int, int, int, int, float, float, float, float, float[:,:], Basemap)
#   -- Takes data from a larger domain and remaps it to a subdomain
# interpolate_to_radar_surface(float[:,:,:], float[:,:,:], float[:,:,:]
#   -- Interpolates 3D fields vertically to the height of a specified radar surface.

#----------------------------------------------------------------------------------------#

[docs]def setup_subdomain(xmin, xmax, ymin, ymax, dx, dy, trulat1, trulat2, var2d, fullmap): """ Takes data from a larger domain and maps it onto a smaller subdomain. Args: xmin: i-coordinate of the west boundary of the subdomain ymin: j-coordinate of the south boundary of the subdomain xmax: i-coordinate of the east boundary of the subdomain ymax: j-coordinate of the north boundary of the subdomain dx: the horizontal grid spacing in the east-west direction, in meters dy: the horizontal grid spacing in the north-south direction, in meters trulat1: the first trulat value of the Lambert conformal map projection (often 30.0) trulat2: the second trulat value of the Lambert conformal map projection (often 60.0) var2d: the variable you need to map to a subdomain (as a 2D x-y slice) fullmap: the Basemap object associated with the larger domain (within which you are putting the subdomain) Returns: map: a Basemap object for the new subdomain x: a 2D array containing the x-coordinate, suitable for plotting with matplotlib y: a 2D array containing the y-coordinate, suitable for plotting with matplotlib var2d: the 2D variable specified in the input, mapped to the subdomain """ from mpl_toolkits.basemap import Basemap from numpy import meshgrid, arange #Define center lat, lon of the subdomain: xctr = int(((xmax + xmin) / 2)*dx) yctr = int(((ymax + ymin) / 2)*dy) lonctr, latctr = fullmap(xctr, yctr, inverse = True) #Trim arrays (including overlays, if applicable) var2d = var2d[ymin:ymax, xmin:xmax] width_x = float(xmax - xmin - 1)*dx width_y = float(ymax - ymin - 1)*dy x = arange(0, width_x+dx, dx) y = arange(0, width_y+dy, dy) x, y = meshgrid(x,y) print "----- ----- -----" print 'Plot will show the following subdomain:' print 'x: (' + str(xmin) + ',' + str(xmax) + ')' print 'y: (' + str(ymin) + ',' + str(ymax) + ')' print 'New ctrlat, ctrlon: (' + str(latctr) + ',' + str(lonctr) + ')' print 'New map will use lat_1 of ' + str(trulat1) + ' and lat_2 of ' + str(trulat2) + '.' print "----- ----- -----" map = Basemap(projection='lcc', width=width_x, height=width_y, lat_1=trulat1, lat_2=trulat2, lat_0=latctr, lon_0=lonctr, resolution='h', area_thresh=10.) #New lambert conformal map for subdomain. return map, x, y, var2d
#-------------------------------------------------------------------------------#