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 Trackobjects to seed the currentTrackSetwith.Encapsulates a set of
Trackobjects with helper methods to more easily manipulate them. Other features besides the internal methods are shown below.The
Trackobjects 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
Trackobjects in the currentTrackSetcan be measured by len():>>> len(ts) 100
The
TrackSetclass has the ability to iterate over everyTrackobject in the currentTrackSet:>>> for t in ts: ... print(t.distance_net) ... 1980.999839794037 ... 739.8863745751776
TrackSetobjects can be combined with otherTrackSetobjects via the addition operator:>>> ts_new = ts + ts >>> len(ts_new) 200
-
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 TrackSetto append.Returns: A combined TrackSet.Raises: TypeError: If other is not of type TrackSet.Append a
TrackSetclass 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 Trackclass in the currentTrackSet.Return every points attribute array from each
Trackobject in the currentTrackSetand 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 Trackclass in the currentTrackSet.Return every growths attribute array from each
Trackobject in the currentTrackSetand 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 Trackclass in the currentTrackSet.Return every mortalities attribute array from each
Trackobject in the currentTrackSetand 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 Trackclass in the currentTrackSet.Return every habitat_qualities attribute array from each
Trackobject in the currentTrackSetand 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 Trackclass in the currentTrackSet.Return every worths attribute array from each
Trackobject in the currentTrackSetand 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 Trackclass in the currentTrackSet.Return every weights attribute array from each
Trackobject in the currentTrackSetand 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 Trackclass in the currentTrackSet.Return every biomasses array from each
Trackobject in the currentTrackSetand 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
Trackclass in the currentTrackSet.Return every specified by index extras attribute array from each
Trackobject in the currentTrackSetand 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
Trackobjects from the currentTrackSet.
-
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
Trackobjects 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
Trackobjects 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
Trackobjects 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
Trackobjects 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
Trackobjects 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
Trackobjects 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
Trackobjects which are experiencing a specified biomasses during the tick specified.
-
static
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
Trackobject 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
Trackobject 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_THRESHOLDconstant.
-
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
TrackSetmethods.