def __init__(self, fig, traj, **kw): self.__dict__.update(kw) if not fig.axes: ax_map = fig.add_subplot(1, 2, 1) ax_ts = fig.add_subplot(2, 2, 2) ax_ts2 = fig.add_subplot(2, 2, 4) else: # assume that ax_map, ax_ts, and/or ax_ts2 were passed in ax_map = self.ax_map ax_ts = self.ax_ts ax_ts2 = self.ax_ts2 if ax_map: pos = ax_map.get_position() plot_wkb.plot_polygon(grid_poly, ax=ax_map, fc='0.8', ec='0.6', lw=0.5, zorder=-2) ax_map.axis('equal') ax_map.axis((606812, 633363, 4222818, 4256651)) ax_map.xaxis.set_visible(0) ax_map.yaxis.set_visible(0) ax_map.plot(traj['traj']['x'], traj['traj']['y'], 'k-', lw=0.5) sel = np.zeros(len(traj['Tfill']), np.bool8) sel[:] = True # thinned out obs = traj['fill_dist'] == 0 sel[obs] = True sizes = 5 * np.ones_like(sel) sizes[obs] = 60 scat = ax_map.scatter(traj['traj']['x'][sel], traj['traj']['y'][sel], sizes[sel], traj['Tfill'][sel], cmap=self.cmap) scat.set_clim(self.clim) if ax_ts: ax_ts.plot(traj['traj']['t'], traj['Tfill'], label='Tfill') ax_ts.set_ylabel('Lagrangian temp $^{\circ}$C') if ax_ts2: ax_ts2.plot(traj['traj']['t'], np.abs(traj['fill_dist']) / 3600., label='fill_dist') ax_ts2.set_ylabel('Hours from observation') if ax_ts: ax_ts2.set_xlim(ax_ts.get_xlim()) fig.autofmt_xdate() if ax_map: cax = fig.add_axes([pos.xmin, pos.ymin - 0.08, pos.width, 0.03]) plt.colorbar(scat, cax=cax, orientation='horizontal', label='$^{\circ}$C')
def __init__(self, fig, t, **kw): self.__dict__.update(kw) snap_data = extract_particle_snapshot(t) if self.ax is None: fig.clf() ax = fig.add_subplot(1, 1, 1) ax.set_position([0, 0, 1, 1]) else: ax = self.ax plot_wkb.plot_polygon(grid_poly, ax=ax, fc='0.8', ec='none', lw=0.5, zorder=-2) plot_wkb.plot_polygon(grid_poly, ax=ax, fc='none', ec='k', lw=0.5, zorder=2) station_xys = np.array([station.xy.values for station in stations]) ax.plot(station_xys[:, 0], station_xys[:, 1], 'ko', ms=5) values = self.snap_to_value(snap_data) sel = np.isfinite(values) stale_s = np.abs(snap_data['fill_dist']) sel = sel & (stale_s < self.stale_thresh_s) scat = ax.scatter(snap_data['x'][sel], snap_data['y'][sel], 40 * (1 / (1 + stale_s[sel] / 1800.)), values[sel]) scat.set_cmap(self.cmap) scat.set_clim(self.clim) pos = ax.get_position() cax = fig.add_axes([ pos.xmin + 0.08, pos.ymin + 0.93 * pos.height, pos.width * 0.25, 0.02 ]) ax.text(0.08, 0.96, utils.to_datetime(t).strftime("%Y-%m-%d %H:%M PST"), transform=ax.transAxes) plt.colorbar(scat, cax=cax, orientation='horizontal', label=self.units_label) ax.xaxis.set_visible(0) ax.yaxis.set_visible(0) ax.axis('equal') ax.axis(self.zoom)
valid1=np.isfinite(per_cell_K) & (per_cell_K>=0) coll1=g.plot_cells(values=per_cell_K.clip(1,np.inf), norm=colors.LogNorm(), mask=valid1,ax=ax1) valid2=np.isfinite(smooth_K)&(smooth_K>=0) coll2=g.plot_cells(values=smooth_K.clip(1,np.inf), norm=colors.LogNorm(), mask=valid2,ax=ax2) for coll in [coll1,coll2]: coll.set_clim([3,300]) coll.set_cmap('inferno_r') for coll,ax in zip([coll1,coll2],[ax1,ax2]): plot_wkb.plot_polygon(grid_poly,ax=ax,fc='none',ec='k',lw=0.5) plt.colorbar(coll, label="log10 K",ax=ax) ax.axis('equal') ax.axis(zoom) ax.xaxis.set_visible(0) ax.yaxis.set_visible(0) ax1.set_title('Output') ax2.set_title('Smoothed') fig.tight_layout() fig.savefig('third-cutb-dispersion.png',dpi=200) ## ax.plot(particles[0,:,0],
xyz_aug = field.XYZField(X=cdt.nodes['x'], F=cdt.nodes['value']) aug_tri = delaunay.Triangulation(xyz_aug.X[:, 0], xyz_aug.X[:, 1], cdt.cells['nodes'][~cdt.cells['deleted']]) xyz_aug._tri = aug_tri dem2 = xyz_aug.to_grid(dx=5, dy=10, interp='linear') ## plt.figure(20).clf() #fig,ax=plt.subplots(1,1,num=20,sharex=True,sharey=True) fig, (ax, ax2) = plt.subplots(1, 2, num=20, sharex=True, sharey=True) plot_wkb.plot_polygon(poly, ax=ax, fc='none') ax.scatter(xyz_sub.X[:, 0], xyz_sub.X[:, 1], 30, xyz_sub.F, lw=1, edgecolor='m') dem1.plot(ax=ax, interpolation='none', zorder=-2) # cdt.plot_edges(ax=ax,edgecolor='k') # Worse: dem2.plot(ax=ax2, interpolation='none', zorder=-2) plot_wkb.plot_polygon(poly, ax=ax2, fc='none')
g_sfb = dfm_grid.DFMGrid('../../sfb_dfm_v2/sfei_v20_net.nc') ## g_roms_poly = g_roms.boundary_polygon() g_sfb_poly = g_sfb.boundary_polygon() ## plt.figure(1).clf() fig, ax = plt.subplots(num=1) g_roms.plot_edges(ax=ax, color='b', lw=0.8) g_sfb.plot_edges(ax=ax, color='g', lw=0.8) plot_wkb.plot_polygon(g_roms_poly, facecolor='b', alpha=0.3) plot_wkb.plot_polygon(g_sfb_poly, facecolor='g', alpha=0.3) ## # Clear out a buffer region sfb_dx_min = 200 roms_dx_typ = 3500 # cheating a bit - ought to be more like 10xn buff_size = (roms_dx_typ - sfb_dx_min) * 6 sfb_buff = g_sfb_poly.buffer(buff_size) ## overlap_cells = g_roms.select_cells_intersecting(sfb_buff)
poly = g.boundary_polygon() ## # zoom=(605889.6569457075, 638002.2586920519, 4217801.158715993, 4241730.226468915) zoom = (597913.7274775933, 648118.8262812896, 4217179.54644355, 4301202.344200377) # zoom=(611280.377359663, 632614.9072567355, 4222938.787804629, 4248182.140275016) plt.figure(1).clf() fig, ax = plt.subplots(num=1) init.plot(ntimes - 1, ax=ax, zoom=zoom, update=False, ms=1) sac.plot(ntimes - 1, ax=ax, zoom=zoom, update=False, color='cyan', ms=1) srv.plot(ntimes - 1, ax=ax, zoom=zoom, update=False, color='g', ms=1) # g.plot_edges(color='k',lw=0.4,ax=ax,clip=zoom) plot_wkb.plot_polygon(poly, ax=ax, fc='0.8', ec='k', lw=0.5) ax.axis(zoom) ## for ti in range(0, ntimes, 2): init.plot(ti, ax=ax, zoom=zoom) sac.plot(ti, ax=ax, zoom=zoom) srv.plot(ti, ax=ax, zoom=zoom) plt.draw() plt.pause(0.001) ##
ax2.yaxis.set_visible(0) ax1.text(0.05, 0.95, 'IM1', transform=ax1.transAxes) ax2.text(0.05, 0.95, 'IM2', transform=ax2.transAxes) ccolls = [] plot_vars = ['IM1', 'IM2'] for v, ax, cax in zip(plot_vars, [ax1, ax2], [cax1, cax2]): ssc = map_ds[v].isel(time=-1, layer=0).values ssc = np.ma.array( ssc, mask=(ssc == -999)) # map_ds[v].isel(time=-1,layer=0).values.copy() ax.set_facecolor('0.6') plot_wkb.plot_polygon(boundary, facecolor='0.8', edgecolor='none', ax=ax, lw=0.25, zorder=-1) ccoll = g.plot_cells(lw=0.5, values=ssc, ax=ax, cmap='CMRmap_r') ccoll.set_clim([0, 50]) ccoll.set_edgecolor('face') ccolls.append(ccoll) plt.colorbar(ccoll, cax=cax) ax.axis('equal') ## for frame, ti in enumerate(range(0, 800, 2)): print "[%04d] %d/%d" % (frame, ti, len(map_ds.time)) for v, ccoll in zip(plot_vars, ccolls): ssc = map_ds[v].isel(time=ti, layer=0).values