Miscellanea

Various helper functions

octant.misc.calc_all_dens(tr_obj, lon2d, lat2d, subsets=None, density_types=['point', 'track', 'genesis', 'lysis'], **kwargs)[source]

Calculate all types of cyclone density for subsets of TrackRun.

Parameters
  • lon2d (numpy.ndarray) – 2D array of longitudes

  • lat2d (numpy.ndarray) – 2D array of latitudes

  • subsets (list, optional) – Subsets of TrackRun to process. By default, all subsets are processed.

  • density_types (list, optional) – Types of cyclone density

  • **kwargs (dict) – Keyword arguments passed to octant.core.TrackRun.density(). Should not include subset and by keywords, because they are passed separately.

Returns

da – 4d array with dimensions (subset, dens_type, latitude, longitude)

Return type

xarray.DataArray

octant.misc.bin_count_tracks(tr_obj, start_year, n_winters, by='M')[source]

Take octant.TrackRun and count cyclone tracks by month or by winter.

Parameters
Returns

counter – Binned counts of shape (N,)

Return type

numpy.ndarray

octant.misc.check_by_mask(ot, trackrun, lsm, lmask_thresh=1, dist=50.0, time_frac=0.5, check_domain_bounds=True, r_planet=6371009.0)[source]

Check how close the OctantTrack is to masked points.

Check if the given track spends less than time_frac of its lifetime within dist away from the land or domain boundaries (if check_domain_bounds is True).

This function can be passed to octant.core.TrackRun.classify() to filter through cyclone tracks.

Parameters
  • ot (octant.core.OctantTrack) – Cyclone track to check

  • trackrun (octant.core.TrackRun) – (parent) track run instance to get lon/lat boundaries if present

  • lsm (xarray.DataArray) – Two-dimensional land-sea mask

  • lmask_thresh (float, optional) – Threshold of lsm values, for flexible land-mask filtering

  • dist (float, optional) – distance in km, passed to mask_tracks() function

  • time_frac (float, optional) – Threshold for track’s lifetime (0-1)

  • check_domain_bounds (bool, optional) – If true, include domain boundary (taken from TrackRun.conf if available) in the mask

  • r_planet (float, optional) – Radius of the planet in metres Default: EARTH_RADIUS

Returns

flag – The track is far away the land mask or from the boundaries.

Return type

bool

Examples

>>> from octant.core import TrackRun
>>> import xarray as xr
>>> land_mask = xr.open_dataarray("path/to/land/mask/file")
>>> tr = TrackRun("path/to/directory/with/tracks/")
>>> random_track = tr.data.loc[123]
>>> check_by_mask(random_track, tr, land_mask, lmask_thresh=0.5)
True
octant.misc.check_far_from_boundaries(ot, lonlat_box, dist, r_planet=6371009.0)[source]

Check if track is not too close to boundaries.

Parameters
  • ot (octant.core.OctantTrack) – Individual cyclone-track object

  • lonlat_box (list) – Boundaries of longitude-latitude rectangle (lon_min, lon_max, lat_min, lat_max) Note that the order matters!

  • dist (float) – Minimum distance from a boundary in kilometres

  • r_planet (float, optional) – Radius of the planet in metres Default: EARTH_RADIUS

Returns

result – True if track is not too close to boundaries

Return type

bool

Examples

>>> from octant.core import TrackRun
>>> tr = TrackRun("path/to/directory/with/tracks/")
>>> random_track = tr.data.loc[123]
>>> check_far_from_boundaries(random_track, lonlat_box=[-10, 20, 60, 80], dist=250)
True
>>> from functools import partial
>>> conds = [
        ('bound', [partial(check_far_from_boundaries, lonlat_box=tr.conf.extent, dist=100)])
    ]  # construct a condition for tracks to be within the boundaries taken from the TrackRun
>>> tr.classify(conds)
>>> tr.cat_labels
['bound']

See also

octant.core.OctantTrack.within_rectangle(), octant.utils.check_by_mask()