API - pytracks.track Module

This is the main module of pytracks which wraps data descibing movement tracks. Please see the examples included to learn how to use it.

Note

In the documentation below a few private methods (methods which begin with an underscore) are documented. Most people can ignore these as they are only useful if the developer wishes to override them. (Which I wouldn’t advise as they work perfectly well!)

TrackSet

class pytracks.track.TrackSet(tracks)
Parameters:tracks (list) – The Track objects to seed the current TrackSet with.

Encapsulates a set of Track objects with helper methods to more easily manipulate them. Other features besides the internal methods are shown below.

The Track objects encapsulated can also be accessed by specifying an index after the object:

>>> ts
<pytracks.track.TrackSet object at 0x7f9f4eb9ce10>
>>> ts.tracks[0]
<pytracks.track.Track object at 0x7f9f3f8b5908>
>>> ts[0]
<pytracks.track.Track object at 0x7f9f3f8b5908>

The number of Track objects in the current TrackSet can be measured by len():

>>> len(ts)
100

The TrackSet class has the ability to iterate over every Track object in the current TrackSet:

>>> for t in ts:
...     print(t.distance_net)
...
1980.999839794037
...
739.8863745751776

TrackSet objects can be combined with other TrackSet objects via the addition operator:

>>> ts_new = ts + ts
>>> len(ts_new)
200
tracks

A list which composes of multiple Track objects in the current TrackSet.

static _point_in_rectangle(point, p1, p2)
Parameters:
  • point (tuple) – The point to be tested.
  • p1 (tuple) – The first point of the rectangle.
  • p2 (tuple) – The other point of the rectangle.
Returns:

True/False if the point is within the defined rectangle.

An internal method which tests if a point is within a defined rectangle.

static _point_in_circle(point, center, radius)
Parameters:
  • point (tuple) – The point to be tested.
  • center (tuple) – The center point of the desired circle.
  • radius (float) – The radius of the desired circle.
Returns:

True/False if the point is within the defined circle.

An internal method which tests if a point is within a defined circle.

classmethod append(other)
Parameters:other (TrackSet) – The other TrackSet to append.
Returns:A combined TrackSet.
Raises:TypeError: If other is not of type TrackSet.

Append a TrackSet class to the current one.

classmethod points(f)
Parameters:f (method) – The method to run on each attribute array. Default returns the whole array.
Returns:A list of values for every Track class in the current TrackSet.

Return every points attribute array from each Track object in the current TrackSet and optionally run a method on each attribute array.

classmethod growths(f)
Parameters:f (method) – The method to run on each attribute array. Default returns the whole array.
Returns:A list of values for every Track class in the current TrackSet.

Return every growths attribute array from each Track object in the current TrackSet and optionally run a method on each attribute array.

classmethod mortalities(f)
Parameters:f (method) – The method to run on each attribute array. Default returns the whole array.
Returns:A list of values for every Track class in the current TrackSet.

Return every mortalities attribute array from each Track object in the current TrackSet and optionally run a method on each attribute array.

classmethod habitat_qualities(f)
Parameters:f (method) – The method to run on each attribute array. Default returns the whole array.
Returns:A list of values for every Track class in the current TrackSet.

Return every habitat_qualities attribute array from each Track object in the current TrackSet and optionally run a method on each attribute array.

classmethod worths(f)
Parameters:f (method) – The method to run on each attribute array. Default returns the whole array.
Returns:A list of values for every Track class in the current TrackSet.

Return every worths attribute array from each Track object in the current TrackSet and optionally run a method on each attribute array.

classmethod weights(f)
Parameters:f (method) – The method to run on each attribute array. Default returns the whole array.
Returns:A list of values for every Track class in the current TrackSet.

Return every weights attribute array from each Track object in the current TrackSet and optionally run a method on each attribute array.

classmethod biomasses(f)
Parameters:f (method) – The method to run on each attribute array. Default returns the whole array.
Returns:A list of values for every Track class in the current TrackSet.

Return every biomasses array from each Track object in the current TrackSet and optionally run a method on each attribute array.

classmethod extras(element_id, f)
Parameters:
  • element_id (int) – The extras id desired.
  • f (method) – The method to run on each attribute array. Default returns the whole array.
Returns:

A list of values for every Track class in the current TrackSet.

Return every specified by index extras attribute array from each Track object in the current TrackSet and optionally run a method on each attribute array.

classmethod get_tracks_id(indexes)
Parameters:indexes (list of ints.) – A list of indexes. Indexes must refer to Tracks stored in the current TrackSet.
Returns:A new TrackSet.

Fetch specific Tracks from the current TrackSet.

classmethod get_tracks_random(num)
Parameters:num (int) – Number to randomly fetch. Default is 1. Must not be larger than the size of the TrackSet.
Returns:A new TrackSet.

Fetch a random number of Track objects from the current TrackSet.

classmethod get_tracks_circle(center, radius, index)
Parameters:
  • center (tuple) – A tuple which is of the form (x, y).
  • radius (float) – The search radius.
  • index (int) – Which tick to look at. Default is (-1), which is the last tick.
Returns:

A new TrackSet.

Get the Track objects which are in the area specified during the tick specified.

classmethod get_tracks_rectangle(p1, p2, index)
Parameters:
  • p1 (tuple) – The first point of the rectangle.
  • p2 (tuple) – The other point of the rectangle.
  • index (int) – Which tick to look at. Default is (-1), which is the last tick.
Returns:

A new TrackSet.

Get the Track objects which are in the area specified during the tick specified.

classmethod get_tracks_mortality(min_mortality, max_mortality, index)
Parameters:
  • min_mortality (float) – The minimum mortality to search for. Default is 0.
  • max_mortality (float) – The maximum mortality to search for. Default is 1.
  • index (int) – Which tick to look at. Default is -1, which is the last tick.
Returns:

A new TrackSet.

Raises:

ValueError: If the minimum specified is greater than the maximum specified.

Get the Track objects which are experiencing a specified range of mortalities during the tick specified.

classmethod get_tracks_growth(min_growth, max_growth, index)
Parameters:
  • min_growth (float) – The minimum growth to search for. Default is 0.
  • max_growth (float) – The maximum growth to search for. Default is 1.
  • index (int) – Which tick to look at. Default is -1, which is the last tick.
Returns:

A new TrackSet.

Raises:

ValueError: If the minimum specified is greater than the maximum specified.

Get the Track objects which are experiencing a specified range of growths during the tick specified.

classmethod get_tracks_growth_mortality(min_growth, max_growth, min_mortality, max_mortality, index)
Parameters:
  • min_growth (float) – The minimum growth to search for. Default is 0.
  • max_growth (float) – The maximum growth to search for. Default is 1.
  • min_mortality (float) – The minimum mortality to search for. Default is 0.
  • max_mortality (float) – The maximum mortality to search for. Default is 1.
  • index (int) – Which tick to look at. Default is -1, which is the last tick.
Returns:

A new TrackSet.

Raises:

ValueError: If the minimum specified is greater than the maximum specified.

Get the Track objects which are experiencing a specified range of mortalities and growths during the tick specified.

classmethod get_tracks_habitat_quality(min_quality, max_quality, index)
Parameters:
  • min_quality (float) – The minimum habitat quality to search for. Default is -1.
  • max_quality (float) – The maximum habitat quality to search for. Default is 1.
  • index (int) – Which tick to look at. Default is -1, which is the last tick.
Returns:

A new TrackSet.

Raises:

ValueError: If the minimum specified is greater than the maximum specified.

Get the Track objects which are experiencing a specified habitat qualities during the tick specified.

classmethod get_tracks_biomass(min_biomass, max_biomass, index)
Parameters:
  • min_biomass (float) – The minimum biomass to search for.
  • max_biomass (float) – The maximum biomass to search for.
  • index (int) – Which tick to look at. Default is -1, which is the last tick.
Returns:

A new TrackSet.

Raises:

ValueError: If the minimum specified is greater than the maximum specified.

Get the Track objects which are experiencing a specified biomasses during the tick specified.

Track

class pytracks.track.Track

Wraps the data describing the lifetime of a single Track.

The data encapsulated can also be accessed as if the current Track object was the extra data list itself by specifying an index:

>>> t
<pytracks.track.Track object at 0x7f9f3f8b5908>
>>> max(t.extra[1])
6.2800000000000002
>>> max(t[1])
6.2800000000000002

The number of ticks the current Track object holds can be measured by len():

>>> len(t)
864
SURVIVAL_THRESHOLD

A constant which defines the threshold of if the individual is still alive.

ids

The ids column.

x

The x coordinate for each tick.

y

The x coordinate for each tick.

growths

The growth attribute for each tick.

mortalities

The mortality attribute for each tick.

worths

The worth attribute for each tick.

weights

The weight attribute for each tick.

distances

The Euclidean distances between each tick.

distance_net

The net Euclidean distance travelled.

distance_total

The total Euclidean distance travelled.

points

The coordinate of each tick.

habitat_qualities

The habitat_quality attribute for each tick.

biomasses

The biomass attribute for each tick.

survived

If the individual survived to the end of its lifetime.

lifetime

The tick the individual went below the SURVIVAL_THRESHOLD constant.

static distance(p1, p2)
Parameters:
  • p1 (tuple) – The first point.
  • p2 (tuple) – The second point.
Returns:

The Euclidean distance between the two points.

Calculate the Euclidean distance between two points.

Extra Methods

pytracks.track.dummy(o)
Parameters:o (object) – An object.

A method to simply return the object itself. Used to shorten code in the TrackSet methods.

pytracks.track.first(l)
Parameters:l (list) – A list.

A method to simply return the first element of the passed list. Useful in various TrackSet methods.

pytracks.track.last(l)
Parameters:l (list) – A list.

A method to simply return the last element of the passed list. Useful in various TrackSet methods.