opendrift.readers.reader_tpxo ============================= .. py:module:: opendrift.readers.reader_tpxo .. autoapi-nested-parse:: Reader for barotropic tidal currents from the TPXO9 global tide model, e.g. to add tides to an ocean model without tides (such as TOPAZ5) with reader arithmetic:: tides = reader_tpxo.Reader('/path/to/tpxo9', corners=[-15, 40, 55, 86]) o.add_reader([topaz + tides, topaz]) ``topaz + tides`` provides only the variables both readers have (the currents), so ``topaz`` is added again for its other variables. TPXO currents are depth-averaged, so the same tidal current is returned at all depths. The harmonic synthesis follows the OTIS/TMD convention TPXO is distributed for (as pyTMD with corrections='OTIS'): constituent phase is omega * (t - 1992-01-01) + phase0 + u, with nodal factors f and angles u from the lunar node only, computed with pyTMD (which must be installed). Reads the OTIS netCDF velocity file of TPXO9.v1 (``u_tpxo9.v1.nc``: ``ua``/``up`` eastward and ``va``/``vp`` northward velocity amplitude (cm/s) and Greenwich phase lag (degrees) on a regular global lon/lat C-grid). Attributes ---------- .. autoapisummary:: opendrift.readers.reader_tpxo.logger opendrift.readers.reader_tpxo.TPXO_UV_FILE opendrift.readers.reader_tpxo.MAJOR_CONSTITUENTS opendrift.readers.reader_tpxo.OTIS_EPOCH opendrift.readers.reader_tpxo.MJD_OTIS_EPOCH opendrift.readers.reader_tpxo._cache Classes ------- .. autoapisummary:: opendrift.readers.reader_tpxo.HarmonicGrid opendrift.readers.reader_tpxo.Reader Functions --------- .. autoapisummary:: opendrift.readers.reader_tpxo.tidal_phasors opendrift.readers.reader_tpxo._load Module Contents --------------- .. py:data:: logger .. py:data:: TPXO_UV_FILE :value: 'u_tpxo9.v1.nc' .. py:data:: MAJOR_CONSTITUENTS :value: ('m2', 's2', 'n2', 'k2', 'k1', 'o1', 'p1', 'q1') .. py:data:: OTIS_EPOCH .. py:data:: MJD_OTIS_EPOCH :value: 48622.0 .. py:function:: tidal_phasors(time, constituents) f * exp(i * (omega t + phase0 + u)) per constituent at ``time`` (naive UTC datetime), as in pyTMD.predict.ocean_load.time_series with corrections='OTIS'. Multiply by a complex harmonic constant (amp * exp(-i * phase_lag)) and take the real part to get the tide. .. py:class:: HarmonicGrid(ds, amp_var, phase_var, lon_var, lat_var, con_index, corners=(-180, 180, -90, 90), amp_scale=0.01) Complex harmonic constants of one TPXO C-grid component on a regular lon/lat grid, bilinearly interpolated to arbitrary positions. Complex values (not amplitude/phase) are interpolated, so phase wrap-around doesn't matter; land nodes are 0 in TPXO and stay 0. .. py:attribute:: dlon .. py:attribute:: dlat .. py:attribute:: periodic .. py:attribute:: values .. py:method:: interpolate(lon, lat) (nc, n) complex constants at lon/lat (degrees). .. py:data:: _cache .. py:function:: _load(tpxo_dir, constituents, corners) (constituents, u grid, v grid), loaded within corners and cached .. py:class:: Reader(tpxo_dir, constituents=None, corners=(-180, 180, -90, 90)) Bases: :py:obj:`opendrift.readers.basereader.continuous.ContinuousReader` Eastward/northward TPXO barotropic tidal current (m/s). Args: tpxo_dir: folder with the TPXO OTIS netCDF velocity file (u_tpxo9.v1.nc). constituents: list of constituents, e.g. ['m2', 's2']. Default: those of the eight major ones (m2 s2 n2 k2 k1 o1 p1 q1) that the file has. corners: [lonmin, lonmax, latmin, latmax] to load TPXO for, e.g. the simulation domain. Default global (about 300 MB in memory). Common constructor for all readers .. py:attribute:: variables :value: ['x_sea_water_velocity', 'y_sea_water_velocity'] .. py:attribute:: proj4 :value: '+proj=latlong' .. py:attribute:: start_time :value: None .. py:attribute:: end_time :value: None .. py:attribute:: time_step :value: None .. py:attribute:: name :value: 'TPXO tides ()' .. py:method:: get_variables(requested_variables, time=None, x=None, y=None, z=None) Obtain and return values of the requested variables at all positions (x, y, z) closest to given time. Returns: Dictionary with arrays of length len(x) with values at exact positions x, y and z.