lfit-python 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lfit_python/__init__.py +27 -0
- lfit_python/chains.py +157 -0
- lfit_python/cli/__init__.py +1 -0
- lfit_python/cli/limbdark.py +64 -0
- lfit_python/cli/mcmcfit.py +168 -0
- lfit_python/cli/physparams.py +154 -0
- lfit_python/cli/reddening.py +50 -0
- lfit_python/cli/summary.py +78 -0
- lfit_python/cli/update_input.py +65 -0
- lfit_python/cli/watch.py +39 -0
- lfit_python/cli/wdparams.py +223 -0
- lfit_python/cv_model.py +864 -0
- lfit_python/data/Bergeron/README +7 -0
- lfit_python/data/Bergeron/Table_DA +257 -0
- lfit_python/data/Bergeron/Table_DA_sdss +307 -0
- lfit_python/data/Bergeron/Table_DB +312 -0
- lfit_python/data/Bergeron/color_correction_tables/color_corrections_HCAM-GTC-super_minus_ntt_ucam.csv +1067 -0
- lfit_python/data/Bergeron/color_correction_tables/color_corrections_HCAM-GTC-super_minus_tnt_uspec.csv +1067 -0
- lfit_python/data/Gianninas13/ld_coeffs_g.txt +654 -0
- lfit_python/data/Gianninas13/ld_coeffs_i.txt +654 -0
- lfit_python/data/Gianninas13/ld_coeffs_r.txt +654 -0
- lfit_python/data/Gianninas13/ld_coeffs_u.txt +654 -0
- lfit_python/data/Gianninas13/ld_coeffs_z.txt +654 -0
- lfit_python/data/Gianninas13/radial_bright_profiles.txt +6925 -0
- lfit_python/data/Hamada/mr_hamada.dat +1307 -0
- lfit_python/data/Panei/12C-MR-H-He/12C-MR-H-He.dat +387 -0
- lfit_python/data/Panei/12C-MR-H-He/12C-MR-H-He.saver +750 -0
- lfit_python/data/Panei/12C-MR-He/12C-MR-He.dat +431 -0
- lfit_python/data/Panei/HS/04He-H-S.dat +158 -0
- lfit_python/data/Panei/HS/12C-H-S.dat +158 -0
- lfit_python/data/Panei/HS/16O-H-S.dat +158 -0
- lfit_python/data/Panei/HS/28Si-H-S.dat +158 -0
- lfit_python/data/Panei/HS/56Fe-H-S.dat +158 -0
- lfit_python/data/Panei/othercores/04He-MR-H.dat +91 -0
- lfit_python/data/Panei/othercores/16O-MR-H-He.dat +602 -0
- lfit_python/data/Panei/othercores/28Si-MR-H-He.dat +386 -0
- lfit_python/data/Panei/othercores/56Fe-MR-H-He.dat +390 -0
- lfit_python/data/Panei/othercores/old/04He-MR-H.save +120 -0
- lfit_python/data/Panei/othercores/old/04He-MR.save +130 -0
- lfit_python/data/Panei/othercores/old/16O-MR-H-He.save +602 -0
- lfit_python/data/Panei/othercores/old/16O-MR-He.save +469 -0
- lfit_python/data/Panei/othercores/old/28Si-MR-H-He.save +386 -0
- lfit_python/data/Panei/othercores/old/28Si-MR-He.save +402 -0
- lfit_python/data/Panei/othercores/old/56Fe-MR-H-He.save +633 -0
- lfit_python/data/Panei/othercores/old/56Fe-MR-He.save +537 -0
- lfit_python/data/Wood95/co040.2.04dt1 +80 -0
- lfit_python/data/Wood95/co050.2.04dt1 +82 -0
- lfit_python/data/Wood95/co060.2.04dt1 +85 -0
- lfit_python/data/Wood95/co070.2.04dt1 +91 -0
- lfit_python/data/Wood95/co080.2.04dt1 +100 -0
- lfit_python/data/Wood95/co090.2.04dt1 +99 -0
- lfit_python/data/Wood95/co100.2.04dt1 +100 -0
- lfit_python/data/althaus/readme.tex +12 -0
- lfit_python/data/althaus/t106.one +1132 -0
- lfit_python/data/althaus/t108.one +679 -0
- lfit_python/data/althaus/t110.one +821 -0
- lfit_python/data/althaus/t112.one +239 -0
- lfit_python/data/althaus/t114.one +355 -0
- lfit_python/data/althaus/t116.one +353 -0
- lfit_python/data/althaus/t118.one +356 -0
- lfit_python/data/althaus/t120.one +882 -0
- lfit_python/data/althaus/t122.one +901 -0
- lfit_python/data/althaus/t124.one +913 -0
- lfit_python/data/althaus/t126.one +739 -0
- lfit_python/data/althaus/t128.one +665 -0
- lfit_python/data/althaus/t130.one +626 -0
- lfit_python/likelihood.py +26 -0
- lfit_python/limbdark.py +47 -0
- lfit_python/model.py +801 -0
- lfit_python/physical_params.py +279 -0
- lfit_python/plotting.py +364 -0
- lfit_python/priors.py +51 -0
- lfit_python/sampling.py +472 -0
- lfit_python/summary.py +327 -0
- lfit_python/watch_app.py +1001 -0
- lfit_python/wdparams.py +587 -0
- lfit_python-0.1.0.dist-info/METADATA +222 -0
- lfit_python-0.1.0.dist-info/RECORD +81 -0
- lfit_python-0.1.0.dist-info/WHEEL +5 -0
- lfit_python-0.1.0.dist-info/entry_points.txt +9 -0
- lfit_python-0.1.0.dist-info/top_level.txt +1 -0
lfit_python/wdparams.py
ADDED
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
"""
|
|
2
|
+
White dwarf model: fit Bergeron model atmosphere fluxes to observed WD fluxes.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import copy
|
|
6
|
+
from enum import Enum
|
|
7
|
+
|
|
8
|
+
import matplotlib.pyplot as plt
|
|
9
|
+
import numpy as np
|
|
10
|
+
import pandas as pd
|
|
11
|
+
import scipy.interpolate as interp
|
|
12
|
+
|
|
13
|
+
from . import DATA_DIR
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def ln_prior(vect, model):
|
|
17
|
+
# first we update the model to use the pars suggested by the MCMC chain
|
|
18
|
+
for i in range(model.npars):
|
|
19
|
+
model[i] = vect[i]
|
|
20
|
+
|
|
21
|
+
lnp = 0.0
|
|
22
|
+
|
|
23
|
+
# teff, (usually uniform between allowed range - 6 to 90,000)
|
|
24
|
+
param = model.teff
|
|
25
|
+
lnp += param.prior.logpdf(param.currVal)
|
|
26
|
+
|
|
27
|
+
# logg, uniform between allowed range (7.01 to 8.99), or Gaussian from constraints
|
|
28
|
+
param = model.logg
|
|
29
|
+
lnp += param.prior.logpdf(param.currVal)
|
|
30
|
+
|
|
31
|
+
# Parallax, gaussian prior of the gaia value.
|
|
32
|
+
param = model.plax
|
|
33
|
+
lnp += param.prior.logpdf(param.currVal)
|
|
34
|
+
|
|
35
|
+
# enforce +ve parallax
|
|
36
|
+
if model.plax.currVal <= 0:
|
|
37
|
+
return -np.inf
|
|
38
|
+
|
|
39
|
+
# reddening, cannot exceed galactic value (should estimate from line of sight)
|
|
40
|
+
# https://irsa.ipac.caltech.edu/applications/DUST/
|
|
41
|
+
param = model.ebv
|
|
42
|
+
lnp += param.prior.logpdf(param.currVal)
|
|
43
|
+
return lnp
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def ln_likelihood(vect, model):
|
|
47
|
+
# first we update the model to use the pars suggested by the MCMC chain
|
|
48
|
+
for i in range(model.npars):
|
|
49
|
+
model[i] = vect[i]
|
|
50
|
+
return -0.5 * model.chisq()
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def ln_prob(vect, model):
|
|
54
|
+
lnp = ln_prior(vect, model)
|
|
55
|
+
if np.isfinite(lnp):
|
|
56
|
+
lnp += ln_likelihood(vect, model)
|
|
57
|
+
if np.isnan(lnp):
|
|
58
|
+
lnp = -np.inf
|
|
59
|
+
return lnp
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def sdss2kg5(g, r):
|
|
63
|
+
KG5 = g - 0.2240 * (g - r) ** 2 - 0.3590 * (g - r) + 0.0460
|
|
64
|
+
return KG5
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
sdss2kg5_vect = np.vectorize(sdss2kg5)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def sdssmag2flux(mag):
|
|
71
|
+
return 3631e3 * np.power(10, -0.4 * mag)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class PhotometricSystem(Enum):
|
|
75
|
+
SDSS = "SDSS"
|
|
76
|
+
HCAM = "HCAM"
|
|
77
|
+
UCAM_SDSS = "UCAM_SDSS"
|
|
78
|
+
UCAM_SUPER = "UCAM_SUPER"
|
|
79
|
+
USPEC = "USPEC"
|
|
80
|
+
|
|
81
|
+
@property
|
|
82
|
+
def bergeron_table(self):
|
|
83
|
+
"""
|
|
84
|
+
Name of correct table for Bergeron mags
|
|
85
|
+
"""
|
|
86
|
+
if self.name == "SDSS":
|
|
87
|
+
return DATA_DIR / "Bergeron" / "Table_DA_sdss"
|
|
88
|
+
else:
|
|
89
|
+
return DATA_DIR / "Bergeron" / "Table_DA"
|
|
90
|
+
|
|
91
|
+
def _strip_band(self, band):
|
|
92
|
+
"""
|
|
93
|
+
Strip the band name of any suffixes, e.g. 'g_s' -> 'g', 'gs' -> 'g'
|
|
94
|
+
"""
|
|
95
|
+
band = band[0]
|
|
96
|
+
BANDS = ("u", "g", "r", "i", "z", "kg5") # bands in the system
|
|
97
|
+
if band not in BANDS:
|
|
98
|
+
raise ValueError(
|
|
99
|
+
f"Band {band} not recognised in {self.name} photometric system."
|
|
100
|
+
)
|
|
101
|
+
return band[0]
|
|
102
|
+
|
|
103
|
+
def color_correction_data(self, band):
|
|
104
|
+
"""
|
|
105
|
+
Information needed for correction from Bergeron table to this band
|
|
106
|
+
|
|
107
|
+
Parameters
|
|
108
|
+
----------
|
|
109
|
+
band: str
|
|
110
|
+
e.g u, g, r, i, z
|
|
111
|
+
|
|
112
|
+
Returns
|
|
113
|
+
-------
|
|
114
|
+
table: str
|
|
115
|
+
Path to color correction tables
|
|
116
|
+
column: str
|
|
117
|
+
Name of column to read from table for correction
|
|
118
|
+
"""
|
|
119
|
+
band = self._strip_band(band)
|
|
120
|
+
if self.name == "USPEC":
|
|
121
|
+
table = (
|
|
122
|
+
DATA_DIR
|
|
123
|
+
/ "Bergeron"
|
|
124
|
+
/ "color_correction_tables"
|
|
125
|
+
/ "color_corrections_HCAM-GTC-super_minus_tnt_uspec.csv"
|
|
126
|
+
)
|
|
127
|
+
column = band
|
|
128
|
+
elif self.name == "SDSS" or self.name == "HCAM":
|
|
129
|
+
table = None
|
|
130
|
+
column = None
|
|
131
|
+
else:
|
|
132
|
+
table = (
|
|
133
|
+
DATA_DIR
|
|
134
|
+
/ "Bergeron"
|
|
135
|
+
/ "color_correction_tables"
|
|
136
|
+
/ "color_corrections_HCAM-GTC-super_minus_ntt_ucam.csv"
|
|
137
|
+
)
|
|
138
|
+
column = f"{band}_s" if "SUPER" in self.name else band
|
|
139
|
+
return table, column
|
|
140
|
+
|
|
141
|
+
def central_wavelength(self, band):
|
|
142
|
+
band = self._strip_band(band)
|
|
143
|
+
super_lambda_c = {
|
|
144
|
+
"u": 352.6,
|
|
145
|
+
"g": 473.2,
|
|
146
|
+
"r": 619.9,
|
|
147
|
+
"i": 771.1,
|
|
148
|
+
"z": 915.6,
|
|
149
|
+
}
|
|
150
|
+
lambda_c = {
|
|
151
|
+
"u": 355.7,
|
|
152
|
+
"g": 482.5,
|
|
153
|
+
"r": 626.1,
|
|
154
|
+
"i": 767.2,
|
|
155
|
+
"z": 909.7,
|
|
156
|
+
"kg5": 507.5,
|
|
157
|
+
}
|
|
158
|
+
lambda_c_dict = (
|
|
159
|
+
super_lambda_c if self.name in ["HCAM", "UCAM_SUPER"] else lambda_c
|
|
160
|
+
)
|
|
161
|
+
return lambda_c_dict[band]
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
class Flux(object):
|
|
165
|
+
BANDS = ["u", "g", "r", "i", "z"]
|
|
166
|
+
# Multiply E(B-V) by these numbers to get extinction in each band
|
|
167
|
+
# from Schlafly & Finkbeiner (2011) @ R_V = 3.1
|
|
168
|
+
EXTINCTION_COEFFS = {
|
|
169
|
+
"u": 4.239,
|
|
170
|
+
"g": 3.303,
|
|
171
|
+
"r": 2.285,
|
|
172
|
+
"i": 1.698,
|
|
173
|
+
"z": 1.263,
|
|
174
|
+
"kg5": 2.751,
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
def __init__(self, val, err, photometric_system, band, syserr=0.03):
|
|
178
|
+
"""
|
|
179
|
+
Representation of an observed WD flux
|
|
180
|
+
|
|
181
|
+
Parameters
|
|
182
|
+
----------
|
|
183
|
+
val, err: float
|
|
184
|
+
Observed value and error
|
|
185
|
+
photometric_system: PhotometricSystem
|
|
186
|
+
The system this flux is observed in e.g SDSS or HCAM
|
|
187
|
+
band: str
|
|
188
|
+
Name of filter, e.g 'u', 'g' etc.
|
|
189
|
+
|
|
190
|
+
Do not use values like 'g_s' here, that is taken
|
|
191
|
+
care of in the photometric system
|
|
192
|
+
syserr: float
|
|
193
|
+
Additional systematic error added to account for calibration
|
|
194
|
+
issues.
|
|
195
|
+
"""
|
|
196
|
+
self.flux = val
|
|
197
|
+
self.err = np.sqrt(err**2 + (val * syserr) ** 2)
|
|
198
|
+
|
|
199
|
+
# This is the actual band observed with.
|
|
200
|
+
self.photometric_system = photometric_system
|
|
201
|
+
self.band = band
|
|
202
|
+
self.mag = 2.5 * np.log10(3631e3 / self.flux)
|
|
203
|
+
self.magerr = 2.5 * 0.434 * (self.err / self.flux)
|
|
204
|
+
|
|
205
|
+
# Create an interpolater for the color corrections
|
|
206
|
+
correction_table_name, column = photometric_system.color_correction_data(
|
|
207
|
+
self.band
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
if correction_table_name is not None:
|
|
211
|
+
correction_table = pd.read_csv(correction_table_name)
|
|
212
|
+
self.correction_func = interp.LinearNDInterpolator(
|
|
213
|
+
correction_table[["Teff", "logg"]], correction_table[column]
|
|
214
|
+
)
|
|
215
|
+
else:
|
|
216
|
+
self.correction_func = None
|
|
217
|
+
|
|
218
|
+
# Create an interpolator for the Bergeron table
|
|
219
|
+
self.band = self.band[0] # strip any suffixes
|
|
220
|
+
DA = pd.read_csv(
|
|
221
|
+
photometric_system.bergeron_table,
|
|
222
|
+
sep=r"\s+",
|
|
223
|
+
skiprows=0,
|
|
224
|
+
header=1,
|
|
225
|
+
)
|
|
226
|
+
self.bergeron_func = interp.LinearNDInterpolator(
|
|
227
|
+
DA[["Teff", "log_g"]], DA[self.band]
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
def __repr__(self):
|
|
231
|
+
return "Flux(val={:.3f}, err={:.3f}, photometric_system={}, band={})".format(
|
|
232
|
+
self.flux, self.err, self.photometric_system, self.band
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
@property
|
|
236
|
+
def extinction_coefficient(self):
|
|
237
|
+
return self.EXTINCTION_COEFFS[self.band]
|
|
238
|
+
|
|
239
|
+
@property
|
|
240
|
+
def central_wavelength(self):
|
|
241
|
+
return self.photometric_system.central_wavelength(self.band)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
class WDModel:
|
|
245
|
+
"""
|
|
246
|
+
Model for calculating WD Fluxes
|
|
247
|
+
|
|
248
|
+
Can be passed to MCMC routines for calculating model and chisq, and prior prob
|
|
249
|
+
|
|
250
|
+
This class also behaves like a list, of the current values of all parameters
|
|
251
|
+
this enables it to be seamlessly used with emcee
|
|
252
|
+
|
|
253
|
+
Note that parallax should be provided in MILLIarcseconds.
|
|
254
|
+
|
|
255
|
+
Parameters
|
|
256
|
+
-----------
|
|
257
|
+
teff, logg, plax, ebv: `mcmc_utils.Param`
|
|
258
|
+
Fittable parameters.
|
|
259
|
+
fluxes: list(Flux)
|
|
260
|
+
A list of observed fluxes.
|
|
261
|
+
"""
|
|
262
|
+
|
|
263
|
+
# arguments are Param objects (see mcmc_utils)
|
|
264
|
+
def __init__(self, teff, logg, plax, ebv, fluxes):
|
|
265
|
+
self.teff = teff
|
|
266
|
+
self.logg = logg
|
|
267
|
+
self.plax = plax
|
|
268
|
+
self.ebv = ebv
|
|
269
|
+
|
|
270
|
+
# initialise list bit of object with parameters
|
|
271
|
+
self.variables = [self.teff, self.logg, self.plax, self.ebv]
|
|
272
|
+
|
|
273
|
+
# Observed data
|
|
274
|
+
self.obs_fluxes = copy.copy(fluxes)
|
|
275
|
+
|
|
276
|
+
# these routines are needed so object will behave like a list
|
|
277
|
+
def __getitem__(self, ind):
|
|
278
|
+
return self.variables[ind].currVal
|
|
279
|
+
|
|
280
|
+
def __setitem__(self, ind, val):
|
|
281
|
+
self.variables[ind].currVal = val
|
|
282
|
+
|
|
283
|
+
def __delitem__(self, ind):
|
|
284
|
+
self.variables.remove(ind)
|
|
285
|
+
|
|
286
|
+
def __len__(self):
|
|
287
|
+
return len(self.variables)
|
|
288
|
+
|
|
289
|
+
def insert(self, ind, val):
|
|
290
|
+
self.variables.insert(ind, val)
|
|
291
|
+
|
|
292
|
+
@property
|
|
293
|
+
def npars(self):
|
|
294
|
+
return len(self.variables)
|
|
295
|
+
|
|
296
|
+
@property
|
|
297
|
+
def dist(self):
|
|
298
|
+
if self.plax.currVal <= 0.0:
|
|
299
|
+
return np.inf
|
|
300
|
+
else:
|
|
301
|
+
return 1000.0 / self.plax.currVal
|
|
302
|
+
|
|
303
|
+
def __repr__(self):
|
|
304
|
+
return "WDModel(teff={:.1f}, logg={:.2f}, plax={:.3f}, ebv={:.1f})".format(
|
|
305
|
+
self.teff.currVal,
|
|
306
|
+
self.logg.currVal,
|
|
307
|
+
self.plax.currVal,
|
|
308
|
+
self.ebv.currVal,
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
@property
|
|
312
|
+
def apparent_mags(self):
|
|
313
|
+
"""
|
|
314
|
+
Calculate apparent magnitudes for each of my observed fluxes
|
|
315
|
+
"""
|
|
316
|
+
mags = []
|
|
317
|
+
t, g = self.teff.currVal, self.logg.currVal
|
|
318
|
+
# Distance modulus
|
|
319
|
+
dmod = -5.0 * np.log10(self.plax.currVal / 100)
|
|
320
|
+
for flux in self.obs_fluxes:
|
|
321
|
+
abs_mag = flux.bergeron_func(t, g)
|
|
322
|
+
# correction from magnitude in bergeron table to observed system
|
|
323
|
+
if flux.correction_func is None:
|
|
324
|
+
correction = 0
|
|
325
|
+
else:
|
|
326
|
+
correction = flux.correction_func(t, g)
|
|
327
|
+
# correction is Bergeron System - Observed System
|
|
328
|
+
# correct to OBSERVED system
|
|
329
|
+
abs_mag -= correction
|
|
330
|
+
# apply distance modulus
|
|
331
|
+
mag = abs_mag + dmod
|
|
332
|
+
|
|
333
|
+
# apply exinction
|
|
334
|
+
extinction = self.ebv.currVal * flux.extinction_coefficient
|
|
335
|
+
mag += extinction
|
|
336
|
+
mags.append(mag)
|
|
337
|
+
|
|
338
|
+
return np.array(mags)
|
|
339
|
+
|
|
340
|
+
def chisq(self):
|
|
341
|
+
"""Calculate Chisq"""
|
|
342
|
+
|
|
343
|
+
mags = self.apparent_mags
|
|
344
|
+
predicted_fluxes = sdssmag2flux(mags)
|
|
345
|
+
observed_fluxes = np.array([f.flux for f in self.obs_fluxes])
|
|
346
|
+
errors = np.array([f.err for f in self.obs_fluxes])
|
|
347
|
+
# Chi-squared
|
|
348
|
+
chisq = np.power(((predicted_fluxes - observed_fluxes) / errors), 2)
|
|
349
|
+
chisq = np.sum(chisq)
|
|
350
|
+
|
|
351
|
+
return chisq
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def plotColors(model, fname="colorplot.pdf"):
|
|
355
|
+
print("\n\n-----------------------------------------------")
|
|
356
|
+
print("Creating color plots...")
|
|
357
|
+
_, ax = plt.subplots(figsize=(6, 6))
|
|
358
|
+
|
|
359
|
+
# OBSERVED DATA
|
|
360
|
+
flux_u = [obs for obs in model.obs_fluxes if "u" in obs.band][0]
|
|
361
|
+
flux_g = [obs for obs in model.obs_fluxes if "g" in obs.band][0]
|
|
362
|
+
flux_r = [obs for obs in model.obs_fluxes if "r" in obs.band][0]
|
|
363
|
+
print("Observations:\n {}\n {}\n {}".format(flux_u, flux_g, flux_r))
|
|
364
|
+
|
|
365
|
+
obs_ug_err = np.sqrt((flux_u.magerr**2) + (flux_g.magerr**2))
|
|
366
|
+
obs_gr_err = np.sqrt((flux_g.magerr**2) + (flux_r.magerr**2))
|
|
367
|
+
|
|
368
|
+
# Correct magnitudes to the Bergeron frame
|
|
369
|
+
t, g = model.teff.currVal, model.logg.currVal
|
|
370
|
+
u_mag = flux_u.bergeron_mag(t, g)
|
|
371
|
+
g_mag = flux_g.bergeron_mag(t, g)
|
|
372
|
+
r_mag = flux_r.bergeron_mag(t, g)
|
|
373
|
+
|
|
374
|
+
if model.DEBUG:
|
|
375
|
+
print("Observation, uncorrected for IS extinction:")
|
|
376
|
+
print(
|
|
377
|
+
" Magnitudes:\n u: {}\n g: {}\n r: {}".format(
|
|
378
|
+
u_mag, g_mag, r_mag
|
|
379
|
+
)
|
|
380
|
+
)
|
|
381
|
+
|
|
382
|
+
# subtract interstellar extinction
|
|
383
|
+
ex = model.ebv
|
|
384
|
+
u_mag -= model.extinction_coefficients["u_s"] * ex.currVal
|
|
385
|
+
g_mag -= model.extinction_coefficients["g_s"] * ex.currVal
|
|
386
|
+
r_mag -= model.extinction_coefficients["r_s"] * ex.currVal
|
|
387
|
+
|
|
388
|
+
print("After correcting (if necessary), and removing IS extinction:")
|
|
389
|
+
print(
|
|
390
|
+
" Magnitudes:\n u: {}\n g: {}\n r: {}".format(u_mag, g_mag, r_mag)
|
|
391
|
+
)
|
|
392
|
+
|
|
393
|
+
ug_mag = u_mag - g_mag
|
|
394
|
+
gr_mag = g_mag - r_mag
|
|
395
|
+
|
|
396
|
+
print(
|
|
397
|
+
"Observed Colors in the HCAM/GTC/super lightpath (corrected for IS extinction):"
|
|
398
|
+
)
|
|
399
|
+
print("u-g = {:> 5.3f}+/-{:< 5.3f}".format(ug_mag, obs_ug_err))
|
|
400
|
+
print("g-r = {:> 5.3f}+/-{:< 5.3f}".format(gr_mag, obs_gr_err))
|
|
401
|
+
|
|
402
|
+
# Generate the model's apparent magnitudes (no atmosphere, no IS extinction), and plot that color too
|
|
403
|
+
# Get absolute magnitudes
|
|
404
|
+
abs_mags = model.gen_absolute_mags()
|
|
405
|
+
# Apply distance modulus
|
|
406
|
+
dmod = 5.0 * np.log10(model.dist / 10.0)
|
|
407
|
+
modelled_mags = abs_mags + dmod
|
|
408
|
+
|
|
409
|
+
# Calculate the colours
|
|
410
|
+
bands = [obs.orig_band for obs in model.obs_fluxes]
|
|
411
|
+
u_index = bands.index(flux_u.orig_band)
|
|
412
|
+
g_index = bands.index(flux_g.orig_band)
|
|
413
|
+
r_index = bands.index(flux_r.orig_band)
|
|
414
|
+
if model.DEBUG:
|
|
415
|
+
print(
|
|
416
|
+
"Bergeron model interpolations for T: {:.0f}, log(g): {:.3f}...".format(
|
|
417
|
+
model.teff.currVal, model.logg.currVal
|
|
418
|
+
)
|
|
419
|
+
)
|
|
420
|
+
print("Observed bands: {}".format(bands))
|
|
421
|
+
print("Modelled mags: {}".format(modelled_mags))
|
|
422
|
+
print("Indexes|| u: {} || g: {} || r: {}\n".format(u_index, g_index, r_index))
|
|
423
|
+
|
|
424
|
+
model_ug = modelled_mags[u_index] - modelled_mags[g_index]
|
|
425
|
+
model_gr = modelled_mags[g_index] - modelled_mags[r_index]
|
|
426
|
+
|
|
427
|
+
# bergeron model magnitudes, will be plotted as tracks
|
|
428
|
+
bergeron_umags = np.array(model.DA["u_s"])
|
|
429
|
+
bergeron_gmags = np.array(model.DA["g_s"])
|
|
430
|
+
bergeron_rmags = np.array(model.DA["r_s"])
|
|
431
|
+
|
|
432
|
+
# calculate colours
|
|
433
|
+
ug = bergeron_umags - bergeron_gmags
|
|
434
|
+
gr = bergeron_gmags - bergeron_rmags
|
|
435
|
+
|
|
436
|
+
# make grid of teff, logg from the bergeron table
|
|
437
|
+
teffs = np.unique(model.DA["Teff"])
|
|
438
|
+
loggs = np.unique(model.DA["log_g"])
|
|
439
|
+
nteff = len(teffs)
|
|
440
|
+
nlogg = len(loggs)
|
|
441
|
+
# reshape colours onto 2D grid of (logg, teff)
|
|
442
|
+
ug = ug.reshape((nlogg, nteff))
|
|
443
|
+
gr = gr.reshape((nlogg, nteff))
|
|
444
|
+
|
|
445
|
+
# Plotting
|
|
446
|
+
# Bergeron cooling tracks and isogravity contours
|
|
447
|
+
for a in range(nlogg):
|
|
448
|
+
ax.plot(ug[a, :], gr[a, :], "k-")
|
|
449
|
+
for a in range(0, nteff, 4):
|
|
450
|
+
ax.plot(ug[:, a], gr[:, a], "r--")
|
|
451
|
+
|
|
452
|
+
# Observed color
|
|
453
|
+
ax.errorbar(
|
|
454
|
+
x=ug_mag,
|
|
455
|
+
y=gr_mag,
|
|
456
|
+
xerr=obs_ug_err,
|
|
457
|
+
yerr=obs_gr_err,
|
|
458
|
+
fmt="o",
|
|
459
|
+
ls="none",
|
|
460
|
+
color="darkred",
|
|
461
|
+
capsize=3,
|
|
462
|
+
label="Observed",
|
|
463
|
+
)
|
|
464
|
+
|
|
465
|
+
# Modelled color
|
|
466
|
+
ax.errorbar(
|
|
467
|
+
x=model_ug,
|
|
468
|
+
y=model_gr,
|
|
469
|
+
fmt="o",
|
|
470
|
+
ls="none",
|
|
471
|
+
color="blue",
|
|
472
|
+
capsize=3,
|
|
473
|
+
label="Modelled - T: {:.0f} | logg: {:.2f}".format(t, g),
|
|
474
|
+
)
|
|
475
|
+
|
|
476
|
+
# annotate for teff
|
|
477
|
+
xa = ug[0, 4] + 0.03
|
|
478
|
+
ya = gr[0, 4]
|
|
479
|
+
val = teffs[4]
|
|
480
|
+
t = ax.annotate(
|
|
481
|
+
"T = %d K" % val,
|
|
482
|
+
xy=(xa, ya),
|
|
483
|
+
color="r",
|
|
484
|
+
horizontalalignment="left",
|
|
485
|
+
verticalalignment="center",
|
|
486
|
+
size="small",
|
|
487
|
+
)
|
|
488
|
+
t.set_rotation(0.0)
|
|
489
|
+
|
|
490
|
+
xa = ug[0, 8] + 0.03
|
|
491
|
+
ya = gr[0, 8]
|
|
492
|
+
val = teffs[8]
|
|
493
|
+
t = ax.annotate(
|
|
494
|
+
"T = %d K" % val,
|
|
495
|
+
xy=(xa, ya),
|
|
496
|
+
color="r",
|
|
497
|
+
horizontalalignment="left",
|
|
498
|
+
verticalalignment="center",
|
|
499
|
+
size="small",
|
|
500
|
+
)
|
|
501
|
+
t.set_rotation(0.0)
|
|
502
|
+
|
|
503
|
+
xa = ug[0, 20] + 0.01
|
|
504
|
+
ya = gr[0, 20] - 0.01
|
|
505
|
+
val = teffs[20]
|
|
506
|
+
t = ax.annotate(
|
|
507
|
+
"T = %d K" % val,
|
|
508
|
+
xy=(xa, ya),
|
|
509
|
+
color="r",
|
|
510
|
+
horizontalalignment="left",
|
|
511
|
+
verticalalignment="top",
|
|
512
|
+
size="small",
|
|
513
|
+
)
|
|
514
|
+
t.set_rotation(0.0)
|
|
515
|
+
|
|
516
|
+
xa = ug[0, 24] + 0.01
|
|
517
|
+
ya = gr[0, 24] - 0.01
|
|
518
|
+
val = teffs[24]
|
|
519
|
+
t = ax.annotate(
|
|
520
|
+
"T = %d K" % val,
|
|
521
|
+
xy=(xa, ya),
|
|
522
|
+
color="r",
|
|
523
|
+
horizontalalignment="left",
|
|
524
|
+
verticalalignment="top",
|
|
525
|
+
size="small",
|
|
526
|
+
)
|
|
527
|
+
t.set_rotation(0.0)
|
|
528
|
+
|
|
529
|
+
ax.set_xlabel("{}-{}".format(flux_u.orig_band, flux_g.orig_band))
|
|
530
|
+
ax.set_ylabel("{}-{}".format(flux_g.orig_band, flux_r.orig_band))
|
|
531
|
+
ax.set_xlim([-0.5, 1])
|
|
532
|
+
ax.set_ylim([-0.5, 0.5])
|
|
533
|
+
ax.legend()
|
|
534
|
+
|
|
535
|
+
plt.savefig(fname)
|
|
536
|
+
plt.show()
|
|
537
|
+
|
|
538
|
+
print("Done!")
|
|
539
|
+
print("-----------------------------------------------\n")
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
def plotFluxes(model, fname="fluxplot.pdf"):
|
|
543
|
+
"""
|
|
544
|
+
Plot observed fluxes vs model fluxes
|
|
545
|
+
"""
|
|
546
|
+
model_mags = model.apparent_mags
|
|
547
|
+
model_flx = sdssmag2flux(model_mags)
|
|
548
|
+
# Central wavelengths for the bands
|
|
549
|
+
lambdas = np.array([obs.central_wavelength for obs in model.obs_fluxes])
|
|
550
|
+
obs_flx = [obs.flux for obs in model.obs_fluxes]
|
|
551
|
+
obs_flx_err = [obs.err for obs in model.obs_fluxes]
|
|
552
|
+
|
|
553
|
+
# Do the actual plotting
|
|
554
|
+
_, ax = plt.subplots(figsize=(5, 5))
|
|
555
|
+
ax.errorbar(
|
|
556
|
+
lambdas,
|
|
557
|
+
model_flx,
|
|
558
|
+
xerr=None,
|
|
559
|
+
yerr=None,
|
|
560
|
+
fmt="P",
|
|
561
|
+
ls="none",
|
|
562
|
+
color="darkred",
|
|
563
|
+
label="Modelled apparent flux",
|
|
564
|
+
markersize=6,
|
|
565
|
+
linewidth=1,
|
|
566
|
+
capsize=None,
|
|
567
|
+
)
|
|
568
|
+
ax.errorbar(
|
|
569
|
+
lambdas,
|
|
570
|
+
obs_flx,
|
|
571
|
+
xerr=None,
|
|
572
|
+
yerr=obs_flx_err,
|
|
573
|
+
fmt="o",
|
|
574
|
+
ls="none",
|
|
575
|
+
color="blue",
|
|
576
|
+
label="Observed flux",
|
|
577
|
+
markersize=6,
|
|
578
|
+
linewidth=1,
|
|
579
|
+
capsize=None,
|
|
580
|
+
)
|
|
581
|
+
ax.set_xlabel("Wavelength, nm")
|
|
582
|
+
ax.set_ylabel("Flux, mJy")
|
|
583
|
+
ax.legend()
|
|
584
|
+
|
|
585
|
+
plt.tight_layout()
|
|
586
|
+
plt.savefig(fname)
|
|
587
|
+
plt.close("all")
|