def compare_ttVSubv(mname, path, bands=('U', 'B', 'V', 'R', 'I'), t_cut=1., is_plot_time_points=False): dic_results = {} model = Stella(mname, path=path) tt = model.get_tt().load() # time cut days mags = tt[tt['time'] > t_cut] n1 = mags.dtype.names def f(x): if len(x) == 2 and x.startswith('M'): return x.replace('M', '') else: return x n2 = map(lambda x: f(x), n1) mags.dtype.names = n2 dic_results['tt'] = mags # ubv serial_spec = model.read_series_spectrum(t_diff=1.05) mags = serial_spec.mags_bands(bands) dic_results['ubv'] = mags plot_all(dic_results, bands, title=mname, is_time_points=is_plot_time_points)
def compare_ttVSubv(mname, path, bands=['U', 'B', 'V', 'R', 'I'], t_cut=1., is_plot_time_points=False): dic_results = {} model = Stella(mname, path=path) tt = model.read_tt_data() # time cut days mags = tt[tt['time'] > t_cut] n1 = mags.dtype.names def f(x): if len(x) == 2 and x.startswith('M'): return x.replace('M', '') else: return x n2 = map(lambda x: f(x), n1) mags.dtype.names = n2 dic_results['tt'] = mags # ubv serial_spec = model.read_series_spectrum(t_diff=1.05) mags = serial_spec.mags_bands(bands) dic_results['ubv'] = mags plot_all(dic_results, bands, title=mname, is_time_points=is_plot_time_points)
def curves_compute(name, path, bands, z=0., distance=10., magnification=1., t_beg=0., t_end=None, is_show_info=False, is_save=False): """ Compute magnitude in bands for the 'name' model. :param name: the name of a model and data files :param path: the directory with data-files :param bands: photometric bands :param z: redshift, default 0 :param distance: distance to star in parsec, default 10 pc :param magnification: gravitational lensing magnification :param t_end: :param t_beg: :param is_show_info: flag to write some information, default True :param is_save: flag to save result in file, default False :return: dictionary with keys = bands, value = star's magnitudes """ if len(bands) == 0: raise ValueError("You have not set any bands for model: " + str(name)) model = Stella(name, path=path) if not model.is_ph_data: model.show_info() raise ValueError("Error: No spectral data for: " + str(model)) if is_show_info: print '' model.show_info() # serial_spec = model.read_serial_spectrum(t_diff=0.) serial_spec = model.read_series_spectrum(t_diff=1.05, t_beg=t_beg, t_end=t_end) curves = serial_spec.flux_to_curves(bands, z=z, d=rf.pc_to_cm(distance), magnification=magnification) # curves = SetLightCurve(name) # for n in bands: # b = band.band_by_name(n) # lc = serial_spec.flux_to_curve(b, z=z, dl=rf.pc_to_cm(distance), magnification=magnification) # # time = serial_spec.times * (1. + z) # # lc = LightCurve(b, time, mags) # curves.add(lc) if is_save: fname = os.path.join(path, name + '.ubv') curves_save(curves, fname) print "Magnitudes have been saved to " + fname if is_show_info: # print the time of maximum LC tmin = 2.0 t = curves.TimeDef for n in bands: t_min = t[t > tmin][curves[n][t > tmin].argmin()] print "t_max(%s) = %f" % (n, t_min) return curves
def compute_mag(name, path, bands, ext=None, z=0., distance=10., magnification=1., t_diff=1.05, is_show_info=True, is_save=False): """ Compute magnitude in bands for the 'name' model. :param name: the name of a model and data files :param path: the directory with data-files :param bands: photometric bands :param ext: extinction :param z: redshift, default 0 :param distance: distance to star in parsec, default 10 pc :param magnification: gravitational lensing magnification :param t_diff: depression between time points :param is_show_info: flag to write some information, default True :param is_save: flag to save result in file, default False :return: dictionary with keys = bands, value = star's magnitudes """ model = Stella(name, path=path) if is_show_info: print '' model.show_info() if not model.is_ph_data: model.show_info() print "Error: No data for: " + str(model) return None # serial_spec = model.read_serial_spectrum(t_diff=0.) serial_spec = model.read_series_spectrum(t_diff=t_diff) mags = serial_spec.mags_bands(bands, z=z, d=rf.pc_to_cm(distance), magnification=magnification) if mags is not None: fname = os.path.join(path, name + '.ubv') if is_save: mags_save(mags, bands, fname) print "Magnitudes have been saved to " + fname if is_show_info: # print the time of maximum LC tmin = 2.0 t = mags['time'] for n in bands: t_min = t[t > tmin][mags[n][t > tmin].argmin()] print "t_max(%s) = %f" % (n, t_min) if ext is not None: # add extinction for n in bands: mags[n] = mags[n] + ext[n] return mags
def compute_mag(name, path, bands, z=0., distance=10., t_cut=0., t_up=400., tdiff=0.): """ Compute magnitude in bands for the 'name' model. :param name: the name of a model and data files :param path: the directory with data-files :param bands: photometric bands :param z: redshift, default 0 :param distance: distance to star in parsec, default 10 pc :param t_cut: :param t_up: :param tdiff: :return: dictionary with keys = bands, value = star's magnitudes """ model = Stella(name, path=path) if not model.is_ph: print("No data for: " + str(model)) return None # serial_spec = model.read_serial_spectrum(t_diff=0.) serial_spec = model.read_series_spectrum(t_diff=1.05) mags = serial_spec.mags_bands(bands, z=z, d=rf.pc_to_cm(distance)) # t_cut time = mags['time'] cut = (t_cut < time) & (time < t_up) mags['time'] = time[cut] for n in bands: mags[n] = mags[n][cut] time = mags['time'] if tdiff > 0.: ts = np.arange(np.min(time), np.max(time), tdiff) for n in bands: tck = interpolate.splrep(time, mags[n]) mags[n] = interpolate.splev(ts, tck) mags['time'] = ts return mags
def compute_tcolor(name, path, bands, d=rf.pc_to_cm(10.0), z=0.0, t_cut=1.0): model = Stella(name, path=path) if not model.is_ph_data: print "No ph-data for: " + str(model) return None if not model.is_tt_data: print "No tt-data for: " + str(model) return None # serial_spec = model.read_series_spectrum(t_diff=1.) # curves = serial_spec.flux_to_curves(bands, d=distance) serial_spec = model.read_series_spectrum(t_diff=1.05, t_beg=t_cut) # curves = serial_spec. mags = serial_spec.mags_bands(bands, z=z, d=d) # read R_ph tt = model.read_tt_data() tt = tt[tt["time"] > t_cut] # time cut days # compute Tnu, W Tnu, Teff, W = compute_Tnu_w(serial_spec, tt=tt) # fit mags by B(T_col) and get \zeta\theta & T_col Tcolors, zetaR, times = compute_Tcolor_zeta(mags, tt=tt, bands=bands, freq=serial_spec.Freq, d=d, z=z) # show results res = np.array( np.zeros(len(Tcolors)), dtype=np.dtype({"names": ["time", "Tcol", "zeta", "Tnu", "Teff", "W"], "formats": [np.float64] * 6}), ) res["time"] = times res["Tcol"] = Tcolors res["zeta"] = zetaR res["Tnu"] = Tnu res["Teff"] = Teff res["W"] = W return res
def compute_mag(name, path, bands, z=0.0, distance=10.0, t_cut=0.0, t_up=400.0, tdiff=0.0): """ Compute magnitude in bands for the 'name' model. :param name: the name of a model and data files :param path: the directory with data-files :param bands: photometric bands :param z: redshift, default 0 :param distance: distance to star in parsec, default 10 pc :return: dictionary with keys = bands, value = star's magnitudes """ model = Stella(name, path=path) if not model.is_ph_data: print "No data for: " + str(model) return None # serial_spec = model.read_serial_spectrum(t_diff=0.) serial_spec = model.read_series_spectrum(t_diff=1.05) mags = serial_spec.mags_bands(bands, z=z, d=rf.pc_to_cm(distance)) # t_cut time = mags["time"] cut = (t_cut < time) & (time < t_up) mags["time"] = time[cut] for n in bands: mags[n] = mags[n][cut] time = mags["time"] if tdiff > 0.0: ts = np.arange(np.min(time), np.max(time), tdiff) for n in bands: tck = interpolate.splrep(time, mags[n]) mags[n] = interpolate.splev(ts, tck) mags["time"] = ts return mags
class TestStellaTt(unittest.TestCase): def setUp(self): # name = 'ccsn2007bi1dNi6smE23bRlDC' name = 'cat_R500_M15_Ni006_E12' # name = 'cat_R1000_M15_Ni007_E15' path = join(dirname(abspath(__file__)), 'data', 'stella') self.stella = Stella(name, path=path) self.tt = self.stella.get_tt() def test_info_parse(self): tt_header = """ <===== HYDRODYNAMIC RUN OF MODEL cat_R1000_M15_Ni007_E15.prf =====> MASS(SOLAR)=15.000 RADIUS(SOLAR)= 1000.000 EXPLOSION ENERGY(10**50 ERG)= 1.50000E+01 <===== =====> INPUT PARAMETERS EPS = 0.00300 Rce = 1.00000E-02 SOL.Rad. HMIN = 1.00000E-11 S AMht = 1.00000E-02 SOL.MASS HMAX = 5.00000E+04 S Tburst= 1.00000E-01 S THRMAT= 1.00000E-30 Ebstht= 1.50000E+01 1e50 ergs METH = 3 CONV = F JSTART= 0 EDTM = T MAXORD= 4 CHNCND= T NSTA = -4500 FitTau= 3.00000E+02 NSTB = -1 TauTol= 1.30000E+00 NOUT = 100 IOUT = -1 TcurA = 0.00000 Rvis = 1.00000 TcurB = 200.00000 BQ = 1.00000E+00 NSTMAX= 360000 DRT = 1.00000E-01 XMNI = 7.00000E-02 SOL.MASS NRT = 1 XNifor= 1.16561E-01 MNicor= 1.16999E-01 SOL.MASS SCAT = T """ pattern = filter(lambda x: len(x) > 0, tt_header.splitlines()) pattern = map(str.strip, pattern) p = r"(.*?)\s*=\s+([-+]?\d*\.\d+|\d+)" for line in pattern: res = re.findall(p, line) if len(res) > 0: for k, v in res: print "key: %s v: %f " % (k, float(v)) def test_info_parse(self): info = self.tt.Info.parse() info.show() tmp = 1000. self.assertEquals(info.R, tmp, "Radius [%f] should be %f" % (info.R, tmp)) tmp = 15. self.assertEquals(info.M, tmp, "Mass [%f] should be %f" % (info.M, tmp)) tmp = 15. self.assertEquals(info.E, tmp, "Ebstht [%f] should be %f" % (info.E, tmp)) def test_tt_vs_ph(self): curves_tt = self.tt.read_curves_tt() bands = curves_tt.BandNames serial_spec = self.stella.read_series_spectrum(t_diff=1.00001) curves_ph = serial_spec.flux_to_curves(bands) models_dic = {'tt': curves_tt, 'ph': curves_ph} lc_types = {'tt': '--', 'ph': '-'} plt.matplotlib.rcParams.update({'font.size': 14}) fig, ax = plt.subplots(1, 1) lcf.plot_models_curves_fixed_bands(ax, models_dic, bands, lc_types=lc_types, ylim=(-10, -24)) # lcf.plot_models_curves(ax, models_dic, bands, lc_types=lc_types, ylim=(-10, -24), xlim=(0, 20)) plt.legend() plt.show() def test_gri_vs_ph(self): curves_gri = self.tt.read_curves_gri() bands = curves_gri.BandNames # bands = ('J','H','K') serial_spec = self.stella.read_series_spectrum(t_diff=1.) curves_ph = serial_spec.flux_to_curves(bands) models_dic = {'gri': curves_gri, 'ph': curves_ph} lc_types = {'gri': '--', 'ph': ':'} plt.matplotlib.rcParams.update({'font.size': 14}) fig, ax = plt.subplots(1, 1) # lcf.plot_models_curves_fixed_bands(ax, models_dic, bands=('r','B','V'), lc_types=lc_types, ylim=(-13, -23), lw=3) lcf.plot_models_curves(ax, models_dic, lc_types=lc_types, ylim=(-10, -23), lw=3) plt.legend() plt.show() def test_tt_vs_gri_vs_ph(self): curves_tt = self.tt.read_curves_tt() bands_tt = curves_tt.BandNames curves_gri = self.tt.read_curves_gri() bands_gri = curves_gri.BandNames bands = np.unique(np.array(bands_tt + bands_gri)) serial_spec = self.stella.read_series_spectrum(t_diff=1.00001) curves_ph = serial_spec.flux_to_curves(bands) models_dic = {'tt': curves_tt, 'gri': curves_gri, 'ph': curves_ph} lc_types = {'tt': ':', 'gri': '--', 'ph': '-'} plt.matplotlib.rcParams.update({'font.size': 14}) fig, ax = plt.subplots(1, 1) lcf.plot_models_curves(ax, models_dic, lc_types=lc_types, ylim=(-10, -19), lw=3) # lcf.plot_models_curves_fixed_bands(ax, models_dic, bands=('B', 'V'), lc_types=lc_types, ylim=(-13, -23), lw=3) plt.legend() plt.show()