Module Reference#
Computing Objects#
- class traccess.access.AccessComputer(supply: Supply, cost: Cost, demand: Demand | None = None)#
Compute access to opportunity metrics.
The access computer uses supplied datasets on supply, cost, and optionally demand to compute popular access to opportunity measures.
- Parameters:
- cost_to_closest(cost_column: str, supply_columns: list[str], n=1) Access#
Compute the cost to the nth closest destination.
This function is generic over any kind of numeric travel cost, such as distance, time and money.
- Parameters:
- Returns:
An Access data object with an id_column matching the origin zone.
- Return type:
- cumulative_cutoff(cost_columns: list[str], cutoffs: list[float], supply_columns: list[str] | None = None) Access#
Compute the total number of opportunities within a specified travel cost cutoff.
- Parameters:
cost_columns (list[str]) – A list of cost columns to apply cutoffs to. Can be a single string for a single column.
cutoffs (list[float]) – A list of cutoff values corresponding to each cost column. Can be a single value for a single cutoff column. Must be the same length as cost_columns.
supply_columns (list[str]) – An optional list of supply columns to use and return. If None, all supply columns are used. By default, None.
- Returns:
An Access data object with an id_column matching the origin zone.
- Return type:
- Raises:
ValueError – If the supplied column list and cutoff lists are not the same length.
- property supply#
Access or set the supply object
- class traccess.access.EquityComputer(access: Access, demographic: Demographic)#
Compute distributive equity metrics across population demographics
An EquityComputer allows for the combination of access measures and demographic data to compute various metrics of distributive equity or transportation justice.
- Parameters:
access (Access) – An Access object which contains data on access to opportunities.
demographic (Demographic) – A Demographic data object which contains data on demographics and populations
- fgt_poverty(access_column: str, poverty_line: float, alpha: float, is_dual=False) Series#
Compute a Foster-Greer-Thorbecke (FGT) index for all demographics.
FGT measures consider the average amount of poverty in a given population by comparing the distance of each individual from the poverty line, raised to some exponent alpha. Common values of alpha are 0, 1, and 2.
When alpha = 0, the function returns the poverty rate
When alpha = 1, the function returns the poverty gap index
When alpha = 2, the function returns the poverty gap weighted by the poverty gap.
- Parameters:
access_column (str) – The access to opportunity column to compare the measure against
poverty_line (float) – The poverty line to compare the access measure against
alpha (float) – The alpha parameter, or the extent which to weight those further below the poverty line
is_dual (bool, optional) – Whether the measure is a dual measure, where lower values are better, by default False
- Returns:
A series with an index for each demographic column, containing the specified measure.
- Return type:
- in_poverty(access_column: str, poverty_line: float, is_dual=False) Series#
Compute the number of individuals in poverty in any given demographic.
- Parameters:
- Returns:
A series with each row consisting of a demogrphic group, containing the number of that group in poverty.
- Return type:
- poverty_index(access_column: str, poverty_line: float, is_dual=False) Series#
Compute the poverty index at each location.
This method computes the poverty index for each location, which is the difference between the poverty line and the supplied access value, divided by the poverty line.
Values above the poverty line are returned as null values.
- Parameters:
- Returns:
A pandas Series containing the poverty index for each location
- Return type:
- weighted_average(access_column: str) Series#
Compute the population group-weighted average access for all groups.
- Parameters:
access_column (str) – The access value to weight
- Returns:
A series with a row for demographic group, with the weighted average access.
- Return type:
- weighted_quantile(access_column: str, quantile=0.5, is_dual=False) Series#
Compute a population-weighted quantile for all demographics.
Population-weighted quantiles are not interpolated, meaning that the values returned by this function are the highest value in the dataset not exceeding the quantile value.
- Parameters:
- Returns:
A series containing each demographic group and the access value of that quantile.
- Return type:
Data Objects#
- class traccess.data.AbstractDataSet(dataframe: DataFrame, id_column='id')#
Bases:
ABCAn abstract data set
- Parameters:
dataframe (pandas.DataFrame) – The dataframe containing the data
id_column (str, optional) – The column which should be used as a unique ID, by default “id”
- classmethod from_csv(csv_filepath, id_column='id', **kwargs)#
Create a Supply object from a csv file
- normalize(columns=None, min=0.0, max=1.0)#
Normalize one or more columns between a range
This method scales a column based on its minimum and maximum values.
- class traccess.data.AbstractMatrix(dataframe: DataFrame, from_id='from_id', to_id='to_id')#
Bases:
ABCA representation of a matrix object.
- Parameters:
dataframe (pandas.DataFrame) – The dataframe for the matrix object
from_id (str, optional) – The first reference id (the origin), by default “from_id”
to_id (str, optional) – The second reference id (the destination), by default “to_id”
- classmethod from_csv(csv_filepath, from_id='from_id', to_id='to_id', **kwargs)#
Load data and create an object from a CSV file
- Parameters:
- Returns:
A matrix dataset.
- Return type:
- classmethod from_parquet(parquet_filepath, from_id='from_id', to_id='to_id', **kwargs)#
Load data and create an object from a Parquet file
- Parameters:
- Returns:
A matrix dataset.
- Return type:
- class traccess.data.Access(dataframe: DataFrame, id_column='id')#
Bases:
AbstractDataSet- classmethod from_csv(csv_filepath, id_column='id', **kwargs)#
Create a Supply object from a csv file
- normalize(columns=None, min=0.0, max=1.0)#
Normalize one or more columns between a range
This method scales a column based on its minimum and maximum values.
- class traccess.data.Cost(dataframe: DataFrame, from_id='from_id', to_id='to_id')#
Bases:
AbstractMatrix- classmethod from_csv(csv_filepath, from_id='from_id', to_id='to_id', **kwargs)#
Load data and create an object from a CSV file
- Parameters:
- Returns:
A matrix dataset.
- Return type:
- classmethod from_parquet(parquet_filepath, from_id='from_id', to_id='to_id', **kwargs)#
Load data and create an object from a Parquet file
- Parameters:
- Returns:
A matrix dataset.
- Return type:
- median(use_to_id=False) DataFrame#
Compute the median cost values across all origins or destinations.
This function is a shorthand for Cost.quantile(quantile=0.5)
- Parameters:
use_to_id (bool, optional) – If true, group by the destination column instead of the origin, by default False
- Returns:
A dataframe with an index for each id and a median value
- Return type:
- class traccess.data.Demand(dataframe: DataFrame, id_column='id')#
Bases:
AbstractDataSet- classmethod from_csv(csv_filepath, id_column='id', **kwargs)#
Create a Supply object from a csv file
- normalize(columns=None, min=0.0, max=1.0)#
Normalize one or more columns between a range
This method scales a column based on its minimum and maximum values.
- class traccess.data.Demographic(dataframe: DataFrame, id_column='id')#
Bases:
AbstractDataSet- classmethod from_csv(csv_filepath, id_column='id', **kwargs)#
Create a Supply object from a csv file
- normalize(columns=None, min=0.0, max=1.0)#
Normalize one or more columns between a range
This method scales a column based on its minimum and maximum values.
- class traccess.data.Supply(dataframe: DataFrame, id_column='id')#
Bases:
AbstractDataSet- classmethod from_csv(csv_filepath, id_column='id', **kwargs)#
Create a Supply object from a csv file
- normalize(columns=None, min=0.0, max=1.0)#
Normalize one or more columns between a range
This method scales a column based on its minimum and maximum values.