示例#1
0
import glob, os
from stompy.model.fish_ptm import ptm_tools

##
run_dir = 'all_source_select_w_const'

bin_files = glob.glob(os.path.join(run_dir, '*_bin.out'))

bin_files.sort()
##

bins = [ptm_tools.PtmBin(bf) for bf in bin_files]

##

for bf, b in zip(bin_files, bins):
    end_count = len(b.read_timestep(-1)[1])
    print(f"{os.path.basename(bf):30s}: {end_count}")
示例#2
0
##
cache_dir="cache"
os.path.exists(cache_dir) or os.mkdir(cache_dir)

##
g=unstructured_grid.UnstructuredGrid.from_ugrid('../../../dflowfm/runs/20180807_grid98_17/ptm_hydro.nc')
grid_poly=g.boundary_polygon()

ll2utm=proj_utils.mapper('WGS84','EPSG:26910')

##

ptm_run_dir="../run_10days"
ptm_groups=["INIT","SAC","SRV"]

ptm_data=[ ptm_tools.PtmBin(os.path.join(ptm_run_dir,grp+"_bin.out"))
           for grp in ptm_groups ]

ntimes=ptm_data[0].count_timesteps()

run_start=ptm_data[0].read_timestep(0)[0]
run_stop =ptm_data[0].read_timestep(ntimes-1)[0]

##
# Define the stations time series

# USGS stations:
usgs_station_codes=dict(
    fpt=11447650,
    sdc=11447890,
    ges=11447905,
示例#3
0
import numpy as np
import pandas as pd

from scipy.optimize import Bounds, minimize

##

hydro_dir = "../hydro/channel"
ptm_dir = "../ptm/uniform_channel"
ptm_bin = os.path.join(ptm_dir, "uniform_bin.out")

##

model = sun_driver.SuntansModel.load(hydro_dir)

pb = ptm_tools.PtmBin(ptm_bin)

##

ptm_bin_dt = pb.dt_seconds()  # 900
hydro_period = 12 * 3600  # 12 hour repeating tide

step0 = 0
stepN = step0 + int(hydro_period / ptm_bin_dt)
d0, parts0 = pb.read_timestep(0)
d, parts = pb.read_timestep(10)

# Get labels from an earlier timestep
labels = np.nan * np.zeros(parts0['id'].max() + 1, np.float64)
labels[parts0['id']] = parts0['x'][:, 0]  # label by original x coordinate
示例#4
0
 def open_binfile(self, group):
     return ptm_tools.PtmBin(os.path.join(self.run_dir, group + '_bin.out'))
示例#5
0
##

ds_map = xr.open_dataset(
    '../../dflowfm/runs/20180807_grid98_16_single/DFM_OUTPUT_flowfm/flowfm_map.nc'
)


def particle_water_depth(x, time):
    tidx = np.searchsorted(ds_map.time, time)
    cell_depths = ds_map.mesh2d_waterdepth.isel(time=tidx).values
    x_cells = [g.select_cells_nearest(xi) for xi in x]
    return cell_depths[x_cells]


##
dist_bspp = ptm_tools.PtmBin('nobspp/DIST_bin.out')
dist_nobspp = ptm_tools.PtmBin('bspp/DIST_bin.out')

##
ntimes = min(dist_bspp.count_timesteps(), dist_nobspp.count_timesteps())

##
zoom_lindsey = (603641.9059474986, 610614.5678962235, 4233101.860312233,
                4237901.354960644)
zoom = zoom_lindsey

plt.figure(1).clf()
fig, ax = plt.subplots(num=1)

g.plot_edges(color='k', lw=0.4, ax=ax, clip=zoom)
示例#6
0
from stompy.grid import unstructured_grid
from stompy.model.fish_ptm import ptm_tools

##

g = unstructured_grid.UnstructuredGrid.from_ugrid(
    '../../dflowfm/runs/20180807_grid98_16_single/ptm_hydro.nc')

##

bspp = ptm_tools.PtmBin('bspp/DIST_bin.out')
bspp_dupe = ptm_tools.PtmBin('bspp/DIST_bin.out')

ntimes = ges.count_timesteps()

##

##

for ti in range(0, ntimes, 2):
    bspp.plot(ti, ax=ax, zoom=zoom)
    plt.draw()
    plt.pause(0.001)

##
bspp_intake = np.array([(605206, 4237111.), (605246, 4237130.),
                        (605238, 4237147.), (605195, 4237129.)])

t_a, parts = bspp.read_timestep(ts=ntimes)

final_cells = [g.select_cells_nearest(x) for x in parts['x'][:, :2]]
示例#7
0
import numpy as np
import xarray as xr
from stompy import utils
from stompy.model.suntans import sun_driver
from stompy.model.fish_ptm import ptm_tools

##

# hydro model
hydro=sun_driver.SuntansModel.load("/opt2/sfb_ocean/suntans/runs/merge_009-20171201/suntans.dat")

## 

# PTM output for a single source, and w:
# Try out SacRiver, rising 2mm/s
pb=ptm_tools.PtmBin("all_sources/all_source_select_w/SacRiver_up2000_bin.out")

##

nsteps=pb.count_timesteps()

ptm_start,_=pb.read_timestep(0)
ptm_end,_  =pb.read_timestep(nsteps-2)

print(f"Range of PTM output: {ptm_start} -- {ptm_end}")

##

# First, weight the particles by the adjusted inflow and concentration in
# that inflow.
示例#8
0
from stompy.grid import unstructured_grid
from stompy.model.fish_ptm import ptm_tools

##

g = unstructured_grid.UnstructuredGrid.from_ugrid('dfm_ptm_hydro.nc')

##
ges = ptm_tools.PtmBin('GES_bin.out')
ntimes = ges.count_timesteps()
##
# zoom=(629582, 629832, 4233134, 4233560)
# zoom=(629375.7037314154, 630090.3968338037, 4232811.347364194, 4234029.184410663)
# zoom=(628897.95707908, 630568.1434861392, 4232811.347364194, 4234029.184410663)
# zoom= (620820.082274368, 633427.7560025024, 4225915.179544365, 4235108.220555253)
zoom = (629674.547743109, 629827.6731611794, 4233121.869190959,
        4233235.97232507)

plt.figure(1).clf()
fig, ax = plt.subplots(num=1)

ges.plot(ntimes - 1, ax=ax, zoom=zoom, update=False)

g.plot_edges(color='k', lw=0.4, ax=ax, clip=zoom)

ax.axis(zoom)

##

for ti in range(0, 2000, 2):
    ges.plot(ti, ax=ax, zoom=zoom)
示例#9
0
"""
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt

from stompy.grid import unstructured_grid
from stompy.model.fish_ptm import ptm_tools

##

hyd = xr.open_dataset('../../dflowfm/runs/20180807_grid98_17/ptm_hydro.nc')
g = unstructured_grid.UnstructuredGrid.from_ugrid(hyd)

##
run_dir = "run_debug_stuck"
init = ptm_tools.PtmBin(run_dir + '/INIT_bin.out')
sac = ptm_tools.PtmBin(run_dir + '/SAC_bin.out')
srv = ptm_tools.PtmBin(run_dir + '/SRV_bin.out')
ntimes = init.count_timesteps()
##

# 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)
# zoom=(626037.7515578158, 626228.6109768279, 4232804.050163795, 4233029.878040465)
zoom = (626114.3567959621, 626237.6438243476, 4232894.817537309,
        4233010.536791836)

plt.figure(1).clf()
fig, ax = plt.subplots(num=1)
示例#10
0
from stompy.grid import unstructured_grid
from stompy.model.fish_ptm import ptm_tools
from stompy.plot import plot_wkb

##

g = unstructured_grid.UnstructuredGrid.from_ugrid(
    '../../dflowfm/runs/20180807_grid98_17/ptm_hydro.nc')

##
init = ptm_tools.PtmBin('run_10days/INIT_bin.out')
sac = ptm_tools.PtmBin('run_10days/SAC_bin.out')
srv = ptm_tools.PtmBin('run_10days/SRV_bin.out')
ntimes = init.count_timesteps()
##

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)
示例#11
0
# Go back to 36 second output to see more clearly how particles
# get stuck.
from stompy.grid import unstructured_grid
from stompy.model.fish_ptm import ptm_tools

##

hyd = xr.open_dataset(
    '../../dflowfm/runs/20180807_grid98_16_single/ptm_hydro.nc')
g = unstructured_grid.UnstructuredGrid.from_ugrid(hyd)

##
init = ptm_tools.PtmBin('../scenario_divergence/DIST_bin.out')

ntimes = init.count_timesteps()
##

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)
# zoom=(626037.7515578158, 626228.6109768279, 4232804.050163795, 4233029.878040465)

plt.figure(1).clf()
fig, ax = plt.subplots(num=1)

ti = 5000

# Just plot stuck particles
tA, pA = init.read_timestep(ti)
tB, pB = init.read_timestep(ti + 1)
示例#12
0
"""
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt

from stompy.grid import unstructured_grid
from stompy.model.fish_ptm import ptm_tools

##

hyd = xr.open_dataset('../../dflowfm/runs/20180807_grid98_17/ptm_hydro.nc')
g = unstructured_grid.UnstructuredGrid.from_ugrid(hyd)

##
run_dir = "run_debug_stuck"
init = ptm_tools.PtmBin(run_dir + '/TEST_bin.out')
ntimes = init.count_timesteps()
##

# 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)
# zoom=(626037.7515578158, 626228.6109768279, 4232804.050163795, 4233029.878040465)
zoom = (626114.3567959621, 626237.6438243476, 4232894.817537309,
        4233010.536791836)

plt.figure(1).clf()
fig, ax = plt.subplots(num=1)

ti = 20
示例#13
0
from stompy.grid import unstructured_grid
from stompy.model.fish_ptm import ptm_tools

##

g = unstructured_grid.UnstructuredGrid.from_ugrid(
    '../../dflowfm/runs/20180807_grid98_16_single/ptm_hydro.nc')

##
ges = ptm_tools.PtmBin('bspp/DIST_bin.out')
ntimes = ges.count_timesteps()
##
# zoom=(629582, 629832, 4233134, 4233560)
# zoom=(629375.7037314154, 630090.3968338037, 4232811.347364194, 4234029.184410663)
# zoom=(628897.95707908, 630568.1434861392, 4232811.347364194, 4234029.184410663)
# zoom= (620820.082274368, 633427.7560025024, 4225915.179544365, 4235108.220555253)
# zoom=(629674.547743109, 629827.6731611794, 4233121.869190959, 4233235.97232507)
# zoom=(605889.6569457075, 638002.2586920519, 4217801.158715993, 4241730.226468915)
zoom_lindsey = (603641.9059474986, 610614.5678962235, 4233101.860312233,
                4237901.354960644)
zoom = zoom_lindsey

plt.figure(1).clf()
fig, ax = plt.subplots(num=1)

ges.plot(ntimes - 1, ax=ax, zoom=zoom, update=False)

g.plot_edges(color='k', lw=0.4, ax=ax, clip=zoom)

ax.axis(zoom)