Exemplo n.º 1
0
 def from_lambda(name, lmd, flux, u_lmd="A"):
     freq = rf.val_to_hz(np.asarray(lmd), inp=u_lmd)  # Spectrum.wl2freq(lmd)
     # flux = flux_freq * freq ** 2 / phys.c
     flux_freq = np.asarray(flux)/freq**2 * phys.c  # Flux_lambda (ergs/s/cm)
     if u_lmd == "A":
         flux_freq *= 1e8  # Flux_lambda (ergs/s/Angstrom)
     return Spectrum(name, freq, flux_freq)
Exemplo n.º 2
0
    def test_spec_kcorr_zplot(self):
        import matplotlib.pyplot as plt

        nf, start, end = 100, 10., 1e5
        wl = np.exp(np.linspace(np.log(end), np.log(start), nf))
        freq = rf.val_to_hz(wl, inp="A")
        Tcolor = 7.e3
        sp = spectrum.SpectrumPlanck(freq, Tcolor, 'test')

        bn_rest = 'B'
        bn_obs = bn_rest
        br = band_by_name(bn_rest)
        bo = band_by_name(bn_obs)

        z_arr = np.linspace(0, 0.3, 33)
        kcoors = []
        for z in z_arr:
            k = kcorrection_spec(sp, z, br, bo)
            kcoors.append(k)

        fig, ax = plt.subplots(figsize=(4, 16))
        ax.plot(z_arr, kcoors, marker='o', ls='', markersize=3)
        # ax.set_ylim(-0., .3)
        ax.grid()
        ax.set_title("{} band, Tcol= {:.0f} K".format(bn_rest, Tcolor))
        ax.set_xlabel('Redshift')
        ax.set_ylabel('k-correction')
        plt.show()
        fig.savefig('k-correction.pdf')
Exemplo n.º 3
0
    def test_spec_kcorr_with_curve(self):
        nf, start, end = 100, 10., 1e5
        wl = np.exp(np.linspace(np.log(end), np.log(start), nf))
        freq = rf.val_to_hz(wl, inp="A")
        Tcolor = 7e3
        sp = spectrum.SpectrumPlanck(freq, Tcolor, 'test')

        z = 0.1
        distance = 1e6  # phys.cosmology_D_by_z(z)
        bn_rest = 'g'
        # bn_obs = 'V'
        bn_obs = bn_rest
        br = band_by_name(bn_rest)
        bo = band_by_name(bn_obs)

        M_Q = sp.to_mag(br, z=0., d=phys.pc2cm(10.))
        m_r = sp.to_mag(bo, z=z, d=phys.pc2cm(distance))
        DM = phys.dist2MD(distance)
        K_QR = m_r - M_Q - DM

        kcorr = kcorrection_spec(sp, z, br, bo)

        print("{}: z= {} K_QR= {:.5f} kcorr= {:.5f}".format(bn_rest, z, K_QR, kcorr))

        self.assertAlmostEqual(K_QR, kcorr, 8, "{}: For z={} kcorr should be like K_QR. But kcorr={:.5f} K_QR= {:.5f}.".
                               format(bn_rest, z, kcorr, K_QR))
Exemplo n.º 4
0
 def setUp(self):
     nf = 100
     start, end = 10., 1e5
     wl = np.exp(np.linspace(np.log(start), np.log(end), nf))
     nu = rf.val_to_hz(wl, inp="A")
     T = 5500
     s = spectrum.SpectrumPlanck(nu, T)
     self.sp = s
Exemplo n.º 5
0
 def setUp(self):
     nf = 100
     start, end = 10., 1e5
     wl = np.exp(np.linspace(np.log(start), np.log(end), nf))
     nu = rf.val_to_hz(wl, inp="A")
     T = 5500
     s = spectrum.SpectrumPlanck(nu, T)
     self.sp = s
Exemplo n.º 6
0
 def setUp(self):
     nf, start, end = 100, 10., 1e5
     wl = np.exp(np.linspace(np.log(end), np.log(start), nf))
     freq = rf.val_to_hz(wl, inp="A")
     flux = np.ones(nf)
     self.sp = spectrum.Spectrum('test_spectrum',
                                 freq=freq,
                                 flux=flux,
                                 is_sort_wl=True)
Exemplo n.º 7
0
def plot_bb(Trad, Tcol, W1, W2, wl_lim=(100., 1e5, 100)):

    # freq
    # nf, start, end = 100, 10., 1e5
    wl = np.exp(np.linspace(np.log(wl_lim[1]), np.log(wl_lim[0]), wl_lim[2]))
    freq = rad_func.val_to_hz(wl, inp="A")

    sp_1 = spectrum.SpectrumDilutePlanck(freq, Trad, W1)
    sp_2 = spectrum.SpectrumDilutePlanck(freq, Tcol, W2)

    # setup figure
    plt.matplotlib.rcParams.update({'font.size': 14})
    fig = plt.figure(num=None,
                     figsize=(7, 11),
                     dpi=100,
                     facecolor='w',
                     edgecolor='k')

    gs1 = gridspec.GridSpec(1, 1)
    ax = fig.add_subplot(gs1[0, 0])
    gs1.update(wspace=0.3, hspace=0.3, left=0.15, right=0.95)

    # plot Trad
    x = sp_1.Wl * phys.cm_to_angs
    y = sp_1.FluxWl
    ax.semilogy(x,
                y,
                color='red',
                ls=":",
                linewidth=2.5,
                label='Diluted 1: Tcol=%6.1f W=%4.2f' % (sp_1.T, sp_1.W))

    # plot Tcol & W
    xx = sp_2.Wl * phys.cm_to_angs
    yy = sp_2.FluxWl
    ax.semilogy(xx,
                yy,
                color='blue',
                ls="--",
                linewidth=2.5,
                label='Diluted 2: Tcol=%6.1f W=%4.2f' % (sp_2.T, sp_2.W))

    ymax = np.max([y, yy])
    ylim = [ymax * 1e-15, ymax * 1e1]
    ax.set_ylim(ylim)

    ax.set_ylabel(r'$F_\lambda, \, [erg\, s^{-1} cm^2]$')
    ax.set_xscale('log')
    # ax.set_yscale('log')
    ax.set_xlabel(r'$\lambda, \, [\AA]$')
    ax.legend(prop={'size': 9}, loc=4, borderaxespad=0.)
    plt.grid()
    plt.show()
Exemplo n.º 8
0
    def setUp(self):
        nf, start, end = 100, 10., 1e5
        wl = np.exp(np.linspace(np.log(end), np.log(start), nf))
        freq = rf.val_to_hz(wl, inp="A")

        times = np.linspace(0., 200., 20)
        ss = spectrum.SeriesSpectrum("test_SeriesSpectrum")

        for k, t in enumerate(times):
            flux = np.ones(nf)  # * np.sin(t)
            s = spectrum.Spectrum('test_spectrum', freq=freq, flux=flux)
            ss.add(t, s)

        self.series = ss
Exemplo n.º 9
0
    def test_spectrum_T_color_zeta(self):
        nf, start, end = 100, 10., 1e5
        wl = np.exp(np.linspace(np.log(end), np.log(start), nf))
        freq = rf.val_to_hz(wl, inp="A")
        W = 0.5
        Tcolor = 7e3
        sp = spectrum.SpectrumDilutePlanck(freq, Tcolor, W, 'test')

        Tbb, zeta = sp.T_color_zeta()
        self.assertAlmostEqual(
            Tcolor, Tbb, 5,
            "Init Tcolor={:.2f} should be as Tbb={:.2f}.".format(Tcolor, Tbb))
        self.assertAlmostEqual(
            W, zeta, 5,
            "Init W={:.2f} should be as zeta={:.2f}.".format(W, zeta))
Exemplo n.º 10
0
    def test_spec_kcorr_positive(self):
        nf = 300
        start, end = 100., 1e5
        wl = np.exp(np.linspace(np.log(end), np.log(start), nf))
        freq = rf.val_to_hz(wl, inp="A")
        Tcolor = 7e3
        sp = spectrum.SpectrumPlanck(freq, Tcolor, 'test')

        z = 0.1
        for bn_rest in ['U', 'B', 'V', 'R', 'u', 'g', 'r']:
            bn_obs = bn_rest
            br = band_by_name(bn_rest)
            bo = band_by_name(bn_obs)

            kcorr = kcorrection_spec(sp, z, br, bo)
            print('{}: z= {}  kcorr= {}'.format(bn_rest, z, kcorr))
            self.assertGreater(kcorr, 0., "{}: For z={} kcorr should be > 0. But kcorr={:.5f}.".
                               format(bn_rest, z, kcorr))
Exemplo n.º 11
0
    def test_spec_kcorr_z0(self):
        nf, start, end = 100, 10., 1e5
        wl = np.exp(np.linspace(np.log(end), np.log(start), nf))
        freq = rf.val_to_hz(wl, inp="A")
        Tcolor = 7e3
        sp = spectrum.SpectrumPlanck(freq, Tcolor, 'test')

        z = 0.
        bn_rest = 'V'
        # bn_obs = 'V'
        for bn_rest in ['U', 'B', 'V', 'R', 'g']:
            bn_obs = bn_rest
            br = band_by_name(bn_rest)
            bo = band_by_name(bn_obs)

            kcorr = kcorrection_spec(sp, z, br, bo)

            self.assertAlmostEqual(kcorr, 0., 8, "{}: For z={} kcorr should be 0. But kcorr={:.5f}.".
                                   format(bn_rest, z, kcorr))
Exemplo n.º 12
0
def plot_bb(Trad, Tcol, W1, W2, wl_lim=[100, 1e5, 100.]):

    # freq
    # nf, start, end = 100, 10., 1e5
    wl = np.exp(np.linspace(np.log(wl_lim[1]), np.log(wl_lim[0]), wl_lim[2]))
    freq = rad_func.val_to_hz(wl, inp="A")

    sp_1 = spectrum.SpectrumDilutePlanck(freq, Trad, W1)
    sp_2 = spectrum.SpectrumDilutePlanck(freq, Tcol, W2)

    # setup figure
    plt.matplotlib.rcParams.update({'font.size': 14})
    fig = plt.figure(num=None, figsize=(7, 11), dpi=100, facecolor='w', edgecolor='k')

    gs1 = gridspec.GridSpec(1, 1)
    ax = fig.add_subplot(gs1[0, 0])
    gs1.update(wspace=0.3, hspace=0.3, left=0.15, right=0.95)

    # plot Trad
    x = sp_1.Wl * phys.cm_to_angs
    y = sp_1.Flux_wl
    ax.plot(x, y, color='red', ls=":", linewidth=2.5, label='Diluted 1: Tcol=%6.1f W=%4.2f' % (sp_1.T, sp_1.W))

    # plot Tcol & W
    xx = sp_2.Wl * phys.cm_to_angs
    yy = sp_2.Flux_wl
    ax.plot(xx, yy, color='blue', ls="--", linewidth=2.5, label='Diluted 2: Tcol=%6.1f W=%4.2f' % (sp_2.T, sp_2.W))

    ymax = np.max([y, yy])
    ylim = [ymax*1e-12, ymax*1e1]
    ax.set_ylim(ylim)

    ax.set_ylabel(r'$F_\lambda, \, [erg\, s^{-1} cm^2]$')
    ax.set_xscale('log')
    ax.set_yscale('log')
    ax.set_xlabel(r'$\lambda, \, [\AA]$')
    ax.legend(prop={'size': 9}, loc=4, borderaxespad=0.)
    plt.grid()
    plt.show()
Exemplo n.º 13
0
 def setUp(self):
     nf, start, end = 100, 10., 1e5
     wl = np.exp(np.linspace(np.log(end), np.log(start), nf))
     freq = rf.val_to_hz(wl, inp="A")
     flux = np.ones(nf)
     self.sp = spectrum.Spectrum('test_spectrum', freq=freq, flux=flux, is_sort_wl=True)