Ejemplo n.º 1
0
 def lomb_code(self,frequencies, m, m_err, available):
     len_av = len(available)
     dx = zeros(len_av,dtype=float)
     num_freq_comps = 4
     out_dict={}
     ytest=m
     dof = len_av # don't know why we need to have two separate variables for this
     if (dof>=5):
         out_dict['frequencies'] = frequencies
         out_dict['freq_searched_min']=min(frequencies)
         out_dict['freq_searched_max']=max(frequencies)
         for i in range(num_freq_comps):
             psd, freqs, signi, sim_signi, peak_sort = lomb_scargle.lomb(available,ytest,delta_time=dx, signal_err=m_err,freqin=frequencies,verbosity=2)
             imax = psd.argmax()
             freq_max = freqs[imax]
             void_ytest, harm_dict = pre_whiten.pre_whiten(available, ytest, freq_max, delta_time=dx, signal_err=m_err, dof=dof, nharm_min=1, nharm_max=99)
             dstr = "freq%i" % (i+1)
             # check for nharm and rerun
             nharm = harm_dict["nharm"]
             if nharm == 0:
                 break
             print "frequency", i+1, "nharm", nharm 
             ytest, harm_dict = pre_whiten.pre_whiten(available, ytest, freq_max, delta_time=dx, signal_err=m_err, dof=dof, nharm_min=nharm, nharm_max=nharm)
             out_dict[dstr] = {}
             freq_dict = out_dict[dstr]
             freq_dict["signif"] = signi
             freq_dict["frequency"] = freq_max
             for elem_k, elem_v in harm_dict.iteritems():
                 freq_dict["harmonics_" + elem_k] = elem_v
                 dof = dof - harm_dict['nharm']*2.
     return out_dict
Ejemplo n.º 2
0
    sys_argv_2 = sys.argv[2]

if sys_argv_1 == 'get_period_fold2':
    source_id = int(sys_argv_2)
    GetPeriodFoldForWeb = GetPeriodFoldForWeb()
    json_out_string = GetPeriodFoldForWeb.main(source_id)
    print json_out_string

if sys_argv_1 == 'get_period_fold4':
    from lomb_scargle import *
    from pre_whiten import *
    from numpy import random
    time = arange(0,7.5,0.3)
    mags = sin(time)
    mags += 15. + 0.1*random.normal(size=len(time))
    psd,freq,signi,simsigni,psdpeak = lomb(time,mags)
    i0=psd.argmax(); freq0=freq[i0]
    cn, out_dict =  pre_whiten(time,mags, freq0)
    plot (time,mags,'o')
    plot (time,mags-cn)
    A = out_dict['amplitude']
    dA = out_dict['amplitude_error']
    ph = out_dict['rel_phase']
    t0 = out_dict['time_offset']
    y0 = out_dict['y_offset']
    f = out_dict['freq']
    tt = min(time) + (max(time)-min(time))*arange(1000)/999.
    modl = y0 + A[0]*sin(2*pi*f[0]*(tt-t0)+ph[0])
    for i in range(len(f)-1):
        j=i+1
        modl += A[j]*sin(2*pi*f[j]*(tt-t0)+ph[j])