velociraptor.tools.lines module¶
Tools to generate various lines from datasets.
-
velociraptor.tools.lines.binned_mean_line(x: unyt.array.unyt_array, y: unyt.array.unyt_array, x_bins: unyt.array.unyt_array, minimum_in_bin: int = 3, return_additional: bool = False, minimum_additional_points: int = 0)[source]¶ Gets a mean (y) line, binned in the x direction.
Parameters: - x (unyt.unyt_array) – Horizontal values, to be binned.
- y (unyt.unyt_array) – Vertical values, to have the mean calculated in the x-bins
- x_bins (unyt.unyt_array) – Horizontal bin edges. Must have the same units as x.
- minimum_in_bin (int, optional) – Minimum number of items in a bin to return that bin. If a bin has fewer values than this, it is excluded from the return values. Default: 3.
- return_additional (bool, optional) – Boolean. If true, makes the function return x and y data points that lie in the bins where the number of data points is smaller than minimum_in_bin, and any points that are higher than the highest bin edge. Default: false.
- minimum_additional_points (int, optional) – Minimum number of additional data points with the highest values of x to return. Has to be used with return_additional=True. If set to N, then at least N additional data points will always be present in the plot, regardless of how the adaptive binning is done. The adaptive binning is stopped at the lowest value of x among the additional data points so that these points and the mean line do not overlap.
Returns: - bin_centers (unyt.unyt_array) – The centers of the bins (taken to be the linear mean of the bin edges).
- means (unyt.unyt_array) – Vertical mean values within the bins.
- standard_deviation (unyt.unyt_array) – Standard deviation within the bins, to be shown as scatter.
- additional_x (unyt.unyt_array, optional) – x data points from the bins where the number of data points is smaller than minimum_in_bin
- additional_y (unyt.unyt_array, optional) – y data points from the bins where the number of data points is smaller than minimum_in_bin
Notes
The return types are such that you can pass this directly to plt.errorbar, as follows:
plt.errorbar( *binned_mean_line(x, y, x_bins, 10) )
-
velociraptor.tools.lines.binned_median_line(x: unyt.array.unyt_array, y: unyt.array.unyt_array, x_bins: unyt.array.unyt_array, percentiles: List[int] = [16, 84], minimum_in_bin: int = 3, return_additional: bool = False, minimum_additional_points: int = 0)[source]¶ Gets a median (y) line, binned in the x direction.
Parameters: - x (unyt.unyt_array) – Horizontal values, to be binned.
- y (unyt.unyt_array) – Vertical values, to have the median calculated in the x-bins
- x_bins (unyt.unyt_array) – Horizontal bin edges. Must have the same units as x.
- percentiles (List[int], optional) – Percentiles to return as the positive and negative errors. By default these are 16 and 84th percentiles.
- minimum_in_bin (int, optional) – Minimum number of items in a bin to return that bin. If a bin has fewer values than this, it is excluded from the return values. Default: 3.
- return_additional (bool, optional) – Boolean. If true, makes the function return x and y data points that lie in the bins where the number of data points is smaller than minimum_in_bin, and any points that are higher than the highest bin edge. Default: false.
- minimum_additional_points (int, optional) – Minimum number of additional data points with the highest values of x to return. Has to be used with return_additional=True. If set to N, then at least N additional data points will always be present in the plot, regardless of how the adaptive binning is done. The adaptive binning is stopped at the lowest value of x among the additional data points so that these points and the median line do not overlap.
Returns: - bin_centers (unyt.unyt_array) – The centers of the bins (taken to be the linear mean of the bin edges).
- medians (unyt.unyt_array) – Vertical median values within the bins.
- deviations (unyt.unyt_array) – Deviation from median vertically using the
percentilesdefined above. This has shape 2xN. - additional_x (unyt.unyt_array, optional) – x data points from the bins where the number of data points is smaller than minimum_in_bin
- additional_y (unyt.unyt_array, optional) – y data points from the bins where the number of data points is smaller than minimum_in_bin
Notes
The return types are such that you can pass this directly to plt.errorbar, as follows:
plt.errorbar( *binned_median_line(x, y, x_bins, 10) )