cross_correlation¶
CrossCorrelation
¶
Compute the time-domain cross-correlation function (CCF) between two light curves or GP models.
This class supports three primary use cases:
-
Regularly sampled
LightCurve
objects (mode="regular"
)
Computes the CCF directly using array-based shifting of flux values. This mode requires both light curves to be sampled on the same time grid. -
Irregularly sampled
LightCurve
objects (mode="lin_interp"
)
Uses the interpolated cross-correlation function (ICCF; Gaskell & Peterson 1987), which linearly interpolates each light curve onto the other's time grid to evaluate the correlation across lags. This supports fully independent time arrays. -
GaussianProcess
models
If both inputs are trained GP models with sampled realizations (via.sample()
), the CCF is computed for each realization pair and averaged. Outputs in this case include the mean and standard deviation of the peak lag, centroid lag, and maximum correlation (rmax
). This mode currently supports onlymode="regular"
.
Optionally, Monte Carlo resampling can be used to estimate uncertainties on lag measurements.
This uses:
- Random Subset Selection (RSS) with replacement
- Flux Randomization (FR) via Gaussian noise
and is only available when using mode="lin_interp"
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lc_or_model1
|
LightCurve or GaussianProcess
|
First input light curve or trained GP model. |
required |
lc_or_model2
|
LightCurve or GaussianProcess
|
Second input light curve or trained GP model. |
required |
mode
|
(regular, lin_interp)
|
CCF computation mode. Use "regular" for array-based shifting, or "lin_interp" for ICCF-based interpolation. |
"regular"
|
monte_carlo
|
bool
|
Whether to estimate lag uncertainties using Monte Carlo resampling (RSS + FR). Only supported with lin_interp mode. |
False
|
n_trials
|
int
|
Number of Monte Carlo trials (default: 1000). |
1000
|
min_lag
|
float or auto
|
Minimum lag to evaluate. If "auto", set to |
'auto'
|
max_lag
|
float or auto
|
Maximum lag to evaluate. If "auto", set to |
'auto'
|
dt
|
float or auto
|
Lag grid spacing. If "auto", uses half the native time resolution in "regular" mode, and ⅓ the mean sampling interval in "lin_interp" mode. |
'auto'
|
centroid_threshold
|
float
|
Threshold (as a fraction of peak correlation) for defining the centroid lag region. |
0.8
|
rmax_threshold
|
float
|
Trials with a maximum correlation (rmax) below this threshold are discarded when using Monte Carlo. |
0.0
|
Attributes:
Name | Type | Description |
---|---|---|
lags |
ndarray
|
Array of lag values evaluated. |
ccf |
ndarray or None
|
Cross-correlation coefficients. Not set when both inputs are GP models. |
peak_lag |
float or tuple
|
Peak lag of the CCF. If using GPs, returns (mean, std) across realizations. |
centroid_lag |
float or tuple
|
Centroid lag of the high-correlation region. If using GPs, returns (mean, std). |
rmax |
float or tuple
|
Maximum correlation value. If using GPs, returns (mean, std). |
peak_lags_mc |
ndarray or None
|
Peak lags from Monte Carlo trials, if enabled. |
centroid_lags_mc |
ndarray or None
|
Centroid lags from Monte Carlo trials. |
peak_lag_ci |
tuple or None
|
68% confidence interval (16th–84th percentile) on peak lag from MC trials. |
centroid_lag_ci |
tuple or None
|
68% confidence interval on centroid lag from MC trials. |
Source code in stela_toolkit/cross_correlation.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 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 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
|
compute_ccf(rates1, rates2)
¶
Compute the cross-correlation function (CCF) via direct shifting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rates1
|
ndarray
|
First time series. |
required |
rates2
|
ndarray
|
Second time series. |
required |
Returns:
Name | Type | Description |
---|---|---|
lags |
ndarray
|
Lag values. |
ccf |
ndarray
|
Pearson correlation coefficients at each lag. |
Source code in stela_toolkit/cross_correlation.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
compute_ccf_interp(times1, rates1, times2, rates2)
¶
Compute the cross-correlation function using linear interpolation on both light curves.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
times1
|
ndarray
|
Time values for the first light curve. |
required |
rates1
|
ndarray
|
Flux values for the first light curve. |
required |
times2
|
ndarray
|
Time values for the second light curve. |
required |
rates2
|
ndarray
|
Flux values for the second light curve. |
required |
Returns:
Name | Type | Description |
---|---|---|
ccf |
ndarray
|
Cross-correlation values at each lag. |
Source code in stela_toolkit/cross_correlation.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
|
compute_confidence_intervals(lower_percentile=16, upper_percentile=84)
¶
Compute percentile-based confidence intervals for Monte Carlo lag distributions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lower_percentile
|
float
|
Lower percentile bound (default is 16). |
16
|
upper_percentile
|
float
|
Upper percentile bound (default is 84). |
84
|
Source code in stela_toolkit/cross_correlation.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
|
find_peak_and_centroid(lags, ccf)
¶
Compute the peak and centroid lag of a cross-correlation function.
The peak lag corresponds to the lag with the maximum correlation value. The centroid lag is computed using a weighted average of lag values in a contiguous region around the peak where the correlation exceeds a fraction of the peak value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lags
|
ndarray
|
Array of lag values (assumed sorted). |
required |
ccf
|
ndarray
|
Cross-correlation values at each lag. |
required |
Returns:
Name | Type | Description |
---|---|---|
peak_lag |
float
|
Lag corresponding to the maximum correlation. |
centroid_lag |
float or nan
|
Correlation-weighted centroid lag near the peak. Returns NaN if a valid centroid region cannot be identified. |
Source code in stela_toolkit/cross_correlation.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
plot(show_mc=True)
¶
Plot the cross-correlation function and optional lag distributions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
show_mc
|
bool
|
Whether to show lag distributions from GP samples or Monte Carlo trials. |
True
|
Source code in stela_toolkit/cross_correlation.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
|
run_monte_carlo()
¶
Run Monte Carlo simulations using RSS (only if mode='lin_interp') + FR to estimate the lag uncertainties.
Each trial performs:
- Random Subset Selection (RSS): Resample with replacement from each light curve
- RSS can only be used when using linear interpolation, for which the time arrays do not need to be the same.
- Flux Randomization (FR): Add Gaussian noise based on measurement errors
- Discard trials with low correlation (if rmax_threshold is set)
Returns:
Name | Type | Description |
---|---|---|
peak_lags |
ndarray
|
Peak lag values from successful trials. |
centroid_lags |
ndarray
|
Centroid lag values from successful trials. |
Source code in stela_toolkit/cross_correlation.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
|