contains TEF framework

class constructorTEF[source]

constructorTEF(inputFile, data_description, **kwargs)

constructorTEF.__init__[source]

constructorTEF.__init__(inputFile, data_description, **kwargs)

Creates a constructor object that is passed to the pyTEF functions.

Args: inputFile (str, xr.Dataset, xr.DataArray): If string is passed, function tries to read an netcdf file, otherwise xarray object can be passed as well. data_description (dict): Describes the data that is read

Raises: IOError: Could not read filename IOError: No filename and invalid xarray object is passed.

Example: data_description = { "lon" : None, "lat" : "yt_ocean", "depth" : "st_ocean", "time" : "time" }

Examples

import xarray as xr
import numpy as np 


# Create random data
lat = np.arange(-180, 180)
lon = 37
depth = np.arange(0, 200)
time = 2
dummy_var = np.zeros((lat.size, depth.size))

ds = xr.Dataset({'dummy': (["lAtiTude", "dePht"], dummy_var)},
                coords = {'lAtiTude': (["lAtiTude"], lat),
                          'dePht': (["dePht"], depth)})

# Create data description

data_description = {
    "lon" : None,
    "lat" : "lAtiTude",
    "depth" : "dePht",
    "time" : None
}    

# Initialize TEF object

tef = constructorTEF(inputFile=ds, 
                     data_description=data_description)
tef.ds
<xarray.Dataset>
Dimensions:  (lat: 360, depth: 200, lon: 1, time: 1)
Coordinates:
  * lat      (lat) int64 -180 -179 -178 -177 -176 -175 ... 175 176 177 178 179
  * depth    (depth) int64 0 1 2 3 4 5 6 7 8 ... 192 193 194 195 196 197 198 199
Dimensions without coordinates: lon, time
Data variables:
    dummy    (time, depth, lat, lon) float64 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0