pyrolite.util.spatial

Baisc spatial utility functions.

pyrolite.util.spatial.great_circle_distance(a, b=None, absolute=False, degrees=True, r=6371.0088, method=None, dtype='float32', max_memory_fraction=0.25)[source]

Calculate the great circle distance between two lat, long points.

Parameters
  • a, b (float | numpy.ndarray) – Lat-Long points or arrays to calculate distance between. If only one array is specified, a full distance matrix (i.e. calculate a point-to-point distance for every combination of points) will be returned.

  • absolute (bool, False) – Whether to return estimates of on-sphere distances [True], or simply return the central angle between the points.

  • degrees (bool, True) – Whether lat-long coordinates are in degrees [True] or radians [False].

  • r (float) – Earth radii for estimating absolute distances.

  • method (str, {'vicenty', 'cosines', 'haversine'}) – Which method to use for great circle distance calculation. Defaults to the Vicenty formula.

  • dtype (numpy.dtype) – Data type for distance arrays, to constrain memory management.

  • max_memory_fraction (float) – Constraint to switch to calculating mean distances where matrix=True and the distance matrix requires greater than a specified fraction of total avaialbe physical memory.

pyrolite.util.spatial.piecewise(segment_ranges: list, segments=2, output_fmt=<class 'numpy.float64'>)[source]

Generator to provide values of quantizable paramaters which define a grid, here used to split up queries from databases to reduce load.

Parameters
  • segment_ranges (list) – List of segment ranges to create a grid from.

  • segments (int) – Number of segments.

  • output_fmt – Function to call on the output.

pyrolite.util.spatial.spatiotemporal_split(segments=4, nan_lims=[nan, nan], **kwargs)[source]

Creates spatiotemporal grid using piecewise function and arbitrary ranges for individial kw-parameters (e.g. age=(0., 450.)), and sequentially returns individial grid cell attributes.

Parameters
  • segments (int) – Number of segments.

  • nan_lims (list | tuple) – Specificaiton of NaN indexes for missing boundaries.

Yields

dict – Iteration through parameter sets for each cell of the grid.

pyrolite.util.spatial.NSEW_2_bounds(cardinal, order=['minx', 'miny', 'maxx', 'maxy'])[source]

Translates cardinal points to xy points in the form of bounds. Useful for converting to the format required for WFS from REST style queries.

Parameters
  • cardinal (dict) – Cardinally-indexed point bounds.

  • order (list) – List indicating order of returned x-y bound coordinates.

Returns

x-y indexed extent values in the specified order.

Return type

list

pyrolite.util.spatial.levenshtein_distance(seq_one, seq_two)[source]

Compute the Levenshtein Distance between two sequences with comparable items. Adapted from Wiki pseudocode.

Parameters

seq_one, seq_two (str | list) – Sequences to compare.

Return type

int