time = pd.date_range(start_date, end_date, freq='1H')

file_list = glob.glob(fn_gesla)

n_port = len(file_list)
n_time = len(time)

longitude = []
latitude = []
site_name = []
contributor = []
ssh = []
qc_flags = []

tg = coast.TIDEGAUGE()
file_count = 0

for ff in range(0, len(file_list)):
    file = file_list[ff]
    print(str(ff) + '_' + file)

    # Read header
    header = tg.read_gesla_header_v3(file)
    lon_tmp = header['longitude']
    lat_tmp = header['latitude']
    if lon_tmp > lonbounds[1] or lon_tmp < lonbounds[0] or lat_tmp > latbounds[
            1] or lat_tmp < latbounds[0]:
        continue

    data = tg.read_gesla_to_xarray_v3(file)
Esempio n. 2
0
fn_nemo_dat = './example_files/COAsT_example_NEMO_data.nc'
fn_nemo_dom = './example_files/COAsT_example_NEMO_domain.nc'
fn_tidegauge = './example_files/tide_gauges/lowestoft-p024-uk-bodc'
fn_tidegauge_mult = './example_files/tide_gauges/l*'

# We need to load in a NEMO object for doing NEMO things.
nemo = coast.NEMO(fn_nemo_dat, fn_nemo_dom, grid_ref='t-grid')

# And now we can load in our ALTIMETRY data. By default, TIDEGAUGE is set up
# to read in GESLA ASCII files. However, if no path is supplied, then the
# object's dataset will be initialised as None. Custom data can then be loaded
# if desired, as long as it follows the data formatting for TIDEGAUGE. Here
# we load data between two specified dates:
date0 = datetime.datetime(2007, 1, 10)
date1 = datetime.datetime(2007, 1, 16)
tidegauge = coast.TIDEGAUGE(fn_tidegauge, date_start=date0, date_end=date1)

# Before comparing our observations to the model, we will interpolate a model
# variable to the same time and geographical space as the tidegauge. This is
# done using the obs_operator() method:
tidegauge.obs_operator(nemo, mod_var_name='ssh', time_interp='nearest')

# Doing this has created a new interpolated variable called interp_ssh and
# saved it back into our TIDEGAUGE object. Take a look at tidegauge.dataset
# to see for yourself.
#
# Next we will compare this interpolated variable to an observed variable
# using some basic metrics. The basic_stats() routine can be used for this,
# which calculates some simple metrics including differences, RMSE and
# correlations. NOTE: This may not be a wise choice of variables.
stats = tidegauge.basic_stats('interp_ssh', 'sea_level')
Esempio n. 3
0
"""
'''
Operation Shed Empty.
Should Tim empty the shed before it floods?
'''

# Begin by importing coast and other packages
import datetime
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

import os, sys
coastdir = os.path.dirname('/Users/jeff/GitHub/COAsT/coast')
sys.path.insert(0, coastdir)
import coast

date_start = np.datetime64('2021-01-25')
date_end = np.datetime64('now')

# Load in data from the Shoothill API. Gladstone dock is loaded by default
hnk = coast.TIDEGAUGE()
hnk.dataset = hnk.read_shoothill_to_xarray(stationId="1032",
                                           date_start=date_start,
                                           date_end=date_end)
hnk.plot_timeseries()
plt.xlabel('date')
plt.ylabel('Water level on Hinksey Stream (Cold Harbour) (m)')
plt.legend().remove()
plt.title('Operation Shed Empty')
Esempio n. 4
0
date_end = np.datetime64('now')
date_start = date_end - np.timedelta64(ndays, 'D')

## Christoph 22 Jan 21
date_end = np.datetime64('2021-01-28')
ndays = 10
date_start = date_end - np.timedelta64(ndays, 'D')

## 2021
date_end = np.datetime64('now')
date_start = np.datetime64('2021-01-01')

#%% Load data

# Load in data from the Shoothill API. Gladstone dock is loaded by default
liv = coast.TIDEGAUGE()
liv.dataset = liv.read_shoothill_to_xarray(date_start=date_start,
                                           date_end=date_end)
#liv.plot_timeseries()

ctrf = coast.TIDEGAUGE()
ctrf.dataset = ctrf.read_shoothill_to_xarray(stationId="7899",
                                             date_start=date_start,
                                             date_end=date_end,
                                             dataType=15)
#ctrf.plot_timeseries()

ctr = coast.TIDEGAUGE()
ctr.dataset = ctr.read_shoothill_to_xarray(stationId="7899",
                                           date_start=date_start,
                                           date_end=date_end)
Esempio n. 5
0
# Begin by importing coast and other packages
import datetime
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

import os, sys
coastdir = os.path.dirname('/Users/jeff/GitHub/COAsT/coast')
sys.path.insert(0, coastdir)
import coast

date_start = np.datetime64('2021-01-11')
date_end = np.datetime64('2021-01-30')

# Load in data from the Shoothill API. Gladstone dock is loaded by default
liv = coast.TIDEGAUGE()
liv.dataset = liv.read_shoothill_to_xarray(date_start=date_start,
                                           date_end=date_end)
#liv.plot_timeseries()

ctr = coast.TIDEGAUGE()
ctr.dataset = ctr.read_shoothill_to_xarray(stationId="7899",
                                           date_start=date_start,
                                           date_end=date_end)
#ctr.plot_timeseries()

plt.close('all')
fig, (ax1, ax2) = plt.subplots(2, sharex=True)

## Only get tides over the weir with 8.75m at Liverpool
fig.suptitle(
    'm4': 57.968,
    'm8': 115.9364,
    'mf': 1.09803,
    'sa': 0.0410686
}

const = np.array(list(speeds.keys()))
values = np.array([speeds[cc] for cc in const]).astype(float)
values = 24 * values / 360

fn_tidegauge = '/Users/dbyrne/data/gesla/gladstone-p234-uk-bodc'
fn_model = '/Users/dbyrne/Projects/CO9_AMM15/p0_liverpool.nc'

# Read tidegauge data
tg = coast.TIDEGAUGE(fn_tidegauge,
                     date_start=datetime.datetime(2011, 1, 1),
                     date_end=datetime.datetime(2012, 1, 1))
tg_ssh = tg.dataset.sea_level.values
tg_ssh[tg.dataset.qc_flags > 3] = np.nan
tg_ssh = tg_ssh - np.nanmean(tg_ssh)
tg_time = tg.dataset.time.values

# Basic QC
std = np.nanstd(tg_ssh)
ind_qc = np.abs(tg_ssh) > 2.2 * std
tg_ssh[ind_qc] = np.nan

# Read model data
mod = xr.open_dataset(fn_model)
mod_time = mod.time.values
mod_ssh = mod.ssh.values
Esempio n. 7
0
const_03 = ['M2','S2','K2','K1','O1','P1']
const_04 = ['M2','S2','K1','K1','O1','P1','M4','M6','M8']
const_05 = ['M2','S2','K1','K1','O1','P1','M4','M6','M8','MM','MF','SA','SSA']
const_auto = 'auto'
all_sets = [const_01, const_02, const_03, const_04, const_05, const_auto]

const_save = ['M2']
fn_out = '/Users/dbyrne/m2var.nc'

years = np.arange(1994, 2013)
base_year = datetime.datetime(1994,1,1)



# Read tidegauge data
tg = coast.TIDEGAUGE(fn_tidegauge, date_start=base_year).dataset
tg_ssh = tg.sea_level.values
tg_ssh[tg.qc_flags>3] = np.nan
tg_ssh = tg_ssh - np.nanmean(tg_ssh)

# Basic QC
std = np.nanstd(tg_ssh)
ind_qc = np.abs(tg_ssh) > 2.5*std
tg_ssh[ind_qc] = np.nan

tg['ssh'] = ('time', tg_ssh)

a_year = np.zeros((len(const_save), len(years), len(all_sets)))*np.nan
a_myear = np.zeros((len(const_save), len(years), len(all_sets)))*np.nan
g_year = np.zeros((len(const_save), len(years), len(all_sets)))*np.nan
g_myear = np.zeros((len(const_save), len(years), len(all_sets)))*np.nan