runtraj.sampling.sample_field#
- runtraj.sampling.sample_field(field, x, y, z=None, times=None, fill_value=nan, step_starts=False)[source]#
Return the field’s value in the cell nearest each point.
A point outside the field horizontally, or in a missing cell, gives
fill_value. Longitudes are wrapped to the field’s convention (-180 to 180 or 0 to 360).- Parameters:
field (
DataArray) – Field with horizontal dimensions (latandlon, oryandx), and optionally a vertical dimension andtime.x (
ArrayLike) – Point coordinates: longitude and latitude for alat/lonfield.y (
ArrayLike) – Point coordinates: longitude and latitude for alat/lonfield.z (
ArrayLike|None) – Vertical coordinate of each point, in the units of the field’s vertical dimension. Required when the field has one. Matched to the nearest level, so a point above the top level takes the top level.times (
ArrayLike|None) – Time of each point, as datetimes or date strings, with none missing. A time with a time zone is converted to UTC, which the field’s times are taken to be in. Required when the field has atimedimension. By default matched to the nearest time, so times outside the field’s span take the first or last step. Seestep_starts.fill_value (
float) – Value for points outside the field and for missing cells. Use 0 for a surface flux, where no data means no emission.NaNsuits a mole fraction, which is unknown there.step_starts (
bool) – Whether the field’stimelabels are the starts of steps, as a flux inventory’s are. A point then takes the last step that starts at or before its time. A point before the first label takesfill_valueand a point after the last takes the last step, since the labels do not say where it ends. The labels must strictly increase: a repeated label is an error. Whenfield["time"]is apandas.IntervalIndex(its CF time bounds, read as each step’s start and end), a point is matched by which step’s bounds hold it instead: one before the first bound, after the last, or in a gap between bounds takesfill_value, since the bounds say where every step starts and ends and there is nothing to guess at either edge. The bounds must not overlap.
- Returns:
One value per point.
- Return type: