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,
)-> 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.

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)
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 extrapolation between the nearest two points to get values in patch coords that aren’t in the dataframe.

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.
new Create new instance with some attributed updated.
coords_from_df Update non-dimensional coordinate of a patch using a dataframe.
reconcile Return the result’s metadata once the data are known; default as is.
run Run the operation: check, get_metadata, kernel, reconcile, record.