composite_about_points#
- rojak.atmosphere.compositing.composite_about_points(target_data, centres, *, time_dim_name='time', lat_dim_name='latitude', lon_dim_name='longitude', vert_dim_name=None, group_dim_name=None, time_column='time', lat_column='latitude', lon_column='longitude', vert_column=None, carry_columns=(), time_tolerance=None, max_km_extent=2000, grid_km_spacing=25, interpolation=CompositeInterpolation.BILINEAR, max_centres_per_task=500, centre_dim_name='n_centre', lat_lon_buffer=0.5)[source]#
Composite a geophysical field onto a common km-scale grid centred on each row of a dataframe.
This is the counterpart of
composite_about_extrema()for when the centres are arbitrary points (e.g. observations) stored in adask.dataframe.DataFramerather than extrema on the grid oftarget_data. For each centre, the nearest time step (and, ifvert_dim_nameis given, nearest vertical level) oftarget_datais re-projected onto a regular Cartesian grid (in km) centred on that point using a WGS-84 orthographic projection.Rather than expanding
target_datato have one slice per centre, the centres are grouped by the chunks oftarget_dataalonggroup_dim_name(time by default, or the vertical dimension). The centres are shuffled so that partitioniof the dataframe contains exactly the centres whose nearest time step (or vertical level) lies in chunkioftarget_data. Each output block is computed by a single task that depends only on its block of centres and the one matching chunk, which keeps the graph small: every task refers to existing chunks by key and no data is duplicated or embedded in the graph.Note
The only computation triggered is the number of centres per chunk, an integer per chunk, which is needed for the shape of the output. Persist
centresbeforehand if it is expensive to compute.The centres in the output are sorted by their index along
group_dim_name, not in the order ofcentres. Usecarry_columnsto keep an identifier.- Parameters:
target_data (xr.DataArray) – Geophysical field to composite with dimensions
time_dim_name,lat_dim_name,lon_dim_nameand optionallyvert_dim_name. It should be chunked alonggroup_dim_nameonly; other dimensions are rechunked to a single chunk.centres (dask.dataframe.DataFrame) – Centres to composite about. Must contain
time_column,lat_column,lon_column(andvert_columnifvert_dim_nameis given) as columns.time_dim_name (str) – Name of the time dimension in
target_data. Defaults to"time".lat_dim_name (str) – Name of the latitude dimension in
target_data. Defaults to"latitude".lon_dim_name (str) – Name of the longitude dimension in
target_data. Defaults to"longitude".vert_dim_name (str, optional) – Name of the vertical dimension in
target_data. The level nearest to the centre’svert_columnvalue is used. Defaults toNone.group_dim_name (str, optional) – Dimension of
target_datawhose chunks the centres are grouped by. Must be eithertime_dim_nameorvert_dim_name, as each centre selects a single slice along these. Each task loads one chunk along this dimension and all of the other dimensions, so it should be the dimensiontarget_datais chunked along. IfNone,time_dim_nameis used. Defaults toNone.time_column (str) – Column with the time of each centre. Naive times are assumed to be UTC. Defaults to
"time".lat_column (str) – Column with the latitude of each centre in degrees. Defaults to
"latitude".lon_column (str) – Column with the longitude of each centre in degrees. Defaults to
"longitude".vert_column (str, optional) – Column with the vertical position of each centre in the same units as
target_data[vert_dim_name]. Required ifvert_dim_nameis given. Defaults toNone.carry_columns (Sequence[str]) – Additional columns of
centresto attach as coordinates alongcentre_dim_name, e.g. a cluster label. Defaults to().time_tolerance (numpy.timedelta64, optional) – Centres further than this from the nearest time step are dropped, e.g.
np.timedelta64(30, "m"). IfNone, all centres are kept. Defaults toNone.max_km_extent (float) – Half-width of the output Cartesian grid in kilometres. Defaults to
2000.grid_km_spacing (float) – Spacing between output grid points in kilometres. Defaults to
25.interpolation (CompositeInterpolation) – Interpolation scheme. Use
CompositeInterpolation.GRIDDATAfor the same results ascomposite_about_extrema(). Defaults toCompositeInterpolation.BILINEAR.max_centres_per_task (int) – Maximum number of centres in a single output block. Bounds the memory of each task to roughly
max_centres_per_task * n_km**2 * 8bytes. Defaults to500.centre_dim_name (str) – Name of the output dimension indexing the centres. Defaults to
"n_centre".lat_lon_buffer (float) – Only used by
CompositeInterpolation.GRIDDATA. See_project_data_about_extrema(). Defaults to0.5.
- Returns:
Dask-backed composited field with dimensions
(centre_dim_name, y_km, x_km)and coordinates:y_km,x_km- symmetric kilometre-coordinate arrays.time_dim_name- time step oftarget_dataused for each centre.vert_dim_name- vertical level oftarget_dataused for each centre, if applicable.centre_latitude,centre_longitude- location of each centre.Each of
carry_columns.
- Return type:
xr.DataArray
- Raises:
ValueError – If
group_dim_nameis not a dimension oftarget_data, is a horizontal dimension, or is neithertime_dim_namenorvert_dim_name.ValueError – If
target_datadoes not have exactly the specified dimensions.ValueError – If only one of
vert_dim_nameandvert_columnis specified.ValueError – If a required column is missing from
centres.ValueError – If there are no centres to composite about.