示例#1
0
文件: tide_gauge.py 项目: omad/fes
def main():
    """
    Main program
    """
    args = usage()

    # Create handler
    short_tide = pyfes.Handler("ocean", "io", args.ocean.name)
    radial_tide = pyfes.Handler("radial", "io", args.load.name)

    # Creating the time series
    dates = np.array([
        args.date + datetime.timedelta(seconds=item * 3600)
        for item in range(24)
    ])

    lats = np.full(dates.shape, 59.195)
    lons = np.full(dates.shape, -7.688)

    # Computes tides
    tide, lp, _ = short_tide.calculate(lons, lats, dates)
    load, load_lp, _ = radial_tide.calculate(lons, lats, dates)

    for idx, date in enumerate(dates):
        print("%s %9.3f %9.3f %9.3f %9.3f %9.3f %9.3f %9.3f" %
              (date, lats[idx], lons[idx], tide[idx], lp[idx], tide[idx] +
               lp[idx], tide[idx] + lp[idx] + load[idx], load[idx]))
示例#2
0
def main():
    """
    Main program
    """
    args = usage()

    # Create handler
    eastward_velocity = pyfes.Handler("ocean", "memory",
                                      args.eastward_velocity.name)
    northward_velocity = pyfes.Handler("ocean", "memory",
                                       args.northward_velocity.name)

    # Creating a grid that will be used to interpolate the tide
    lats = np.arange(-90, 90, 1.0)
    lons = np.arange(-180, 180, 2.0)

    assert lons.shape == lats.shape
    size = lats.size

    lons, lats = np.meshgrid(lons, lats)

    dates = np.empty(lons.shape, dtype='datetime64[us]')
    dates.fill(args.date)

    # Create handler
    u_tide, lp, _ = eastward_velocity.calculate(lons.ravel(), lats.ravel(),
                                                dates.ravel())
    v_tide, _, _ = northward_velocity.calculate(lons.ravel(), lats.ravel(),
                                                dates.ravel())

    # Creating an image to see the result in meters
    u_tide = u_tide.reshape((size, size))
    u_tide = np.ma.masked_where(np.isnan(u_tide), u_tide)
    plt.figure(1)
    plt.title("eastward velocity")
    plt.pcolormesh(u_tide)

    v_tide = v_tide.reshape((size, size))
    v_tide = np.ma.masked_where(np.isnan(v_tide), v_tide)
    plt.figure(2)
    plt.title("northward velocity")
    plt.pcolormesh(v_tide)

    plt.show()
示例#3
0
文件: fes_slev.py 项目: omad/fes
def main():
    """
    Main program
    """
    args = usage()

    # Create handler
    short_tide = pyfes.Handler("ocean", "memory", args.ocean.name)
    if args.load is not None:
        radial_tide = pyfes.Handler("radial", "memory", args.load.name)
    else:
        radial_tide = None

    # Creating a grid that will be used to interpolate the tide
    lats = np.arange(-90, 90, 0.5)
    lons = np.arange(-180, 180, 0.5)

    lons, lats = np.meshgrid(lons, lats)

    shape = lons.shape

    dates = np.empty(shape, dtype='datetime64[us]')
    dates.fill(args.date)

    # Create handler
    tide, lp, _ = short_tide.calculate(lons.ravel(), lats.ravel(),
                                       dates.ravel())
    tide, lp = tide.reshape(shape), lp.reshape(shape)
    if radial_tide is not None:
        load, load_lp, _ = radial_tide.calculate(lons.ravel(), lats.ravel(),
                                                 dates.ravel())
        load, load_lp = load.reshape(shape), load_lp.reshape(shape)
    else:
        load = np.zeros(lons.shape)
        load_lp = load

    # Creating an image to see the result in meters
    geo_tide = (tide + lp + load) * 0.01
    geo_tide = geo_tide.reshape(lons.shape)
    geo_tide = np.ma.masked_where(np.isnan(geo_tide), geo_tide)
    plt.pcolormesh(geo_tide)
    plt.show()
示例#4
0
def main():
    """
    Main program
    """

    # study location
    # location = 'la_figueirette'
    # lon_study = 6.93494
    # lat_study = 43.4835
    location = 'Cannes'
    lon_study = 7.027011
    lat_study = 43.545697

    fes_data = '/home/florent/ownCloud/R&D/DATA/TIDE/FES_2014/FES2014_b_elevations_extrapolated/ocean_tide_extrapolated/'
    os.environ['FES_DATA'] = fes_data
    f_tide_out = '/home/florent/Projects/Cannes/Water_levels/tide_from_harmonic_constituents/tide_from_fes_constituents_{location}.pk'.format(
        location=location)
    tide_results = {}
    tide_results['tide_from_fes'] = []
    args = usage()
    visu = False

    # Create handler
    short_tide = pyfes.Handler("ocean", "memory", args.ocean.name)
    if args.load is not None:
        radial_tide = pyfes.Handler("radial", "memory", args.load.name)
    else:
        radial_tide = None

    # Creating a grid that will be used to interpolate the tide
    # lats = np.arange(43.4, 43.6, 0.01)
    # lons = np.arange(6.8, 7.0, 0.01)
    lats = np.arange(43.5, 43.6, 0.01)
    lons = np.arange(6.8, 7.2, 0.01)
    grid_lons, grid_lats = np.meshgrid(lons, lats)
    shape = grid_lons.shape

    # dates
    start_date = np.datetime64('2020-03-11 12:00')
    end_date = np.datetime64('2021-03-01 12:00')
    step = 10
    vec_dates = compute_dates(start_date, end_date, step)
    tide_results['dates'] = vec_dates
    dates = np.empty(shape, dtype='datetime64[us]')
    for date in vec_dates:
        print(date)
        dates.fill(date)

        # Calculate tide
        tide, lp, _ = short_tide.calculate(grid_lons.ravel(),
                                           grid_lats.ravel(), dates.ravel())
        tide, lp = tide.reshape(shape), lp.reshape(shape)
        if radial_tide is not None:
            load, load_lp, _ = radial_tide.calculate(grid_lons.ravel(),
                                                     grid_lats.ravel(),
                                                     dates.ravel())
            load, load_lp = load.reshape(shape), load_lp.reshape(shape)
        else:
            load = np.zeros(grid_lons.shape)
            load_lp = load

        # Convert tide to cm and to a 2d numpy masked array
        geo_tide = (tide + lp + load) * 0.01
        geo_tide = geo_tide.reshape(grid_lons.shape)
        geo_tide = np.ma.masked_where(np.isnan(geo_tide), geo_tide)

        # Extract tide at study location
        tide_extract, lon_extract, lat_extract = get_fes_wl_at_extraction_point(
            lons, lats, lon_study, lat_study, geo_tide)

        # save tide results in dictionnary
        tide_results['tide_from_fes'].append(tide_extract)

        # Affichage
        if visu:
            plt.pcolormesh(grid_lons, grid_lats, geo_tide)
            plt.text(lon_extract, lat_extract, '%.3f' % tide_extract)
            plt.colorbar()
            plt.show()

    # save tide results into pickle
    with open(f_tide_out, 'wb') as file_tide_out:
        pickle.dump(tide_results, file_tide_out, protocol=2)
                   _ < settings_slope['date_range'][1])
    for _ in output['dates']
]
dates_sat = [output['dates'][_] for _ in np.where(idx_dates)[0]]
for key in cross_distance.keys():
    cross_distance[key] = cross_distance[key][idx_dates]

#%% 3. Tide levels

# Option 1. if FES2014 global tide model is setup
import pyfes
filepath = r'C:\Users\00084142\Dropbox\Research\Tides\fes-2.9.1-Source\data\fes2014'
config_ocean = os.path.join(filepath, 'ocean_tide.ini')
config_ocean_extrap = os.path.join(filepath, 'ocean_tide_extrapolated.ini')
config_load = os.path.join(filepath, 'load_tide.ini')
ocean_tide = pyfes.Handler("ocean", "io", config_ocean)
load_tide = pyfes.Handler("radial", "io", config_load)

# coordinates of the location (always select a point 1-2km offshore from the beach)
coords = [115.668029, -33.149916]
# get tide time-series with 15 minutes intervals
time_step = 15 * 60
dates_fes, tide_fes = SDS_slope.compute_tide(coords,
                                             settings_slope['date_range'],
                                             time_step, ocean_tide, load_tide)
# get tide level at time of image acquisition
tide_sat = SDS_slope.compute_tide_dates(coords, dates_sat, ocean_tide,
                                        load_tide)

# plot tide time-series
fig, ax = plt.subplots(1, 1, figsize=(12, 3), tight_layout=True)