lt_toolbox.TrajFrame.compute_binned_statistic_2d#
- TrajFrame.compute_binned_statistic_2d(var_x: str, var_y: str, values: str, statistic: str, bin_breaks: list, alias: str | None = None, group: str | None = None, append: bool = False) Self[source]#
Compute a 2-dimensional binned statistic using the variables stored in a TrajFrame.
This is a generalization of a 2-D histogram function. A 2-D histogram divides the chosen column varaibles into bins, and returns the count of the number of points in each bin. This function allows the computation of the sum, mean, median, or other statistic of the values within each bin.
- Parameters:
var_x (str) – Name of variable whose values to be binned along the first dimension.
var_y (str) – Name of variable whose values to be binned along the second dimension.
values (str) – Name of variable on which the statistic will be computed. This must be the same length as var_x & var_y.
statistic (str) – The statistic to compute; empty bins will be assigned a Null value. The following statistics are available: * ‘mean’ : compute the mean of values for points within each bin. * ‘std’ : compute the standard deviation within each bin. * ‘median’ : compute the median of values for points within each bin. * ‘count’ : compute the count of points within each bin. This is identical to an unweighted histogram. * ‘sum’ : compute the sum of values for points within each bin. This is identical to a weighted histogram. * ‘min’ : compute the minimum of values for points within each bin. * ‘max’ : compute the maximum of values for point within each bin.
bin_breaks (list) – List of lists including bin edges used in the binning of var_x and var_y variables.
alias (str, default: None) – New name of output statistics.
group (str, default: None) – Name of variable to group according to unique values using group_by() method. A 1-dimensional binned statistic will be computed for each group member.
append (bool, default: False) – If set to True, the 2-dimensional binned statistic will be appended to the existing summary_data, otherwise summary_data will be replaced with a new DataSet.
- Returns:
TrajFrame is returned with the 2-dimensional binned statistic included in the summary_data where the mid-points of the specified bins are given as the coordinate dimensions.
- Return type:
TrajFrame
Examples
Calculating the mean potential temperature recorded along Lagrangian trajectories in discrete longitude-latitude bins.
>>> bin_lon = np.arange(-40, 10, 1).tolist() >>> bin_lat = np.arange(30, 60, 1).tolist() >>> trajectories.compute_binned_statistic_2d(var_x='lon', var_y='lat', values='potemp', statistic='mean', bin_breaks=[bin_lon, bin_lat], alias='potemp_mean')