path_tools

This module contains functions used to generate paths and explore them.

Functions

create_paths(blx, bly, origin, destinations) Creates a path to each destination.
path_stats(df_paths, ras, df[, fun_dic]) Applies <function> to values in ras along each path in df_paths dataframe
create_paths(blx, bly, origin, destinations, start_path=0)[source]

Creates a path to each destination.

Parameters:
  • blx (2D numpy array) – horizontal backlink
  • bly (2D numpy array) – vertical backlink
  • origin (list) – list of origins [[row, colum],…]
  • destinations (list) – list of destinations [[row, colum],…]
  • start_path (int) – path identifier, optional
Returns:

  • paths (2D numpy array) – array that results from adding all paths
  • path_lst (list) – a list of paths. Each path is represented by a dictionary containing three entries:
    • ’destination’: [row,col] of destination
    • ’origin’: [row, col] of origin
    • ’track’ : list containing two lists: [rows], [cols] for each cell making up the path

Notes

Depending on the size of the chamfer window used, backlink arrays may contain jumps that are greater than one cell.

path_stats(df_paths, ras, df, fun_dic={'fun': <function sum>, 'name': 'sum'})[source]

Applies <function> to values in ras along each path in df_paths dataframe

Parameters:
  • df_paths (dataframe) – contains information for various paths
  • ras (2D numpy array) – raster from where values are going to be extracted
  • df (dataframe) – original dataframe with location information
  • fun_dic (dictionary) –

    a dictionary with two entries:

    • ’fun’: a numpy function to compute values along a path track
    • ’name’: function name
Returns:

df_paths – updated version of df_paths with an additional name column containing the results obtained after applying <function> on ras values along each path.

Return type:

dataframe

Notes

df_paths dataframe must contain a column with the path track (a 2D numpy array with the row and columns that make up a path)