CoordsFromDf

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

CoordsFromDf(
    *args ,
    dataframe: DataFrame ,
    units: dict[dict[str, Any], None] = None,
    extrapolate: bool = False,
    max_gap: float | None[float, None] = None,
)-> None

Update non-dimensional coordinate of a patch using a dataframe.

Parameters

Parameter Description
dataframe Table with a column matching in title to one of patch.dims along with other
coordinates to associate with dimension. Example one column matching distance
axis and then latitude and longitude attached to the distances.
units Dictionary mapping column name in dataframe to its units.
extrapolate If True, extrapolate outside provided range in dataframe.
max_gap If given, positions between two neighbouring rows further apart than
this (in the dimension’s units) are NaN rather than interpolated,
for tables that leave stretches unsurveyed.

Examples

import dascore as dc
import pandas as pd
# get example patch and create example dataframe
pa = dc.get_example_patch()
distance = pa.coords.get_array("distance")[::10]
df = pd.DataFrame(distance, columns=['distance'])
df['x'] = df['distance'] * 3 + 10
df['y'] = df['distance'] * 2.5 - 10
# attach dataframe to patch, interpolating when needed. This
# adds coordinates x and y which are associated with dimension distance.
patch_with_coords = pa.coords_from_df(df)
# Leave channels NaN where neighbouring rows are over 50 m apart.
patch_with_gaps = pa.coords_from_df(df.iloc[[0, 1, -2, -1]], max_gap=50)
Note
  • Exactly one of the column names in the dataframe must map to one of the patch.dims. This will either add new coordinates, or update existing ones if they already exist.

  • This function uses linear interpolation between the nearest two points to get values in patch coords that aren’t in the dataframe. Row order does not matter, but each value of the dimension column may appear only once.

Methods

Name Description
check Refuse a patch which does not carry what the operation needs.
get_metadata Return the coordinates the table interpolates onto a dimension.
model_copy Copy the model, dropping cached values the update invalidates.
new Create new instance with some attributed updated.
coords_from_df Update non-dimensional coordinate of a patch using a dataframe.
reconcile Return metadata or a patch holding the final data; default as is.
run Run the operation: check, get_metadata, kernel, reconcile, record.