def test_scalar_grid(min_lon=0.0, max_lon=np.pi, min_lat=-np.pi/2.0, max_lat=np.pi/2.0,\ nlats=181, nlons=181, field='tens', cmap=plt.cm.gray_r): #{{{ satfile = "input/ConvectingEuropa_GlobalDiurnalNSR.ssrun" europa = ss.Satellite(open(satfile, 'r')) NSR = ss.StressCalc([ ss.NSR(europa), ]) the_fig = plt.figure(figsize=(10, 10)) map_ax = the_fig.add_subplot(1, 1, 1) map_ax.set_title("Rasterized scalar stress field (%s)" % (field, )) scalar_basemap = basemap.Basemap(llcrnrlon = np.degrees(min_lon),\ llcrnrlat = np.degrees(min_lat),\ urcrnrlon = np.degrees(max_lon),\ urcrnrlat = np.degrees(max_lat),\ ax = map_ax) scalar_grid(stresscalc=NSR, nlons=nlons, nlats=nlats, min_lon=min_lon, max_lon=max_lon, min_lat=min_lat, max_lat=max_lat,\ field=field, cmap=cmap, basemap_ax=scalar_basemap) scalar_basemap.drawmeridians(np.degrees(np.linspace(min_lon, max_lon, 7)), labels=[1, 0, 0, 1], linewidth=0.5, color='gray') scalar_basemap.drawparallels(np.degrees(np.linspace(min_lat, max_lat, 7)), labels=[1, 0, 0, 1], linewidth=0.5, color='gray') scalar_basemap.drawmapboundary()
def test_scalar_lin(lin, field='tens', cmap=plt.cm.jet): #{{{ import lineament satfile="input/ConvectingEuropa_GlobalDiurnalNSR.ssrun" europa = ss.Satellite(open(satfile,'r')) NSR = ss.StressCalc([ss.NSR(europa),]) mp_lons, mp_lats = lin.seg_midpoints() seg_lengths = lin.seg_lengths() min_lat = 0 max_lat = np.pi/2.0 min_lon = 0.0 max_lon = np.pi the_fig = plt.figure(figsize=(10,10)) map_ax = the_fig.add_subplot(1,1,1) map_ax.set_title("Point by Point scalar stresses field (%s)" % (field,) ) scalar_basemap = basemap.Basemap(llcrnrlon = np.degrees(min_lon),\ llcrnrlat = np.degrees(min_lat),\ urcrnrlon = np.degrees(max_lon),\ urcrnrlat = np.degrees(max_lat),\ ax = map_ax) scalar_points(stresscalc=NSR, lons=np.mod(mp_lons,np.pi), lats=np.mod(mp_lats,np.pi/2.0), symb_sizes=5000*seg_lengths, field=field, cmap=cmap, basemap_ax=scalar_basemap) junk = lineament.plotlinmap([lin,], map=scalar_basemap, lat_mirror=True, lon_cyc=np.pi) scalar_basemap.drawmeridians(np.degrees(np.linspace(min_lon, max_lon, 7)), labels=[1,0,0,1], linewidth=0.5, color='gray') scalar_basemap.drawparallels(np.degrees(np.linspace(min_lat, max_lat, 7)), labels=[1,0,0,1], linewidth=0.5, color='gray') scalar_basemap.drawmapboundary()
def main(): usage = "usage: %prog [options] satfile gridfile outfile" description = __doc__ op = OptionParser(usage) (options, args) = op.parse_args() # Do a (very) little error checking on the arguments: if len(args) != 3: op.error("incorrect number of arguments") # The satfile defines the satellite and forcings it is subject to: satfile = open(args[0], 'r') the_sat = ss.Satellite(satfile) satfile.close() # The gridfile defines the scope and resolution of the calculation: # Note here that we're actually storing information about the satellite in # two places: once in the Grid, and once in the StressDef objects that make # up the StressCalc object. This is probably bad - since one could twiddle # with the parameters on one place, and not the other, and end up getting # apparently bogus output. Be careful. gridfile = open(args[1], 'r') the_grid = Grid(gridfile, satellite=the_sat) gridfile.close() the_stresscalc = ss.StressCalc([ss.NSR(the_sat), ss.Diurnal(the_sat)]) the_gridcalc = GridCalc(the_grid, the_stresscalc) the_gridcalc.write_netcdf(args[2])
def test_vector_grid(plot_tens=True, plot_comp=True, plot_greater=True, plot_lesser=True, min_lon=0.0, max_lon=np.pi, nlons=13, min_lat=-np.pi/2.0, max_lat=np.pi/2.0, nlats=13, t=0.0): #{{{ """ An attempt to exercise the above routines... """ satfile="input/ConvectingEuropa_GlobalDiurnalNSR.ssrun" europa = ss.Satellite(open(satfile,'r')) NSR = ss.StressCalc([ss.NSR(europa),]) grid_min_lon = min_lon grid_max_lon = max_lon grid_min_lat = min_lat grid_max_lat = max_lat vector_grid_nlons = nlons vector_grid_nlats = nlats # Lon/Lat locations to plot the principal components: vector_grid_lons = np.linspace(grid_min_lon, grid_max_lon, vector_grid_nlons) vector_grid_lats = np.linspace(grid_min_lat, grid_max_lat, vector_grid_nlats) vector_mesh_lons, vector_mesh_lats = np.meshgrid(vector_grid_lons, vector_grid_lats) vector_mesh_lons = np.ravel(vector_mesh_lons) vector_mesh_lats = np.ravel(vector_mesh_lats) vector_grid_fig = plt.figure(figsize=(10,10)) vector_grid_ax = vector_grid_fig.add_subplot(1,1,1) vector_grid_ax.set_title("Regularly gridded vectors") vector_grid_basemap = basemap.Basemap(llcrnrlon = np.degrees(grid_min_lon),\ llcrnrlat = np.degrees(grid_min_lat),\ urcrnrlon = np.degrees(grid_max_lon),\ urcrnrlat = np.degrees(grid_max_lat),\ ax = vector_grid_ax) vector_points(stresscalc=NSR, lons=vector_mesh_lons, lats=vector_mesh_lats, time_t=t,\ plot_greater=plot_greater, plot_lesser=plot_lesser,\ plot_comp=plot_comp, plot_tens=plot_tens, basemap_ax=vector_grid_basemap) vector_grid_basemap.drawmeridians(np.degrees(vector_grid_lons), labels=[1,0,0,1], linewidth=0.5, color='gray') vector_grid_basemap.drawparallels(np.degrees(vector_grid_lats), labels=[1,0,0,1], linewidth=0.5, color='gray') vector_grid_basemap.drawmapboundary()
def lingen_nsr_library(nlats=36): #{{{ """ Create a regularaly spaced "grid" of synthetic NSR lineaments, for use in visualizing the expected NSR trajectories, and in fast fitting of lineaments to the stress field. """ import satstress satfile = "input/ConvectingEuropa_GlobalDiurnalNSR.ssrun" europa = satstress.Satellite(open(satfile,'r')) NSR = satstress.StressCalc([satstress.NSR(europa),]) linlist = [] for lat in linspace(0,pi/2,nlats+2)[1:-1]: linlist.append(lingen_nsr(NSR, init_lon=0.0, init_lat=lat, max_length=2*pi, prop_dir='both')) # Now mirror and shift that set of regular lineaments to cover the surface entirely: linlist += [Lineament(lons=lin.lons, lats=-lin.lats, stresscalc=lin.stresscalc) for lin in linlist] linlist += [Lineament(lons=lin.lons+pi, lats=lin.lats, stresscalc=lin.stresscalc) for lin in linlist] return linlist
def test_vector_lin(lin, t=0.0, w_stress=False, w_length=False, scale=5e7, plot_tens=True, plot_comp=False, plot_greater=True, plot_lesser=False): #{{{ import lineament satfile="input/ConvectingEuropa_GlobalDiurnalNSR.ssrun" europa = ss.Satellite(open(satfile,'r')) NSR = ss.StressCalc([ss.NSR(europa),]) best_b = lin.best_fit()[1] mp_lons, mp_lats = lin.seg_midpoints() if w_length is True: scale_arr = len(mp_lons)*lin.seg_lengths()/lin.length else: scale_arr = np.ones(np.shape(mp_lons)) min_lat = 0 max_lat = np.pi/2.0 min_lon = 0.0 max_lon = np.pi vector_lin_fig = plt.figure() vector_lin_ax = vector_lin_fig.add_subplot(1,1,1) vector_lin_ax.set_title("Vectors at arbitrary locations (e.g. along a feature)") vector_lin_basemap = basemap.Basemap(llcrnrlon = np.degrees(min_lon),\ llcrnrlat = np.degrees(min_lat),\ urcrnrlon = np.degrees(max_lon),\ urcrnrlat = np.degrees(max_lat),\ ax = vector_lin_ax) junk = lineament.plotlinmap([lin,], map=vector_lin_basemap, lat_mirror=True, lon_cyc=np.pi) vector_lin_basemap.drawmeridians(np.degrees(np.linspace(min_lon, max_lon,13)), labels=[1,0,0,1], linewidth=0.5, color='gray') vector_lin_basemap.drawparallels(np.degrees(np.linspace(min_lat, max_lat, 7)), labels=[1,0,0,1], linewidth=0.5, color='gray') vector_lin_basemap.drawmapboundary() vector_points(stresscalc=NSR, lons=np.mod(mp_lons,np.pi), lats=mp_lats, time_t=0.0, lonshift=best_b,\ plot_tens=plot_tens, plot_greater=plot_greater, plot_comp=plot_comp, plot_lesser=plot_lesser, basemap_ax=vector_lin_basemap, scale=scale, scale_arr=scale_arr, w_stress=w_stress)