lt_toolbox.TrajFrame.compute_binned_statistic_1d#
- TrajFrame.compute_binned_statistic_1d(var: str, values: str, statistic: str, bin_breaks: list, alias: str | None = None, group: str | None = None, append: bool = False) Self[source]#
Compute a 1-dimensional binned statistic using variables stored in a TrajFrame.
This is a generalization of a histogram function. A histogram divides the chosen column varaible 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 (str) – Name of column variable whose values will binned.
values (str) – Name of the column variable on which the statistic will be computed.
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 bin edges used in the binning of var variable.
alias (str, default: None) – New name of output statistics.
group (str, default: None) – Name of column 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 1-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 1-dimensional binned statistic included in the summary_data where the mid-points of the specified bins are given as the coordinate dimension.
- Return type:
TrajFrame
Examples
Calculating the total volume transport of the Lagrangian trajectories according to the longitude of their starting positions.
>>> bin_lon = np.arange(-40, 10, 1).tolist() >>> trajectories.compute_binned_statistic_1d(var='start_lon', values='vol', statistic='sum', bin_breaks=bin_lon, alias='vol_transport')