add_distance_to

function of dascore.proc.coords source

add_distance_to(
    patch: Patch ,
    origin: Series ,
    ord = None,
    prefix: str = origin,
)-> ‘PatchType’

Calculate the distance to “origin” and create new coordinate.

A new coordinate called origin_distance (or another name controlled by the pre-fix argument) is added to the output patch to specify the exact distance. Coordinates representing the origin location (eg origin_x, origin_y, origin_z) are also added as non-associated coordinates.

Parameters

Parameter Description
patch The patch object which contains some overlap in coordiantes as
index names in origin.
origin A series which contains index names that overlap with patch coordinates.
All the referenced coordinates must be associated with the same
dimension.
ord Controls the norm type. Default is Frobenius norm, see the norm
function of numpy.linalg for supported options.
prefix The prefix name for the added coordinates and attributes.

Examples

import pandas as pd

import dascore as dc

# Add a coordinate specifying the distance to a theoretical shot.
shot = pd.Series({"x": 10, "y": 10, "z": 0})
patch = dc.get_example_patch("random_patch_with_xyz")
patch_with_origin_dist = patch.add_distance_to(shot)
# Now the new coordinates of distance and shot origin exist.
dist = patch_with_origin_dist.get_array("origin_distance")
origin_x = patch_with_origin_dist.get_array("origin_x")

# Of course, the new coordinate can be used for sorting.
sorted_patch = patch_with_origin_dist.sort_coords("origin_distance")