Esempio n. 1
0
def test():
    tempname = 'data/templates/F0_+0.5_Dwarf.fits'
    objname1 = '/home/zzx/workspace/data/xiamen/P200-Hale_spec/blue/reduce_second/specdir/fawftbblue0073.fits'
    objname2 = '/home/zzx/workspace/data/xiamen/P200-Hale_spec/red/reduced_second/specdir/fawftbred0073.fits'
    templat = Model(tempname)
    spec1 = specio.Spectrum(objname1)
    spec2 = specio.Spectrum(objname2)
    maskwindow = [[6270.0, 6320.0], [6860.0, 6970.0], [7150.0, 7340.0]]
    fit2(templat, spec1, spec2, mask=maskwindow)
Esempio n. 2
0
def main():
    lstname = '/home/zzx/workspace/data/xiamen/P200-Hale_spec/spec2/F0/name.lst'
    dirname = os.path.dirname(lstname)
    lst = open(lstname).readlines()
    bluelst = [i.split()[0] for i in lst]
    redlst = [i.split()[1] for i in lst]
    tempname = 'data/templates/F0_+0.5_Dwarf.fits'
    templat = template.Model(tempname)
    # spec1 = specio.Spectrum(objname1)
    # spec2 = specio.Spectrum(objname2)
    maskwindow = [[6270.0, 6320.0], [6860.0, 6970.0], [7150.0, 7340.0]]
    for i in range(len(bluelst)):
        specb = specio.Spectrum(dirname + os.sep + bluelst[i])
        specr = specio.Spectrum(dirname + os.sep + redlst[i])
        # plt.plot(specb.wave, specb.flux)
        # plt.plot(specr.wave, specr.flux)
        # plt.show()
        out = template.fit2(templat, specb, specr, mask=maskwindow)
Esempio n. 3
0
def main():
    fname = sys.argv[1]
    dirname = os.path.dirname(fname)
    if dirname is '':
        dirname = '.'
    spec = specio.Spectrum(fname)
    outname = fname.replace('.fits', '') + '.txt'
    fulloutname = dirname + os.sep + outname
    text = 'write to file ' + fulloutname
    print(text)
    fil = open(fulloutname, 'w')
    for ind in range(len(spec.wave)):
        text = '%.4f  %.6e  %.6e' % (spec.wave[ind], spec.flux[ind],
                                     spec.err[ind])
        fil.write(text + '\n')
    fil.close()
Esempio n. 4
0
def main():
    spec = specio.Spectrum('data/spec-4961-55719-0378.fits')
    # spec = specio.Spectrum('/home/zzx/workspace/data/xiamen/P200-Hale_spec/spec2/fawftbred0027.fits')

    shift = np.arange(-300, 300, 1.0)
    print(len(shift))
    result = libccf.iccf_spec(spec.wave, spec.flux, spec.wave, spec.flux,
                              shift)
    # print(type(result))
    # print(result)
    plt.plot(shift, result)
    plt.show()
    # print(spec.err)
    peak, cent = libccf.iccf_mc(spec.wave, spec.flux_unit, spec.err_unit,
                                spec.wave, spec.flux_unit, spec.err_unit,
                                shift, 1000)
    print(len(peak))
    print(len(cent))
    # plt.hist(peak, bins=50)
    plt.hist(cent, bins=50)
    plt.show()
Esempio n. 5
0
def fit_lamost():
    bluelst, redlst = [], []
    namelst = glob.glob('/home/zzx/workspace/data/stellar_X/*.fits')
    namelst = [
        '/home/zzx/workspace/data/stellar_X/med-58409-TD045606N223435B01_sp16-102.fits'
    ]
    for name in namelst:
        # fig1 = plt.figure()
        # fig2 = plt.figure()
        # ax1 = fig1.add_subplot(111)
        # ax2 = fig2.add_subplot(111)
        print(name)
        size = len(fits.open(name))
        for ind in range(3, size):
            spec = specio.Spectrum(name, ind)
            spec.clean_cosmic_ray()
            if 'B' in spec.header['EXTNAME']:
                bluelst.append(spec)
            else:
                redlst.append(spec)
    name = namelst[0]
    model_blue = Model(name, 3)
    model_blue.clean_cosmic_ray()
    model_red = Model(name, 11)
    model_red.clean_cosmic_ray()
    params = Parameters()
    shiftparname = set_pars(params, 'shift', [1], valuelst=[0.0])
    scalevalst = [
        0.99608100, -0.00931768, 0.00319284, 5.5658e-04, -4.4060e-04, 0.0
    ]
    bscaleparname = set_pars(params, 'b_scale', 5, valuelst=scalevalst)
    rscaleparname = set_pars(params, 'r_scale', 5, valuelst=scalevalst)
    bsimgapar = set_pars(params, 'b_sigma', [1], valuelst=[0.0004])
    rsigmapar = set_pars(params, 'r_sigma', [1], valuelst=[0.0004])
    model_blue.set_lmpar_name(bscaleparname, bsimgapar, shiftparname)
    model_red.set_lmpar_name(rscaleparname, rsigmapar, shiftparname)
    shiftlst, shifterrlst = [], []

    def residual(pars, x1, data1, eps1, x2, data2, eps2):
        res1 = model_blue.residual(pars, x1, data1, eps1)
        res2 = model_red.residual(pars, x2, data2, eps2)
        return np.append(res2, res1)
        return res2

    for ind in range(len(redlst)):
        bspec = bluelst[ind]
        # bspec = redlst[ind]
        rspec = redlst[ind]
        arg1 = func.select(bspec.wave, [[4920, 5300]])
        bnw = bspec.wave[arg1]
        bnf = bspec.flux[arg1]
        bne = bspec.err[arg1]
        arg2 = func.select(rspec.wave, [[6320, 6860]])
        rnw = rspec.wave[arg2]
        rnf = rspec.flux[arg2]
        rne = rspec.err[arg2]
        bfakeerr = np.ones(len(bnw), dtype=np.float64) * 0.01
        rfakeerr = np.ones(len(rnw), dtype=np.float64) * 0.01
        bne = bfakeerr
        rne = rfakeerr
        # out = minimize(model_blue.residual, params, args=(nw, nf))
        # out = minimize(model_red.residual, params, args=(nw, nf))
        out = minimize(residual, params, args=(bnw, bnf, bne, rnw, rnf, rne))
        report_fit(out)
        shiftlst.append(out.params['shift1'].value * c)
        shifterrlst.append(out.params['shift1'].stderr * c)

        plt.figure()

        spec_fit_blue = model_blue.get_spectrum(out.params, model_blue.wave)
        spec_fit_red = model_red.get_spectrum(out.params, model_red.wave)

        plt.plot(bnw, bnf)
        plt.plot(model_blue.wave, spec_fit_blue)

        plt.figure()
        plt.plot(rnw, rnf)
        plt.plot(model_red.wave, spec_fit_red)
        plt.show()

    for ind, value in enumerate(shiftlst):
        # print(value.to('km/s'))
        print(value.to('km/s'), shifterrlst[ind].to('km/s'))