data_simulator¶
SimulateLightCurve
¶
Simulates light curves with a specified power spectral density (PSD) and optional lag injection via an impulse response function (IRF), using the Timmer & Koenig (1995) method.
The light curve is generated in Fourier space, with random phases and amplitudes shaped by the PSD. It is then inverse-Fourier transformed to the time domain, rescaled to the desired mean and standard deviation, and optionally passed through Poisson or Gaussian noise models.
Supports both regularly and irregularly sampled time grids: - For regular grids: oversamples the light curve before trimming to the desired grid. - For irregular grids: simulates on a fine grid and selects nearest times (no interpolation).
Optional lag injection is applied via convolution with an impulse response kernel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_grid
|
ndarray
|
Target time grid for the simulated light curve (must be sorted). |
required |
psd_type
|
str
|
Type of PSD to simulate. Options are:
|
required |
psd_params
|
dict
|
Parameters for the PSD model. Depends on
|
required |
mean
|
float
|
Desired mean of the light curve after rescaling. |
required |
std
|
float
|
Desired standard deviation of the light curve after rescaling. |
required |
add_noise
|
str or None
|
Type of noise to add. Options are:
|
None
|
gaussian_frac_err
|
float or None
|
Fractional error to use when |
None
|
bkg_rate
|
float
|
Background count rate (used in Poisson noise simulation). Default is 0. |
0.0
|
oversample
|
int
|
Oversampling factor for regularly spaced grids. Default is 10. |
10
|
fine_factor
|
int
|
Factor controlling the resolution of simulation for irregular grids. Default is 100. |
100
|
inject_lag
|
bool
|
Whether to apply a lag by convolving with an impulse response function. Default is False. |
False
|
response_type
|
str or None
|
Type of IRF for lag injection. Options are:
|
None
|
response_params
|
dict or None
|
Parameters for the IRF. Depends on
|
None
|
Attributes:
Name | Type | Description |
---|---|---|
rates |
ndarray
|
Simulated light curve values after noise is added. |
errors |
ndarray
|
Estimated uncertainties for each time point. |
simlc |
LightCurve
|
The simulated light curve object (with noise). |
simlc_lagged |
LightCurve or None
|
Lagged version of the light curve, if |
Source code in stela_toolkit/data_simulator.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 |
|
add_gaussian_noise(lc, frac_err=0.05, min_error_floor=1e-10)
¶
Add Gaussian noise to a simulated light curve in flux units.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lc
|
ndarray
|
Simulated light curve values (flux units). |
required |
frac_err
|
float
|
Fractional error (e.g., 0.05 = 5%). |
0.05
|
min_error_floor
|
float
|
Minimum allowed error value to prevent zeros. |
1e-10
|
Returns:
Name | Type | Description |
---|---|---|
noisy_lc |
ndarray
|
Light curve with added Gaussian noise. |
errors |
ndarray
|
Standard deviation of the Gaussian noise at each point. |
Source code in stela_toolkit/data_simulator.py
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 |
|
add_poisson_noise(lc, time_grid, bkg_rate=0.0, exposure_times=None, min_error_floor=1e-10)
¶
Add Poisson noise to a simulated light curve.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lc
|
ndarray
|
Clean light curve values. |
required |
time_grid
|
ndarray
|
Time values. |
required |
bkg_rate
|
float
|
Background count rate. |
0.0
|
exposure_times
|
ndarray or None
|
Exposure duration for each point. If None, use time spacing to approximate integration time per bin. |
None
|
min_error_floor
|
float
|
Minimum uncertainty to avoid zeros. |
1e-10
|
Returns:
Name | Type | Description |
---|---|---|
noisy_lc |
ndarray
|
Noisy light curve. |
noise_estimate |
ndarray
|
Estimated error bars. |
Source code in stela_toolkit/data_simulator.py
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 |
|
add_regular_gaps(lc, time_grid, gap_period, gap_duration)
¶
Simulate regular gaps in the light curve.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lc
|
ndarray
|
Input light curve values. |
required |
time_grid
|
ndarray
|
Time values. |
required |
gap_period
|
float
|
Period between gaps. |
required |
gap_duration
|
float
|
Duration of each gap. |
required |
Returns:
Name | Type | Description |
---|---|---|
gapped_lc |
ndarray
|
Light curve with NaNs inserted for gaps. |
Source code in stela_toolkit/data_simulator.py
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 |
|
create_psd(freq)
¶
Construct the PSD array based on the selected type and parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
freq
|
ndarray
|
Frequency array. |
required |
Returns:
Name | Type | Description |
---|---|---|
psd |
ndarray
|
Power spectral density values. |
Source code in stela_toolkit/data_simulator.py
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 |
|
generate(time_grid)
¶
Generate the clean (noise-free) light curve.
Handles regular vs. irregular time grids and applies normalization. If lag injection is enabled, convolves with a response function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_grid
|
array - like
|
Desired output time grid. |
required |
Returns:
Name | Type | Description |
---|---|---|
rates |
ndarray
|
Simulated light curve values. |
rates_lagged |
ndarray or None
|
Lagged version of the light curve if |
Source code in stela_toolkit/data_simulator.py
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 |
|
plot()
¶
Plot the simulated light curve/s. Shows both the original and lagged data (if available).
Source code in stela_toolkit/data_simulator.py
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 |
|