def post_frame(self,t,data2d,data3d): if self.plot_mode is None: return import matplotlib.pyplot as plt import stompy.plot.cmap as scmap if self.fig is None: self.fig=plt.figure() ax=self.fig.add_subplot(1,1,1) # min/max over entire period #vmin=self.data['value'].min() #vmax=self.data['value'].max() # min/max for this moment vmin=data2d.min() vmax=data2d.max() cmap=scmap.load_gradient('turbo.cpt') self.coll=self.grid.plot_cells(values=data2d,clim=[vmin,vmax], lw=0.5, cmap=cmap,ax=ax) self.coll.set_edgecolor('face') ax.axis('equal') plt.colorbar(self.coll,ax=ax) self.txt=ax.text(0.05,0.05,"text",transform=ax.transAxes) else: self.coll.set_array(data2d) self.txt.set_text( str(t) ) if self.plot_mode=='each': self.fig.canvas.draw() plt.pause(0.01) elif self.plot_mode=='save': time_str=utils.to_datetime(t).strftime('%Y%m%dT%H%M') self.fig.savefig('extrap-%s.png'%time_str)
# Load in Lidar and pre-compiled DEMs, particularly in N Marsh # import os, shutil import pandas as pd from stompy.spatial import field, wkb2shp import six import matplotlib.pyplot as plt import numpy as np import stompy.plot.cmap as scmap from stompy.plot import plot_wkb from stompy import utils from stompy.spatial import interp_orthogonal six.moves.reload_module(interp_orthogonal) turbo = scmap.load_gradient('turbo.cpt') turbo_gray = scmap.load_gradient('turbo.cpt') turbo_gray.set_over("0.8") sst = scmap.load_gradient('oc-sst.cpt') ## fig_dir = "figs-20201211" if not os.path.exists(fig_dir): os.makedirs(fig_dir) ## version = "existing" # "asbuilt" date_str = "20201230"
scat = ax.scatter(xyz_samples[:, 0], xyz_samples[:, 1], 15, xyz_samples[:, 2], cmap='jet') plot_utils.cbar(scat, label='m NAVD88', ax=ax, orientation='horizontal') img = dem.plot(ax=ax, interpolation='nearest', cmap='jet') crange = [-6, 2.25] scat.set_clim(crange) img.set_clim(crange) div_cmap = scmap.load_gradient('ViBlGrWhYeOrRe.cpt') # And show the difference: scat = ax2.scatter(xyz_samples[:, 0], xyz_samples[:, 1], 15, delta, cmap='seismic') plot_utils.cbar(scat, label='ADCP - DEM (m)', ax=ax2, orientation='horizontal') img = dem.plot(ax=ax2, interpolation='nearest', cmap='gray') scat.set_clim([-1, 1]) img.set_clim([-10, 5]) for a in [ax, ax2]:
- north_channel_and_ditch-1m.tif - lagoon-1m.tif """ from stompy.grid import unstructured_grid import stompy.grid.quad_laplacian as quads from stompy.spatial import wkb2shp import matplotlib.pyplot as plt import stompy.plot.cmap as scmap from stompy.spatial import field from stompy import utils import numpy as np import six import os turbo = scmap.load_gradient('turbo.cpt') ## fig_dir = "figs-20201230" os.path.exists(fig_dir) or os.makedirs(fig_dir) ## all_points = wkb2shp.shp2geom('../data/cbec/cbec-survey/All_Points.shp', target_srs='EPSG:26910') xyz = np.array([np.array(p) for p in all_points['geom']]) xyz[:, 2] = all_points['Z_m'] ## gen = unstructured_grid.UnstructuredGrid.read_pickle(
def test_load_gradient(): assert cmap.load_gradient('hot_desaturated.cpt') is not None
centr=g_complete.cells_centroid() g_complete.cells['depth'][sel_cells]=dem(centr[sel_cells]) sel_edges=np.nonzero(np.isnan(g_complete.edges['edge_depth']))[0] e2c=g_complete.edge_to_cells() nc1=e2c[sel_edges,0].copy() nc2=e2c[sel_edges,1].copy() nc1[nc1<0]=nc2[nc1<0] nc2[nc2<0]=nc1[nc2<0] cell_depth=g_complete.cells['depth'] g_complete.edges['edge_depth'][sel_edges] = np.maximum( cell_depth[nc1], cell_depth[nc2] ) ## import stompy.plot.cmap as scmap cmap=scmap.load_gradient('hot_desaturated.cpt') plt.figure(1).clf() g_complete.plot_cells(values=g_complete.cells['depth'],clim=[-4000,10],cmap=cmap) g_complete.plot_edges(values=g_complete.edges['edge_depth'],clim=[-4000,10],cmap=cmap) plt.setp(plt.gca().collections,clim=[-100,10]) ## g_complete.write_ugrid('spliced_grids_01_bathy.nc',overwrite=True)
import numpy as np import pandas as pd import stompy.model.delft.waq_scenario as dwaq from stompy.memoize import memoize import logging as log from stompy import utils from stompy import filters from stompy.plot import plot_wkb import netCDF4 import warnings from stompy.model.data_comparison import calc_metrics import os import six from matplotlib import gridspec cmap = scmap.load_gradient('turbo.cpt') # a less offensive 'jet' def hydro_name(hydro): """ Convenience method -- get a representative name for a hydro object to use in naming runs. Attempts hydro.name, falls back on base dir if a HydroFiles object. """ try: return hydro.name except AttributeError: pass if isinstance(hydro, dwaq.HydroFiles): return os.path.basename(os.path.dirname(hydro.hyd_path)) raise Exception("Can't figure out good name for %s" % hydro)
""" Calculate several distance along axis metrics for the CSC grid and compare. """ import six import numpy as np import matplotlib.pyplot as plt from stompy.grid import unstructured_grid from stompy import utils from sklearn.linear_model import LinearRegression import stompy.plot.cmap as scmap from stompy.plot import plot_utils cmap=scmap.load_gradient('ncview_banded.cpt') ## grid_file="~/src/csc/dflowfm/CacheSloughComplex_v111-edit19fix-bathy.nc" six.moves.reload_module(unstructured_grid) g=unstructured_grid.UnstructuredGrid.read_ugrid(grid_file) ds=g.write_to_xarray() ## # Define a downstream d=0 x_down=np.array([610016, 4215971.]) ## from stompy.model import unstructured_diffuser
import matplotlib.pyplot as plt import prepare_pings from stompy.spatial import field import stompy.plot.cmap as scmap from stompy.plot import plot_utils import six ## dem = field.GdalGrid("../../bathy/junction-composite-20200604-w_smooth.tif") ## six.moves.reload_module(prepare_pings) years = [2018, 2019, 2020] plt.figure(1).clf() fig, axs = plt.subplots(1, len(years), figsize=(6.5, 3.75), num=1) terrain = scmap.load_gradient('BlueYellowRed.cpt') for ax, year in zip(axs, years): rx_locs = prepare_pings.rx_locations(year=year) ax.plot(rx_locs.x, rx_locs.y, 'go') img = dem.plot(ax=ax, cmap=terrain, vmin=-9, vmax=10) plt.setp(ax.get_xticklabels(), visible=0) plt.setp(ax.get_yticklabels(), visible=0) #plot_utils.scalebar(ax=ax,
from stompy.grid import unstructured_grid import matplotlib.pyplot as plt from matplotlib import colors from matplotlib.transforms import Bbox import stompy.plot.cmap as scmap from stompy.plot import plot_utils ## sfb_ocean = "." grid_ocean = unstructured_grid.UnstructuredGrid.from_ugrid( os.path.join(sfb_ocean, "grid-merge-suisun", "spliced-bathy.nc")) ## cmap = scmap.load_gradient('oc-sst.cpt', reverse=True) fig = plt.figure(1) fig.clf() fig.set_size_inches((7, 9), forward=True) ax = fig.add_axes([0, 0, 1, 1]) ax.xaxis.set_visible(0) ax.yaxis.set_visible(0) grid_ocean.plot_edges(ax=ax, lw=0.5, color='k', alpha=0.2) ccoll = grid_ocean.plot_cells(ax=ax, values=(-grid_ocean.cells['z_bed']).clip( 1, np.inf), norm=colors.LogNorm(), cmap=cmap) cax = fig.add_axes([0.07, 0.15, 0.03, 0.35])
salt = np.zeros(G.Ncells(), 'f8') for proc in procs: # steps 3 and 4 should be clear of the 3h ramp up. one_salt = all_ds[proc].sa1.isel(time=time, laydim=9).values salt[global_to_G[all_ds[proc].FlowElemGlobalNr.values]] = one_salt ## plt.figure(1).clf() fig, ax = plt.subplots(num=1) coll = G.plot_cells(ax=ax, lw=0.5, values=salt) coll.set_clim([10, 36]) coll.set_cmap(scmap.load_gradient('hot_desaturated.cpt')) plt.setp(coll, edgecolor='face') plt.colorbar(coll) ax.xaxis.set_visible(0) ax.yaxis.set_visible(0) fig.tight_layout() ## def update_salt(tidx): salt = np.zeros(G.Ncells(), 'f8') for proc in procs: # steps 3 and 4 should be clear of the 3h ramp up.
from stompy.spatial import field import six import numpy as np import glob import numpy as np import skimage.graph from scipy import ndimage from stompy import memoize, utils import matplotlib.pyplot as plt import stompy.plot.cmap as scmap turbo = scmap.load_gradient('turbo.cpt') import subprocess ## # 9k x 10k dem = field.GdalGrid('../bathy/DEM_VegCorr_DWR_2m_NAVD88.tif') ## from stompy.spatial import wkb2shp six.moves.reload_module(wkb2shp) gdb_fn = "../bathy/levees/ESRI ArcGIS/SFBayShoreInventory__SFEI_2016.gdb" levees = wkb2shp.shp2geom(gdb_fn, layer_patt='.*with_elevation', target_srs='EPSG:26910') # 'San_Francisco_Bay_Shore_Inventory__100ft_segments_with_elevation' ##
ax=ax, zorder=-.5) cax = fig.add_axes([0.08, 0.2, 0.3, 0.03]) return fig, ax, cax ## fig, ax, cax = setup_figure(1) Gvar = np.zeros(G.Ncells(), 'f8') coll = G.plot_cells(values=Gvar, clip=zoom, ax=ax) cmap = scmap.load_gradient('StepSeq25.cpt') plt.setp(coll, lw=1, edgecolor='face', clim=[0, 33], cmap=cmap) date_txt = ax.text(0.08, 0.27, "1111-22-33 44:55", transform=ax.transAxes) cell_mask = G.cell_clip_mask(zoom) def set_time(t_idx): Gvar[:] = merge( lambda ds: ds['sa1'].isel(time=t_idx).isel(laydim=0).values) depth = merge(lambda ds: ds['waterdepth'].isel(time=t_idx).values) coll.set_array(np.ma.array(Gvar[cell_mask], mask=depth[cell_mask] < 0.05)) t = dss[0].time.values[t_idx] date_txt.set_text(utils.to_datetime(t).strftime('%Y-%m-%d %H:%M'))