Track#
- class tracklib.core.Track.Track(list_of_obs=None, user_id=0, track_id=0, base=None)[source]#
Bases:
object
Representation of a GPS track.
Methods:
__init__
([list_of_obs, user_id, track_id, base])Takes a (possibly empty) list of points as input
copy
()TODO
__str__
()TODO
getSRID
()TODO
TODO
setTimeZone
(zone)TODO
convertToTimeZone
(zone)TODO
duration
()TODO
frequency
([mode])Average frequency in Hz (resp.
interval
([mode])Inverse of average frequency in pt/sec (resp.
toECEFCoords
([base])TODO
toENUCoords
([base])TODO
toGeoCoords
([base])TODO
toProjCoords
(srid)TODO
toImageCoords
(P1, P2, p1, p2)Function to convert 2D coordinates (GEO or ENU) into image local coordinates Input: two points p1, p2 (image coordinates), P1, P2 (track coordinate system) p1 and p2 are provided as lists.
Function to convert track to ENUCoords if it is in GeoCoords.
size
()TODO
TODO
TODO
TODO
getObs
(i)TODO
getX
([i])TODO
getY
([i])TODO
getZ
([i])TODO
getT
([i])TODO
getTimestamps
([i])TODO
TODO
TODO
getMinX
()TODO
getMinY
()TODO
getMinZ
()TODO
getMaxX
()TODO
getMaxY
()TODO
getMaxZ
()TODO
TODO
TODO
bbox
()TODO
shiftTo
(idx_point[, new_coords])makeOdd
()TODO
makeEven
()TODO
loop
([add])hasAnalyticalFeature
(af_name)TODO
getAnalyticalFeatures
(af_names)TODO
getAnalyticalFeature
(af_name)getObsAnalyticalFeatures
(af_names, i)TODO
getObsAnalyticalFeature
(af_name, i)TODO
setObsAnalyticalFeature
(af_name, i, val)TODO
TODO
setXFromAnalyticalFeature
(af_name)TODO
setYFromAnalyticalFeature
(af_name)TODO
setZFromAnalyticalFeature
(af_name)TODO
setTFromAnalyticalFeature
(af_name)TODO
setOrder
([name, start])TODO
sort
()TODO
isSorted
()TODO
addObs
(obs)TODO
insertObs
(obs[, i])Adds a new observation at the specified position of the track.
TODO
setObs
(i, obs)TODO
setObsList
(list_of_obs)TODO
removeObs
(arg)TODO
TODO
TODO
popObs
(idx)TODO
removeObsList
(tab)TODO
setUid
(used_id)TODO
setTid
(trace_id)TODO
TODO
removeObsDup
([et, ep])TODO
removeTpsDup
([et])removePosDup
([ep])TODO
print
([n, af_names])TODO
summary
()TODO
length
()Total length of track
toWKT
()Transforms track into WKT string
extract
(id_ini, id_fin)Extract between two indices from a track
extractSpanTime
(tini[, tfin])Extract span time from a track
addSeconds
(sec_number)Adds seconds to timestamps in track sec_number: number of seconds to add (may be < 0)
roundTimestamps
([unit])Rounds timestamps in a track unit: round timestamps up to unit seconds (default = 1)
addAnalyticalFeature
(algorithm[, name])Execute l'algo de l'AF.
createAnalyticalFeature
(name[, val_init])Ajout de l'AF dans le dico et dans le features de Obs.
updateAnalyticalFeature
(name, new_val)Update values of an AF.
removeAnalyticalFeature
(name)TODO
cleanDuplicates
([code])TODO
op
(operator[, arg1, arg2, arg3])Shortcut for
operate()
functionoperate
(operator[, arg1, arg2, arg3])General function to perform computations on analytical features.
biop
(track, expression)Shortcut for
bioperate()
functionbioperate
(track, expression)Algebraic operation on 2 tracks.
reverse
()Return a reversed track (based on index)
resample
([delta, algo, mode, npts, factor])Resampling a track with linear interpolation
smooth
([width])TODO
incrementTime
([dt, offset])Add 1 sec to each subsequent record.
mapOn
(reference, TP1[, TP2, init, ...])Geometric affine transformation to align two tracks with different coordinate systems.
noise
([sigma, kernel, force, cycle])TODO
plotAsMarkers
([size, frg, bkg, sym_frg, ...])TODO
plotEllipses
([sym, factor, af, append, v])Plot track uncertainty (as error ellipses) Input track must contain an AF with (at least) a 2 x 2 covariance matrix.
plot
([sym, type, af_name, cmap, append, ...])Method to plot a track (short cut from Plot) Append: - True : append to the current plot - False: create a new plot - Ax : append to the fiven ax object # ---------------------------------------------------- Output: Ax object (may be input into append parameter)
estimate_speed
([kernel])Compute and return speed for each points 2nd order time centered time finite difference if raw speeds are required.
getSpeed
()TODO
TODO
query
(cmd)Query observations in a track with SQL-like commands.
rotate
(theta)TODO
rotate3D
(R)TODO
scale
(h)TODO
scale3D
(h[, center])TODO
translate
(tx, ty[, tz])TODO
symmetrize
(dim[, val])TODO
removeIdleEnds
(parameter[, mode])Removal of idle points at the begining or end of track
- __init__(list_of_obs=None, user_id=0, track_id=0, base=None)[source]#
Takes a (possibly empty) list of points as input
- frequency(mode='temporal')[source]#
Average frequency in Hz (resp. m/pt) for temporal (resp. spatial) mode
- Return type
float
- interval(mode='temporal')[source]#
Inverse of average frequency in pt/sec (resp. pt/m) for temporal (resp. spatial) mode
- Return type
float
- toImageCoords(P1, P2, p1, p2)[source]#
Function to convert 2D coordinates (GEO or ENU) into image local coordinates Input: two points p1, p2 (image coordinates), P1, P2 (track coordinate system) p1 and p2 are provided as lists. P1 and P2 are GeoCoords or ENUCoords.
- toENUCoordsIfNeeded()[source]#
Function to convert track to ENUCoords if it is in GeoCoords. Returns None if no transformation operated, and returns used reference point otherwise
- __transmitAF(track)#
TODO
- __removeObsById(i)#
TODO
- __removeObsByTimestamp(tps)#
TODO
- __removeObsListById(tab_idx)#
TODO
- __removeObsListByTimestamp(tab_tps)#
TODO
- __getInsertionIndex(timestamp)#
TODO
- extract(id_ini, id_fin)[source]#
Extract between two indices from a track
- Parameters
id_ini (
int
) – Initial index of extractionid_fin (
int
) – final index of extraction
- Retun
TODO
- Return type
- extractSpanTime(tini, tfin=None)[source]#
Extract span time from a track
tini: Initial time of extraction tfin: final time of extraction
- addSeconds(sec_number)[source]#
Adds seconds to timestamps in track sec_number: number of seconds to add (may be < 0)
- roundTimestamps(unit=1)[source]#
Rounds timestamps in a track unit: round timestamps up to unit seconds (default = 1)
- __controlName()#
TODO
- addAnalyticalFeature(algorithm, name=None)[source]#
Execute l’algo de l’AF. L’AF est déjà dans le dico, dans les features de Obs et initialisé.
- createAnalyticalFeature(name, val_init=0.0)[source]#
Ajout de l’AF dans le dico et dans le features de Obs. Initialise tous les obs.
- __compare(k1, k2, code)#
TODO
- op(operator, arg1=None, arg2=None, arg3=None)[source]#
Shortcut for
operate()
function- Parameters
operator – TODO
arg1 – TODO
arg2 – TODO
arg3 – TODO
- Returns
TODO
- operate(operator, arg1=None, arg2=None, arg3=None)[source]#
General function to perform computations on analytical features.
Case 1 : operator and operand listed separately
operator : to be selected in
Operator
classUnary void operator : arg2 = F(arg1), arg1, arg2 must be provided
Binary void operator : arg3 = F(arg1, arg2)
Unary operator : F(arg1), arg1 must be provided
Binary operator : F(arg1, arg2), arg1, arg2 must be provided
Note that arg2 may be an AF name or a scalar value. When output AF name is not provided, it is automatically set as the first AF input in the formula. AF “x”, “y”, “z”, “t”, “timestamp” and “idx” are right away availables as “virtual” analytical features.
Case 2 : operator and operand listed in an algebraic expression
arg1 defines the algebraic expression. If this expression contains ‘=’ sign, then output is registered as an AF in track, with name defined by the left-hand side of arg1. For example :
>>> track.operate("P=X+Y")
performs the sum of AFs X and Y, and returns the result as an AF named P in track.
Available operators : +, -, /, *, ^ in scalar and AF versions.
Available functions : almost all those listed in Operator class
Functions are expressed with
'{}'
. E.g:>>> track.operate("P=LOG{X}")
Special shorthand functions: D for differentiation, I for integration D2 for second-order differentiation and >> (resp. <<) for advance (resp. delay) scalar operators. E.g:
>>> track.operate("v=3.6*D{s}/D{t}")
performs speed computation (in km/h), provided that curvilinear abscissa s is already definedinside track. It is equivalent to the somehow more sophisticated following version with delay operator:
>>> track.operate("v=3.6*(s-(s>>1))/(t-(t>>1))")
It is possible to add external identificator to the computations by using passing a dictionnary of variables in arg2. For example, to divide an AF A in a track by a (beforehand unknown) variable var:
>>> track.operate("A=A/factor", {'factor' : var}])
- Parameters
operator – TODO
arg1 – TODO
arg2 – TODO
arg3 – TODO
- Returns
TODO
- biop(track, expression)[source]#
Shortcut for
bioperate()
function
- bioperate(track, expression)[source]#
Algebraic operation on 2 tracks.
If expression contains a left hand side AF, it is added to self track. Self track and second track may have same name AF. Any AF referring to to the second track must be terminated with single ° character.
For example :
>>> t1.bioperate(t2, "a=b°+c")
adds 1st track’s AF c with 2nd track’s AF b and the result a is stored in 1st track AF a.
- reverse()[source]#
Return a reversed track (based on index)
Important: track may not be valid for some other functions Used mostly to simplify backward kalman filter formulation
- resample(delta=None, algo=1, mode=1, npts=None, factor=1)[source]#
Resampling a track with linear interpolation
Resampling a track with linear interpolation delta: interpolation interval
(time in sec if temporal mode is selected, space in meters if spatial).
npts = number of points If none of delta and npts are specified, the track is resampled regularly with the same number of points * factor. If both are specified, priority is given to delta.
Available modes are:
MODE_SPATIAL (mode=1)
MODE_TEMPORAL (mode=2)
Algorithm:
ALGO_LINEAR (algo=1)
ALGO_THIN_SPLINE (algo=2)
ALGO_B_SPLINES (algo=3)
ALGO_GAUSSIAN_PROCESS (algo=4)
In temporal mode, argument may be:
an integer or float: interval in seconds
a list of timestamps where interpolation should be computed
a reference track
- incrementTime(dt=1, offset=0)[source]#
Add 1 sec to each subsequent record. Use incrementTime to get valid timestamps sequence when timestamps are set as default date on 1970/01/01 00:00:00 for example
- mapOn(reference, TP1, TP2=[], init=[], N_ITER_MAX=20, mode='2D', verbose=True)[source]#
Geometric affine transformation to align two tracks with different coordinate systems.
Deprecated since version 1.0.0: TODO: Check if is really deprecated
For “2D” mode, coordinates must be
core.Coords.ENUCoords
orcore.Coords.GeoCoords
. For “3D” mode, any type of coordinates is valid. In general, it is recommended to avoid usage of non-metriccore.Coords.GeoCoords
coordinates for mapping operation, since it is relying on an isotropic error model.Inputs:
reference: another track we want to align on or a list of points
TP1: list of tie points indices (relative to track self)
TP2: list of tie points indices (relative to track)
mode: could be “2D” (default) or “3D” if TP2 is not specified, it is assumed equal to TP1.
TP1 and TP2 must have same size. Adjustment is performed with least squares. The general transformation from point X to point X’ is provided below:
\[X' = kRX + T\]with: \(k\) a positive real value, \(R\) a 2D or 3D rotation matrix and \(T\) a 2D or 3D translation vector.
Transformation parameters are returned in standard output in the following format: [theta, k, tx, ty] (theta in radians) Track argument may also be replaced ny a list of points. Note that mapOn does not handle negative determinant (symetries not allowed)
- plotAsMarkers(size=8, frg='k', bkg='w', sym_frg='+', sym_bkg='o', type=None, append=True, v=None)[source]#
TODO
- plotEllipses(sym='r-', factor=3, af=None, append=True, v=None)[source]#
Plot track uncertainty (as error ellipses) Input track must contain an AF with (at least) a 2 x 2 covariance matrix. If this matrix has dim > 2, first two dimensions are arbitrarily considered
- plot(sym='k-', type='LINE', af_name='', cmap=-1, append=True, label=None, pointsize=5, v=None)[source]#
Method to plot a track (short cut from Plot) Append:
True : append to the current plot
False: create a new plot
Ax : append to the fiven ax object
# —————————————————- Output:
Ax object (may be input into append parameter)
af_name: test si isAFTransition
- estimate_speed(kernel=None)[source]#
Compute and return speed for each points 2nd order time centered time finite difference if raw speeds are required. If kernel is specified smoothed speed estimation is computed.
- __condition(operator, val2)#
TODO
- query(cmd)[source]#
Query observations in a track with SQL-like commands.
Output depends on the
SELECT
clause:If
SELECT *
then output is a copied track of the original track (with all its AF hopefully)If
SELECT f1, f2... fp
, then output is a (p x n)-dimensional array, with p = number of fields queried and n = number of observations selected by the WHERE conditions.If
SELECT AGG1(f1), AGG2(f2)... AGGp(fp)
, with AGG1, AGG2,.. AGGp, a set of p aggregators, then output is a p-dimensional array, with on value for each aggregatorIf
SELECT AGG(f)
, then output is the floating point value returned by the operator.
Note that operators take as input only analytical feature names. Therefore,
SELECT COUNT(*)
syntax is not allowed and must be replaced equivalently bySELECT COUNT(f)
with any AF name f.General rules:
Only
SELECT
andWHERE
keywords (SET
andDELETE
available soon)All analytical features + x, y, z, t, and timestamp are available as fields
Fields are written without quotes. They must not contain blank spaces
“t” is time as integer in seconds since 1970/01/01 00:00:00, and “timestamp” is
core.GPSTime.GPSTime
objectBlank space must be used between every other words, symbols and operators
WHERE
clause may contain as many conditions as needed, separated byOR
/AND
key wordsParenthesis are not allowed within
WHERE
clause. Use boolean algebra rules to reformulate query without parenthesis: e.g.A AND (B OR C) = A AND B OR A AND C
. Or use successive queries.Each condition must contain exactly 3 parts (separated by blank spaces) in this exact order:
the name of an analytical feature to test
a comparison operator among >, <, >=, <=, ==, != and LIKE (with % in str and timestamps)
a threshold value which is automatically casted to the type of the AF given in (1). Intended types accepted are:
int
,float
,str
,bool
andcore.ObsTime.ObsTime
. Whencore.ObsTime.ObsTime
is used as a threshold value, eventhough it may contain 2 parts (date and time), it must not be enclosed within quotes. For boolean, “1”, “T” and “TRUE” are considered as logical True, all other values are considered as False.
Important: no computation allowed in
WHERE
conditions. E.g. “…WHERE z-2 > 10
” not allowedAvailable aggregators: all unary operators as described in *
core.Operator.Operator
, exceptcore.Operator.Mse
Capital letters must be used for SQL keywords
SELECT, WHERE, AND, OR
and aggregator
- Parameters
cmd (
str
) – TODO- Return type
list
[Any
]- Returns
TODO
- __makeRPN()#
TODO
- __applyOperation(op1, op2, operator, temp_af_counter)#
TODO
- __evaluateRPN(expression, external=[])#
TODO
- __convertReflexOperator()#
TODO
- __unaryOp()#
TODO
- __specialOpChar()#
TODO
- __prime()#
TODO
- __double_prime()#
TODO
- __evaluate(expression, external=[])#
TODO