def show_simple_position(stations_url, sat_name, times, description): # TO DO: FIND METHOD FOR HANDLING sexagesimal <=> decimal units conversion from skyfield.api import Topos, load # %matplotlib inline import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemap satellites = load.tle(stations_url, reload=True) satellite = satellites[sat_name] t = times fig = plt.figure(figsize=(8, 8)) m = Basemap( projection='lcc', resolution=None, width=35E6, height=35E6, lat_0=1, lon_0=1, ) m.etopo(scale=0.5, alpha=0.5) geocentric = satellite.at(t) subpoint = geocentric.subpoint() sign1, d1, m1, s1 = subpoint.latitude.signed_dms() lat = sign1 * (d1 + m1 / 60 + s1 / 3600) sign2, d2, m2, s2 = subpoint.longitude.signed_dms() lon = sign2 * (d2 + m2 / 60 + s2 / 3600) x, y = m(lon, lat) plt.plot(x, y, 'ok', markersize=4) fig.suptitle(description, fontsize=20, fontweight='bold') return ()
def run(pot, method, m, f, g, h, x0): print("\n Optimizing using " + str(method) + " Method and " + str(pot) + " Potential:") start = time.time() x, y = m(x0, f, g, h) end = time.time() t = end - start return x, y, t
def run(self): br = m() br.set_handle_equiv(True) br.set_handle_gzip(True) br.set_handle_redirect(True) br.set_handle_referer(True) br.set_handle_robots(False) br.set_handle_refresh(m._http.HTTPRefreshProcessor(), max_time=1) _ = br.open('http://reddit.tlys.us') br.select_form(nr=1) br.form['user'] = u br.form['passwd'] = p r = br.submit() r.read()
def plot_datacoverage(self, depth, name='Megavolume', filter='rff2', conversion='EU60', factor=2.): fig = plt.figure(figsize=(6, 6)) d = np.argmin(np.abs(self.VOL.grid_depth - depth)) slice = self.VOL.volumeweight[:, :, d].copy() xx, yy = np.meshgrid(self.VOL.grid_lon, self.VOL.grid_lat) m = Basemap(projection='merc', llcrnrlat=np.min(self.VOL.grid_lat), urcrnrlat=np.max(self.VOL.grid_lat), llcrnrlon=np.min(self.VOL.grid_lon), urcrnrlon=np.max(self.VOL.grid_lon), lat_ts=20, resolution='i') m.drawparallels(np.arange(self.VOL.latmin, self.VOL.latmax, 2.), labels=[1, 0, 0, 1], linewidth=0.5, dashes=[4, 2], labelstyle='+/-', fontsize=10) m.drawmeridians(np.arange(self.VOL.lonmin, self.VOL.lonmax, 2.), labels=[1, 0, 0, 1], linewidth=0.5, dashes=[4, 2], labelstyle='+/-', fontsize=10) m.drawcountries() coasts = m.drawcoastlines(zorder=2, color='k', linewidth=1) m.drawmapboundary(fill_color=[1.0, 1.0, 1.0]) x, y = m(xx, yy) contours = [1., 15, 1.e2, 1.e3, 1.e4] #[1.e0,1.e1,1.e2,1.e3,1.e4] im = plt.contourf(x, y, slice.T, contours, norm=LogNorm(), zorder=1) fig.subplots_adjust(bottom=.2) cbar_ax = fig.add_axes([0.2, 0.1, 0.6, 0.05]) cb = fig.colorbar(im, cax=cbar_ax, orientation='horizontal') cb.set_label('Sum of weights at ' + str(depth) + ' km')
def vizInterp(nLons, nLats, ufunct, vfunct, files): '''Creates a visualization of the interpolation function nLons: list of mesh node logitudes nLats: list of mesh node latitudes uFunct: interpolation function of interpolated current u component magnitudes at each mesh node vFunct: interpolation function of interpolated current v component magnitudes at each mesh node files: list of file input names and directories for data retreival. ''' iModule = np.sqrt(ufunct**2 + vfunct**2) * 1.94384 m = Basemap(llcrnrlon=-100., llcrnrlat=0., urcrnrlon=30., urcrnrlat=70, projection='merc', resolution='l') x, y = m(np.array(nLons), np.array(nLats)) print x[:10] print y[:10] print iModule.squeeze()[:10] #print len(iModule.squeeze()) #print len(x) sys.exit() m.drawcoastlines() #m.fillcontinents(color='coral',lake_color='white') m.drawparallels(np.arange(0., 81., 20.), labels=[True, False, False, False]) m.drawmeridians(np.arange(-180., 181., 20.), labels=[False, False, False, True]) #m.drawmapboundary(fill_color='aqua') m.pcolormesh(x, y, iModule.squeeze(), cmap='jet', vmin=0, vmax=2) #m.quiver(x[::n, ::n], y[::n, ::n], ufunct[::n, ::n], vfunct[::n, ::n], scale=10, pivot='mid') m.colorbar(ticks=np.arange(0, 2.1, .2)) plt.savefig(files[8], bbox_inches='tight') plt.show()
def plot_crosssection_any(self, lon1, lon2, lat1, lat2, numpoints=200, amplify=1., name='Megavolume', filter='rff2', conversion='EU60', factor=2., zoom=False, mincoverage=10.): # set volume lats and lons inv = geo.WGS84.Inverse(lat1, lon1, lat2, lon2) points = np.linspace(0, inv['s12'], numpoints) line = geo.WGS84.Line(lat1, lon1, inv['azi1']) lats = [] lons = [] for i in range(len(points)): lats.append(line.Position(points[i])['lat2']) lons.append(line.Position(points[i])['lon2']) lats = np.array(lats) lons = np.array(lons) crossec = [] vol_sig = [] w = [] dist = [] for i in range(len(lats)): dist.append( haversine(lats[0], lons[0], [lats[i]], [lons[i]]) / 111194.) # pixelize lon and lat row = (lons - np.min(self.VOL.grid_lon)) / (self.VOL.grid_lon[1] - self.VOL.grid_lon[0]) for i in range(len(row)): if row[i] < 0: row[i] = row[i] + len(self.lon) col = (lats - np.min(self.VOL.grid_lat)) / (self.VOL.grid_lat[1] - self.VOL.grid_lat[0]) for dp in range(len(self.VOL.grid_depth)): crossec.append( scipy.ndimage.map_coordinates(self.VOL.volume[:, :, dp], np.vstack((row, col)))) vol_sig.append( scipy.ndimage.map_coordinates(self.VOL.volumesigma[:, :, dp], np.vstack((row, col)))) w.append( scipy.ndimage.map_coordinates(self.VOL.volumeweight[:, :, dp], np.vstack((row, col)))) crossec = np.array(crossec) vol_sig = np.array(vol_sig) w = np.array(w) xaxis = self.VOL.grid_lat xlabel = 'latitude (dg)' xends = [lon1, lon2] yends = [lat1, lat2] depths = self.VOL.grid_depth # normalize for i in range(np.shape(w)[0]): for j in range(np.shape(w)[1]): if w[i, j] > mincoverage: crossec[i, j] = crossec[i, j] / w[i, j] if crossec[i, j] > 0: vol_sig[i, j] = crossec[i, j] - 1.96 * np.sqrt( vol_sig[i, j] / (w[i, j] * w[i, j])) if vol_sig[i, j] < 0: vol_sig[i, j] = 0. if crossec[i, j] < 0: vol_sig[i, j] = crossec[i, j] + 1.96 * np.sqrt( vol_sig[i, j] / (w[i, j] * w[i, j])) if vol_sig[i, j] > 0: vol_sig[i, j] = 0. else: crossec[i, j] = 100. plt.subplot(2, 2, 2) m = Basemap(projection='merc', llcrnrlat=self.VOL.latmin, urcrnrlat=self.VOL.latmax, llcrnrlon=self.VOL.lonmin, urcrnrlon=self.VOL.lonmax, lat_ts=20, resolution='i') m.drawparallels(np.arange(0, 90, 10.), labels=[1, 0, 0, 1], labelstyle='+/-', fontsize=10) m.drawmeridians(np.arange(-180, 60, 10.), labels=[1, 0, 0, 1], labelstyle='+/-', fontsize=10) m.drawcoastlines() m.drawcountries() m.drawmapboundary(fill_color=[1.0, 1.0, 1.0]) x1, y1 = m(xends[0], yends[0]) x2, y2 = m(xends[1], yends[1]) m.plot([x1, x2], [y1, y2], color='r', linewidth=1, zorder=1) plt.subplot(2, 2, 1) xx, yy = np.meshgrid(dist, depths) cs = plt.pcolor(xx, yy, crossec, vmin=-0.15, vmax=0.15, rasterized=True, cmap=cm.coolwarm) plt.colorbar() cs.cmap.set_over([0.8, 0.8, 0.8]) if zoom: plt.ylim([200, 900]) else: plt.ylim([min(depths), max(depths)]) plt.gca().invert_yaxis() # corrected by 3D model # normalize norm = 0.2 / amplify #np.max(np.max(np.abs(crossec_3D)))/amplify ax = plt.subplot(2, 1, 2) pos1 = ax.get_position() # get the original position pos2 = [pos1.x0, pos1.y0, pos1.width / 14 * 8, pos1.height] pos2 = [pos1.x0, pos1.y0, pos1.width, pos1.height] print(pos1, pos2) ax.set_position(pos2) # set a new position print(ax.get_position()) # print(ax.get_position()) # plot for t in np.arange(0, len(dist), 1): lx = [ x for x in range(len(depths)) if (np.abs(w[x, t]) > mincoverage) ] # and np.abs(vol_sig[x,t])>std[x,t]/1.96)] RF = vol_sig[lx, t] / norm + dist[t] RFfull = crossec[lx, t] / norm + dist[t] plt.fill_betweenx(depths[lx], RFfull, dist[t], where=RFfull >= dist[t], facecolor='k', rasterized=True) plt.fill_betweenx(depths[lx], RFfull, dist[t], where=dist[t] >= RFfull, facecolor='k', rasterized=True) plt.fill_betweenx(depths[lx], RF, dist[t], where=RF >= dist[t], facecolor=[1.0, 0., 0.], rasterized=True) plt.fill_betweenx(depths[lx], RF, dist[t], where=dist[t] >= RF, facecolor=[0.0, 0.0, 1.], rasterized=True) RF2 = crossec[lx, t] / norm l410 = [ x for x in range(len(depths[lx])) if depths[lx[x]] > 366 and depths[lx[x]] < 454 ] l660 = [ x for x in range(len(depths[lx])) if depths[lx[x]] > 616 and depths[lx[x]] < 704 ] if len(l410) > 20: max410 = np.argmax(RF2[l410]) ind = lx[l410[max410]] plt.plot([dist[t] + 0.1, 0.5 * RF2[l410[max410]] + dist[t]], [depths[ind], depths[ind]], 'y', linewidth=2) if len(l660) > 20: max660 = np.argmax(RF2[l660]) ind = lx[l660[max660]] plt.plot([dist[t] + 0.1, 0.5 * RF2[l660[max660]] + dist[t]], [depths[ind], depths[ind]], 'y', linewidth=2) plt.ylabel('Depth (km)', fontsize=28) plt.xlabel('Angular distance (dg)', fontsize=28) plt.xlim([min(dist), max(dist)]) plt.plot([-5, 40], [410, 410], '--k', linewidth=2) plt.plot([-5, 40], [660, 660], '--k', linewidth=2) if zoom: plt.ylim([200, 800]) else: plt.ylim([min(depths), max(depths)]) plt.gca().invert_yaxis() print(ax.get_position())
def plot_datacoverage(self, depth, name='Megavolume', filter='rff2', conversion='EU60', factor=2.): fig = plt.figure(figsize=(6, 6)) d = np.argmin(np.abs(self.VOL.grid_depth - depth)) slice = self.VOL.volumeweight[:, :, d].copy() xx, yy = np.meshgrid(self.VOL.grid_lon, self.VOL.grid_lat) m = Basemap(projection='merc', llcrnrlat=np.min(self.VOL.grid_lat), urcrnrlat=np.max(self.VOL.grid_lat), llcrnrlon=np.min(self.VOL.grid_lon), urcrnrlon=np.max(self.VOL.grid_lon), lat_ts=20, resolution='i') m.drawparallels(np.arange(0, 80, 10.), labels=[1, 0, 0, 1], linewidth=0.5, dashes=[4, 2], labelstyle='+/-', fontsize=22) m.drawmeridians(np.arange(-160, -130, 20.), labels=[1, 0, 0, 1], linewidth=0.5, dashes=[4, 2], labelstyle='+/-', fontsize=22) m.drawcountries() coasts = m.drawcoastlines(zorder=2, color='k', linewidth=1) m.drawmapboundary(fill_color=[1.0, 1.0, 1.0]) x, y = m(xx, yy) contours = [1., 1.e1, 1.e2, 1.e3, 1.e4] #[1.e0,1.e1,1.e2,1.e3,1.e4] im = plt.contourf(x, y, slice.T, contours, norm=LogNorm(), zorder=1) lonmin = -157 lonmax = -143 latmin = 58 latmax = 67 #plot_line (m,lonmin,lonmax,latmin,latmax,col="Black") lonmin = -159 lonmax = -131 latmin = 59.5 latmax = 66.5 plot_line(m, lonmin, lonmax, latmin, latmax, col="Black") #BB lonmin = -160 lonmax = -142 latmin = 58 latmax = 63 plot_line(m, lonmin, lonmax, latmin, latmax, col="Black") #CC lonmin = -157 lonmax = -140 latmin = 57 latmax = 69 plot_line(m, lonmin, lonmax, latmin, latmax, col="Black") #AA lonmin = -164 lonmax = -154 latmin = 56.5 latmax = 60.5 plot_line(m, lonmin, lonmax, latmin, latmax, col="Black") #DD lonmin = -155.5 lonmax = -152 latmin = 66 latmax = 68 #plot_rectangle(m, lonmin,lonmax,latmin,latmax, col="Black") lonmin = -154 lonmax = -148.5 latmin = 58 latmax = 60.5 #plot_rectangle(m, lonmin,lonmax,latmin,latmax, col="Black") fig.subplots_adjust(bottom=.2) cbar_ax = fig.add_axes([0.2, 0.1, 0.6, 0.05]) cb = fig.colorbar(im, cax=cbar_ax, orientation='horizontal') cb.set_label('Sum of weights at ' + str(depth) + ' km', fontsize=36)
def markdown(value): return m(value)
def plot_crosssection(self, direction, lonorlat, amplify=1., name='Megavolume', filter='rff2', conversion='EU60', factor=2., zoom=False, mincoverage=10): # set volume lats and lons if direction == 'NS': lon = lonorlat n = np.argmin(np.abs(self.VOL.grid_lon - lon)) crossec = self.VOL.volume[n, :, :].T.copy() vol_sig = self.VOL.volumesigma[n, :, :].T.copy() w = self.VOL.volumeweight[n, :, :].T xaxis = self.VOL.grid_lat xlabel = 'latitude (dg)' yends = [lon, lon] xends = [self.VOL.latmin, self.VOL.latmax] lons = lon * np.ones_like(xaxis) lats = xaxis if direction == 'EW': lat = lonorlat n = np.argmin(np.abs(self.VOL.grid_lat - lat)) crossec = self.VOL.volume[:, n, :].T.copy() vol_sig = self.VOL.volumesigma[:, n, :].T.copy() w = self.VOL.volumeweight[:, n, :].T xaxis = self.VOL.grid_lon xlabel = 'longitude (dg)' xends = [self.VOL.lonmin, self.VOL.lonmax] yends = [lat, lat] lons = xaxis lats = lat * np.ones_like(xaxis) depths = self.VOL.grid_depth # normalize for i in range(np.shape(w)[0]): for j in range(np.shape(w)[1]): if w[i, j] > mincoverage: crossec[i, j] = crossec[i, j] / w[i, j] if crossec[i, j] > 0: vol_sig[i, j] = crossec[i, j] - 1.96 * np.sqrt( vol_sig[i, j] / (w[i, j] * w[i, j])) if vol_sig[i, j] < 0: vol_sig[i, j] = 0. if crossec[i, j] < 0: vol_sig[i, j] = crossec[i, j] + 1.96 * np.sqrt( vol_sig[i, j] / (w[i, j] * w[i, j])) if vol_sig[i, j] > 0: vol_sig[i, j] = 0. else: crossec[i, j] = 1000. plt.figure(figsize=(14, 8)) plt.subplot(2, 2, 2) m = Basemap(projection='merc', llcrnrlat=self.VOL.latmin, urcrnrlat=self.VOL.latmax, llcrnrlon=self.VOL.lonmin, urcrnrlon=self.VOL.lonmax, lat_ts=20, resolution='i') m.drawparallels(np.arange(0, 70, 10.), labels=[1, 0, 0, 1], labelstyle='+/-', fontsize=10) m.drawmeridians(np.arange(-10, 60, 10.), labels=[1, 0, 0, 1], labelstyle='+/-', fontsize=10) m.drawcoastlines() m.drawcountries() m.drawmapboundary(fill_color=[1.0, 1.0, 1.0]) if direction == 'NS': x1, y1 = m(yends[0], xends[0]) x2, y2 = m(yends[1], xends[1]) m.plot([x1, x2], [y1, y2], color='r', linewidth=1, zorder=1) x3, y3 = m(lon * np.ones(len(xaxis), ), np.round(xaxis / 10.) * 10.) m.scatter(x3, y3, 80, xaxis, zorder=2) if direction == 'EW': x1, y1 = m(xends[0], yends[0]) x2, y2 = m(xends[1], yends[1]) m.plot([x1, x2], [y1, y2], color='r', linewidth=1, zorder=1) x3, y3 = m(np.round(xaxis / 10.) * 10, lat * np.ones(len(xaxis), )) m.scatter(x3, y3, 80, xaxis, zorder=2) norm = 0.2 / amplify # plot plt.subplot(2, 2, 1) xx, yy = np.meshgrid(xaxis, depths) print(xx) cs = plt.pcolor(xx, yy, crossec, vmin=-0.3, vmax=0.3, rasterized=True, cmap=cm.coolwarm) #cs = plt.pcolor(xx, yy, crossec, vmin=-0.15, vmax=0.15, rasterized=True,cmap=cm.coolwarm) plt.colorbar() cs.cmap.set_over([0.8, 0.8, 0.8]) if zoom: plt.ylim([300, 800]) else: plt.ylim([min(depths), max(depths)]) plt.gca().invert_yaxis() plt.xlim(xends) plt.subplot(2, 1, 2) for t in np.arange(0, len(xaxis), 1): lx = [ x for x in range(0, len(depths)) if (np.abs(w[x, t]) > mincoverage) ] # and np.abs(vol_sig[x,t])>std[x,t]/1.96)] RF = vol_sig[lx, t] / norm + xaxis[t] RFfull = crossec[lx, t] / norm + xaxis[t] plt.fill_betweenx(depths[lx], RFfull, xaxis[t], where=RFfull >= xaxis[t], facecolor='k', rasterized=True) plt.fill_betweenx(depths[lx], RFfull, xaxis[t], where=xaxis[t] >= RFfull, facecolor='k', rasterized=True) plt.fill_betweenx(depths[lx], RF, xaxis[t], where=RF >= xaxis[t], facecolor=[1.0, 0., 0.], rasterized=True) plt.fill_betweenx(depths[lx], RF, xaxis[t], where=xaxis[t] >= RF, facecolor=[0.0, 0.0, 1.], rasterized=True) plt.scatter(np.round(xaxis / 10.) * 10., 80. * np.ones(len(xaxis), ), 80, xaxis, rasterized=True) plt.plot([-180, 140], [410, 410], '--k', linewidth=2) #plt.plot([-180, 140], [520, 520], '--k', linewidth=2) plt.plot([-180, 140], [660, 660], '--k', linewidth=2) plt.ylabel('Depth (km)') plt.xlabel(xlabel, fontsize=12) plt.xlim([min(xaxis), max(xaxis)]) if zoom: plt.ylim([300, 800]) else: plt.ylim([min(depths), max(depths)]) plt.gca().invert_yaxis() print(min(depths))
import re from re import compile as rec from tornado.escape import _unicode, xhtml_escape, url_escape from misaka import HtmlRenderer, Markdown import misaka as m from bnw.web.linkshit import LinkParser, shittypes from bnw.web.linkshit import _URL_RE, _USER_RE, _MSG_RE #: Displaying thumbs allowed for the following hostings: linkhostings = [ (ur'(?i)http://rghost.(net|ru)/([0-9]+)', lambda m,s: 'http%s://rghost.%s/%s/thumb.png' % (s,m(1),m(2))), (ur'(?i)https?://imgur.com/([A-Za-z0-9]+)', lambda m,s: 'http%s://i.imgur.com/%ss.png' % (s,m(1),)), (ur'http://(2ch.hk|2ch.pm|2ch.re|2ch.tf|2ch.wf|2ch.yt|2-ch.so)/([a-z]+)/src/([0-9]+).(png|gif|jpg)', lambda m,s: 'http%s://%s/%s/thumb/%ss.gif' % (s,m(1),m(2),m(3))), (ur'https?://(?:www\.)?youtube.com/watch\?(?:.+&)?v\=([A-Z0-9a-z_-]+)(?:&.+)?', lambda m,s: 'http%s://img.youtube.com/vi/%s/default.jpg' % (s,m(1))), (ur'(?i)https?://upload.wikimedia.org/wikipedia/commons/([0-9]{1}\/[A-Za-z0-9]+)/([A-Za-z0-9_.]+)', lambda m,s: 'http%s://upload.wikimedia.org/wikipedia/commons/thumb/%s/%s/256px-%s' % (s,m(1),m(2),m(2))), (ur'(?i)https?://(.+.(?:png|gif|jpg|jpeg))', lambda m,s: 'http%s://bnw-thumb.r.worldssl.net/thumb?img=%s' % (s,url_escape(m(0)),)), ] linkhostings = [(re.compile('^' + k + '$'), v, k) for (k, v) in linkhostings] def thumbify(text, format='markdown', secure=False): """Format text and generate thumbs using available formatters. :param format: default: 'markdown'. Specify text formatter. Variants: 'moinmoin', 'markdown' or None, which fallbacks to markdown. Return: (formatted_text, thumbs)
l.append(coords[i]) cluster_points[x[i]] = l plt.figure(figsize=(12, 12)) #plotting points on map m = Basemap(projection='merc', resolution='l', epsg=4269, llcrnrlon=-122.567288, llcrnrlat=37.696627, urcrnrlon=-122.329308, urcrnrlat=37.852144) # plot the aftershock x, y = m(coords[:, 1], coords[:, 0]) m.scatter(x, y, 5, marker='o', color='b') m.arcgisimage(service='World_Shaded_Relief', xpixels=5000, verbose=False) plt.show() def get_cmap(N): ''' Returns a function that maps each index in 0, 1, ... N-1 to a distinct RGB color. ''' color_norm = colors.Normalize(vmin=0, vmax=N - 1) scalar_map = cmx.ScalarMappable(norm=color_norm, cmap='nipy_spectral') def map_index_to_rgb_color(index): return scalar_map.to_rgba(index)
def plot_topography(self, mindepth, maxdepth, name='Megavolume', filter='rff2', conversion='prem', factor=2., mincoverage=15., amplitude=False, color_scheme='spectral', reverse=False): # Plots topography of maximum between mindepth and maxdepth, masking if sum of weights is beneath mincoverage. # If amplitude =True, it will plot the amplitude and not the depth plt.figure(figsize=(10, 8)) depths = self.VOL.grid_depth val_list = [ x for x in range(len(depths)) if depths[x] > mindepth and depths[x] < maxdepth ] thickness = np.empty((len(self.VOL.grid_lon), len(self.VOL.grid_lat))) dmap = np.empty((len(self.VOL.grid_lon), len(self.VOL.grid_lat))) coverage = np.empty((len(self.VOL.grid_lon), len(self.VOL.grid_lat))) for i in range(len(self.VOL.grid_lon)): for j in range(len(self.VOL.grid_lat)): RF = self.VOL.volume[i, j, :] / self.VOL.volumeweight[i, j, :] std = 1.96 * np.sqrt(self.VOL.volumesigma[i, j, :] / (self.VOL.volumeweight[i, j, :] * self.VOL.volumeweight[i, j, :])) maxmap = np.argmax(RF[val_list]) if amplitude == False: dmap[i, j] = depths[val_list[maxmap]] else: dmap[i, j] = RF[val_list[maxmap]] if self.VOL.volumeweight[i, j, val_list[maxmap]] < mincoverage: dmap[i, j] = 1000. # Prepare map m = Basemap(projection='merc', llcrnrlat=np.min(self.VOL.grid_lat) - 0, urcrnrlat=np.max(self.VOL.grid_lat) + 0, llcrnrlon=np.min(self.VOL.grid_lon) - 0, urcrnrlon=np.max(self.VOL.grid_lon) + 0, lat_ts=10, resolution='i') m.drawparallels(np.arange(0, 70, 10.), labels=[1, 0, 0, 1], linewidth=0.5, dashes=[4, 2], labelstyle='+/-', fontsize=8) #[1,0,0,1]) m.drawmeridians(np.arange(-20, 60, 10.), labels=[1, 0, 0, 1], linewidth=0.5, dashes=[4, 2], labelstyle='+/-', fontsize=8) #[1,0,0,1]) m.drawcountries() m.drawstates() m.drawcoastlines() coasts = m.drawcoastlines(zorder=1, color='k', linewidth=0.1) xx, yy = np.meshgrid(self.VOL.grid_lon, self.VOL.grid_lat) x, y = m(xx, yy) #----------------------------------------------------------------------- if color_scheme == 'rainbow' and reverse == True: cmap = cm.rainbow_r if color_scheme == 'rainbow' and reverse == False: cmap = cm.rainbow if color_scheme == 'spectral' and reverse == True: cmap = cm.Spectral_r if color_scheme == 'spectral' and reverse == False: cmap = cm.Spectral #------------------------------------------------------------------------ if amplitude is False: cs = plt.pcolor(x, y, dmap.T, vmin=mindepth, vmax=maxdepth, cmap=cmap, linewidth=0, rasterized=False) else: cs = plt.pcolor(x, y, dmap.T, vmin=0.01, vmax=0.12, cmap=cm.cmap, linewidth=0, rasterized=False) cs.cmap.set_under([0.8, 0.8, 0.8]) cs.cmap.set_over([0.8, 0.8, 0.8]) cb = plt.colorbar() cb.set_label('Maximum map between ' + str(mindepth) + ' and ' + str(maxdepth) + ' (km)') # cb.set_ticks([380,400,420,440]) cb.solids.set_rasterized(True) xt, yt = m(-13.2, 70.6) m.drawcoastlines(zorder=1, color='k', linewidth=1) dmapall = np.ravel(dmap) if amplitude == False: l = [ l for l in range(len(dmapall)) if dmapall[l] > mindepth + 1. and dmapall[l] < maxdepth - 1. ] print('median', np.median((dmapall[l]))) print('variance', np.var((dmapall[l])))
def plot_mtzwidth_write(self, name='Megavolume', filter='rff2', conversion='EU60', factor=2.): #This routine is also used to make a txt file with the significant depths of the 410 and the 660 #depth410660 = open('/raid3/annemijn/scripts/CCP/mincov40MTZ_'+conversion+'_'+filter+'_'+str(int(factor))+'.txt', 'w') depth410660 = open( '/raid1/annemijn/scripts/CCP/MTZsign_mincov40_' + conversion + '_' + filter + '_' + str(int(factor)) + '.txt', 'w') plt.figure(figsize=(18, 8)) depths = self.VOL.grid_depth l410 = [ x for x in range(len(depths)) if depths[x] > 380 and depths[x] < 430 ] l660 = [ x for x in range(len(depths)) if depths[x] > 630 and depths[x] < 700 ] thickness1D = np.empty( (len(self.VOL.grid_lon), len(self.VOL.grid_lat))) d4101D = np.empty((len(self.VOL.grid_lon), len(self.VOL.grid_lat))) d6601D = np.empty((len(self.VOL.grid_lon), len(self.VOL.grid_lat))) for i in range(len(self.VOL.grid_lon)): for j in range(len(self.VOL.grid_lat)): RF = self.VOL.volume[i, j, :] / self.VOL.volumeweight[i, j, :] std = 1.96 * np.sqrt(self.VOL.volumesigma[i, j, :] / (self.VOL.volumeweight[i, j, :] * self.VOL.volumeweight[i, j, :])) max410 = np.argmax(RF[l410]) max660 = np.argmax(RF[l660]) maxamp410 = np.max(RF[l410]) maxamp660 = np.max(RF[l660]) # If both picks are significant, store thickness if RF[l410[max410]] > std[l410[max410]] and RF[ l660[max660]] > std[l660[max660]]: d4101D[i, j] = depths[l410[max410]] d6601D[i, j] = depths[l660[max660]] thickness1D[i, j] = (depths[l660[max660]] - depths[l410[max410]]) if self.VOL.volumeweight[i, j, l410[max410]] >= 40: #This routine is also used to make a txt file with the depth of the 410 and the 660 depth410660.write(str(self.VOL.grid_lat[j]) + '\t') depth410660.write(str(self.VOL.grid_lon[i]) + '\t') depth410660.write(str(depths[l410[max410]]) + '\t') depth410660.write(str(depths[l660[max660]]) + '\t') depth410660.write(str(maxamp410) + '\t') depth410660.write(str(maxamp660) + '\n') # Prepare map m = Basemap(projection='merc', llcrnrlat=np.min(self.VOL.grid_lat), urcrnrlat=np.max(self.VOL.grid_lat), llcrnrlon=np.min(self.VOL.grid_lon), urcrnrlon=np.max(self.VOL.grid_lon), lat_ts=20, resolution='i') m.drawparallels(np.arange(np.min(self.VOL.grid_lat), np.max(self.VOL.grid_lat), 10.), labels=[0, 0, 0, 0]) #[1,0,0,1]) m.drawmeridians(np.arange(np.min(self.VOL.grid_lon), np.max(self.VOL.grid_lon), 10.), labels=[0, 0, 0, 0]) #[1,0,0,1]) m.drawcoastlines(color='k') m.drawcountries(color='k') m.drawmapboundary(fill_color=[1.0, 1.0, 1.0]) xx, yy = np.meshgrid(self.VOL.grid_lon, self.VOL.grid_lat) x, y = m(xx, yy) cs = plt.contourf(x, y, thickness1D.T, levels=np.linspace(220., 300., 81.), cmap=cm.gist_earth_r) cs.cmap.set_under('w') cs.cmap.set_over('w') plt.colorbar() plt.title('MTZ width') #This routine is also used to make a txt file with the depth of the 410 and the 660 depth410660.close()
# More map configuration # draw coastlines, country boundaries m.drawcoastlines(linewidth=0.25) m.drawcountries(linewidth=0.25) # draw parallels. parallels = np.arange(-40., 40, 10.) m.drawparallels(parallels, labels=[1, 0, 0, 0], fontsize=10) # draw meridians meridians = np.arange(80., 180., 10.) m.drawmeridians(meridians, labels=[0, 0, 0, 1], fontsize=10) # Make grid for TRMM data ny = trmm_precip.shape[0] nx = trmm_precip.shape[1] lons, lats = m.makegrid(nx, ny) # get lat/lons of ny by nx evenly spaced grid. x, y = m(lons, lats) # compute map proj coordinates. # Make grid for SACA data ny_saca = saca_precip.shape[0] nx_saca = saca_precip.shape[1] lons_saca, lats_saca = m.makegrid(nx_saca, ny_saca) x_saca, y_saca = m(lons_saca, lats_saca) # Make grid for TRMM Land Sea mask (updated) lons_mask, lats_mask = np.meshgrid(lons_ls_mask, lats_ls_mask) x_mask, y_mask = m(lons_mask, lats_mask) print 'lons_mask', lons_mask print 'lats_mask', lats_mask print
# draw coastlines, country boundaries m.drawcoastlines(linewidth=0.25) m.drawcountries(linewidth=0.25) # draw parallels. parallels = np.arange(-40., 40, 10.) m.drawparallels(parallels, labels=[1, 0, 0, 0], fontsize=10) # draw meridians meridians = np.arange(80., 180., 10.) m.drawmeridians(meridians, labels=[0, 0, 0, 1], fontsize=10) # Make grid for TRMM data ny = trmm_precip.shape[0] nx = trmm_precip.shape[1] lons, lats = m.makegrid(nx, ny) # get lat/lons of ny by nx evenly spaced grid. x, y = m(lons, lats) # compute map proj coordinates. # Make grid for SACA data ny_saca = saca_precip.shape[0] nx_saca = saca_precip.shape[1] lons_saca, lats_saca = m.makegrid( nx_saca, ny_saca) # get lat/lons of ny by nx evenly space grid. x_saca, y_saca = m(lons_saca, lats_saca) # compute map proj coordinates. # Actual plotting and rendering # ================================================================ # Plot TRMM # =============== # cs = m.contourf(x,y,trmm_precip*trmm_lsmask,clevs,cmap=cm.s3pcpn) # # Add colorbar
norm = matplotlib.colors.BoundaryNorm(levels, 16) # draw coastlines, country boundaries, fill continents. m.drawcoastlines(linewidth=0.25) m.drawcountries(linewidth=0.25) # draw parallels. parallels = np.arange(-40., 40, 10.) m.drawparallels(parallels, labels=[1, 0, 0, 0], fontsize=10) # draw meridians meridians = np.arange(80., 180., 10.) m.drawmeridians(meridians, labels=[0, 0, 0, 1], fontsize=10) ny = trmm_precip.shape[0] nx = trmm_precip.shape[1] lons, lats = m.makegrid(nx, ny) # get lat/lons of ny by nx evenly space grid. x, y = m(lons, lats) # compute map proj coordinates. #print x # Land sea mask #topo = maskoceans(lons, lats, topoin) #cs = m.pcolor(lons,lats,trmm_precip) #cs = plt.contour(trmm_precip, cmap=cm.jet) # From my old script #m.drawlsmask(land_color='white',ocean_color='white') #trmm_precip.mask cs = m.contourf(x, y, trmm_precip * trmm_lsmask, clevs, cmap=cm.s3pcpn) # works #cs = m.pcolormesh(x,y,trmm_precip) # works but standard matlab look
import re from re import compile as rec from tornado.escape import _unicode, xhtml_escape, url_escape from misaka import HtmlRenderer, Markdown import misaka as m from bnw_web.linkshit import LinkParser, shittypes from bnw_web.linkshit import _URL_RE, _USER_RE, _MSG_RE #: Displaying thumbs allowed for the following hostings: linkhostings = [ (ur'(?i)http://rghost.ru/([0-9]+)', lambda m: 'http://rghost.ru/%s/thumb.png' % (m(1),)), (ur'(?i)http://imgur.com/([A-Za-z0-9]+)', lambda m: 'http://i.imgur.com/%ss.png' % (m(1),)), (ur'http://ompldr.org/v([A-Za-z0-9]+)(/.+)?', lambda m: 'http://ompldr.org/t%s' % (m(1),)), (ur'http://2-ch.ru/([a-z]+)/src/([0-9]+).(png|gif|jpg)', lambda m: 'http://2-ch.ru/%s/thumb/%ss.%s' % (m(1),m(2),m(3))), (ur'(?i)http://(.+.(?:png|gif|jpg|jpeg))', lambda m: 'http://f**k.blasux.ru/thumb?img=%s' % (url_escape(m(0)),)), ] linkhostings = [(re.compile('^' + k + '$'), v, k) for (k, v) in linkhostings] def thumbify(text, format='markdown'): """Format text and generate thumbs using available formatters. :param format: default: 'markdown'. Specify text formatter. Variants: 'moinmoin', 'markdown' or None, which fallbacks to markdown. Return: (formatted_text, thumbs) Thumbs: list of (original_file_url, thumb_url)
def plot_slip(self, slip, filename=None,slipmax=None): sbfs=self.sbfs sbf_ind=self.sbf_ind num_sbr=self.num_sbr plt.clf() fig = plt.figure(figsize=(8,8)) ax = fig.add_axes([0.1, 0.15, .8, 0.6]) m=self.drawmap() cmap=plt.cm.seismic#jet #if slipmax==None: slipmax=slip.max() slipmin=slip.min() slipmag=slipmax-slipmin if slipmag==0: slipmag=1.0 plot_ind=True for k in range(num_sbr): sbf=sbfs[k][1] sfply = [] for xyz in sbf: sfply.append(m(xyz[0],xyz[1])) cmval=(slip[k]+slipmax)/float(2*slipmax) #print k, slip[k], cmval color = cmap(cmval) poly = Polygon(sfply,facecolor=rgb2hex(color),edgecolor='blue') ax.add_patch(poly) #plt.text(ln,lt,'%s'%int(slip[k])) if plot_ind: if k%13==0: cntx,cnty=sbfs[k][0] (ln,lt)=m(cntx,cnty) plt.text(ln,lt,'%d'%(sbf_ind[k])) # draw trench line x = [] y = [] for line in open('trench.xy','r'): if line.startswith('>'): if len(x) > 0: (x0,y0) = m(x,y) plt.plot(x0,y0,'-r',linewidth=2) x = [] y = [] continue x.append(float(line.split()[0])) y.append(float(line.split()[1])) hlon, hlat=self.hypo yc,xc=m(hlon, hlat) plt.plot(yc, xc,'r*',markersize=18) norm1 = MidpointNormalize(vmin=-slipmax, vmax=slipmax, midpoint=0) #norm1 = mpl.colors.Normalize(vmin=slipmin, vmax=slipmax) ax2 = fig.add_axes([0.72, .15, 0.045, 0.6]) cb1 = mpl.colorbar.ColorbarBase(ax2, cmap=cmap, norm=norm1, orientation='vertical') cb1.set_label('amplitude(m)') extent = ax.get_window_extent().transformed(fig.dpi_scale_trans.inverted()) plt.savefig(filename,bbox_inches='tight',pad_inches = 0.02)
def plot_topography(self, mindepth, maxdepth, name='Megavolume', filter='rff2', conversion='prem', factor=2., mincoverage=10., amplitude=True, blobs=True): # Plots topography of maximum between mindepth and maxdepth, masking if sum of weights is beneath mincoverage. # If amplitude =True, it will plot the amplitude and not the depth plt.figure(figsize=(10, 8)) depths = self.VOL.grid_depth #print('depths are ', depths) val_list = [ x for x in range(len(depths)) if depths[x] > mindepth and depths[x] < maxdepth ] thickness = np.empty((len(self.VOL.grid_lon), len(self.VOL.grid_lat))) dmap = np.empty((len(self.VOL.grid_lon), len(self.VOL.grid_lat))) coverage = np.empty((len(self.VOL.grid_lon), len(self.VOL.grid_lat))) dsign = np.empty((len(self.VOL.grid_lon), len(self.VOL.grid_lat))) amparray = [] for i in range(len(self.VOL.grid_lon)): for j in range(len(self.VOL.grid_lat)): RF = self.VOL.volume[i, j, :] / self.VOL.volumeweight[i, j, :] plt.plot(RF) std = 1.96 * np.sqrt(self.VOL.volumesigma[i, j, :] / (self.VOL.volumeweight[i, j, :] * self.VOL.volumeweight[i, j, :])) maxmap = np.argmax(RF[val_list]) if amplitude == False: dmap[i, j] = depths[val_list[maxmap]] else: dmap[i, j] = RF[val_list[maxmap]] #array for significance, 0=significant, 1=not significant if abs(RF[val_list[maxmap]]) > std[val_list[maxmap]]: dsign[i, j] = 0.0 else: dsign[i, j] = 1. if self.VOL.volumeweight[i, j, val_list[maxmap]] < mincoverage: dmap[i, j] = 1000. dsign[i, j] = 0. #plt.show() # Prepare map m = Basemap(projection='merc', llcrnrlat=np.min(self.VOL.grid_lat), urcrnrlat=np.max(self.VOL.grid_lat), llcrnrlon=np.min(self.VOL.grid_lon), urcrnrlon=np.max(self.VOL.grid_lon), lat_ts=20, resolution='i') m.drawparallels(np.arange(0, 90, 5.), labels=[1, 0, 0, 1], linewidth=0.5, dashes=[4, 2], labelstyle='+/-', fontsize=20) m.drawmeridians(np.arange(-180, -110, 10.), labels=[1, 0, 0, 1], linewidth=0.5, dashes=[4, 2], labelstyle='+/-', fontsize=20) m.drawcountries() coasts = m.drawcoastlines(zorder=1, color='k', linewidth=1) xx, yy = np.meshgrid(self.VOL.grid_lon, self.VOL.grid_lat) x, y = m(xx, yy) if amplitude is False: cs = plt.pcolor(x, y, dmap.T, vmin=mindepth, vmax=maxdepth, cmap=cm.BrBG, linewidth=0, rasterized=True) #mask area if not significant dsign = ma.masked_array(dsign, dsign == 0) sign = plt.contourf(x, y, dsign.T, vmin=0.5, vmax=1.0, cmap=cm.Greys, linewidth=0, alpha=0.7, rasterized=False) else: cs = plt.pcolor(x, y, dmap.T, vmin=0.02, vmax=0.12, cmap=cm.pink_r, linewidth=0, rasterized=True) cs.cmap.set_under([0.8, 0.8, 0.8]) cs.cmap.set_over([0.8, 0.8, 0.8]) #mindepth=np.argmin(dmap.T) #maxdepth=np.argmax(dmap.T) cb = plt.colorbar(cs, ticks=[ mindepth, mindepth + (maxdepth - mindepth) / 6, mindepth + 2 * (maxdepth - mindepth) / 6, mindepth + 3 * (maxdepth - mindepth) / 6, mindepth + 4 * (maxdepth - mindepth) / 6, mindepth + 5 * (maxdepth - mindepth) / 6, maxdepth ]) #cb.set_label('Maximum map between ' + str(mindepth)+' and ' + str(maxdepth)+' (km)', size=30) if mindepth == 380: cb.set_label('Depth of 410 (km)', size=30) else: cb.set_label('Depth of 660 (km)', size=30) cb.ax.tick_params(labelsize=30) #cb.set_label('Amplitude') # cb.set_ticks([380,400,420,440]) cb.solids.set_rasterized(True) xt, yt = m(-13.2, 70.6) m.drawcoastlines(zorder=1, color='k', linewidth=1) dmapall = np.ravel(dmap) if amplitude == False: l = [ l for l in range(len(dmapall)) if dmapall[l] > mindepth + 1. and dmapall[l] < maxdepth - 1. ] print('median', np.median((dmapall[l]))) print('variance', np.var((dmapall[l]))) if blobs == True: latblob = [] lonblob = [] with open('/raid1/annemijn/scripts/CCP/areared.txt') as blobs: for line in blobs: row = line.split() latblob.append(float(row[0])) lonblob.append(float(row[1])) print(latblob) x, y = m(lonblob, latblob) m.scatter(x, y, marker='o', color='firebrick') latblob = [] lonblob = [] with open('/raid1/annemijn/scripts/CCP/areayellow.txt') as blobs: for line in blobs: row = line.split() latblob.append(float(row[0])) lonblob.append(float(row[1])) print(latblob) x, y = m(lonblob, latblob) m.scatter(x, y, marker='o', color='gold') latblob = [] lonblob = [] with open('/raid1/annemijn/scripts/CCP/areagreen.txt') as blobs: for line in blobs: row = line.split() latblob.append(float(row[0])) lonblob.append(float(row[1])) print(latblob) x, y = m(lonblob, latblob) m.scatter(x, y, marker='o', color='forestgreen') latblob = [] lonblob = [] with open('/raid1/annemijn/scripts/CCP/areablue.txt') as blobs: for line in blobs: row = line.split() latblob.append(float(row[0])) lonblob.append(float(row[1])) print(latblob) x, y = m(lonblob, latblob) m.scatter(x, y, marker='o', color='dodgerblue') lonmin = -142.1 lonmax = -128 latmin = 69 latmax = 74 #plot_rectangle(m, lonmin,lonmax,latmin,latmax) lonmin = -136 lonmax = -128 latmin = 54 latmax = 63 #plot_rectangle(m, lonmin,lonmax,latmin,latmax) lonmin = -157 lonmax = -150 latmin = 67.5 latmax = 69 #plot_rectangle(m, lonmin,lonmax,latmin,latmax) lonmin = -154 lonmax = -149 latmin = 66 latmax = 68 #plot_rectangle(m, lonmin,lonmax,latmin,latmax, col="Black") lonmin = -155 lonmax = -150 latmin = 56.5 latmax = 59.5 #plot_rectangle(m, lonmin,lonmax,latmin,latmax, col="Black") lonmin = -159 lonmax = -131 latmin = 59.5 latmax = 66.5 #plot_line (m,lonmin,lonmax,latmin,latmax,col="Black")#BB lonmin = -160 lonmax = -142 latmin = 58 latmax = 63 #plot_line (m,lonmin,lonmax,latmin,latmax,col="Black")#CC lonmin = -157 lonmax = -140 latmin = 57 latmax = 69
# draw coastlines, country boundaries m.drawcoastlines(linewidth=0.25) m.drawcountries(linewidth=0.25) # draw parallels. parallels = np.arange(-40.,40,10.) m.drawparallels(parallels,labels=[1,0,0,0],fontsize=10) # draw meridians meridians = np.arange(80.,180.,10.) m.drawmeridians(meridians,labels=[0,0,0,1],fontsize=10) # Make grid for TRMM data ny = trmm_precip.shape[0] nx = trmm_precip.shape[1] lons, lats = m.makegrid(nx, ny) # get lat/lons of ny by nx evenly spaced grid. x, y = m(lons, lats) # compute map proj coordinates. # Make grid for SACA data ny_saca = saca_precip.shape[0] nx_saca = saca_precip.shape[1] lons_saca, lats_saca = m.makegrid(nx_saca, ny_saca) x_saca, y_saca = m(lons_saca, lats_saca) # Make grid for TRMM Land Sea mask (updated) lons_mask, lats_mask = np.meshgrid(lons_ls_mask, lats_ls_mask) x_mask, y_mask = m(lons_mask, lats_mask) print 'lons_mask', lons_mask print 'lats_mask', lats_mask print
def plot_mtzwidth(self, name='Megavolume', filter='rff2', conversion='EU60', factor=2., mincoverage=10.): # Plots topography of maximum between mindepth and maxdepth, masking if sum of weights is beneath mincoverage. #depth410660 = open('/raid3/annemijn/scripts/CCP/mincov20MTZ_'+conversion+'_'+filter+'_'+str(int(factor))+'.txt', 'w') plt.figure(figsize=(10, 8)) depths = self.VOL.grid_depth print(depths) l410 = [ x for x in range(len(depths)) if depths[x] > 380 and depths[x] < 430 ] l660 = [ x for x in range(len(depths)) if depths[x] > 630 and depths[x] < 700 ] thickness = np.empty((len(self.VOL.grid_lon), len(self.VOL.grid_lat))) dmap = np.empty((len(self.VOL.grid_lon), len(self.VOL.grid_lat))) coverage = np.empty((len(self.VOL.grid_lon), len(self.VOL.grid_lat))) amparray = [] for i in range(len(self.VOL.grid_lon)): for j in range(len(self.VOL.grid_lat)): RF = self.VOL.volume[i, j, :] / self.VOL.volumeweight[i, j, :] plt.plot(RF) std = 1.96 * np.sqrt(self.VOL.volumesigma[i, j, :] / (self.VOL.volumeweight[i, j, :] * self.VOL.volumeweight[i, j, :])) maxmap410 = np.argmax(RF[l410]) maxmap660 = np.argmax(RF[l660]) if RF[l410[maxmap410]] > std[l410[maxmap410]] and RF[ l660[maxmap660]] > std[l660[maxmap660]]: dmap[i, j] = depths[l660[maxmap660]] - depths[l410[maxmap410]] #depth410660.write(str(self.VOL.grid_lat[j])+'\t') #depth410660.write(str(self.VOL.grid_lon[i])+'\t') #depth410660.write(str(depths[l410[maxmap410]])+'\t') #depth410660.write(str(depths[l660[maxmap660]])+'\t') if self.VOL.volumeweight[i, j, l410[maxmap410]] < mincoverage: dmap[i, j] = 1000. # Prepare map m = Basemap(projection='merc', llcrnrlat=np.min(self.VOL.grid_lat), urcrnrlat=np.max(self.VOL.grid_lat), llcrnrlon=np.min(self.VOL.grid_lon), urcrnrlon=np.max(self.VOL.grid_lon), lat_ts=20, resolution='i') m.drawparallels(np.arange(0, 90, 5.), labels=[1, 0, 0, 1], linewidth=0.5, dashes=[4, 2], labelstyle='+/-', fontsize=20) m.drawmeridians(np.arange(-180, -110, 10.), labels=[1, 0, 0, 1], linewidth=0.5, dashes=[4, 2], labelstyle='+/-', fontsize=20) m.drawcountries() coasts = m.drawcoastlines(zorder=1, color='k', linewidth=1) xx, yy = np.meshgrid(self.VOL.grid_lon, self.VOL.grid_lat) x, y = m(xx, yy) #cs = plt.contourf(x, y, dmap.T, vmin=220.,levels=np.linspace(220., 280., 81.), cmap=cm.RdBu) cs = plt.pcolor(x, y, dmap.T, vmin=220., vmax=280., cmap=cm.RdBu, linewidth=0, rasterized=True) cs.cmap.set_under([0.8, 0.8, 0.8]) cs.cmap.set_over([0.8, 0.8, 0.8]) cb = plt.colorbar() cb.set_label('Transition zone thickness (km)', size=30) cb.set_ticks([220, 235, 250, 265, 280]) cb.ax.tick_params(labelsize=30) cb.solids.set_rasterized(True) xt, yt = m(-13.2, 70.6) m.drawcoastlines(zorder=1, color='k', linewidth=1) dmapall = np.ravel(dmap) lonmin = -158 lonmax = -154 latmin = 57.5 latmax = 60
import re from re import compile as rec from tornado.escape import _unicode, xhtml_escape, url_escape from misaka import HtmlRenderer, Markdown import misaka as m from bnw_web.linkshit import LinkParser, shittypes from bnw_web.linkshit import _URL_RE, _USER_RE, _MSG_RE #: Displaying thumbs allowed for the following hostings: linkhostings = [ (ur'(?i)http://rghost.ru/([0-9]+)', lambda m: 'http://rghost.ru/%s/thumb.png' % (m(1),)), (ur'(?i)http://imgur.com/([A-Za-z0-9]+)', lambda m: 'http://i.imgur.com/%ss.png' % (m(1),)), (ur'http://ompldr.org/v([A-Za-z0-9]+)(/.+)?', lambda m: 'http://ompldr.org/t%s' % (m(1),)), (ur'http://2-ch.ru/([a-z]+)/src/([0-9]+).(png|gif|jpg)', lambda m: 'http://2-ch.ru/%s/thumb/%ss.%s' % (m(1),m(2),m(3))), (ur'https?://(?:www\.)?youtube.com/watch\?(?:.+&)?v\=([A-Z0-9a-z_-]+)(?:&.+)?', lambda m: 'http://img.youtube.com/vi/%s/default.jpg' % (m(1),)), (ur'(?i)http://(.+.(?:png|gif|jpg|jpeg))', lambda m: 'http://f**k.blasux.ru/thumb?img=%s' % (url_escape(m(0)),)), ] linkhostings = [(re.compile('^' + k + '$'), v, k) for (k, v) in linkhostings] def thumbify(text, format='markdown'): """Format text and generate thumbs using available formatters. :param format: default: 'markdown'. Specify text formatter. Variants: 'moinmoin', 'markdown' or None, which fallbacks to markdown. Return: (formatted_text, thumbs)
# draw parallels. parallels = np.arange(-40., 40, 10.) m.drawparallels(parallels, labels=[1, 0, 0, 0], fontsize=10) # draw meridians meridians = np.arange(80., 180., 10.) m.drawmeridians(meridians, labels=[0, 0, 0, 1], fontsize=10) # Make grid for TRMM data # ny = trmm_precip.shape[0] # nx = trmm_precip.shape[1] # lons, lats = m.makegrid(nx, ny) # get lat/lons of ny by nx evenly spaced grid. # x, y = m(lons, lats) # compute map proj coordinates. # Alternative grid lonst, latst = np.meshgrid(lons, lats) x, y = m(lonst, latst) # Make grid for SACA data ny_saca = saca_precip.shape[0] nx_saca = saca_precip.shape[1] lons_saca, lats_saca = m.makegrid(nx_saca, ny_saca) x_saca, y_saca = m(lons_saca, lats_saca) # Make grid for TRMM Land Sea mask (updated) lons_mask, lats_mask = np.meshgrid(lons_ls_mask, lats_ls_mask) x_mask, y_mask = m(lons_mask, lats_mask) print 'lons_mask', lons_mask print 'lats_mask', lats_mask print
"#FCBC00", "#FFAF58", "#FFA28D", "#FF97BA") print 'plt_diff_fc_abs_error' fig, axarr = plt.subplots(1, 2, figsize=(7.87, 3)) for itim, tim in enumerate(timelist): print itim, tim dateobj = datetime.datetime.strptime(tim, '%Y%m%d') ax = axarr[itim] plt.sca(ax) m = Basemap(projection='cyl', llcrnrlon=-40, \ urcrnrlon=30.,llcrnrlat=25,urcrnrlat=80, \ resolution='i', area_thresh=10000.) m.drawcoastlines(False) m.drawcountries() m.drawcoastlines(linewidth=0.5) x, y = m(lon, lat) mylevels = np.arange(520, 590, 5) # cs0 = m.contourf(x,y,((datadict_od_geopot_500[itim][timelist[itim]]/9.80665)/10.)-((datadict_od_geopot_1000[itim][timelist[itim]]/9.80665)/10.), # shading='flat',latlon=True, levels=mylevels, # cmap=plt.cm.gist_rainbow_r, extend = 'both', # alpha=0.8) # cs1 = m.contour(x,y,(datadict_od_geopot_500[itim][timelist[itim]]/9.80665)/10., # latlon = True, levels = np.arange(520,581,5), # colors='k', linewidths=2, # zorder=3) cs1 = m.contourf( x, y, (datadict_od_geopot_500[itim][timelist[itim]] / 9.80665) / 10., latlon=True, levels=np.arange(520, 601, 5), colors=colors,
def plot_mtzwidth(self, name='Megavolume', filter='rff2', conversion='prem', factor=2., Max_Thickness=290, Min_Thickness=230): plt.figure(figsize=(18, 8)) depths = self.VOL.grid_depth l410 = [ x for x in range(len(depths)) if depths[x] > 370 and depths[x] < 460 ] # limit between 370 and 460 l660 = [ x for x in range(len(depths)) if depths[x] > 630 and depths[x] < 710 ] # limit between 630 and 710 thickness1D = np.empty( (len(self.VOL.grid_lon), len(self.VOL.grid_lat) )) # create grids the size of the box to plot the data into d4101D = np.empty((len(self.VOL.grid_lon), len(self.VOL.grid_lat))) d6601D = np.empty((len(self.VOL.grid_lon), len(self.VOL.grid_lat))) with open( root + 'CCP_Stack/MTZ_' + conversion + '_' + filter + '_' + str(int(factor)) + '.txt', 'w') as output: for i in range(len(self.VOL.grid_lon)): for j in range(len(self.VOL.grid_lat)): RF = self.VOL.volume[i, j, :] / self.VOL.volumeweight[i, j, :] std = 1.96 * np.sqrt(self.VOL.volumesigma[i, j, :] / (self.VOL.volumeweight[i, j, :] * self.VOL.volumeweight[i, j, :])) max410 = np.argmax(RF[l410]) max660 = np.argmax(RF[l660]) # If both picks are significant, store thickness if RF[l410[max410]] > std[l410[max410]] and RF[ l660[max660]] > std[l660[max660]]: d4101D[i, j] = depths[l410[max410]] d6601D[i, j] = depths[l660[max660]] thickness1D[i, j] = (depths[l660[max660]] - depths[l410[max410]]) output.write( str(depths[l410[max410]]) + '\t' + str(depths[l660[max660]]) + '\n') output.close() # Prepare map m = Basemap(projection='merc', llcrnrlat=np.min(self.VOL.grid_lat), urcrnrlat=np.max(self.VOL.grid_lat), llcrnrlon=np.min(self.VOL.grid_lon), urcrnrlon=np.max(self.VOL.grid_lon), lat_ts=20, resolution='i') m.drawparallels(np.arange(np.min(self.VOL.grid_lat), np.max(self.VOL.grid_lat), 5.), labels=[1, 0, 0, 1]) m.drawmeridians(np.arange(np.min(self.VOL.grid_lon), np.max(self.VOL.grid_lon), 5.), labels=[1, 0, 0, 1]) m.drawcoastlines(color='k') m.drawcountries(color='k') m.drawstates() m.drawmapboundary(fill_color=[1.0, 1.0, 1.0]) xx, yy = np.meshgrid(self.VOL.grid_lon, self.VOL.grid_lat) x, y = m(xx, yy) cs = plt.contourf(x, y, thickness1D.T, levels=np.linspace(Min_Thickness, Max_Thickness, 81.), cmap=cm.RdYlBu) cs.cmap.set_under('w') #Max_Thickness = 290, Min_Thickness=230 cs.cmap.set_over('w') plt.colorbar() plt.title('MTZ width')
parallels = np.arange(-40.,40,10.) m.drawparallels(parallels,labels=[1,0,0,0],fontsize=10) # draw meridians meridians = np.arange(80.,180.,10.) m.drawmeridians(meridians,labels=[0,0,0,1],fontsize=10) # Make grid for TRMM data # ny = trmm_precip.shape[0] # nx = trmm_precip.shape[1] # lons, lats = m.makegrid(nx, ny) # get lat/lons of ny by nx evenly spaced grid. # x, y = m(lons, lats) # compute map proj coordinates. # Alternative grid lonst, latst = np.meshgrid(lons, lats) x, y = m(lonst, latst) # Make grid for SACA data ny_saca = saca_precip.shape[0] nx_saca = saca_precip.shape[1] lons_saca, lats_saca = m.makegrid(nx_saca, ny_saca) x_saca, y_saca = m(lons_saca, lats_saca) # Make grid for TRMM Land Sea mask (updated) lons_mask, lats_mask = np.meshgrid(lons_ls_mask, lats_ls_mask) x_mask, y_mask = m(lons_mask, lats_mask) print 'lons_mask', lons_mask print 'lats_mask', lats_mask
print temp m = Basemap(width=width,height=width,resolution='h',projection='aeqd', lat_0=lat_0,lon_0=lon_0) m.bluemarble(ax=None, scale=None) m.warpimage(image='bluemarble', scale=None) #m.arcgisimage(server='http://server.arcgisonline.com/ArcGIS', service='ESRI_Imagery_World_2D', xpixels=400, ypixels=None, dpi=96, verbose=False) # fill background. m.drawmapboundary(fill_color='aqua') # draw coasts and fill continents. m.drawcoastlines(linewidth=0.5) #m.fillcontinents(color='coral',lake_color='aqua') # 20 degree graticule. m.drawparallels(np.arange(-80,81,20)) m.drawmeridians(np.arange(-180,180,20)) # draw a black dot at the center. xpt, ypt = m(lon_0, lat_0) m.plot([xpt],[ypt],'ko') # draw the title. plt.title('Azimuthal Equidistant Projection') plt.show() # for x in range(len(fakeDataLat)): # plotGPSMap(fakeDataLong[x],fakeDataLat[x],canvas) #canvas.update()
# draw coastlines, country boundaries m.drawcoastlines(linewidth=0.25) m.drawcountries(linewidth=0.25) # draw parallels. parallels = np.arange(-40.,40,10.) m.drawparallels(parallels,labels=[1,0,0,0],fontsize=10) # draw meridians meridians = np.arange(80.,180.,10.) m.drawmeridians(meridians,labels=[0,0,0,1],fontsize=10) # Make grid for TRMM data ny = trmm_precip.shape[0]; nx = trmm_precip.shape[1] lons, lats = m.makegrid(nx, ny) # get lat/lons of ny by nx evenly spaced grid. x, y = m(lons, lats) # compute map proj coordinates. # Make grid for SACA data ny_saca = saca_precip.shape[0]; nx_saca = saca_precip.shape[1] lons_saca, lats_saca = m.makegrid(nx_saca, ny_saca) # get lat/lons of ny by nx evenly space grid. x_saca, y_saca = m(lons_saca, lats_saca) # compute map proj coordinates. # Actual plotting and rendering # ================================================================ # Plot TRMM # =============== # cs = m.contourf(x,y,trmm_precip*trmm_lsmask,clevs,cmap=cm.s3pcpn) # # Add colorbar