AddDistanceTo

class of dascore.proc.coords
inherits from: PatchProcessor, DascoreBaseModel, pydantic.main.BaseModel
source

AddDistanceTo(
    *args ,
    origin: Any ,
    ord: Any = None,
    prefix: Any = origin,
)-> None

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
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")

Methods

Name Description
check Refuse a patch which does not carry what the operation needs.
get_metadata Return the metadata with the distance and origin coordinates added.
model_copy Copy the model, dropping cached values the update invalidates.
from_names Return the operation for bare dimension names and named values.
new Create new instance with some attributed updated.
add_distance_to Calculate the distance to “origin” and create new coordinate.
reconcile Return metadata or a patch holding the final data; default as is.
run Run the operation: check, get_metadata, kernel, reconcile, record.