Skip to content

Commit

Permalink
REL: v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
griffin-h committed Feb 8, 2022
2 parents b3a514e + 4fc5ab3 commit 564f518
Show file tree
Hide file tree
Showing 53 changed files with 1,737 additions and 88,791 deletions.
9 changes: 9 additions & 0 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ Installation
At the command line::

$ pip install lightcurve-fitting

To install the stable version directly from GitHub::

$ pip install git+https://github.com/griffin-h/lightcurve_fitting.git

If you want the bleeding-edge "development" version (not recommended)::

$ pip install git+https://github.com/griffin-h/lightcurve_fitting.git@dev

15 changes: 15 additions & 0 deletions docs/source/release-history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
Release History
===============

v0.4.0 (2022-02-08)
-------------------
* Fix bug in min/max validity times when using intrinsic scatter parameter
* Change prior on blackbody temperature from log-uniform to uniform
* Don't italicize some filter names
* Return axes objects in light curve corner plot
* Give option to plot magnitudes in light curve corner plot
* Fix plotting of wavelength when units are supplied
* Add option to calculate phase in rest-frame hours
* Issue warning when filters do not receive extinction correction
* Switch from to generic filter curves from the SVO Filter Profile Service where possible
* Add progress bars for MCMC fitting
* Add option to save chain plots. Burn-in and sampling plots are combined into the same figure.
* Add option to save chain in bolometric light curve fitting

v0.3.0 (2021-09-22)
-------------------
* Switch the default table format from ``'ascii.fixed_width'`` to just ``'ascii'``
Expand Down
2 changes: 1 addition & 1 deletion docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ If you used the Rabinak & Waxman option, the model fails even earlier, but you w
.. code-block:: python
p_mean = sampler.flatchain.mean(axis=0)
t_max = ShockCooling2.t_max(*p_mean)
t_max = ShockCooling2.t_max(p_mean)
print(t_max)
if lc_early['MJD'].max() > t_max:
print('Warning: your model is not valid for all your observations')
Expand Down
2 changes: 1 addition & 1 deletion lightcurve_fitting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
"outputs": [],
"source": [
"p_mean = sampler.flatchain.mean(axis=0)\n",
"t_max = model.t_max(*p_mean)\n",
"t_max = model.t_max(p_mean)\n",
"print(t_max)\n",
"if lc_early['MJD'].max() > t_max:\n",
" print('Warning: your model is not valid for all your observations')"
Expand Down
17 changes: 12 additions & 5 deletions lightcurve_fitting/bolometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def pseudo(temp, radius, z, filter0=filtdict['I'], filter1=filtdict['U'], cutoff


def blackbody_mcmc(epoch1, z, p0=None, show=False, outpath='.', nwalkers=10, burnin_steps=200, steps=100,
T_range=(1., 100.), R_range=(0.01, 1000.), cutoff_freq=np.inf, prev_temp=None):
T_range=(1., 100.), R_range=(0.01, 1000.), cutoff_freq=np.inf, prev_temp=None, save_chains=False):
"""
Fit a blackbody spectrum to a spectral energy distribution using a Markov-chain Monte Carlo routine
Expand Down Expand Up @@ -83,6 +83,8 @@ def blackbody_mcmc(epoch1, z, p0=None, show=False, outpath='.', nwalkers=10, bur
Cutoff frequency (in terahertz) for a modified blackbody spectrum (see https://doi.org/10.3847/1538-4357/aa9334)
prev_temp : scipy.stats.gaussian_kde, optional
Temperature distribution from fitting the previous epoch's SED. If given, this is used as the prior.
save_chains : bool, optional
If True, save the MCMC chain histories to the directory ``outpath``. Default: only save the corner plot
Returns
-------
Expand All @@ -104,7 +106,7 @@ def log_prior(p): # p = [T, R]
elif prev_temp is not None:
return prev_temp.logpdf(p[0]) - np.log(p[1])
else:
return -np.sum(np.log(p))
return -np.log(p[1])

def log_likelihood(p, filtobj, y, dy):
y_fit = blackbody_to_filters(filtobj, p[0], p[1], z, cutoff_freq)
Expand Down Expand Up @@ -155,6 +157,9 @@ def log_posterior(p, filtobj, y, dy):
filename = os.path.join(outpath, f'{mjdavg:.1f}.png')
print(filename)
f4.savefig(filename)
if save_chains:
chain_filename = os.path.join(outpath, f'{mjdavg:.1f}.npy')
np.save(chain_filename, sampler.flatchain)
if show:
plt.show()
else:
Expand Down Expand Up @@ -458,7 +463,7 @@ def plot_color_curves(t, colors=None, fmt='o', limit_length=0.1, xcol='MJD'):

def calculate_bolometric(lc, z, outpath='.', res=1., nwalkers=10, burnin_steps=200, steps=100,
T_range=(1., 100.), R_range=(0.01, 1000.), save_table_as=None, min_nfilt=3,
cutoff_freq=np.inf, show=False, colors=None, do_mcmc=True):
cutoff_freq=np.inf, show=False, colors=None, do_mcmc=True, save_chains=False):
"""
Calculate the full bolometric light curve from a table of broadband photometry
Expand All @@ -469,7 +474,7 @@ def calculate_bolometric(lc, z, outpath='.', res=1., nwalkers=10, burnin_steps=2
z : float
Redshift between the blackbody (rest frame) and the filters (observed frame)
outpath : str, optional
Directory to which to save the corner plots. Default: current directory
Directory to which to save the corner plots and MCMC chains. Default: current directory
res : float, optional
Approximate resolution for grouping, in days. Default: 1 day.
nwalkers : int, optional
Expand All @@ -495,6 +500,8 @@ def calculate_bolometric(lc, z, outpath='.', res=1., nwalkers=10, burnin_steps=2
do_mcmc : bool, optional
If True (default), also fit the spectral energy distribution with an MCMC routine. This is slower but gives
more realistic uncertainties.
save_chains : bool, optional
If True, save the MCMC chain histories to the directory ``outpath``. Default: only save the corner plot
Returns
-------
Expand Down Expand Up @@ -567,7 +574,7 @@ def calculate_bolometric(lc, z, outpath='.', res=1., nwalkers=10, burnin_steps=2
raise ValueError
sampler = blackbody_mcmc(epoch1, z, p0, outpath=outpath, nwalkers=nwalkers, burnin_steps=burnin_steps,
steps=steps, T_range=T_range, R_range=R_range, cutoff_freq=cutoff_freq, show=show,
prev_temp=prev_temp)
prev_temp=prev_temp, save_chains=save_chains)
L_mcmc_opt = pseudo(sampler.flatchain[:, 0], sampler.flatchain[:, 1], z, cutoff_freq=cutoff_freq)
(T_mcmc, R_mcmc), (dT0_mcmc, dR0_mcmc), (dT1_mcmc, dR1_mcmc) = median_and_unc(sampler.flatchain)
L_mcmc, dL_mcmc0, dL_mcmc1 = median_and_unc(L_mcmc_opt)
Expand Down
49 changes: 30 additions & 19 deletions lightcurve_fitting/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Filter:
The line color used when plotting photometry in this filter. Default: same as ``color``.
textcolor : str, tuple, optional
The color used when printing the name of this filter. Default: same as ``linecolor``.
italics : bool, optional
Italicize the filter name when used with LaTeX. Default: True.
Attributes
----------
Expand All @@ -53,6 +55,8 @@ class Filter:
The line color used when plotting photometry in this filter
textcolor : str, tuple
The color used when printing the name of this filter
italics : bool
Italicize the filter name when used with LaTeX
mec : str, tuple
The marker edge color used when plotting photometry in this filter
plotstyle : dict
Expand Down Expand Up @@ -86,7 +90,7 @@ class Filter:
"""The names of recognized filters listed in (approximate) decreasing order of effective frequency"""

def __init__(self, names, color='k', offset=0, system=None, fnu=3.631e-23, filename='', angstrom=False,
linecolor=None, textcolor=None):
linecolor=None, textcolor=None, italics=True):
if type(names) == list:
self.name = names[0]
self.names = names
Expand All @@ -110,6 +114,7 @@ def __init__(self, names, color='k', offset=0, system=None, fnu=3.631e-23, filen
self.textcolor = textcolor
else:
self.textcolor = self.linecolor
self.italics = italics
self.system = system
if self.system == 'Johnson':
self.mec = 'k'
Expand Down Expand Up @@ -191,6 +196,9 @@ def read_curve(self, show=False, force=False):
ax2.set_xlabel('Frequency (THz)')
ax2.set_ylabel('Transmission')

self.wl_eff = wl_eff
self.dwl = dwl
self.wl_range = (wl_eff.value - wl0, wl1 - wl_eff.value)
self.freq_eff = freq_eff
self.dfreq = -dfreq
self.freq_range = (freq_eff.value - freq0, freq1 - freq_eff.value)
Expand Down Expand Up @@ -252,39 +260,42 @@ def _resample_filter_curve(filename, outfile):
Filter(['UVW2', 'uvw2', 'W2', '2', 'uw2'], '#FF007F', 8, 'Swift', 7.379e-24, 'Swift_UVOT.UVW2.dat', angstrom=True),
Filter(['UVM2', 'uvm2', 'M2', 'M', 'um2'], 'm', 8, 'Swift', 7.656e-24, 'Swift_UVOT.UVM2.dat', angstrom=True),
Filter(['UVW1', 'uvw1', 'W1', '1', 'uw1'], '#7F00FF', 4, 'Swift', 9.036e-24, 'Swift_UVOT.UVW1.dat', angstrom=True),
Filter(['u', "u'", 'up'], '#4700CC', 3, 'Gunn', filename='sdss-up-183.asci'), # brightened from '#080017'
Filter(['u', "u'", 'up'], '#4700CC', 3, 'Gunn', filename='SLOAN_SDSS.u.dat', angstrom=True), # brightened from '#080017'
Filter(['U_S', 's', 'us'], '#230047', 3, 'Swift', 1.419e-23, filename='Swift_UVOT.U.dat', angstrom=True),
Filter('U', '#3C0072', 3, 'Johnson', 1.790e-23, filename='jnsn-uv-183.asci'),
Filter('B', '#0057FF', 2, 'Johnson', 4.063e-23, filename='jnsn-bu-183.asci'),
Filter('U', '#3C0072', 3, 'Johnson', 1.790e-23, filename='Generic_Johnson.U.dat', angstrom=True),
Filter('B', '#0057FF', 2, 'Johnson', 4.063e-23, filename='Generic_Johnson.B.dat', angstrom=True),
Filter(['B_S', 'b', 'bs'], '#4B00FF', 2, 'Swift', 4.093e-23, filename='Swift_UVOT.B.dat', angstrom=True),
Filter(['g', "g'", 'gp', 'F475W'], '#00CCFF', 1, 'Gunn', filename='sdss-gp-183.asci'),
Filter(['g', "g'", 'gp', 'F475W'], '#00CCFF', 1, 'Gunn', filename='SLOAN_SDSS.g.dat', angstrom=True),
Filter('g-DECam', '#00CCFF', 1, 'DECam', filename='CTIO_DECam.g.dat', angstrom=True),
Filter(['c', 'cyan'], 'c', 1, 'ATLAS', filename='ATLAS_cyan.txt'),
Filter('V', '#79FF00', 1, 'Johnson', 3.636e-23, filename='jnsn-vx-183.asci', textcolor='#46CC00'),
Filter('V', '#79FF00', 1, 'Johnson', 3.636e-23, filename='Generic_Johnson.V.dat', angstrom=True, textcolor='#46CC00'),
Filter(['V_S', 'v', 'vs'], '#00FF30', 1, 'Swift', 3.664e-23, filename='Swift_UVOT.V.dat', angstrom=True),
Filter(['unfilt.', '0', 'Clear', 'C', 'clear'], 'w', 0, 'Itagaki', filename='KAF-1001E.asci', linecolor='k'),
Filter('white', 'w', 0, 'MOSFiT', filename='white.txt', linecolor='k'),
Filter(['pseudobolometric', 'griz'], 'w', 0, 'MOSFiT', filename='pseudobolometric.txt', linecolor='k'),
Filter('Itagaki', 'w', 0, 'Itagaki', filename='KAF-1001E.asci', linecolor='k', italics=False),
Filter('white', 'w', 0, 'MOSFiT', filename='white.txt', linecolor='k', italics=False),
Filter(['unfilt.', '0', 'Clear', 'C', 'clear', 'pseudobolometric', 'griz'], 'w', 0, 'MOSFiT',
filename='pseudobolometric.txt', linecolor='k', italics=False),
Filter('G', 'w', 0, 'Gaia', filename='GAIA_GAIA0.G.dat', angstrom=True, linecolor='k'),
Filter('Kepler', 'r', 0, 'Kepler', filename='Kepler_Kepler.K.dat', angstrom=True),
Filter('TESS', 'r', 0, 'TESS', filename='TESS_TESS.Red.dat', angstrom=True),
Filter('w', 'w', 0, 'Gunn', filename='pstr-wx-183.asci', linecolor='k'),
Filter('Kepler', 'r', 0, 'Kepler', filename='Kepler_Kepler.K.dat', angstrom=True, italics=False),
Filter('TESS', 'r', 0, 'TESS', filename='TESS_TESS.Red.dat', angstrom=True, italics=False),
Filter('DLT40', 'w', 0, 'DLT40', filename='QE_E2V_MBBBUV_Broadband.csv', linecolor='k', italics=False),
Filter('w', 'w', 0, 'Gunn', filename='PAN-STARRS_PS1.w.dat', angstrom=True, linecolor='k'),
Filter(['o', 'orange'], 'orange', 0, 'ATLAS', filename='ATLAS_orange.txt'),
Filter(['r', "r'", 'rp', 'F625W'], '#FF7D00', 0, 'Gunn', filename='sdss-rp-183.asci'),
Filter(['r', "r'", 'rp', 'F625W'], '#FF7D00', 0, 'Gunn', filename='SLOAN_SDSS.r.dat', angstrom=True),
Filter('r-DECam', '#FF7D00', 0, 'DECam', filename='CTIO_DECam.r.dat', angstrom=True),
Filter(['R', 'Rc', 'R_s'], '#FF7000', 0, 'Johnson', 3.064e-23, filename='cous-rs-183.asci'), # '#CC5900'
Filter(['i', "i'", 'ip', 'F775W'], '#90002C', -1, 'Gunn', filename='sdss-ip-183.asci'),
Filter(['R', 'Rc', 'R_s'], '#FF7000', 0, 'Johnson', 3.064e-23, filename='Generic_Cousins.R.dat', angstrom=True), # '#CC5900'
Filter(['i', "i'", 'ip', 'F775W'], '#90002C', -1, 'Gunn', filename='SLOAN_SDSS.i.dat', angstrom=True),
Filter('i-DECam', '#90002C', -1, 'DECam', filename='CTIO_DECam.i.dat', angstrom=True),
Filter(['I', 'Ic'], '#66000B', -1, 'Johnson', 2.416e-23, filename='cous-ic-183.asci'), # brightened from '#1C0003'
Filter(['z', "z'", 'Z', 'zs'], '#000000', -2, 'Gunn', filename='pstr-zs-183.asci'),
Filter(['I', 'Ic'], '#66000B', -1, 'Johnson', 2.416e-23, filename='Generic_Cousins.I.dat', angstrom=True), # brightened from '#1C0003'
Filter('zs', '#000000', -2, 'Gunn', filename='PAN-STARRS_PS1.z.dat', angstrom=True),
Filter(['z', "z'", 'zp'], '#000000', -2, 'Gunn', filename='SLOAN_SDSS.z.dat', angstrom=True),
Filter('z-DECam', '#000000', -2, 'DECam', filename='CTIO_DECam.z.dat', angstrom=True),
Filter('y', 'y', -3, 'Gunn', filename='pstr-yx-183.asci'),
Filter('y', 'y', -3, 'Gunn', filename='PAN-STARRS_PS1.y.dat', angstrom=True),
Filter('y-DECam', 'y', -3, 'DECam', filename='CTIO_DECam.Y.dat', angstrom=True),
Filter('J', '#444444', -2, 'UKIRT', 1.589e-23, filename='Gemini_Flamingos2.J.dat', angstrom=True),
Filter('H', '#888888', -3, 'UKIRT', 1.021e-23, filename='Gemini_Flamingos2.H.dat', angstrom=True),
Filter(['K', 'Ks'], '#CCCCCC', -4, 'UKIRT', 0.640e-23, filename='Gemini_Flamingos2.Ks.dat', angstrom=True),
Filter('L', 'r', -4, 'UKIRT', 0.285e-23),
Filter(['unknown', '?'], 'w', 0, 'unknown', linecolor='k')]
Filter(['unknown', '?'], 'w', 0, 'unknown', linecolor='k', italics=False)]
Filter.order = [f.name for f in all_filters]
filtdict = {}
for filt in all_filters:
Expand Down
21 changes: 0 additions & 21 deletions lightcurve_fitting/filters/Generic_Bessell.B.dat

This file was deleted.

24 changes: 0 additions & 24 deletions lightcurve_fitting/filters/Generic_Bessell.V.dat

This file was deleted.

43 changes: 43 additions & 0 deletions lightcurve_fitting/filters/Generic_Cousins.I.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
7000 0.000
7050 0.005
7100 0.020
7150 0.050
7200 0.100
7250 0.170
7300 0.330
7350 0.700
7400 0.820
7450 0.900
7500 0.950
7550 0.980
7600 0.990
7650 0.994
7700 0.980
7750 0.950
7800 0.913
7850 0.870
7900 0.830
7950 0.790
8000 0.750
8050 0.710
8100 0.673
8150 0.650
8200 0.630
8250 0.610
8300 0.580
8350 0.550
8400 0.510
8450 0.470
8500 0.405
8550 0.330
8600 0.250
8650 0.180
8700 0.140
8750 0.110
8800 0.080
8850 0.060
8900 0.035
8950 0.020
9000 0.010
9050 0.005
9100 0.000
53 changes: 53 additions & 0 deletions lightcurve_fitting/filters/Generic_Cousins.R.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
5400 0.000
5450 0.002
5500 0.010
5550 0.030
5600 0.070
5650 0.180
5700 0.400
5750 0.770
5800 0.890
5850 0.960
5900 0.990
5950 0.999
6000 1.000
6050 0.997
6100 0.990
6150 0.976
6200 0.960
6250 0.946
6300 0.930
6350 0.912
6400 0.895
6450 0.880
6500 0.860
6550 0.845
6600 0.825
6650 0.806
6700 0.788
6750 0.765
6800 0.742
6850 0.720
6900 0.700
6950 0.676
7000 0.650
7050 0.626
7100 0.600
7150 0.568
7200 0.530
7250 0.480
7300 0.395
7350 0.300
7400 0.215
7450 0.155
7500 0.120
7550 0.100
7600 0.085
7650 0.075
7700 0.060
7750 0.050
7800 0.040
7850 0.029
7900 0.020
7950 0.010
8000 0.000
13 changes: 13 additions & 0 deletions lightcurve_fitting/filters/Generic_Johnson.U.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
3000.0 0.0000000000
3100.0 0.1000000000
3200.0 0.6100000000
3300.0 0.8400000000
3400.0 0.9300000000
3500.0 0.9700000000
3600.0 1.0000000000
3700.0 0.9700000000
3800.0 0.7300000000
3900.0 0.3600000000
4000.0 0.0500000000
4100.0 0.0100000000
4200.0 0.0000000000
Loading

0 comments on commit 564f518

Please sign in to comment.