def plot_ubv(ax, path, jd_shift=0., mshift=0.): colors = band.bands_colors() curves = read_curves(path) for lc in curves: x = lc.Time + jd_shift y = lc.Mag + mshift bcolor = colors[lc.Band.Name] ax.plot(x, y, label='%s SN 1987A' % lc.Band.Name, ls="", color=bcolor, markersize=6, marker=".")
def plot_all(models_vels, models_dic, bands, call=None, xlim=None, ylim=None, is_time_points=False, title='', fsave=None, bshift=None): colors = band.bands_colors() band_shift = dict((k, 0) for k, v in colors.items()) # no y-shift if bshift is not None: for k, v in bshift.items(): band_shift[k] = v # band_shift['UVW1'] = 3 # band_shift['UVW2'] = 5 # band_shift['i'] = -1 is_vel = models_vels is not None # setup figure plt.matplotlib.rcParams.update({'font.size': 14}) fig = plt.figure(num=None, figsize=(12, 12), dpi=100, facecolor='w', edgecolor='k') if is_vel: gs1 = gridspec.GridSpec(4, 1) axUbv = fig.add_subplot(gs1[:-1, 0]) axVel = fig.add_subplot(gs1[3, 0]) else: gs1 = gridspec.GridSpec(1, 1) axUbv = fig.add_subplot(gs1[0, 0]) axVel = None gs1.update(wspace=0.3, hspace=0.3, left=0.1, right=0.95) # plot the light curves lcf.plot_ubv_models(axUbv, models_dic, bands, band_shift=band_shift, xlim=xlim, ylim=ylim, is_time_points=is_time_points) # plot callback if call is not None: call.plot(axUbv, {'ax2': axVel}) # finish plot axUbv.set_ylabel('Magnitude') axUbv.set_xlabel('Time [days]') axUbv.legend(prop={'size': 8}, loc=4) # ax.set_title(bset) if title: axUbv.set_title(title) # plot velocities if is_vel: vel.plot_vels_models(axVel, models_vels, xlim=axUbv.get_xlim()) # vel.plot_vels_sn87a(axVel, z=1.49) axVel.legend(prop={'size': 8}, loc=4) plt.grid() plt.show() if fsave is not None: print "Save plot to %s " % fsave fig.savefig(fsave, bbox_inches='tight')
def test_fit_GP_SNRefsdal_all_lc(self): # k = gptools.SquaredExponentialKernel(param_bounds=[(0, 1e3), (0, 100)]) # gp = gptools.GaussianProcess(k, mu=gptools.LinearMeanFunction()) # add data dm = -29.38 # D = 7.5e6 pc # dm = -30.4 # D = 12.e6 pc image = "S1" bands = ['F160W', 'F105W', 'F125W'] # bands = ('F160W','F140W','F105W', 'F125W') curves = snrefsdal.read_curves(snrefsdal.path_data, image) for bname in bands: lc = curves.get(bname) # lc.mshift = dm t = lc.Time y = lc.Mag yerr = lc.MagErr # Gaussian process k = gptools.SquaredExponentialKernel(param_bounds=[(min(np.abs(y)), max(np.abs(y))), (0, np.std(t))]) # k = gptools.SquaredExponentialKernel(param_bounds=[(min(np.abs(y)), max(np.abs(y))), # (0, np.std(t))]) gp = gptools.GaussianProcess(k) # gp = gptools.GaussianProcess(k, mu=gptools.LinearMeanFunction()) gp.add_data(t, y, err_y=yerr) is_mcmc = True if is_mcmc: out = gp.predict(t, use_MCMC=True, full_MCMC=True, return_std=True, num_proc=0, nsamp=100, plot_posterior=True, plot_chains=False, burn=10, thin=1) else: gp.optimize_hyperparameters() out = gp.predict(t, use_MCMC=False) y_star, err_y_star = out # y_star, err_y_star = gp.predict(t) fig = plt.figure() ax = fig.add_axes((0.1, 0.3, 0.8, 0.65)) ax.invert_yaxis() bcolor = band.bands_colors()[bname] ax.plot(t, y, color=bcolor, label='L bol', lw=2.5) ax.errorbar(t, y, yerr=yerr, fmt='o', color=bcolor, label='%s obs.') # # ax.plot(t, y_star, color='red', ls='--', lw=1.5, label='GP') ax.plot(t, y_star, '-', color=bcolor) ax.fill_between(t, y_star - 2 * err_y_star, y_star + 2 * err_y_star, color=bcolor, alpha=0.3) plt.show()
def plot(ax, arg): lw = 2. band_shift = arg colors = band.bands_colors() fname = "~/Desktop/Downloads/2/100z0E60Ni_6.ph.hsc.2" data = np.loadtxt(fname, comments='#') fs = list('grizy') x = data[:, 0] for i in range(len(fs)): y = data[:, i + 1] bcolor = colors[fs[i]] ax.plot(x, y, label='%s Tolstov' % lc.lbl(fs[i], band_shift), color=bcolor, ls="-.", linewidth=lw)
def plot_ubv(ax, path, jd_shift=0., mshift=0.): path = os.path.expanduser(path) colors = band.bands_colors() curves = read_curves_master(path) for lc in curves: x = lc.Time + jd_shift y = lc.Mag # todo + mshift bcolor = colors[lc.Band.Name] ax.plot(x, y, label='%s Master' % lc.Band.Name, ls=":", color=bcolor, markersize=7, marker="o") ax.errorbar(x, y, yerr=lc.MagErr, color='gray', fmt='.', zorder=1) print "jd_shift=%f mshift=%f " % (jd_shift, mshift) curves = read_curves_kurtenkov(path) for lc in curves: x = lc.Time + jd_shift y = lc.Mag + mshift bcolor = colors[lc.Band.Name] ax.plot(x, y, label='%s Kurtenkov' % lc.Band.Name, ls=":", color=bcolor, markersize=7, marker="*") ax.errorbar(x, y, yerr=lc.MagErr, color='gray', fmt='.', zorder=1)
import numpy as np import os import matplotlib.pyplot as plt from matplotlib import gridspec import pystella.rf.rad_func as rf from pystella.model import sn_swd from pystella.model.stella import Stella from pystella.rf import band from pystella.rf import extinction from pystella.rf.lc import LightCurve __author__ = 'bakl' lc_colors = band.bands_colors() lc_lntypes = dict(U="-", B="-", V="-", R="-", I="-", UVM2="-.", UVW1="-.", UVW2="-.", F125W="--", F160W="-.", F140W="--", F105W="-.", F435W="--", F606W="-.", F814W="--", u="--", g="--", r="--", i="--", z="--", bol='-') markers = {u'D': u'diamond', 6: u'caretup', u's': u'square', u'x': u'x', 5: u'caretright', u'^': u'triangle_up', u'd': u'thin_diamond', u'h': u'hexagon1', u'+': u'plus', u'*': u'star', u'o': u'circle', u'p': u'pentagon', u'3': u'tri_left', u'H': u'hexagon2', u'v': u'triangle_down', u'8': u'octagon', u'<': u'triangle_left'} markers = markers.keys() def lbl(b, band_shift):
def test_band_colors_name(self): bands = band.band_load_names() for bname in bands: self.assertTrue(bname in band.bands_colors(), "You have not color for band: %s" % bname)