def get_topo(makeplots=False):
    """
    Retrieve the topo file from the GeoClaw repository.
    """
    from clawpack.geoclaw import topotools, etopotools

    topo_fname = 'etopo1_-140_-60_-60_10_10min.tt3'

    if os.path.exists(topo_fname):
        print "*** Not regenerating dtopo file (already exists): %s" \
                    % dtopo_fname
    else:
        xlimits = (-140,-60)
        ylimits = (-60,10)
        resolution = 10./60.   # degrees

        topo = etopotools.etopo1_download(xlimits,ylimits, dx=resolution, \
                output_dir=scratch_dir, file_name=topo_fname, return_topo=True)

    if makeplots:
        from matplotlib import pyplot as plt
        topo = topotools.Topography(os.path.join(scratch_dir,topo_fname), topo_type=2)
        topo.plot()
        fname = os.path.splitext(topo_fname)[0] + '.png'
        plt.savefig(fname)
        print "Created ",fname
示例#2
0
def test_fetch_etopo():
    """
    Test fetching etopo1 data from the NCEI (NGDC) website.
    """
    
    xlimits = (-120,-60)
    ylimits = (-60,0)
    resolution = 10./60.   # in degrees

    try:
        temp_path = tempfile.mkdtemp()

        topo = etopotools.etopo1_download(xlimits,ylimits, dx=resolution, \
                output_dir=temp_path, return_topo=True)

        assert topo.Z.shape==(361,361), "*** topo file has wrong shape"
        assert topo.Z[0,0]==-4516, "*** topo.Z[0,0]=%g has unexpected value"\
                                % topo.Z[0,0]

    except AssertionError as e:
        # If the assertion failed then copy the contents of the directory
        shutil.copytree(temp_path, os.path.join(os.getcwd(), 
                                                "test_fetch_etopo"))
        raise e
    finally:
        shutil.rmtree(temp_path)
示例#3
0
def get_topo(makeplots=False):
    """
    Retrieve the topo file from the GeoClaw repository.
    """
    from clawpack.geoclaw import topotools, etopotools

    topo_fname = 'etopo1_-140_-60_-60_10_10min.tt3'

    if os.path.exists(topo_fname):
        print("*** Not regenerating dtopo file (already exists): %s" \
                    % dtopo_fname)
    else:
        xlimits = (-140, -60)
        ylimits = (-60, 10)
        resolution = 10. / 60.  # degrees

        topo = etopotools.etopo1_download(xlimits,ylimits, dx=resolution, \
                output_dir=scratch_dir, file_name=topo_fname, return_topo=True)

    if makeplots:
        from matplotlib import pyplot as plt
        topo = topotools.Topography(os.path.join(scratch_dir, topo_fname),
                                    topo_type=2)
        topo.plot()
        fname = os.path.splitext(topo_fname)[0] + '.png'
        plt.savefig(fname)
        print("Created ", fname)
示例#4
0
# Set the limits of the domain and resolution:
xlimits = (-120, -60)
ylimits = (-60, 0)
resolution = 10. / 60.  # in degrees

# If user environment variable ETOPO is set to a valid path to a directory,
# downloaded data will be stored there.  Allows sharing same data among
# various projects.

try:
    etopo_dir = os.environ['ETOPO']
    os.chdir(etopo_dir)  # make sure it's a valid directory
except:
    print "ETOPO not set or invalid directory, setting etopo_dir='.'"
    etopo_dir = '.'

topo = etopotools.etopo1_download(xlimits,ylimits, dx=resolution, \
        output_dir=etopo_dir, return_topo=True)

if plot_topo:
    # plot the topo and save as a png file...
    import matplotlib.pyplot as plt
    topo.plot()
    topo_file_name = os.path.split(topo.path)[-1]
    plt.title('Topo file %s' % topo_file_name)
    fname = os.path.splitext(topo_file_name)[0] + '.png'
    fname = os.path.join(etopo_dir, fname)
    plt.savefig(fname)
    print 'Created %s' % fname
示例#5
0
"""

import os
from clawpack.geoclaw import etopotools

plot_topo = False
etopo_dir = '.'  # put the file here


# Set the limits of the domain and resolution:

xlimits = (-128,-122)
ylimits = (40,50)
resolution = 1./60.   # degrees

topo = etopotools.etopo1_download(xlimits,ylimits, dx=resolution, \
        output_dir=etopo_dir, return_topo=True)


if plot_topo:
    # plot the topo and save as a png file...
    import matplotlib.pyplot as plt
    topo.plot()
    topo_file_name = os.path.split(topo.path)[-1]
    plt.title('Topo file %s' % topo_file_name)
    fname = os.path.splitext(topo_file_name)[0] + '.png'
    fname = os.path.join(etopo_dir, fname)
    plt.savefig(fname)
    print 'Created %s' % fname