Пример #1
0
def cfit_model(p,full_model,wavelens):
    #S make a chunk of the model shifted by doppler factor z
    ipmodel = mb.numconv(full_model.data,gaussian(p))
    factor = np.polyval(p[:1:-1],full_model.wavelens)
    unbin_model = factor*ipmodel/np.max(ipmodel) 
#    model = mb.john_rebin(full_model.wavelens,full_model.data,wavelens,p[0])
    model = mb.john_rebin(full_model.wavelens,unbin_model,wavelens,p[0])
    return model
Пример #2
0
def cfit_model(p,full_model,wavelens,order):
    #S make a chunk of the model shifted by doppler factor z
    ipmodel = mb.numconv(full_model.data,gaussian(p))
#    model = mb.john_rebin(full_model.wavelens,full_model.data,wavelens,p[0])
    #S continuum subtraction
#    coeffs = np.polyfit(wavelens,model,5)
    #S do we need to add 1? will just come out in the wash. might want to boost
    #S the observed though
#    cs_model = model - np.polyval(coeffs,wavelens) + 1.
    factor = np.polyval(p[:1:-1],full_model.wavelens)
    unbinmodel = factor*ipmodel/np.max(ipmodel)
    model = mb.john_rebin(full_model.wavelens,full_model.data,wavelens,p[0])
    return model
Пример #3
0
def chunk_func(p,model,star,order,chunk):
    z = p['z'].value
    ipwidth = p['ipwidth'].value
    c0 = p['c0'].value
    c1 = p['c1'].value
    c2 = p['c2'].value

    #S get all inds for the chunk
    ckinds = np.arange(star.cklen)+star.skipf+star.cklen*chunk
    #S get all wavelens and data for the chunk
    ckwaves = star.wavelens[order][ckinds]
    ckdata = star.data[order][ckinds]
    ckerrs = star.errs[order][ckinds]
    
    #S get the trimmed indices
    inds = star.inds['o'+str(order)+'_c'+str(chunk)]

    #S get the wavelengths in the model relevant to the order
    lowwave = ckwaves.min()-30.
    highwave = ckwaves.max()+30.
    low = np.where(full_model.wavelens > lowwave)[0]
    high = np.where(full_model.wavelens[low] < highwave)[0]
    # the relevant model inds for the order                             
    minds = low[high]
    
    # get the model wavelens and ipdata for the order                  
    modwaves = full_model.wavelens[minds]
    #S convolve the model over the relevant wavelengths
    modck = mb.numconv(full_model.data[minds],gaussian(ipwidth))
    #S add some wavelength scaling
    factor = np.polyval([c2,c1,c0],modwaves)
    unbinmodel = factor*modck/np.max(modck)
    #S rebin the convolved model, and 
    tmodel = mb.john_rebin(modwaves,unbinmodel,ckwaves,z)

    return tmodel
Пример #4
0
def all_err_func(p,model,star,plot_check=False):
    z = p['z'].value
    amp = p['amp'].value
    ipwidth = p['ipwidth'].value
    all_errs = np.array([])
    all_edge_errs = np.array([])
    j=0
    skipf = 148
    cklen = 300
#    print p[0], p[1]

    #S convolve the entire model spectrum, want to trim to just relevant wave-
    #S lengths, as well as only when the ip changes. 
    ipdb.set_trace()
    full_model.ipdata = mb.numconv(full_model.data,gaussian(amp,ipwidth))
    for order in star.fit_orders: 
        for ck in star.fit_chunks:
            #S indices for all the wavelengths in a chunk, for rebinning 
            #S purposes
            ckinds = np.arange(cklen) + skipf + ck*cklen
            #S wavelengths we want to rebin for in the chunk
            ckwaves = star.wavelens[order][ckinds]
            ckdata = star.data[order][ckinds]
            ckerrs = star.errs[order][ckinds]

            # get the wavelengths in the model relevant to the order
            lowwave = ckwaves.min()-10.
            highwave = ckwaves.max()+10.
            low = np.where(full_model.wavelens > lowwave)[0]
            high = np.where(full_model.wavelens[low] < highwave)[0]
            # the relevant model inds for the order
            minds = low[high]

            #S get the model wavelens and ipdata for the order
            modwaves = full_model.wavelens[minds]
            modck = full_model.ipdata[minds]
            #S the index 'zero' point
            c0 = p['c0_o'+str(order)+'_c'+str(ck)].value
            c1 = p['c1_o'+str(order)+'_c'+str(ck)].value
            c2 = p['c2_o'+str(order)+'_c'+str(ck)].value
#            j = (order-np.min(star.fit_orders))*5+ck
#            temp_params = [p[0],p[1],p[3*j+2],p[3*j+3],p[3*j+4]]

            factor = np.polyval([c2,c1,c0],modwaves)
            unbinmodel = factor*modck/np.max(modck)
            tmodel = mb.john_rebin(modwaves,unbinmodel,ckwaves,z)
            
            inds = blg.inds['o'+str(order)+'_c'+str(ck)]
            star.fit_data['o'+str(order)+'_c'+str(ck)] = tmodel[inds]
            
            if plot_check:
                #ipdb.set_trace()
                plt.plot(ckwaves[inds],ckdata[inds],zorder=2)
                plt.plot(ckwaves[inds],tmodel[inds],linewidth=2,zorder=2)

            errs = (tmodel[inds] - ckdata[inds])/(ckerrs[inds])#/1.75)

            if ck != star.fit_chunks[0]:
                edge_errs = (star.fit_data['o'+str(order)+'_c'+str(ck-1)][-1]-\
                     star.fit_data['o'+str(order)+'_c'+str(ck)][0])

            else: 
                edge_errs = 0.
#            all_errs=np.concatenate([all_errs,errs])
            all_errs=np.concatenate([all_errs,errs,[edge_errs]])
            all_edge_errs=np.concatenate([all_edge_errs,[edge_errs]])

        if plot_check:
            print('All errors, and the shape')
            print all_errs, np.shape(all_errs)
            print('All edge errors, and the shape')
            print all_edge_errs, np.shape(all_edge_errs)
            plt.plot(blg.wavelens[order],blg.data[order],zorder=1)
#            plt.errorbar(blg.wavelens[order],blg.data[order],blg.errs[order],
#                         zorder=1)
#            imsave_path = '/Users/samsonjohnson/Desktop/spitzer/blg_ccorr'+\
#                '/images0412/'+'orders'+str(min(blg.fit_orders))+'_'+\
#                str(max(blg.fit_orders))+'/order'+str(order)+'cklen'+\
#                str(cklen)+'.pdf'
#            plt.savefig(imsave_path)
            plt.show()
    
    if plot_check:
        prevpts = 0
        prevmax = 0
        for order in blg.fit_orders:
            for ck in blg.fit_chunks:
                x = np.arange(len(blg.inds['o'+str(order)+'_c'+str(ck)]))+\
                    prevpts
                prevpts += len(x)
                tdata = blg.fit_data['o'+str(order)+'_c'+str(ck)]
                adata = blg.data[order][np.arange(400)+skipf+ck*cklen]\
                    [blg.inds['o'+str(order)+'_c'+str(ck)]]
                errs = blg.errs[order][np.arange(400)+skipf+ck*cklen]\
                    [blg.inds['o'+str(order)+'_c'+str(ck)]]/1.75
                plt.plot(x,prevmax+np.cumsum(((tdata-adata)/errs)**2),\
                             label=str(order)+' '+str(ck))
#                ipdb.set_trace()
                prevmax = np.cumsum(((tdata-adata)/errs)**2)[-1] + prevmax
        plt.plot(np.arange(prevpts))
        plt.axis([0,prevpts+1000,0,prevpts+1000])
        plt.legend()
        plt.show()
    return np.array(all_errs)