velociraptor.tools.adaptive module¶
Tools for creating adaptive bins based on an input array.
-
velociraptor.tools.adaptive.adaptive_bin_hash(values, lowest_value, highest_value, base_n_bins, minimum_in_bin, logarithmic, stretch_final_bin)[source]¶ Hash for adaptive binning. Note that this can raise AttributeError in the case where the array is unhashable.
-
velociraptor.tools.adaptive.create_adaptive_bins(values: unyt.array.unyt_array, lowest_value: unyt.array.unyt_quantity, highest_value: unyt.array.unyt_quantity, base_n_bins: int = 25, minimum_in_bin: int = 3, logarithmic: bool = True, stretch_final_bin: bool = False)[source]¶ Creates a set of adaptive bins based on the input values.
Parameters: - values (unyt.unyt_array) – The array that you want to create a mass function of (usually this is for example halo masses or stellar masses).
- lowest_value (unyt.unyt_quantity) – the lowest value edge of the bins
- highest_value (unyt.unyt_quantity) – the highest value edge of the bins
- base_n_bins (unyt.unyt_array, optional) – The number of equal width bins across the range to use in the case where no adaptive sampling is required. This returns the minimal allowed bin width. Default: 25.
- minimum_in_bin (int, optional) – The number of objects in a bin for it to be classed as valid. Bins with a number of objects smaller than this are not returned. Bins are stretched so that they have at least this many items in them. Default: 3.
- logarithmic (bool, optional) – Whether or not to use logarithmically spaced bins. Default: True.
- stretch_final_bin (bool, optional) – Stretch the final bin to include all values. If
False, some values may fall outside of all of the bins.
Returns: - bin_centers (unyt.unyt_array) – The centers of the bins (taken to be the median of the items in the bin).
- bin_edges (unyt.unyt_array, optional) – Bin edges that were used in the binning process.
Notes
Caches the output as this procedure can be very expensive, and will be repeated several times.