mirror of
https://github.com/Richard-Sti/csiborgtools.git
synced 2024-12-23 03:48:02 +00:00
optionally return counts as well
This commit is contained in:
parent
d69012424e
commit
d4f89fc343
1 changed files with 12 additions and 2 deletions
|
@ -51,7 +51,7 @@ def binned_counts(x, bins):
|
||||||
return centres, out
|
return centres, out
|
||||||
|
|
||||||
|
|
||||||
def number_density(data, feat, bins, max_dist, to_log10):
|
def number_density(data, feat, bins, max_dist, to_log10, return_counts=False):
|
||||||
"""
|
"""
|
||||||
Calculate volume-limited number density of a feature `feat` from array
|
Calculate volume-limited number density of a feature `feat` from array
|
||||||
`data`, normalised also by the bin width.
|
`data`, normalised also by the bin width.
|
||||||
|
@ -70,6 +70,9 @@ def number_density(data, feat, bins, max_dist, to_log10):
|
||||||
to_log10 : bool
|
to_log10 : bool
|
||||||
Whether to take a logarithm of base 10 of the feature. If so, then the
|
Whether to take a logarithm of base 10 of the feature. If so, then the
|
||||||
bins must also be logarithmic.
|
bins must also be logarithmic.
|
||||||
|
return_counts : bool, optional
|
||||||
|
Whether to also return number counts in each bin. By default `False`.
|
||||||
|
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
|
@ -80,6 +83,9 @@ def number_density(data, feat, bins, max_dist, to_log10):
|
||||||
Number density of shape `(n_edges - 1, )`.
|
Number density of shape `(n_edges - 1, )`.
|
||||||
nd_err : 1-dimensional array
|
nd_err : 1-dimensional array
|
||||||
Poissonian uncertainty of `nd` of shape `(n_edges - 1, )`.
|
Poissonian uncertainty of `nd` of shape `(n_edges - 1, )`.
|
||||||
|
counts: 1-dimensional array, optional
|
||||||
|
Counts in each bin of shape `(n_edges - 1, )`. Returned only if
|
||||||
|
`return_counts`.
|
||||||
"""
|
"""
|
||||||
# Extract the param and optionally convert to log10
|
# Extract the param and optionally convert to log10
|
||||||
x = data[feat]
|
x = data[feat]
|
||||||
|
@ -104,4 +110,8 @@ def number_density(data, feat, bins, max_dist, to_log10):
|
||||||
# Convert bins to linear space if log10
|
# Convert bins to linear space if log10
|
||||||
if to_log10:
|
if to_log10:
|
||||||
bin_centres = 10**bin_centres
|
bin_centres = 10**bin_centres
|
||||||
return bin_centres, nd, nd_err
|
|
||||||
|
out = (bin_centres, nd, nd_err)
|
||||||
|
if return_counts:
|
||||||
|
out += counts
|
||||||
|
return out
|
||||||
|
|
Loading…
Reference in a new issue