def __init__(self, **kwargs): self.t = 0 self.utm_zone = kwargs["utm_zone"] self.utm_band = kwargs["utm_band"] tide = uptide.Tides(kwargs["constituents"]) tide.set_initial_time(kwargs["initial_time"]) self.tnci = uptide.tidal_netcdf.OTPSncTidalInterpolator( tide, kwargs["grid_file_name"], kwargs["data_file_name"], kwargs["ranges"])
def __init__(self): self.t = 0 self.tnci_time = None constituents = ['Q1', 'O1', 'P1', 'K1', 'N2', 'M2', 'S2', 'K2'] tide = uptide.Tides(constituents) tide.set_initial_time(datetime.datetime(2001, 9, 18, 0, 0, 0)) self.tnci = uptide.tidal_netcdf.OTPSncTidalInterpolator( tide, 'gridES2008.nc', 'hf.ES2008.nc', ranges=((-4.0, 0.0), (58.0, 61.0)))
def __init__(self, grid_file_name, data_file_name, ranges, utm_zone, utm_band, initial_time, constituents): """ This function initializes a new TidalForcing object. The parameters are: """ self.t = 0 self.utm_zone = utm_zone self.utm_band = utm_band tide = uptide.Tides(constituents) tide.set_initial_time(initial_time) self.tnci = uptide.tidal_netcdf.OTPSncTidalInterpolator( tide, grid_file_name, data_file_name, ranges)
def test(): constituents = ('M2', 'S2', 'N2', 'K2', 'K1', 'O1', 'P1', 'Q1') lat = 58.708 lon = -3.287 dt0 = datetime.datetime(2003, 3, 28, 0, 0, 0) trange = numpy.arange(0., 24. * 32., 0.25) * 3600. tide = uptide.Tides(constituents) tide.set_initial_time(dt0) series = {} tnci = uptide.FES2014TidalInterpolator( '/home/angel/tools/fes-2.9.1-Source/data/fes2014/ocean_tide.ini') tnci.set_initial_time(dt0) series['FES2014'] = extract_series(tnci, (lat, 360. + lon), trange)
def generate_tidal_periods(t: pd.Series, constituents: list = default_tidal_constituents): tide = uptide.Tides(constituents) t0 = t[0] td = t - t0 td = td.dt.total_seconds().to_numpy().astype(int) tide.set_initial_time(t0) # calc tides amplitudes = np.ones_like(td) phases = np.zeros_like(td) eta = {} for name, f, amplitude, omega, phase, phi, u in zip( tide.constituents, tide.f, amplitudes, tide.omega, phases, tide.phi, tide.u): eta[name] = f * amplitude * np.cos(omega * td - phase + phi + u) df_eta = pd.DataFrame(eta, index=t) return df_eta
def __init__(self, tidal_field, init_date, constituents=None, boundary_ids=None): assert init_date.tzinfo is not None, 'init_date must have time zone information' if constituents is None: constituents = ['Q1', 'O1', 'P1', 'K1', 'N2', 'M2', 'S2', 'K2'] # determine nodes at the boundary self.tidal_field = tidal_field fs = tidal_field.function_space() if boundary_ids is None: # interpolate in the whole domain self.nodes = np.arange( self.tidal_field.dat.data_with_halos.shape[0]) else: bc = DirichletBC(fs, 0., boundary_ids, method='geometric') self.nodes = bc.nodes self._empty_set = self.nodes.size == 0 xy = SpatialCoordinate(fs.mesh()) fsx = Function(fs).interpolate(xy[0]).dat.data_ro_with_halos fsy = Function(fs).interpolate(xy[1]).dat.data_ro_with_halos if not self._empty_set: latlon = [] for node in self.nodes: x, y = fsx[node], fsy[node] lat, lon = to_latlon(x, y) latlon.append((lat, lon)) self.latlon = np.array(latlon) # compute bounding box bounds_lat = [self.latlon[:, 0].min(), self.latlon[:, 0].max()] bounds_lon = [self.latlon[:, 1].min(), self.latlon[:, 1].max()] ranges = (bounds_lat, bounds_lon) tide = uptide.Tides(constituents) tide.set_initial_time(init_date) self.tnci = uptide.tidal_netcdf.FESTidalInterpolator(tide, tide_file, ranges=ranges)
print('Reading h5 files. Time ', i, len(range(t_n))) checkpoint_file = checkpointing.DumbCheckpoint(inputs.input_file_paths.paraview_output_folder + '/elev_' + str(t_start+(i + 1) * dt), mode=FILE_READ) checkpoint_file.load(elev) checkpoint_file.close() elev_data_set[i, :] = elev.dat.data[:] # if i+1==4: # break detector_amplitudes = [] detector_phases = [] for i in range(elev.dat.data.shape[0]): thetis_elev = elev_data_set[:, i] tide = uptide.Tides(constituents) tide.set_initial_time(datetime.datetime(2003, 5, 6, 8, 0)) # Subtract mean thetis_elev = thetis_elev - thetis_elev.mean() thetis_amplitudes, thetis_phases = uptide.analysis.harmonic_analysis(tide, thetis_elev[:], thetis_times[:]) detector_amplitudes.append(thetis_amplitudes) detector_phases.append(thetis_phases) M2_amp.dat.data[:] = np.array(detector_amplitudes)[:, 0] M2_phase.dat.data[:] = np.array(detector_phases)[:, 0] S2_amp.dat.data[:] = np.array(detector_amplitudes)[:, 1] S2_phase.dat.data[:] = np.array(detector_phases)[:, 1]
def __init__(self, elev_field, init_date, to_latlon, target_coordsys, uv_field=None, constituents=None, boundary_ids=None, data_dir=None): """ :arg elev_field: Function where tidal elevation will be interpolated. :arg init_date: Datetime object defining the simulation init time. :arg to_latlon: Python function that converts local mesh coordinates to latitude and longitude: 'lat, lon = to_latlon(x, y)' :arg target_coordsys: coordinate system in which the model grid is defined. This is used to rotate vectors to local coordinates. :kwarg uv_field: Function where tidal transport will be interpolated. :kwarg constituents: list of tidal constituents, e.g. ['M2', 'K1'] :kwarg boundary_ids: list of boundary_ids where tidal data will be evaluated. If not defined, tides will be in evaluated in the entire domain. :kward data_dir: path to directory where tidal model netCDF files are located. """ assert init_date.tzinfo is not None, 'init_date must have time zone information' if constituents is None: constituents = ['Q1', 'O1', 'P1', 'K1', 'N2', 'M2', 'S2', 'K2'] self.data_dir = data_dir if data_dir is not None else '' if not self.compute_velocity and uv_field is not None: warning( '{:}: uv_field is defined but velocity computation is not supported. uv_field will be ignored.' .format(__class__.__name__)) self.compute_velocity = self.compute_velocity and uv_field is not None # determine nodes at the boundary self.elev_field = elev_field self.uv_field = uv_field fs = elev_field.function_space() if boundary_ids is None: # interpolate in the whole domain self.nodes = np.arange( self.elev_field.dat.data_with_halos.shape[0]) else: bc = DirichletBC(fs, 0., boundary_ids, method='geometric') self.nodes = bc.nodes self._empty_set = self.nodes.size == 0 xy = SpatialCoordinate(fs.mesh()) fsx = Function(fs).interpolate(xy[0]).dat.data_ro_with_halos fsy = Function(fs).interpolate(xy[1]).dat.data_ro_with_halos if not self._empty_set: latlon = [] for node in self.nodes: x, y = fsx[node], fsy[node] lat, lon = to_latlon(x, y, positive_lon=True) latlon.append((lat, lon)) self.latlon = np.array(latlon) # compute bounding box bounds_lat = [self.latlon[:, 0].min(), self.latlon[:, 0].max()] bounds_lon = [self.latlon[:, 1].min(), self.latlon[:, 1].max()] if self.coord_layout == 'lon,lat': self.ranges = (bounds_lon, bounds_lat) else: self.ranges = (bounds_lat, bounds_lon) self.tide = uptide.Tides(constituents) self.tide.set_initial_time(init_date) self._create_readers() if self.compute_velocity: lat = self.latlon[:, 0] lon = self.latlon[:, 1] self.vect_rotator = coordsys.VectorCoordSysRotation( coordsys.LL_WGS84, target_coordsys, lon, lat)
def setUp(self): self.tide = uptide.Tides() self.tide.set_initial_time(datetime.datetime(2003, 1, 17, 19, 30))
def test(): constituents = ('M2', 'S2', 'N2', 'K2', 'K1', 'O1', 'P1', 'Q1') lat = 58.708 lon = -3.287 lon = -1. dt0 = datetime.datetime(2003, 3, 28, 0, 0, 0) trange = numpy.arange(0., 24. * 32., 0.25) * 3600. tide = uptide.Tides(constituents) tide.set_initial_time(dt0) series = {} if 'AMCG_TIDAL_FILE' in os.environ: tnci = uptide.tidal_netcdf.AMCGTidalInterpolator( tide, os.environ['AMCG_TIDAL_FILE'], ranges=((58.0, 61.0), (-4.0, 0.0))) series['AMCG'] = extract_series(tnci, (lat, lon), trange) if 'OTPS_GRID_FILE' in os.environ: tnci = uptide.tidal_netcdf.OTPSncTidalInterpolator( tide, os.environ['OTPS_GRID_FILE'], os.environ['OTPS_DATA_FILE'], ranges=((-4.0, 0.0), (58.0, 61.0))) series['OTPS'] = extract_series(tnci, (lon, lat), trange) if 'FES2004_FILE' in os.environ: tnci = uptide.tidal_netcdf.FESTidalInterpolator( tide, os.environ['FES2004_FILE'], ranges=((58.0, 61.0), (356., 360.0))) series['FES2004'] = extract_series(tnci, (lat, 360. + lon), trange) if 'FES2014_INI_FILE' in os.environ: tnci = uptide.FES2014TidalInterpolator(os.environ['FES2014_INI_FILE']) tnci.set_initial_time(dt0) series['FES2014'] = extract_series(tnci, (lat, 360. + lon), trange) if 'FES2014_INI_FILE' in os.environ: tnci = uptide.FES2014TidalInterpolator(os.environ['FES2014_INI_FILE'], include_long_period=False) tnci.set_initial_time(dt0) series['FES2014 short'] = extract_series(tnci, (lat, 360. + lon), trange) if 'FES2014_DATA_PATH' in os.environ: # check that the FES2014 tide is the same using a Tides object with all the # constituents that are in the standard ocean_tide.ini file tide2 = uptide.Tides(uptide.ALL_FES2014_TIDAL_CONSTITUENTS) tide2.set_initial_time(dt0) tnci = uptide.FES2014TidalInterpolator(tide2, os.environ['FES2014_DATA_PATH']) series['FES2014 all specified'] = extract_series( tnci, (lat, 360. + lon), trange) if 'FES2014' in series: assert_equal(series['FES2014'], series['FES2014 all specified']) pylab.figure() for label, etas in series.items(): pylab.plot(trange / uptide.tidal.day, etas, label=label) pylab.legend() pylab.show()
def mntide(): td = uptide.Tides(['M' + str(n) for n in range(2, 13)]) td.set_initial_time(datetime.datetime(2003, 1, 17, 19, 30)) return td
def tide(request): td = uptide.Tides() td.set_initial_time(request.param) return td
import h5py import uptide import datetime #from matplotlib.pylab import * import matplotlib.pyplot as plt import numpy as np from math import sqrt det_file = '../outputs/diagnostic_detectors.hdf5' output_file = '../processed/' df = h5py.File(det_file, 'r+') data_constituents = ['Q1', 'O1', 'P1', 'S1', 'K1', '2N2', 'MU2', 'N2', 'NU2', 'M2', 'L2', 'T2', 'S2', 'K2', 'M4', 'Z0'] # the ones present in the data thetis_constituents = ['Q1', 'O1', 'P1', 'K1', 'N2', 'M2', 'S2', 'K2', 'M4']# the ones you want to analyse for tide = uptide.Tides(thetis_constituents) tide.set_initial_time(datetime.datetime(2003,5,6,8,0)) # make sure this is the same as in the tidal forcing of your run tidegauge_file = '../inputs/tide_constituents_hyphen_names.dat' gauge_names = np.loadtxt(tidegauge_file, skiprows=22, usecols=(1,), dtype=str) gauge_amps = np.loadtxt(tidegauge_file, skiprows=22, usecols=np.arange(6, 36, 2)) gauge_phases = np.loadtxt(tidegauge_file, skiprows=22, usecols=np.arange(7, 36, 2)) t = df['time'] dt=100. spin = int(8*24*60*60/dt) spin = 0 print(len(t),spin)
import uptide import uptide.tidal_netcdf import os.path import datetime import numpy import utm import sys import pyfes as fes tide = uptide.Tides(uptide.ALL_FES2014_TIDAL_CONSTITUENTS) tide.set_initial_time(datetime.datetime(2005, 3, 1, 0, 0)) tnci = uptide.FES2014TidalInterpolator( tide, '/home/angel/tools/fes-2.9.1-Source/data/fes2014/ocean_tide.ini')