コード例 #1
0
Look at the aggregated and lowpass data - is it actually lowpassing?
"""
import numpy as np
import matplotlib.pyplot as plt
import xarray as xr

from stompy import utils

import stompy.model.delft.waq_scenario as waq
import dwaq_transport
from stompy.plot import plot_utils

##

# This does not integrate over the timesteps, but dwaq_transport will handle that.
hydro=waq.HydroFiles('hydro-wy2013c_adj-agg_lp_2d/com-wy2013c_adj_agg_lp_2d.hyd')


##
scalar_name="stormwater"
scalar3_data_fn="scalar_data/%s-with_bc3.nc"%scalar_name
scalar4_data_fn="scalar_data_agg_lp_2d/%s-with_bc4.nc"%scalar_name

scalar3_nc=xr.open_dataset(scalar3_data_fn)
scalar4_nc=xr.open_dataset(scalar4_data_fn)

##

g=unstructured_grid.UnstructuredGrid.from_ugrid(scalar_nc)

##
コード例 #2
0
        return cleaned
    else:
        return shp_in


# Processing:

# remove multipolygons from inputs
shp = clean_shapefile(agg_grid_shp)

##
six.moves.reload_module(waq)

# open the original dwaq hydrodynamics
hydro_orig = waq.HydroFiles(hyd_fn)

# create object representing aggregated hydrodynamics
# sparse_layers: for z-layer inputs this can be True, in which cases cells are only output for the
#    layers in which they are above the bed.  Usually a bad idea.  Parts of DWAQ assume
#    each 2D cell exists across all layers
# agg_boundaries: if True, multiple boundary inputs entering a single aggregated cell will be
#   merged into a single boundary input.  Generally best to keep this as False.
hydro_agg = waq.HydroAggregator(hydro_in=hydro_orig,
                                agg_shp=shp,
                                sparse_layers=False,
                                agg_boundaries=False)

##

bdefs = hydro_agg.boundary_defs()
コード例 #3
0
ファイル: basic_test.py プロジェクト: fkarimpour/stompy
    # Some preprocessing (this is necessary even if it's not an MPI run)
    model.partition()
    # Do it
    model.run_model()

    return model

# Run/load small hydro run:
model=base_model(force=False)

##

# 'model' represents the whole DFM model.
# dwaq.Hydro, and subclasses like dwaq.HydroFiles, represent
# the hydro information used by DWAQ.
base_hydro=dwaq.HydroFiles(model.hyd_output())

##
                           
# Design a tracer release
#  this is a simple gaussian blob.
def release_conc_fn(X):
    X=X[...,:2] # drop z coordinate if it's there
    X0=np.array([250,250]) # center of gaussian
    L=50
    c=np.exp( -((X-X0)**2).sum(axis=-1)/L**2 )
    c=c/c.max() # make max value 1
    return c

# Get the grid that DWAQ will use:
grid=base_hydro.grid()
コード例 #4
0
"""
from __future__ import print_function

import argparse
import sys, os
import numpy as np

import stompy.model.delft.waq_scenario as waq

parser = argparse.ArgumentParser(
    description='Adjust DFM D-WAQ output to add missing BC fluxes.')

parser.add_argument('hyd_fn',
                    metavar='dfm_out.hyd',
                    type=str,
                    help='path to hyd file')

args = parser.parse_args()

hyd_fn = args.hyd_fn

print("Opening hydro from %s" % hyd_fn)
hydro = waq.HydroFiles(hyd_fn)

print("Adjusting flows, updating %s in place" % hydro.get_path('flows-file'))

hydro.adjust_boundaries_for_conservation()

print("Done")
コード例 #5
0
        extra_fields=('salinity',
                      'temp',
                      'TotalDepth',
                      'VertDisper',
                      'volume',
                      'depth')
        self.map_format=['binary']
        self.map_output+=extra_fields
        self.hist_output+=extra_fields
        
        self.map_time_step=10000 # hourly
        self.mon_time_step=3000 # half-hourly (had been daily)
        self.hist_time_step=3000 # half-hourly (had been daily)
##

hydro=waq.HydroFiles(hyd_path="../../delft/sfb_ocean/sfb_ocean/runs/short_test_13/global/com-merged.hyd",
                     enable_write_symlink=True)


sec=datetime.timedelta(seconds=1)
start_time=hydro.time0+hydro.t_secs[ 0]*sec
stop_time=hydro.time0+hydro.t_secs[-4]*sec 
    
scen=Scen(hydro=hydro,
          start_time=start_time,
          stop_time=stop_time,
          base_path='dwaqA01')

##

scen.cmd_default()
コード例 #6
0
import os
import stompy.model.delft.waq_scenario as dwaq
from stompy.model.delft import dfm_grid

six.moves.reload_module(dfm_grid)
six.moves.reload_module(dwaq)

##
# 'Feb15_Feb20_2017_09172018'
# 'Feb11_Jun06_2017_08082018-rusty'
hyd_path = ('/home/rusty/mirrors/ucd-X/mwtract/TASK2_Modeling/'
            'Hydrodynamic_Model_Files/DELFT3D/Model Run Files/'
            'Feb15_Feb20_2017_09172018'
            '/DFM_DELWAQ_FlowFM/FlowFM.hyd')

hydro = dwaq.HydroFiles(hyd_path)

##


class AgeTracers(dwaq.Scenario):
    # not required, but dwaq allows 3 lines of descriptive
    # text for the run.
    desc = ('Age tracers', 'testing multiple tracer approaches', 'v00')
    # time steps are in HHMMSS, so 1000 is 10 minutes
    # 1 hour unstable, 10 minutes okay.
    time_step = 1000
    # map output hourly - and 10000 is 1 hour
    map_time_step = 10000

    def init_substances(self):
コード例 #7
0
ファイル: marsh_time.py プロジェクト: rustychris/csc
            params['ACTIVE_VertDisp'] = 1.0

        return params

    def init_substances(self):
        subs = super(Scen, self).init_substances()
        subs['NO3'] = Sub(0)

        return subs

    #def init_bcs(self):
    #def init_loads(self):


hydro = waq.HydroFiles(
    "../../dflowfm/runs/20180807_grid98_16_single/DFM_DELWAQ_flowfm/flowfm.hyd"
)

# if it runs all the way to the end of the hydro, the bad fluxes on the last step
# appear to cause a gmres error.
scen = Scen(hydro)  # this is still setup

scen.delft_bin = "/home/rusty/src/dfm/1.4.6/bin"
os.environ['LD_LIBRARY_PATH'] = "/home/rusty/src/dfm/1.4.6/lib"
scen.share_path = "/home/rusty/src/dfm/1.4.6/share/delft3d"
scen.map_output += ('TotalDepth', 'Depth', 'LocalDepth')

os.path.exists(scen.base_path) and shutil.rmtree(scen.base_path)  # for dev

scen.cmd_default()  # actually write delwaq's input files
scen.cmd_delwaq1(
コード例 #8
0
"""

import six
import os
import shutil
import datetime

import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()

import stompy.model.delft.waq_scenario as waq

##

hydro_in = waq.HydroFiles(
    "hydro-wy2013c_adj-agg_lp_2d/com-wy2013c_adj_agg_lp_2d.hyd")


class TimeIntegrator(waq.TimeIntegrator):
    enable_write_symlink = False
    sparse_layers = False
    agg_boundaries = False


stride_secs = 86400 * 1


def get_hydro():
    # Trying a 3 day cutoff
    return TimeIntegrator(hydro_in, stride_secs=stride_secs)
コード例 #9
0
# Specify locations of outside data sources:

# POTW data, checked out in subdirectory:
potw_fn='/hpcvol1/zhenlin/sfbay/common/sfbay_potw/outputs/sfbay_potw.nc'

# Selection of hydrodynamics data:
# this has spatially variable shear stresses output from the hydrorun
rel_hyd_path="/hpcvol1/Mugunthan/Inputs/hydro/WY2013/agg141_tau-lp-pass_params/com-agg141_tau-lp.hyd"

# Load those external datasets:
sfbay_potw=xr.open_dataset(potw_fn)

# External reference to radiance data defined in radsurf() in Scen() class

hydro=waq_scenario.HydroFiles(hyd_path=rel_hyd_path,enable_write_symlink=True)

## 

PC=waq_scenario.ParameterConstant
Sub=waq_scenario.Substance
IC=waq_scenario.Initial

class Scen(BayDynamo.BayDynamo):
    name="sfbay_dynamo000"
    desc=('sfbay_dynamo000',
          'wy2013',
          'full run')
    base_x_dispersion = 0. # m**2/s - constant horizontal dispersion coefficient 
    integration_option="""16.62 ;
    LOWER-ORDER-AT-BOUND NODISP-AT-BOUND
コード例 #10
0
ファイル: gen_inp.py プロジェクト: rustychris/csc
import six
import os
import shutil

from stompy.model.delft import waq_scenario as waq
from stompy.model.delft import dfm_grid

##

six.moves.reload_module(waq)

##

hydro = waq.HydroFiles("../../dflowfm/csc_95/DFM_DELWAQ_FlowFM/FlowFM.hyd")

Sub = waq.Substance


class Scen(waq.Scenario):
    # csc_sed_9500: map output interval too small
    # csc_sed_9501: output every 30 minutes
    base_path = "csc_sed_9501"
    map_formats = ['binary']

    # With integration_option="15.60"
    # 3000 was unstable.
    # 1000 was unstable.
    #  500 stable at least to 5%, running ~ 600x realtime
    # Also tried 1000 with integration_option="21.70" and "16.70", no better.
    # 21.70 appears to be about 15% faster than 15.60, a little over 700x.
    #  that was outputting a lot.
コード例 #11
0
##

g=dfm_grid.DFMGrid(map_ds)

##

plt.figure(1).clf()
g.plot_edges(lw=0.5,color='k')


ncoll=g.plot_nodes(values=map_ds.NetNode_z.values )
cbar=plot_utils.cbar(ncoll)

##

hydro=waq.HydroFiles('runs/short_28/DFM_DELWAQ_short_28/short_28.hyd')

hyd_g=hydro.grid()

# This file is truncated, and currently waq won't infer n_seg:
kmx=20
hydro._n_seg=hyd_g.Ncells() * kmx

vols=hydro.volumes(hydro.t_secs[1])

A=hydro.planform_areas()

seg_depth = vols/A.data


##
コード例 #12
0
aggregator=agg.get_hydro()

##

g_agg=aggregator.grid()
Nagg=1+aggregator.elt_global_to_agg_2d.max()

# Get a consistent unaggregated grid -- the one from scalar_map is bad.
# g_waq=dfm_grid.DFMGrid(scalar_map) # BAD

# This grid matches both the scalar fields coming out of WAQ, and
# the aggregation mapping
waq_hyd_dir='/opt/data/delft/sfb_dfm_v2/runs/wy2013c/DFM_DELWAQ_wy2013c_adj'
g_waq=dfm_grid.DFMGrid(os.path.join(waq_hyd_dir,'wy2013c_waqgeom.nc'))
# 
hyd=waq.HydroFiles(os.path.join(waq_hyd_dir,"wy2013c.hyd"))


# Not needed, right?
agg_lp_2d_dir='hydro-wy2013c_adj-agg_lp_2d'
hydro_2d=waq.HydroFiles('hydro-wy2013c_adj-agg_lp_2d/com-wy2013c_adj_agg_lp_2d.hyd')


import lowpass_wy2013c
lp_secs=lowpass_wy2013c.lp_secs
lp_hyd=lowpass_wy2013c.get_hydro()

## 

npad=int(5*lp_secs / 86400.)
daily_pad=np.zeros(npad)
コード例 #13
0
ファイル: check_tidal_bc.py プロジェクト: rustychris/csc
import xarray as xr
import matplotlib.pyplot as plt
from stompy.spatial import proj_utils
from stompy.grid import unstructured_grid
import stompy.model.delft.waq_scenario as waq
from stompy.model.delft import hydro_utils
from stompy import utils

srv_xy=[615117,4224383]
pc_ll=[-(122+2.4/60.),(38+3.3/60.)]
pc_xy=proj_utils.mapper('WGS84','EPSG:26910')(pc_ll)

ges_xy=[629223,4233353]
fpx_xy=[630728,4257433]

hydro=waq.HydroFiles('/hpcvol1/cascade/WY2011/DFM_DELWAQ_sal+temp/sal+temp.hyd')

g=hydro.grid()

plt.figure()
g.plot_edges(lw=0.3,color='k')
plt.axis('equal')

t0=utils.to_dt64(hydro.time0)

t1=t0+np.timedelta64(170,'D')
tn=t1+np.timedelta64(10,'D')

srv=hydro_utils.extract_water_level(hydro,srv_xy,t1,tn).isel(station=0)
pc=hydro_utils.extract_water_level(hydro,pc_xy,t1,tn).isel(station=0)
ges=hydro_utils.extract_water_level(hydro,ges_xy,t1,tn).isel(station=0)
コード例 #14
0
"""

import six
import os
import shutil
import datetime

import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()

import stompy.model.delft.waq_scenario as waq

##

hydro_lp = waq.HydroFiles(
    hyd_path='hydro-wy2013c_adj-agg_lp/com-wy2013c_adj_agg_lp.hyd')

# Depth-integrate


class DepthAggregator(waq.HydroAggregator):
    def __init__(self, **kwargs):
        super(DepthAggregator, self).__init__(merge_only=True, **kwargs)

    def find_maxima(self):
        super(DepthAggregator, self).find_maxima()
        self.n_agg_layers = 1

    def get_agg_k(self, proc, k, seg):
        return 0  # all layers to 1