ILAMB.Variable.Variable

class ILAMB.Variable.Variable(**keywords)[source]

A class for managing variables and their analysis.

There are two ways to create a Variable object. Because python does not support multiple constructors, we will use keyword arguments so that the users intent may be captured. The first way to specify a Variable is by loading a netCDF4 file. You can achieve this by specifying the ‘filename’ and ‘variable_name’ keywords. The second way is to use the remaining keyword arguments to specify data arrays directly. If you use the second way, you must specify the keywords ‘data’ and ‘unit’. The rest are truly optional and depend on the nature of your data.

Parameters
  • filename (str, optional) – Name of the netCDF4 file from which to extract a variable

  • variable_name (str, optional) – Name of the variable to extract from the netCDF4 file

  • data (numpy.ndarray, optional) – The array which contains the data which constitutes the variable

  • unit (str, optional) – The unit of the input data

  • name (str, optional) – The name of the variable, will be how it is saved in the netCDF4 file

  • time (numpy.ndarray, optional) – a 1D array of times in days since 1850-01-01 00:00:00

  • time_bnds (numpy.ndarray, optional) – a 2D array of time bounds in days since 1850-01-01 00:00:00

  • lat (numpy.ndarray, optional) – a 1D array of latitudes of cell centroids

  • lon (numpy.ndarray, optional) – a 1D array of longitudes of cell centroids

  • area (numpy.ndarray, optional) – a 2D array of the cell areas

  • ndata (int, optional) – number of data sites this data represents

  • alternate_vars (list of str, optional) – a list of alternate acceptable variable names

  • depth_bnds (numpy.ndarray, optional) – a 2D array representing the boundaries of the cells in the vertical dimension

Examples

You can initiate a Variable by specifying the data directly.

>>> lat = np.linspace(- 90, 90, 91)
>>> lon = np.linspace(-180,180,181)
>>> data = np.random.rand(91,181)
>>> v = Variable(name="some_variable",unit="some_unit",lat=lat,lon=lon,data=data)

Or you can initiate a variable by extracting a specific field from a netCDF4 file.

>>> v = Variable(filename="some_netcdf_file.nc",variable_name="name_of_var_to_extract")

Variable.accumulateInTime()

For each time interval, accumulate variable from the beginning.

Variable.annualCycle()

Computes mean annual cycle information (climatology) for the variable.

Variable.bias(var)

Computes the bias between a given variable and this variable.

Variable.coarsenInTime(intervals[, window])

Compute the mean function value in each of the input intervals.

Variable.convert(unit[, density, molar_mass])

Convert the variable to a given unit.

Variable.correlation(var, ctype[, region])

Computes the correlation between two variables.

Variable.extractDatasites(lat, lon)

Extracts a variable at sites defined by a set of latitude and longitude.

Variable.integrateInDepth(**keywords)

Integrates the variable over a given layer limits.

Variable.integrateInSpace([region, mean, …])

Integrates the variable over a given region.

Variable.integrateInTime(**keywords)

Integrates the variable over a given time period.

Variable.interannualVariability()

Computes the interannual variability.

Variable.interpolate([time, lat, lon, …])

Use nearest-neighbor interpolation to interpolate time and/or space at given values.

Variable.nbytes()

Estimate the memory usage of a variable in bytes.

Variable.phaseShift(var[, method])

Computes the phase shift between a variable and this variable.

Variable.plot(ax, **keywords)

Plots the variable on the given matplotlib axis.

Variable.rms()

Computes the RMS of this variable.

Variable.rmse(var)

Computes the RMSE between a given variable and this variable.

Variable.siteStats([region, weight, intabs])

Computes the mean and standard deviation of the variable over all data sites.

Variable.spatialDifference(var)

Computes the point-wise difference of two spatially defined variables.

Variable.spatialDistribution(var[, region])

Evaluates how well the input variable is spatially distributed relative to this variable.

Variable.timeOfExtrema([etype])

Returns the time of the specified extrema.

Variable.toNetCDF4(dataset[, attributes, group])

Adds the variable to the specified netCDF4 dataset.

Variable.trim([lat, lon, t, d])

Trim away a variable in space/time in place.

Variable.variability([mean])

Computes the variability of the variable.