Documentation page for AR_tracer.py

Functions to compute Hausdorff distance between AR axes pairs and link ARs across time steps to form tracks.

Author: guangzhi XU (xugzhi1987@gmail.com) Update time: 2020-06-05 22:46:19.

class AR_tracer.AR(id, data)

Ojbect representing an AR entity

Hausdorff(lats, lons)

Compute modified Hausdorff distance from the lastest record to given axis

Parameters:
  • lats (ndarray) – 1d array, the target axis’s latitude coordinates.
  • lons (ndarray) – 1d array, the target axis’s longitude coordinates.
Returns:

float – modified Hausdorff distance from this AR to the given axis.

__init__(id, data)
Parameters:
  • id (int) – a numeric id for each AR.
  • data (pandas.DataFrame) – DataFrame storing an AR’s records.
anchor_lats

1d array, get the latitude coordinates from roughly evenly spaced points from the AR axis.

Type:ndarray
anchor_lons

1d array, get the longitude coordinates from roughly evenly spaced points from the AR axis.

Type:ndarray
append(ar)

Add new records to the AR track

backwardHausdorff(lats, lons)

Compute backward Hausdorff distance from the lastest record to given axis

Parameters:
  • lats (ndarray) – 1d array, the target axis’s latitude coordinates.
  • lons (ndarray) – 1d array, the target axis’s longitude coordinates.
Returns:

float – backward Hausdorff distance from this AR to the given axis.

coor

(Nx3) ndarray, (time, lat_centroid, lon_centroid) coordinates of an AR track.

Type:ndarray
duration

track duration in hours.

Type:int
forwardHausdorff(lats, lons)

Compute forward Hausdorff distance from the lastest record to given axis

Parameters:
  • lats (ndarray) – 1d array, the target axis’s latitude coordinates.
  • lons (ndarray) – 1d array, the target axis’s longitude coordinates.
Returns:

float – forward Hausdorff distance from this AR to the given axis.

latest

the AR record of the latest time point in an AR track.

Type:Series
lats

1d array, the latitude coordinates of the AR axis in the latest record in an AR’s track.

Type:ndarray
lons

1d array, the longitude coordinates of the AR axis in the latest record in an AR’s track.

Type:ndarray
rdp_lats

1d array, the latitude coordinates of the simplified AR axis in the latest record in an AR’s track.

Type:ndarray
rdp_lons

1d array, the longitude coordinates of the simplified AR axis in the latest record in an AR’s track.

Type:ndarray
times

sorted time stamps of an AR track.

Type:Series
AR_tracer.filterTracks(tr_list, min_duration, min_nonrelax, verbose=True)

Filter tracks

Parameters:
  • tr_list (list) – list of AR objects, found tracks.
  • min_duration (int) – min duration in hrs to keep a track.
  • min_nonrelax (int) – min number of non-relaxed records in a track to keep a track.
Keyword Arguments:
 

verbose (bool) – print some messages or not.

Returns:

tr_list (list) – list of AR objects, filtered tracks.

Tracks that are filtered:
  • tracks that are too short, controlled by ‘min_duration’
  • tracks that consist of solely relaxed records.
AR_tracer.forwardHausdorff(lats1, lons1, lats2, lons2)

Compute forward Hausdorff distance betweem 2 tracks

Parameters:
  • lats1 (list or 1D array) – latitudes of track1.
  • lons1 (list or 1D array) – longitudes of track1.
  • lats2 (list or 1D array) – latitudes of track2.
  • lons2 (list or 1D array) – longitudes of track2.
Returns:

forward Hausdorff distance in km.

AR_tracer.getAnchors(arr, num_anchors=7)

Get anchor points along from an axis.

Parameters:arr (ndarray) – 1D array from which to sample the anchor points.
Returns:(ndarray) – 1D array of the sampled anchor points from <arr>.
AR_tracer.getDistMatrix(tr_list, newlats, newlons)

Compute distance matrix among track axis anchors

Parameters:
  • tr_list (list) – list of AR objs, existing systems at time t=t.
  • newlats (list or 1D array) – latitudes at t=t+1.
  • newlons (list or 1D array) – longitudes at t=t+1.
Returns:

dists (ndarray)

n*m matrix consisting distances between existing

and new tracks. Rows as new records at tnow, columns as existing tracks.

AR_tracer.matchCenters(tr_list, newrec, time_gap_allow, max_dist_allow, track_scheme='simple', isplot=False, plot_dir=None, verbose=True)

Match and link nearby centers at 2 consecutive time steps

Parameters:
  • tr_list (list) – list of AR objs, existing systems at time t=t.
  • newrec (DataFrame) – new center data at time t=t+1.
  • time_gap_allow (int) – max allowed gap between 2 records, in number of hours.
  • max_dist_allow (float) – max allowed Hausdorff distance allowed between 2 records, in km.
Keyword Arguments:
 
  • track_scheme (str) – tracking scheme. ‘simple’: all tracks are simple
  • 'full' (paths.) – use the network scheme, tracks are connected by their
  • points. (joint) –
  • isplot (bool) – create schematic plot or not.
  • plot_dir (str) – folder to save schematic plot. Only used if isplot=True.
  • verbose (bool) – print some messages or not.
Returns:

tr_list (list)

list of AR objs, ARs with new matching records

appended at the end.

allocated_recs (list): list of ints, ids of new records that are

attributed to existing systems during the process.

Matching is based on geo-distances and uses nearest neighbour strategy.

AR_tracer.plotHD(y1, x1, y2, x2, timelabel=None, linkflag='', ax=None, show=True)

Plot Hausdorff links

Parameters:
  • y1,x1 (ndarray) – 1d array, y, x coordinates of AR axis A.
  • y2,x2 (ndarray) – 1d array, y, x coordinates of AR axis B.
Keyword Arguments:
 
  • timelabel (str or None) – string of the time stamp. If given, plot as subplot title.
  • linkflag (str) – a single char to denote the type of linking, used in generated plot. ‘’ for initial linking, ‘M’ for a merging, ‘S’ for a splitting.
  • ax (plt axis obj) – if not give, create a new axis to plot with.
  • show (bool) – whether to show the figure or not.
AR_tracer.readCSVRecord(abpath_in)

Read in individual AR records from .csv file

Parameters:abpath_in (str) – absolute file path to AR record file.
Returns:ardf (pandas.DataFrame) – record saved in DataFrame.

New in v2.0.

AR_tracer.trackARs(record, time_gap_allow, max_dist_allow, track_scheme='simple', isplot=False, plot_dir=None, verbose=True)

Track ARs at consecutive time points to form tracks

Parameters:
  • record (DataFrame) – AR records at different time slices.
  • time_gap_allow (int) – max allowed gap between 2 records, in number of hours.
  • max_dist_allow (float) – max allowed Hausdorff distance allowed between 2 records, in km.
Keyword Arguments:
 
  • track_scheme (str) – tracking scheme. ‘simple’: all tracks are simple
  • 'full' (paths.) – use the network scheme, tracks are connected by their
  • points. (joint) –
  • isplot (bool) – whether to create schematic plots of linking.
  • plot_dir (str) – folder to save schematic plot.
  • verbose (bool) – print some messages or not.
Returns:

finished_list (list) – list of AR objs. Found tracks.