Esempio n. 1
0
def write_topo_file(topo_file,topo_type=1,factor=4,bathy_type=None,plot=False,
                        force=False,verbose=False):
    """Creates topography file needed by the simulation"""
    
    if os.path.exists(topo_file):
        if not force:
            ans = raw_input("The file %s already exists, replace: [Y/n] " % topo_file)
            if ans[0].capitalize() == 'N':
                print "File %s already exists, use force if you want to replace the existing file." % topo_file
                return
    print "Creating topography file ",topo_file
    
    # Look at parameters of domain
    data = Data('./amr2ez.data')
    dx = abs(data.xupper-data.xlower) / (data.mx)
    dy = abs(data.yupper-data.ylower) / (data.my)
    d = min(dx,dy)
    mx = int((data.xupper-data.xlower) / d) + 8
    my = int((data.yupper-data.ylower) / d) + 8

    xlower = data.xlower-d*4.0
    ylower = data.ylower-d*4.0
    xupper = data.xupper+d*4.0
    yupper = data.yupper+d*4.0
    
    bathy_profiles = generate_profiles()

    # Pick out bathymetry profile
    if bathy_type is None:
        bathy_profile = 'flat'
    if bathy_type in bathy_profiles.keys():
        bathy_profile = bathy_profiles[bathy_type]
    else:
        err_msg = "Bathy profile %s not found, available options are" % bathy_type
        for name in bathy_profiles.keys():
            err_msg = '\n   '.join((err_msg,name))
        raise Exception(err_msg)
    if verbose:
        print "%s profile: %s" % (bathy_type,bathy_profile)

    # Create and write topography
    bathy_func = util.create_topo_func(bathy_profile,verbose=verbose)
    N = len(bathy_profile)
    if topo_type == 1:
        tt.topo1writer(topo_file,bathy_func,xlower,xupper,ylower,yupper,
            factor*mx,factor*my)
    elif topo_type == 2:
        print (xlower - xupper) / (factor*mx)
        print (ylower - yupper) / (factor*my)
        tt.topo2writer(topo_file,bathy_func,xlower,xupper,ylower,yupper,
            factor*mx,factor*my)
    else:
        raise Exception("Unknown topo type %s requested" % topo_type)

    # Plotting
    if plot:
        plot_profiles({bathy_type:bathy_profile},factor=factor)
Esempio n. 2
0
import numpy as np
import matplotlib.pyplot as plt

import pyclaw.util as util
import pyclaw.plotters.geoplot as geoplot
import pyclaw.plotters.gaugetools as gt
import pyclaw.plotters.colormaps as colormaps

# Generate bathy
N = 100
x = np.linspace(-200e3,500e3,N)
y = np.linspace(-300e3,300e3,N)
[X,Y] = np.meshgrid(x,y)
shallow_shelf = [(477e3,-100),(500e3,80.0)]
topo = util.create_topo_func(shallow_shelf)
bath = np.empty(X.shape)
for i in xrange(len(x)):
    for j in xrange(len(y)):
        bath[i,j] = topo(x[i],y[j])

# Profile plot
topo_file = '/Users/mandli/Documents/research/Papers/awr10/figures/ss_topo.png'
if not os.path.exists(topo_file):
    plt.figure(1)
    index = np.trunc(N/2.0)
    plt.hold(True)
    plt.plot(x,bath[:,index],'k',linewidth=2)
    plt.fill_between(x,bath[:,index],x*0.0,where=(bath[:,index] < 0.0),color=[0,0.5,1])
    plt.axis([-200e3,500e3,-120,100])
    plt.title("Bathymetry Cross-Section")
Esempio n. 3
0
bathys = {"gulf_shelf":[(0.0,-3228),(312e3,-2438),(467e3,-188),(479e3,0.0),(579e3,300.0)],
          "step_shelf1":[(0.0,-2000.0),(470e3-0.001,-2000.0),(470e3,-200.0),(500e3,-200.0)],
          "step_shelf2":[(0.0,-4000.0),(450e3-0.001,-4000.0),(450e3,-200.0),(500e3,-200.0)],
          "continental_shelf":[(2000e3,-7000),(2800e3,-3000),(2900e3,-100),(3000e3,0.0)],
          "flat":[(0.0,-2000)]}
bathy_profile = bathys["step_shelf2"]

ylimits = [0.0,0.0]
for i in xrange(len(bathy_profile)):
    coord = bathy_profile[i][1]
    ylimits = [min(coord,ylimits[0]),max(coord,ylimits[1])]
ylimits = [ylimits[0]*0.1+ylimits[0],ylimits[1]*0.1+ylimits[1]]
if ylimits[1] == 0.0:
    ylimits[1] = ylimits[1] + abs(ylimits[0]*0.1)

topo = util.create_topo_func(bathy_profile)
bath = np.empty(X.shape)
for i in xrange(len(x)):
    for j in xrange(len(y)):
        bath[i,j] = topo(x[i],y[j])

# Profile plot
# topo_file = '/Users/mandli/Documents/research/Papers/awr10/figures/ss_topo.png'
topo_file = './ss_topo.png'
if not os.path.exists(topo_file):
    plt.figure(1)
    index = np.trunc(N/2.0)
    plt.hold(True)
    plt.plot(x,bath[:,index],'k',linewidth=2)
    plt.fill_between(x,bath[:,index],x*0.0,where=(bath[:,index] < 0.0),color=[0,0.5,1])
    plt.axis([-200e3,500e3,ylimits[0],ylimits[1]])
Esempio n. 4
0
def plot_profiles(profiles,topo_type=1,factor=4,verbose=True):
    
    import tempfile
    import shutil
    import matplotlib.pyplot as plt
    
    # Assume an amr2ez.data file is present
    data = Data('./amr2ez.data')
    dx = abs(data.xupper-data.xlower) / (data.mx)
    dy = abs(data.yupper-data.ylower) / (data.my)
    d = min(dx,dy)
    mx = int((data.xupper-data.xlower) / d) + 8
    my = int((data.yupper-data.ylower) / d) + 8

    xlower = data.xlower-d*4.0
    ylower = data.ylower-d*4.0
    xupper = data.xupper+d*4.0
    yupper = data.yupper+d*4.0
    
    bathy_path = tempfile.mkdtemp()
    grid_size = int(np.ceil(np.sqrt(len(profiles.keys()))))
    index = 1
    plt.figure(1)
    
    for (name,profile) in profiles.iteritems():
        topo_file = os.path.join(bathy_path,name)
        
        # Write out temporary file
        bathy_func = util.create_topo_func(profile,verbose=verbose)
        N = len(profile)
        factor = 4
        if topo_type == 1:
            tt.topo1writer(topo_file,bathy_func,xlower,xupper,ylower,yupper,
                        factor*mx,factor*my)
        elif topo_type == 2:
            tt.topo2writer(topo_file,bathy_func,xlower,xupper,ylower,yupper,
                        factor*mx,factor*my)
        else:
            raise Exception("Invalid topo_type %s." % topo_type)
                        
        # Read it back in
        (X,Y,Z) = tt.topofile2griddata(topo_file,topotype=topo_type)
        slice_index = int(X.shape[0] / 2.0)
        x = X[slice_index,:]
        b = Z[slice_index,:]
        
        limits = [np.min(x),np.max(x),np.min(b)*1.05,np.max(b)*1.05]
        wet_index = np.nonzero(b < 0.0)
        
        plt.subplot(grid_size,grid_size,index)
        plt.hold(True)
        plt.plot(x,b,'k',linewidth=2)
        plt.plot(x[wet_index],np.zeros(x[wet_index].shape),'b')
        plt.axis(limits)
        plt.title(name)
        plt.xlabel('km')
        plt.ylabel('m')
        locs,labels = plt.xticks()
        labels = locs/1e3
        plt.xticks(locs,labels)
        plt.hold(False)
        index = index + 1
        
    plt.show()
        
    shutil.rmtree(bathy_path)