gaiaspec.spectrum_correction¶
Empirical flux correction of Gaia XP spectra.
gaiaspec.spectrum_correction ¶
Empirical flux correction of Gaia XP spectra against CALSPEC references.
Gaia XP spectra carry a smooth flux-calibration residual. This module correlates a target spectrum against a bundled table of Gaia spectra with known CALSPEC counterparts, picks the best-matching reference and returns the multiplicative wavelength-dependent correction that maps the Gaia flux onto the CALSPEC flux.
load_gaia_corrections ¶
load_gaia_corrections()
Load the bundled Gaia flux-correction table.
Returns:
| Type | Description |
|---|---|
|
pandas.DataFrame: The |
|
|
per-row |
Source code in gaiaspec/spectrum_correction.py
17 18 19 20 21 22 23 24 25 26 27 | |
compute_gaia_correlation ¶
compute_gaia_correlation(df_gaia_correction, wavelength, flux)
Correlate one spectrum against every reference in the correction table.
Interpolates the input flux onto each reference wavelength grid (ignoring NaNs) and computes the Pearson correlation coefficient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_gaia_correction
|
DataFrame
|
Correction table (see
:func: |
required |
wavelength
|
ndarray
|
Input wavelength grid. |
required |
flux
|
ndarray
|
Input flux. |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: Correlation coefficient with each reference row. |
Source code in gaiaspec/spectrum_correction.py
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 | |
find_best_gaia_correction ¶
find_best_gaia_correction(df_gaia_correction, wavelength, corr_threshold=0.8, choose_corr='m3', verbose=True)
Return the correction of the best-correlated reference above a threshold.
Sorts references by correlation and, for the best one above
corr_threshold, returns the corrected_flux / gaia_spectrum ratio
interpolated onto wavelength (unity where no acceptable match exists).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_gaia_correction
|
DataFrame
|
Correction table with a
|
required |
wavelength
|
ndarray
|
Target wavelength grid. |
required |
corr_threshold
|
float
|
Minimum acceptable correlation. |
0.8
|
choose_corr
|
str
|
Correction variant column suffix
(e.g. |
'm3'
|
verbose
|
bool
|
Print when no correction is found. |
True
|
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: Multiplicative correction on |
Source code in gaiaspec/spectrum_correction.py
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 | |
return_gaia_spectra_correction ¶
return_gaia_spectra_correction(wavelength, flux, corr_threshold=0.8, choose_corr='m3')
Compute the empirical flux correction for a single spectrum.
Convenience wrapper chaining :func:load_gaia_corrections,
:func:compute_gaia_correlation and :func:find_best_gaia_correction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wavelength
|
ndarray
|
Input wavelength grid. |
required |
flux
|
ndarray
|
Input flux. |
required |
corr_threshold
|
float
|
Minimum acceptable correlation. |
0.8
|
choose_corr
|
str
|
Correction variant suffix. |
'm3'
|
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: Multiplicative correction on |
Source code in gaiaspec/spectrum_correction.py
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 | |
multi_pearsonr ¶
multi_pearsonr(x, y)
Pearson correlation of many row-vectors x against one vector y.
Vectorised equivalent of calling :func:scipy.stats.pearsonr for each row
of x against y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Array of shape |
required |
y
|
ndarray
|
Reference vector of length |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: Length- |
|
|
|
Source code in gaiaspec/spectrum_correction.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
compute_gaia_correlation_multiple_spectra ¶
compute_gaia_correlation_multiple_spectra(df_gaia_correction, wavelength, fluxes)
Correlate many spectra against every reference in the correction table.
Vectorised counterpart of :func:compute_gaia_correlation for a batch of
input spectra sharing one wavelength grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_gaia_correction
|
DataFrame
|
Correction table. |
required |
wavelength
|
ndarray
|
Shared input wavelength grid. |
required |
fluxes
|
iterable[ndarray]
|
Input fluxes. |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: Correlation array of shape |
Source code in gaiaspec/spectrum_correction.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
return_gaia_spectra_correction_multiple ¶
return_gaia_spectra_correction_multiple(wavelength, fluxes, corr_threshold=0.8, choose_corr='m3')
Compute the empirical flux correction for several spectra at once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wavelength
|
ndarray
|
Shared input wavelength grid. |
required |
fluxes
|
iterable[ndarray]
|
Input fluxes. |
required |
corr_threshold
|
float
|
Minimum acceptable correlation. |
0.8
|
choose_corr
|
str
|
Correction variant suffix. |
'm3'
|
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: One multiplicative correction per input flux. |
Source code in gaiaspec/spectrum_correction.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |