Note
Go to the end to download the full example code.
Plot the lightcurve of a flaring star with spots#
This example plots the lightcurve caused by a flaring star when it also has spots.
from astropy import units as u
import matplotlib.pyplot as plt
from pathlib import Path
import numpy as np
import libpypsg
from VSPEC import ObservationModel,PhaseAnalyzer
from VSPEC import params
from VSPEC import config
from VSPEC.params.gcm import vspec_to_pygcm
SEED = 42
libpypsg.docker.set_url_and_run()
Saved settings to /home/runner/.libpypsg/settings.json
Reloading settings...
Initialize the VSPEC run parameters#
For this example, we will create the parameter objects explicitly. This can also be done using a YAML file.
header = params.Header(
data_path=Path('.vspec/flare_spot_lightcurve'),
seed=SEED,verbose=1,
spec_grid = params.VSPECGridParameters(
max_teff=3400*u.K,min_teff=2900*u.K,
impl_bin='rust',impl_interp='scipy',fail_on_missing=False
)
)
star = params.StarParameters(
psg_star_template='M',
teff=3300*u.K,
mass = 0.1*u.M_sun,
radius=0.15*u.R_sun,
period = 6*u.day,
misalignment_dir=0*u.deg,
misalignment=0*u.deg,
ld = params.LimbDarkeningParameters.solar(),
faculae=params.FaculaParameters.none(),
spots=params.SpotParameters(
distribution='iso',
initial_coverage=0.1,
area_mean=300*config.MSH,
area_logsigma=0.2,
teff_umbra=2900*u.K,
teff_penumbra=3000*u.K,
equillibrium_coverage=0.1,
burn_in=0*u.day,
growth_rate=0/u.day,
decay_rate=0*config.MSH/u.day,
initial_area=10*config.MSH
),
flares=params.FlareParameters(
dist_teff_mean=9000*u.K,
dist_teff_sigma=500*u.K,
dist_fwhm_mean=3*u.hr,
dist_fwhm_logsigma=0.4,
alpha=-0.829,
beta=26.87,
min_energy=1e32*u.erg,
cluster_size=3
),
granulation=params.GranulationParameters.none(),
grid_params=(500, 1000),
)
planet = params.PlanetParameters.std(init_phase=180*u.deg,init_substellar_lon=0*u.deg)
system = params.SystemParameters(
distance=1.3*u.pc,
inclination=80*u.deg,
phase_of_periastron=0*u.deg
)
observation = params.ObservationParameters(
observation_time=10*u.day,
integration_time=4*u.hr
)
psg_params = params.psgParameters(
gcm_binning=200,
phase_binning=1,
use_molecular_signatures=True,
use_continuum_stellar=True,
nmax=0,
lmax=0,
continuum=['Rayleigh', 'Refraction', 'CIA_all'],
)
instrument = params.InstrumentParameters.mirecle()
def gcm_getter():
return vspec_to_pygcm(
shape=(30,30,30),
epsilon=7,
star_teff=3800*u.K,
r_star=0.2*u.R_sun,
r_orbit=0.05*u.AU,
lat_redistribution=0.0,
p_surf=1*u.bar,
p_stop=1e-5*u.bar,
wind_u=0*u.km/u.s,
wind_v=0*u.km/u.s,
albedo=0.3,
emissivity=1.0,
gamma=1.4,
molecules={'CO2':1e-4}
)
gcm = params.gcmParameters(
gcm_getter=gcm_getter,
mean_molec_weight=28,
is_static=True
)
parameters = params.InternalParameters(
header = header,
star = star,
planet = planet,
system = system,
obs=observation,
psg = psg_params,
inst=instrument,
gcm = gcm
)
Run the simulation#
model = ObservationModel(params=parameters)
model.build_planet()
model.build_spectra()
Starting at phase 180.0 deg, observe for 10.0 d in 60 steps
Phases = [180. 186. 192. 198. 204. 210. 216. 222. 228. 234. 240. 246. 252. 258.
264. 270. 276. 282. 288. 294. 300. 306. 312. 318. 324. 330. 336. 342.
348. 354. 0. 6. 12. 18. 24. 30. 36. 42. 48. 54. 60. 66.
72. 78. 84. 90. 96. 102. 108. 114. 120. 126. 132. 138. 144. 150.
156. 162. 168. 174. 180.] deg
Build Planet: 0%| | 0/61 [00:00<?, ?it/s]
Build Planet: 2%|▏ | 1/61 [00:01<01:09, 1.16s/it]
Build Planet: 3%|▎ | 2/61 [00:02<01:11, 1.22s/it]
Build Planet: 5%|▍ | 3/61 [00:03<01:10, 1.22s/it]
Build Planet: 7%|▋ | 4/61 [00:04<01:07, 1.19s/it]
Build Planet: 8%|▊ | 5/61 [00:06<01:08, 1.22s/it]
Build Planet: 10%|▉ | 6/61 [00:07<01:05, 1.20s/it]
Build Planet: 11%|█▏ | 7/61 [00:08<01:04, 1.20s/it]
Build Planet: 13%|█▎ | 8/61 [00:09<01:02, 1.17s/it]
Build Planet: 15%|█▍ | 9/61 [00:10<01:00, 1.16s/it]
Build Planet: 16%|█▋ | 10/61 [00:11<00:58, 1.15s/it]
Build Planet: 18%|█▊ | 11/61 [00:12<00:57, 1.15s/it]
Build Planet: 20%|█▉ | 12/61 [00:14<00:56, 1.15s/it]
Build Planet: 21%|██▏ | 13/61 [00:15<00:55, 1.15s/it]
Build Planet: 23%|██▎ | 14/61 [00:16<00:53, 1.14s/it]
Build Planet: 25%|██▍ | 15/61 [00:17<00:52, 1.15s/it]
Build Planet: 26%|██▌ | 16/61 [00:18<00:51, 1.14s/it]
Build Planet: 28%|██▊ | 17/61 [00:19<00:50, 1.14s/it]
Build Planet: 30%|██▉ | 18/61 [00:20<00:49, 1.14s/it]
Build Planet: 31%|███ | 19/61 [00:22<00:47, 1.14s/it]
Build Planet: 33%|███▎ | 20/61 [00:23<00:46, 1.14s/it]
Build Planet: 34%|███▍ | 21/61 [00:24<00:45, 1.14s/it]
Build Planet: 36%|███▌ | 22/61 [00:25<00:44, 1.14s/it]
Build Planet: 38%|███▊ | 23/61 [00:26<00:43, 1.15s/it]
Build Planet: 39%|███▉ | 24/61 [00:27<00:42, 1.15s/it]
Build Planet: 41%|████ | 25/61 [00:28<00:41, 1.14s/it]
Build Planet: 43%|████▎ | 26/61 [00:30<00:40, 1.15s/it]
Build Planet: 44%|████▍ | 27/61 [00:31<00:38, 1.14s/it]
Build Planet: 46%|████▌ | 28/61 [00:32<00:37, 1.14s/it]
Build Planet: 48%|████▊ | 29/61 [00:33<00:36, 1.15s/it]
Build Planet: 49%|████▉ | 30/61 [00:34<00:35, 1.14s/it]
Build Planet: 51%|█████ | 31/61 [00:35<00:34, 1.15s/it]
Build Planet: 52%|█████▏ | 32/61 [00:36<00:33, 1.14s/it]
Build Planet: 54%|█████▍ | 33/61 [00:38<00:32, 1.14s/it]
Build Planet: 56%|█████▌ | 34/61 [00:39<00:31, 1.15s/it]
Build Planet: 57%|█████▋ | 35/61 [00:40<00:29, 1.15s/it]
Build Planet: 59%|█████▉ | 36/61 [00:41<00:28, 1.14s/it]
Build Planet: 61%|██████ | 37/61 [00:42<00:27, 1.14s/it]
Build Planet: 62%|██████▏ | 38/61 [00:43<00:26, 1.14s/it]
Build Planet: 64%|██████▍ | 39/61 [00:44<00:25, 1.14s/it]
Build Planet: 66%|██████▌ | 40/61 [00:46<00:24, 1.14s/it]
Build Planet: 67%|██████▋ | 41/61 [00:47<00:22, 1.14s/it]
Build Planet: 69%|██████▉ | 42/61 [00:48<00:21, 1.14s/it]
Build Planet: 70%|███████ | 43/61 [00:49<00:20, 1.13s/it]
Build Planet: 72%|███████▏ | 44/61 [00:50<00:19, 1.14s/it]
Build Planet: 74%|███████▍ | 45/61 [00:51<00:18, 1.14s/it]
Build Planet: 75%|███████▌ | 46/61 [00:52<00:17, 1.14s/it]
Build Planet: 77%|███████▋ | 47/61 [00:54<00:15, 1.13s/it]
Build Planet: 79%|███████▊ | 48/61 [00:55<00:14, 1.14s/it]
Build Planet: 80%|████████ | 49/61 [00:56<00:13, 1.13s/it]
Build Planet: 82%|████████▏ | 50/61 [00:57<00:12, 1.14s/it]
Build Planet: 84%|████████▎ | 51/61 [00:58<00:11, 1.14s/it]
Build Planet: 85%|████████▌ | 52/61 [00:59<00:10, 1.14s/it]
Build Planet: 87%|████████▋ | 53/61 [01:00<00:09, 1.14s/it]
Build Planet: 89%|████████▊ | 54/61 [01:02<00:07, 1.13s/it]
Build Planet: 90%|█████████ | 55/61 [01:03<00:06, 1.14s/it]
Build Planet: 92%|█████████▏| 56/61 [01:04<00:05, 1.14s/it]
Build Planet: 93%|█████████▎| 57/61 [01:05<00:04, 1.14s/it]
Build Planet: 95%|█████████▌| 58/61 [01:06<00:03, 1.14s/it]
Build Planet: 97%|█████████▋| 59/61 [01:07<00:02, 1.14s/it]
Build Planet: 98%|█████████▊| 60/61 [01:08<00:01, 1.14s/it]
Build Planet: 100%|██████████| 61/61 [01:10<00:00, 1.14s/it]
Build Planet: 100%|██████████| 61/61 [01:10<00:00, 1.15s/it]
Generated 29 mature spots
Creating interpolators:
thermal
thermal, combined
thermal, combined, stellar
thermal, combined, stellar, photon noise
thermal, combined, stellar, photon noise, detector noise
thermal, combined, stellar, photon noise, detector noise, telescope noise
thermal, combined, stellar, photon noise, detector noise, telescope noise, background noise
thermal, combined, stellar, photon noise, detector noise, telescope noise, background noise, transit
Finished!
Build Spectra: 0%| | 0/60 [00:00<?, ?it/s]
Loading Spectra: 0%| | 0/6 [00:00<?, ?it/s]
Loading Spectra: 17%|█▋ | 1/6 [00:00<00:01, 3.20it/s]
Loading Spectra: 33%|███▎ | 2/6 [00:00<00:01, 3.21it/s]
Loading Spectra: 50%|█████ | 3/6 [00:00<00:00, 3.21it/s]
Loading Spectra: 67%|██████▋ | 4/6 [00:01<00:00, 3.21it/s]
Loading Spectra: 83%|████████▎ | 5/6 [00:01<00:00, 3.21it/s]
Loading Spectra: 100%|██████████| 6/6 [00:01<00:00, 3.21it/s]
Loading Spectra: 100%|██████████| 6/6 [00:01<00:00, 3.21it/s]
Build Spectra: 2%|▏ | 1/60 [00:02<02:26, 2.48s/it]
Build Spectra: 3%|▎ | 2/60 [00:03<01:19, 1.36s/it]
Build Spectra: 5%|▌ | 3/60 [00:03<00:57, 1.01s/it]
Build Spectra: 7%|▋ | 4/60 [00:04<00:47, 1.18it/s]
Build Spectra: 8%|▊ | 5/60 [00:04<00:41, 1.31it/s]
Build Spectra: 10%|█ | 6/60 [00:05<00:38, 1.41it/s]
Build Spectra: 12%|█▏ | 7/60 [00:06<00:35, 1.48it/s]
Build Spectra: 13%|█▎ | 8/60 [00:06<00:33, 1.54it/s]
Build Spectra: 15%|█▌ | 9/60 [00:07<00:32, 1.57it/s]
Build Spectra: 17%|█▋ | 10/60 [00:07<00:31, 1.59it/s]
Build Spectra: 18%|█▊ | 11/60 [00:08<00:30, 1.61it/s]
Build Spectra: 20%|██ | 12/60 [00:09<00:29, 1.62it/s]
Build Spectra: 22%|██▏ | 13/60 [00:09<00:28, 1.64it/s]
Build Spectra: 23%|██▎ | 14/60 [00:10<00:27, 1.65it/s]
Build Spectra: 25%|██▌ | 15/60 [00:10<00:27, 1.66it/s]
Build Spectra: 27%|██▋ | 16/60 [00:11<00:26, 1.66it/s]
Build Spectra: 28%|██▊ | 17/60 [00:12<00:25, 1.66it/s]
Build Spectra: 30%|███ | 18/60 [00:12<00:25, 1.66it/s]
Build Spectra: 32%|███▏ | 19/60 [00:13<00:24, 1.66it/s]
Build Spectra: 33%|███▎ | 20/60 [00:13<00:24, 1.66it/s]
Build Spectra: 35%|███▌ | 21/60 [00:14<00:23, 1.66it/s]
Build Spectra: 37%|███▋ | 22/60 [00:15<00:22, 1.66it/s]
Build Spectra: 38%|███▊ | 23/60 [00:15<00:22, 1.67it/s]
Build Spectra: 40%|████ | 24/60 [00:16<00:21, 1.66it/s]
Build Spectra: 42%|████▏ | 25/60 [00:16<00:20, 1.67it/s]
Build Spectra: 43%|████▎ | 26/60 [00:17<00:20, 1.68it/s]
Build Spectra: 45%|████▌ | 27/60 [00:18<00:19, 1.68it/s]
Build Spectra: 47%|████▋ | 28/60 [00:18<00:19, 1.66it/s]
Build Spectra: 48%|████▊ | 29/60 [00:19<00:18, 1.67it/s]
Build Spectra: 50%|█████ | 30/60 [00:19<00:17, 1.67it/s]
Build Spectra: 52%|█████▏ | 31/60 [00:20<00:17, 1.67it/s]
Build Spectra: 53%|█████▎ | 32/60 [00:21<00:17, 1.58it/s]
Build Spectra: 55%|█████▌ | 33/60 [00:21<00:16, 1.61it/s]
Build Spectra: 57%|█████▋ | 34/60 [00:22<00:16, 1.62it/s]
Build Spectra: 58%|█████▊ | 35/60 [00:22<00:15, 1.64it/s]
Build Spectra: 60%|██████ | 36/60 [00:23<00:14, 1.65it/s]
Build Spectra: 62%|██████▏ | 37/60 [00:24<00:13, 1.66it/s]
Build Spectra: 63%|██████▎ | 38/60 [00:24<00:13, 1.67it/s]
Build Spectra: 65%|██████▌ | 39/60 [00:25<00:12, 1.69it/s]
Build Spectra: 67%|██████▋ | 40/60 [00:25<00:11, 1.70it/s]
Build Spectra: 68%|██████▊ | 41/60 [00:26<00:11, 1.70it/s]
Build Spectra: 70%|███████ | 42/60 [00:27<00:10, 1.70it/s]
Build Spectra: 72%|███████▏ | 43/60 [00:27<00:09, 1.71it/s]
Build Spectra: 73%|███████▎ | 44/60 [00:28<00:09, 1.71it/s]
Build Spectra: 75%|███████▌ | 45/60 [00:28<00:08, 1.72it/s]
Build Spectra: 77%|███████▋ | 46/60 [00:29<00:08, 1.72it/s]
Build Spectra: 78%|███████▊ | 47/60 [00:29<00:07, 1.73it/s]
Build Spectra: 80%|████████ | 48/60 [00:30<00:06, 1.73it/s]
Build Spectra: 82%|████████▏ | 49/60 [00:31<00:06, 1.73it/s]
Build Spectra: 83%|████████▎ | 50/60 [00:31<00:05, 1.73it/s]
Build Spectra: 85%|████████▌ | 51/60 [00:32<00:05, 1.73it/s]
Build Spectra: 87%|████████▋ | 52/60 [00:32<00:04, 1.73it/s]
Build Spectra: 88%|████████▊ | 53/60 [00:33<00:04, 1.74it/s]
Build Spectra: 90%|█████████ | 54/60 [00:34<00:03, 1.74it/s]
Build Spectra: 92%|█████████▏| 55/60 [00:34<00:02, 1.74it/s]
Build Spectra: 93%|█████████▎| 56/60 [00:35<00:02, 1.74it/s]
Build Spectra: 95%|█████████▌| 57/60 [00:35<00:01, 1.74it/s]
Build Spectra: 97%|█████████▋| 58/60 [00:36<00:01, 1.74it/s]
Build Spectra: 98%|█████████▊| 59/60 [00:36<00:00, 1.74it/s]
Build Spectra: 100%|██████████| 60/60 [00:37<00:00, 1.74it/s]
Build Spectra: 100%|██████████| 60/60 [00:37<00:00, 1.60it/s]
Load in the data#
We can use VSPEC to read in the synthetic data we just created.
data = PhaseAnalyzer(model.directories['all_model'])
Make the figure#
time = (data.time - data.time[0]).to_value(u.day)
wl = data.wavelength.to_value(u.um)
emission = (data.thermal/data.total).to_value(u.dimensionless_unscaled)*1e6
variation = (data.star/data.star[:,0,np.newaxis]-1).to_value(u.dimensionless_unscaled)*100
fig,ax = plt.subplots(1,2,figsize=(8,4))
im=ax[0].pcolormesh(time,wl,emission,cmap='cividis')
fig.colorbar(im,ax=ax[0],label='Planet Thermal Emission (ppm)',location='top')
# ax[0].set_title('Planet')
im=ax[1].pcolormesh(time,wl,variation,cmap='cividis')
fig.colorbar(im,ax=ax[1],label='Stellar Variation (%)',location='top')
# ax[1].set_title('Star')
ax[0].set_ylabel('Wavelength (${\\rm \\mu m}$)')
fig.text(0.5,0.02,'Time (days)',ha='center')

Text(0.5, 0.02, 'Time (days)')
Total running time of the script: (2 minutes 8.537 seconds)