frequency_binning¶
FrequencyBinning
¶
A utility class for binning data over frequency space.
Provides methods for defining bins (linear or logarithmic, or user-defined), binning frequency data and corresponding values, and calculating statistics for binned data.
Source code in stela_toolkit/frequency_binning.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
bin_data(freqs, values, bin_edges)
staticmethod
¶
Bins frequencies and corresponding values into the specified bin edges.
For each bin, computes the mean frequency, bin half-width (for error bars), mean value, and standard deviation of values within the bin.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
freqs
|
array - like
|
Array of frequency values to be binned. |
required |
values
|
array - like
|
Array of values corresponding to each frequency. |
required |
bin_edges
|
array - like
|
Array of bin edges that define the frequency bins. |
required |
Returns:
Name | Type | Description |
---|---|---|
binned_freqs |
array - like
|
Mean frequency for each bin. |
binned_freq_widths |
array - like
|
Half-width of each frequency bin (for plotting error bars). |
binned_values |
array - like
|
Mean value of the data within each bin. |
binned_value_errors |
array - like
|
Standard deviation of the values in each bin. |
Source code in stela_toolkit/frequency_binning.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
count_frequencies_in_bins(spectrum, fmin=None, fmax=None, num_bins=None, bin_type=None, bin_edges=[])
staticmethod
¶
Counts the number of frequencies in each bin for the power spectrum.
If bin_edges
are provided, they are used directly. Otherwise, bins are
defined using fmin
, fmax
, num_bins
, and bin_type
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spectrum
|
object
|
Object containing attributes like |
required |
fmin
|
float
|
Minimum frequency. If not provided, defaults to |
None
|
fmax
|
float
|
Maximum frequency. If not provided, defaults to |
None
|
num_bins
|
int
|
Number of bins to create (used only if |
None
|
bin_type
|
str
|
Type of binning to use: "log" or "linear". |
None
|
bin_edges
|
array - like
|
Custom array of bin edges. If provided, overrides |
[]
|
Returns:
Name | Type | Description |
---|---|---|
bin_counts |
list of int
|
List containing the number of frequencies in each bin. |
Source code in stela_toolkit/frequency_binning.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
define_bins(fmin, fmax, num_bins=None, bin_type='log', bin_edges=[])
staticmethod
¶
Defines bin edges for a frequency range using the specified binning type.
If bin_edges
are provided, they are used directly. Otherwise, bin edges are
computed between fmin
and fmax
using either logarithmic or linear spacing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fmin
|
float
|
Minimum frequency value. |
required |
fmax
|
float
|
Maximum frequency value. |
required |
num_bins
|
int
|
Number of bins to create (used only if |
None
|
bin_type
|
str
|
Type of binning to use: "log" for logarithmic or "linear" for linear spacing. |
'log'
|
bin_edges
|
array - like
|
Custom array of bin edges. If provided, overrides |
[]
|
Returns:
Name | Type | Description |
---|---|---|
bin_edges |
array - like
|
Array of frequency bin edges based on the specified settings. |
Source code in stela_toolkit/frequency_binning.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|