ptrail.core package

Submodules

ptrail.core.Datasets module

The Datasets.py module is used to load built-in datasets to variables. All the datasets loaded are stored and returned in a PTRAILDataFrame Currently, the library has the following datasets available to use:

1. Atlantic Hurricanes Dataset
2. Traffic Dataset (a smaller subset)
3. Geo-life Dataset (a smaller subset)
4. Seagulls Dataset
5. Ships Dataset (a smaller subset)
6. Starkey Animals Dataset
7. Starkey Habitat Dataset (accompanies the starkey dataset)

The Starkey Habitat Dataset is not loaded is not loaded into a PTrailDataframe since it is not a movement dataset and rather contains contextual information about the starkey habitat. It is rather loaded into a pandas dataframe and returned as is.

Authors: Yaksh J Haranwala
class ptrail.core.Datasets.Datasets[source]

Bases: object

static load_geo_life_sample()[source]

Load the Geo-Life Sample dataset into the PTRAILDataFrame and return it.

Returns

The geo-life sample dataset loaded into a PTrailDataFrame.

Return type

PTRAILDataFrame

static load_hurricanes()[source]

Load the Atlantic Hurricane dataset into the PTRAILDataFrame and return it.

Returns

The atlantic hurricanes dataset loaded into a PTrailDataFrame.

Return type

PTRAILDataFrame

static load_seagulls()[source]

Load the Sea-Gulls dataset into the PTRAILDataFrame and return it.

Returns

The seagulls dataset loaded into a PTrailDataFrame.

Return type

PTRAILDataFrame

static load_ships()[source]

Load the Sea-Gulls dataset into the PTRAILDataFrame and return it.

Returns

The Ships dataset loaded into a PTrailDataFrame.

Return type

PTRAILDataFrame

static load_starkey()[source]

Load the Starkey dataset into the PTRAILDataFrame and return it.

Returns

The Starkey dataset loaded into a PTrailDataFrame.

Return type

PTRAILDataFrame

static load_starkey_habitat()[source]

Load the Starkey dataset into a pandas dataframe and return it.

Returns

The Starkey habitat dataset.

Return type

PTRAILDataFrame

static load_traffic_data()[source]

Load the Traffic dataset into the PTRAILDataFrame and return it.

Returns

The traffic dataset loaded into a PTrailDataFrame.

Return type

PTRAILDataFrame

ptrail.core.TrajectoryDF module

The TrajectoryDF module is the main module containing the PTRAILDataFrame Dataframe for storing the Trajectory Data with PTRAIL Library. The Dataframe has certain restrictions on what type of data is mandatory in order to be stored as a PTRAILDataFrame which is mentioned in the documentation of the constructor.

Authors: Yaksh J Haranwala, Salman Haidri
class ptrail.core.TrajectoryDF.PTRAILDataFrame(*args: Any, **kwargs: Any)[source]

Bases: pandas.DataFrame

__init__(data_set: Union[pandas.DataFrame, List, Dict], latitude: str, longitude: str, datetime: str, traj_id: str, rest_of_columns: Optional[List[str]] = None)[source]

Construct a trajectory dataframe to store and represent the Trajectory Data.

Note

The mandatory columns in the dataset are:
1. DateTime
2. Trajectory ID
3. Latitude
4. Longitude
rest_of_columns makes sure that if the data_set is a list, it has appropriate headers that the user wants instead of the default numerical values.
Parameters
  • data_set (List, Dictionary or pandas DF.) – The data provided by the user that needs to be represented and stored.

  • datetime (str) – The header of the datetime column.

  • traj_id (str) – The header of the Trajectory ID column.

  • latitude (str) – The header of the latitude column.

  • longitude (str) – The header of the longitude column.

  • rest_of_columns (Optional[list[Text]]) – A list containing headers of the columns other than the mandatory ones.

property datetime

Accessor method for the DateTime column of the PTRAILDataFrame DataFrame.

Returns

The Series containing all the DateTime values from the DataFrame.

Return type

pandas.core.series.Series

Raises

MissingColumnsException – DateTime column is missing from the data.

property latitude

Accessor method for the latitude column of the PTRAILDataFrame DataFrame.

Returns

The Series containing all the latitude values from the DataFrame.

Return type

pandas.core.series.Series

Raises

MissingColumnsException – Latitude column is missing from the data.

property longitude

Accessor method for the longitude column of the PTRAILDataFrame DataFrame.

Returns

The Series containing all the longitude values from the DataFrame.

Return type

pandas.core.series.Series

Raises

MissingColumnsException – Longitude column is missing from the data

set_default_index()[source]

Set the Index of the dataframe back to traj_id and DateTime.

Raises

MissingColumnsException – DateTime/traj_id column is missing from the dataset.

sort_by_traj_id_and_datetime(ascending=True)[source]

Sort the trajectory in Ascending or descending order based on the following 2 columns in order:

  1. Trajectory ID

  2. DateTime

Parameters

ascending (bool) – Whether to sort the values in ascending order or descending order.

Returns

The sorted dataframe.

Return type

PTRAILDataFrame

to_numpy(dtype=None, copy: bool = False, na_value=pandas._libs.lib.no_default) numpy.ndarray[source]

Convert the DataFrame to a NumPy array.By default, the dtype of the returned array will be the common dtype of all types in the DataFrame. For example, if the dtypes are float16 and float32, the results dtype will be float32. This may require copying data and coercing values, which may be expensive

Parameters
  • dtype – The dtype to pass to numpy.asarray().

  • copy – Whether to ensure that the returned value is not a view on another array. Note that copy=False does not ensure that to_numpy() is no-copy. Rather, copy=True ensure that a copy is made, even if not strictly necessary.

  • na_value – The value to use for missing values. The default value depends on dtype and the dtypes of the DataFrame columns.

property traj_id

Accessor method for the Trajectory_ID column of the DaskTrajectoryDF.

Returns

The Series containing all the Trajectory_ID values from the DataFrame.

Return type

pandas.core.series.Series

Raises

MissingColumnsException – traj_id column is missing from the data.

Module contents