Documentation page for utils/funcs.py

Only some functions from this module are documented. The other undocumented functions are intended as private functions, not to be exposed to the user.

Utility functions

Author: guangzhi XU (xugzhi1987@gmail.com) Update time: 2020-07-22 09:27:36.

utils.funcs.get3DEllipse(t, y, x)

Get a binary 3D ellipse structuring element

Parameters:
  • t (int) – ellipse axis length in the t (1st) dimension.
  • y (int) – ellipse axis length in the y (2nd) dimension.
  • x (int) – ellipse axis length in the x (3rd) dimension.
  • that the axis length is half the size of the ellipse (Note) –
  • that dimension. (in) –
Returns:

result (ndarray)

3D binary array, with 1s side the ellipse

defined as (T/t)^2 + (Y/y)^2 + (X/x)^2 <= 1.

utils.funcs.dLatitude(lats, lons, R=6371000, verbose=True)

Return a slab of latitudinal increment (meter) delta_y.

Parameters:
  • lats (ndarray) – 1d array, latitude coordinates in degrees.
  • lons (ndarray) – 1d array, longitude coordinates in degrees.
Keyword Arguments:
 

R (float) – radius of Earth;

Returns:

delta_x (ndarray)

2d array, latitudinal increments.

<var>.

utils.funcs.dLongitude(lats, lons, side='c', R=6371000)

Return a slab of longitudinal increment (meter) delta_x.

Parameters:
  • lats (ndarray) – 1d array, latitude coordinates in degrees.
  • lons (ndarray) – 1d array, longitude coordinates in degrees.
Keyword Arguments:
 
  • side (str) –
    ‘n’: northern boundary of each latitudinal band;
    ’s’: southern boundary of each latitudinal band; ‘c’: central line of latitudinal band;

    —– ‘n’

    /—– ‘c’

    /_______ ‘s’

  • R (float) – radius of Earth.
Returns:

delta_x (ndarray) – 2d array, longitudinal increments.

utils.funcs.readVar(abpath_in, varid)

Read in netcdf variable

Parameters:
  • abpath_in (str) – absolute file path to nc file.
  • varid (str) – id of variable to read.
Returns:

var (TransientVariable) – 4d TransientVariable.

NOTE: deprecated, use netCDF4 instead of CDAT.

utils.funcs.getTimeAxis(times, ntime, ref_time='days since 1900-01-01')

Create a time axis

Parameters:
  • times (list or tuple or array) – array of datetime objs, or strings, giving the time stamps in the format of ‘yyyy-mm-dd HH:MM’. It is assumed to be in chronological order. If None, default to create a dummy time axis, with 6-hourly time step, starting from <ref_time>, with a length of <ntime>.
  • ntime (int) – length of the time axis. If <times> is not None, it is checked to insure that length of <times> equals <ntime>. If <times> is None, <ntime> is used to create a dummy time axis with a length of <ntime>.
Keyword Arguments:
 

ref_time (str) – reference time point. If <times> is not None, used to create the numerical values of the resulant time axis with this reference time. If <times> is None, used to create a dummy time axis with this reference time.

Returns:

result (list)

a list of datetime objs. If <times> is not None,

the datetime objs are using the provided time stamps. Otherwise, it is a new time series, with 6-hourly time step, starting from <ref_time>, with a length of <ntime>.

New in v2.0.