Beispiel #1
0
 def __call__(self, x, y=None, observed=True, regularize=True):
     out = Covariance.__call__(self,x,y,observed,regularize)
     if self.nugget is None:
         return out
     if x is y:
         for i in xrange(out.shape[0]):
             out[i,i] += self.nugget
     elif y is None:
         out += self.nugget
     return out
Beispiel #2
0
 def __call__(self, x, y=None, observed=True, regularize=True):
     out = Covariance.__call__(self, x, y, observed, regularize)
     if self.nugget is None:
         return out
     if x is y:
         for i in xrange(out.shape[0]):
             out[i, i] += self.nugget
     elif y is None:
         out += self.nugget
     return out
    def __call__(self, x, y=None, observed=True, regularize=True, return_Uo_Cxo=False):
        out = Covariance.__call__(self,x,y,observed,regularize,return_Uo_Cxo=return_Uo_Cxo)

        if self.nugget is None:
            return out
        
        if return_Uo_Cxo:
            out, Uo_Cxo = out
        if x is y:
            for i in xrange(out.shape[0]):
                out[i,i] += self.nugget
        elif y is None:
            out += self.nugget
        if return_Uo_Cxo:
            return out, Uo_Cxo
        else:
            return out
Beispiel #4
0
    def __call__(self, x, y=None, observed=True, regularize=True, return_Uo_Cxo=False):
        out = Covariance.__call__(self,x,y,observed,regularize,return_Uo_Cxo=return_Uo_Cxo)

        if self.nugget is None:
            return out

        if return_Uo_Cxo:
            out, Uo_Cxo = out
        if x is y:
            for i in xrange(out.shape[0]):
                out[i,i] += self.nugget
        elif y is None:
            out += self.nugget
        if return_Uo_Cxo:
            return out, Uo_Cxo
        else:
            return out
Beispiel #5
0
tsindexes = obs.get_indexes()
m = len(tsindexes)
sp = obs.get_sp()
offsets = obs.get_offsets()
noisemodels = obs.get_noisemodels()
F = obs.gen_F_matrix()
min_method = obs.get_min_method()

periods = [365.25, 182.625]

#   Create DesignMatrix
H = DesignMatrix.create_DesignMatrix(sp, offsets, tsindexes, periods)

#   Guess [fraction, kappa] values and create covariance model
param = [0.514662,-0.9] 
cov = Covariance(noisemodels)



# ---------------------------------------------- #
# MLE TEST 1 
# ---------------------------------------------- #
"""
#--- MLE
mle = MLE(x, F, 'Fullcov', H, cov)
print("Timing MLE fullcov...\n")

#--- run MLE
start_time = time.time()
[theta, C_theta, ln_det_C, sigma_eta, param] = mle.estimate_parameters()
end_time = time.time()
 def __init__(self, eval_fun, relative_precision=1.0E-15, **params):
     Covariance.__init__(self,
                         eval_fun,
                         relative_precision,
                         rank_limit=0,
                         **params)
    def Transformation(addressTop, addressBot, cutterCells, victimCells):
        condition = [True, True, True, True]
        preCelltop = XMLinterpreter(addressTop)
        Celltop = CellCointainer(preCelltop, condition)
        Nodestop= Celltop.allNodesExtract(0)

        preCellbot = XMLinterpreter(addressBot)
        Cellbot = CellCointainer(preCellbot, condition)
        Nodesbot= Cellbot.allNodesExtract(0)
        
        coef = Transformation.getPlaneCoef2(Nodestop)
        
        Nodestop = Transformation.convertCoord(coef, Nodestop)
        Nodesbot = Transformation.convertCoord(coef, Nodesbot)
        
        topX = Transformation.getAvgPoint(Nodestop)[2]
        botX = Transformation.getAvgPoint(Nodesbot)[2]
        
        preCellcut = XMLinterpreter(cutterCells)
        Cellcut = CellCointainer(preCellcut, condition)
        Nodescut= Cellcut.Nodes  #dictionary
        
        preCellvic = XMLinterpreter(victimCells)
        Cellvic = CellCointainer(preCellvic, condition)
        Nodesvic= Cellvic.Nodes #dictionary
        
        #Nodesvic = Cellvic.commentWithKeywordExtractDict("ibbon")
        
        ###
        #NodesvicAid = Cellvic.Nodes
        ###
       
        
        #DicNodesCCells = {}
        #for item1 in Nodescut.keys():
        #    DicNodesCCells.setdefault(item1)
        #    temp = Transformation.convertCoord(coef, Nodescut[item1])
        #    
        #    DicNodesCCells[item1] = temp
        
        DicNodesVCells = {}
        
        for item2 in Nodesvic.keys():
            DicNodesVCells.setdefault(item2)
            temp1 = Transformation.convertCoord(coef, Nodesvic[item2])
            
            DicNodesVCells[item2] = temp1
            
            """##
        DicNodesVaidCells = {}
        
        for item3 in Nodesvic.keys(): 
            DicNodesVaidCells.setdefault(item3)
            temp2 = Transformation.convertCoord(coef, NodesvicAid[item3])
            
            DicNodesVaidCells[item3] = temp2
           
        
       
        for item4 in DicNodesVCells.keys():
            
            aEllipse = Covariance.toEllipse(DicNodesVCells[item4])
            
            cellcorX = Transformation.getAvgPoint(DicNodesVCells[item4])[2]
            Relength2 = (topX - cellcorX)/(topX - botX)
            
            
            plt.scatter( Relength2  , CONF95 * pi * aEllipse[2] * aEllipse[3])
        
        show()
        
        #cutVal = Transformation.findMin(DicNodesCCells)
        #DicNodesVCells = Transformation.cutCellX(DicNodesVCells, cutVal)
        
        """
        ells = []
        
        for item3 in DicNodesVCells.keys():
                       
            cellcorX = Transformation.getAvgPoint(DicNodesVCells[item3])[2]
            Relength2 = (topX - cellcorX)/(topX - botX)
            
            if Relength2 > 1.15:
                continue #showing mosaic bigger than 1.15
            
            aEllipse = Covariance.toEllipse(DicNodesVCells[item3])
            
            #output [ycor zcor Principle1 Principle2 Angle cellname]
           
            temparr = []            
            
            xcordz = aEllipse[0]
            ycordz = aEllipse[1]
            widthz = aEllipse[2] * 2 * math.sqrt(CONF95) #
            heightz = aEllipse[3] * 2 * math.sqrt(CONF95)  #  
            anglez = aEllipse[4]
            
            xyz = []
            xyz.append(xcordz)
            xyz.append(ycordz)
            
            temparr.append(Ellipse(xy =xyz, width =widthz, height= heightz, angle = anglez * 180/ pi )) 
            temparr.append(xyz)
            temparr.append(item3)
            ells.append(temparr)
            
            
            
        fig = figure()
        ax = fig.add_subplot(111, aspect='equal')
        
        for e in ells:
            ax.add_artist(e[0])
            e[0].set_clip_box(ax.bbox)
            e[0].set_alpha(rand())
            e[0].set_facecolor(rand(3))
            plt.text(e[1][0], e[1][1], e[2], ha="center", family='sans-serif', size=14)
            
        
        ax.set_xlim(-100000,200000)
        ax.set_ylim(000000,200000)
        show()
    def areaVSrelength(addressTop, addressBot, victimCells):
        condition = [True, True, True, True]
        preCelltop = XMLinterpreter(addressTop)
        Celltop = CellCointainer(preCelltop, condition)
        Nodestop= Celltop.allNodesExtract(0)

        preCellbot = XMLinterpreter(addressBot)
        Cellbot = CellCointainer(preCellbot, condition)
        Nodesbot= Cellbot.allNodesExtract(0)
        
        coef = Transformation.getPlaneCoef2(Nodestop)
        
        Nodestop = Transformation.convertCoord(coef, Nodestop)
        Nodesbot = Transformation.convertCoord(coef, Nodesbot)
        
        topX = Transformation.getAvgPoint(Nodestop)[2]
        botX = Transformation.getAvgPoint(Nodesbot)[2]
        

        
        preCellvic = XMLinterpreter(victimCells)
        Cellvic = CellCointainer(preCellvic, condition)
        
        Nodesvic= Cellvic.commentWithKeywordExtractDict("utput") #dictionary// smaller
        print Nodesvic
        #Nodesvic = Cellvic.Nodes
        NodesvicAid = Cellvic.Nodes
        
        DicNodesVCells = {}
        DicNodesVaidCells = {}
        DicNodesError = {}
        ells = [] 
               
        for item1 in Nodesvic.keys():
            DicNodesVCells.setdefault(item1)
            
            temp1 = Transformation.convertCoord(coef, Nodesvic[item1])
            
            #temp1 = Transformation.convertCoord(coef, Transformation.cutCell2(Nodesvic[item2], 0.25, 0.75))
            
            cellcorX = Transformation.getAvgPoint(temp1)[2]
            Relength2 = (topX - cellcorX)/(topX - botX)
            DicNodesVCells[item1] = Relength2
            
            DicNodesError.setdefault(item1)
            
            stdev = Transformation.stdev1D(temp1)
            stdev = stdev/(topX-botX)
            DicNodesError[item1] = stdev
            
            
            
            DicNodesVaidCells.setdefault(item1)
            temp2 = Transformation.convertCoord(coef, NodesvicAid[item1])
            #temp2 = temp1
            
            aEllipse = Covariance.toEllipse(temp2)
            DicNodesVaidCells[item1] = CONF95 * pi * aEllipse[2] * aEllipse[3]
            
            #if DicNodesVCells[item1] < 1.2:
            #    continue #showing mosaic bigger than 1.15            
            

            aEllipse = Covariance.toEllipse(temp2)
            
            #output [ycor zcor Principle1 Principle2 Angle cellname]
           
            temparr = []            
            
            xcordz = aEllipse[0]
            ycordz = aEllipse[1]
            widthz = aEllipse[2] * 2 * math.sqrt(CONF95) #
            heightz = aEllipse[3] * 2 * math.sqrt(CONF95)  #  
            anglez = aEllipse[4]
            
            xyz = []
            xyz.append(xcordz)
            xyz.append(ycordz)
            
            
            
            temparr.append(Ellipse(xy =xyz, width =widthz, height= heightz, angle = anglez * 180/ pi )) 
            temparr.append(xyz)
            temparr.append(item1)
            ells.append(temparr)            
        """        
        ## del ##
        
        DicNodesVCells.setdefault("top")
             
        cellcorX = Transformation.getAvgPoint(Nodestop)[2]
        Relength2 = (topX - cellcorX)/(topX - botX)
        DicNodesVCells["top"] = Relength2
            
        DicNodesError.setdefault("top")
            
        stdev = Transformation.stdev1D(Nodestop)
        stdev = stdev/(topX-botX)
        DicNodesError["top"] = stdev
            
            
            
        DicNodesVaidCells.setdefault("top")
        temp2 = Transformation.convertCoord(coef, Nodestop)
            #temp2 = temp1
            
        aEllipse = Covariance.toEllipse(temp2)
        DicNodesVaidCells["top"] = CONF95 * pi * aEllipse[2] * aEllipse[3]
        



        DicNodesVCells.setdefault("bot")
             
        cellcorX = Transformation.getAvgPoint(Nodesbot)[2]
        Relength2 = (topX - cellcorX)/(topX - botX)
        DicNodesVCells["bot"] = Relength2
            
        DicNodesError.setdefault("bot")
            
        stdev = Transformation.stdev1D(Nodesbot)
        stdev = stdev/(topX-botX)
        DicNodesError["bot"] = stdev
            
            
            
        DicNodesVaidCells.setdefault("bot")
        temp2 = Transformation.convertCoord(coef, Nodesbot)
            #temp2 = temp1
            
        aEllipse = Covariance.toEllipse(temp2)
        DicNodesVaidCells["bot"] = CONF95 * pi * aEllipse[2] * aEllipse[3]
        
        """     
        
        ####
        """
        for item4 in DicNodesVCells.keys():
            #if DicNodesVCells[item4] > 1.0:
            #    continue
            
            
            plt.scatter( DicNodesVCells[item4], DicNodesVaidCells[item4], color = Transformation.color(0.8,DicNodesError[item4]), s = 130 )
            
            plt.text(DicNodesVCells[item4], DicNodesVaidCells[item4], item4, ha="center", family='sans-serif', size=10)
            #plt.errorbar(DicNodesVCells[item4], DicNodesVaidCells[item4], xerr = DicNodesError[item4], linestyle = "None", ecolor = Transformation.color(0.8,DicNodesError[item4]))
        show()
        """
        
        

        ###             
        """
            
        fig = figure()
        ax = fig.add_subplot(111, aspect='equal')
        
        
        for e in ells:
            print e
            ax.add_artist(e[0])
            e[0].set_clip_box(ax.bbox)
            e[0].set_alpha(0.3)
            e[0].set_facecolor(Transformation.color(0.8 ,DicNodesError[e[2]]))
            plt.text(e[1][0], e[1][1], e[2], ha="center", family='sans-serif', size=14)
            
        
        ax.set_xlim(-300000,300000)
        ax.set_ylim(-300000,300000)
        show()
        """
#############convex haul###########################################    
    
        ells1 = []
        for item2 in DicNodesVCells.keys():

            
            #if DicNodesVCells[item2] < 1.2:
            #    continue #showing mosaic bigger than 1.15
## 
            newNode = []
            
            DicNodesVCells.setdefault(item2)
            
            temp1 = Transformation.convertCoord(coef, Nodesvic[item2])
            

            
            cellcorX = Transformation.getAvgPoint(temp1)[2]
            Relength2 = (topX - cellcorX)/(topX - botX)
            DicNodesVCells[item2] = Relength2
            
            DicNodesError.setdefault(item2)
            
            stdev = Transformation.stdev1D(temp1)
            stdev = stdev/(topX-botX)
            DicNodesError[item2] = stdev
            
            
            
            DicNodesVaidCells.setdefault(item2)
            temp2 = Transformation.convertCoord(coef, NodesvicAid[item2])
            #print Transformation.yzExtract(temp2)
            hull = ConvexHull(Transformation.yzExtract(temp2))
            
            newNode.append(hull)
            newNode.append(item2)
            newNode.append(Transformation.yzExtract(temp2))
            ells1.append(newNode)
            
        
            
        fig = figure()
        ax = fig.add_subplot(111, aspect='equal')
        
        for e in ells:
            
            #ax.add_artist(e[0])
            #e[0].set_clip_box(ax.bbox)
            #e[0].set_alpha(0.2)
            #e[0].set_facecolor(Transformation.color(0.8 ,DicNodesError[e[2]]))
            plt.text(e[1][0], e[1][1], e[2], ha="center", family='sans-serif', size=14)
                 
        
        
        
        for arr in ells1:
            
            points = arr[2]
            hull = arr[0]

            
            for vertex in hull.simplices:
 
                plt.plot([(points[(vertex[0])])[0], (points[(vertex[1])])[0]], [(points[(vertex[0])])[1],(points[(vertex[1])])[1]], c =Transformation.color(0.8 ,DicNodesError[arr[1]]) )
            
            
            #convex_hull_plot_2d(arr[0], ax)
        
        i = 0
        
        while i < (len(ells1) - 1):
            fIndex = i
            sIndex = i-1
            
            first = Transformation.verticesToPoints(ells1[fIndex][0], ells1[fIndex][2])
            second = Transformation.verticesToPoints(ells1[sIndex][0], ells1[sIndex][2])
            
            
            i = i + 1
            
            collidng = Transformation.ClipPolygon(first, second)
            for item in collidng:
                 plt.scatter( item[0], item[1], s = 130 )
        
        
        ax.set_xlim(-300000,300000)
        ax.set_ylim(-300000,300000)
        show()    
    def transformationCSV(filename, addressTop, addressBot, cutterCells, victimCells):
        condition = [True, True, True, True]
        preCelltop = XMLinterpreter(addressTop)
        Celltop = CellCointainer(preCelltop, condition)
        Nodestop= Celltop.allNodesExtract(0)

        preCellbot = XMLinterpreter(addressBot)
        Cellbot = CellCointainer(preCellbot, condition)
        Nodesbot= Cellbot.allNodesExtract(0)
        
        coef = Transformation.getPlaneCoef2(Nodestop)
        
        Nodestop = Transformation.convertCoord(coef, Nodestop)
        Nodesbot = Transformation.convertCoord(coef, Nodesbot)
        
        topX = Transformation.getAvgPoint(Nodestop)[2]
        botX = Transformation.getAvgPoint(Nodesbot)[2]
        
  
        
        preCellcut = XMLinterpreter(cutterCells)
        Cellcut = CellCointainer(preCellcut, condition)
        Nodescut= Cellcut.Nodes  #dictionary
        
        preCellvic = XMLinterpreter(victimCells)
        Cellvic = CellCointainer(preCellvic, condition)
        Nodesvic= Cellvic.Nodes #dictionary
        
        #Nodesvic = Cellvic.commentWithKeywordExtractDict("ibbon")
        
        ###
        NodesvicAid = Cellvic.Nodes
        ###
       
        
        #DicNodesCCells = {}
        #for item1 in Nodescut.keys():
        #    DicNodesCCells.setdefault(item1)
        #    temp = Transformation.convertCoord(coef, Nodescut[item1])
        #    
        #    DicNodesCCells[item1] = temp
        
        DicNodesVCells = {}
        
        for item2 in Nodesvic.keys():
            DicNodesVCells.setdefault(item2)
            temp1 = Transformation.convertCoord(coef, Nodesvic[item2])
            
            DicNodesVCells[item2] = temp1
            
            """##
        DicNodesVaidCells = {}
        
        for item3 in Nodesvic.keys(): 
            DicNodesVaidCells.setdefault(item3)
            temp2 = Transformation.convertCoord(coef, NodesvicAid[item3])
            
            DicNodesVaidCells[item3] = temp2
            """##
        
        with open(filename, 'wb') as csvfile:
            fieldnames = ['relative_length', 'area']
            writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
            
            for item4 in DicNodesVCells.keys():
                
                
                #writer.writeheader()
                
                aEllipse = Covariance.toEllipse(DicNodesVCells[item4])
            
                cellcorX = Transformation.getAvgPoint(DicNodesVCells[item4])[2]
                Relength2 = (topX - cellcorX)/(topX - botX)
                area = CONF95 * pi * aEllipse[2] * aEllipse[3]
                writer.writerow({'relative_length':str(Relength2) , 'area':str(area)})
Beispiel #10
0
def create_bfgs_dask(resettable,
                     output_folder,
                     N,
                     datapack,
                     L_ne,
                     size_cell,
                     i0,
                     ant_idx=-1,
                     dir_idx=-1,
                     time_idx=[0]):
    try:
        os.makedirs(output_folder)
    except:
        pass
    print("Using output folder: {}".format(output_folder))
    state_file = "{}/state".format(output_folder)
    straight_line_approx = True
    tmax = 1000.
    antennas, antenna_labels = datapack.get_antennas(ant_idx=ant_idx)
    patches, patch_names = datapack.get_directions(dir_idx=dir_idx)
    times, timestamps = datapack.get_times(time_idx=time_idx)
    datapack.set_reference_antenna(antenna_labels[i0])
    #plot_datapack(datapack,ant_idx = ant_idx, time_idx = time_idx, dir_idx = dir_idx,figname='{}/dobs'.format(output_folder))
    dobs = datapack.get_dtec(ant_idx=ant_idx,
                             time_idx=time_idx,
                             dir_idx=dir_idx)
    Na = len(antennas)
    Nt = len(times)
    Nd = len(patches)
    fixtime = times[Nt >> 1]
    phase = datapack.get_center_direction()
    array_center = datapack.radio_array.get_center()
    #Average time axis down and center on fixtime
    if Nt == 1:
        var = (0.5 * np.percentile(dobs[dobs > 0], 25) +
               0.5 * np.percentile(-dobs[dobs < 0], 25))**2
        Cd = np.ones([Na, 1, Nd], dtype=np.double) * var
        Ct = (np.abs(dobs) * 0.05)**2
        CdCt = Cd + Ct
    else:
        dt = times[1].gps - times[0].gps
        print("Averaging down window of length {} seconds [{} timestamps]".
              format(dt * Nt, Nt))
        Cd = np.stack([np.var(dobs, axis=1)], axis=1)
        dobs = np.stack([np.mean(dobs, axis=1)], axis=1)
        Ct = (np.abs(dobs) * 0.05)**2
        CdCt = Cd + Ct
        time_idx = [Nt >> 1]
        times, timestamps = datapack.get_times(time_idx=time_idx)
        Nt = len(times)
    print("E[S/N]: {} +/- {}".format(
        np.mean(np.abs(dobs) / np.sqrt(CdCt + 1e-15)),
        np.std(np.abs(dobs) / np.sqrt(CdCt + 1e-15))))
    vmin = np.min(
        datapack.get_dtec(ant_idx=ant_idx, time_idx=time_idx, dir_idx=dir_idx))
    vmax = np.max(
        datapack.get_dtec(ant_idx=ant_idx, time_idx=time_idx, dir_idx=dir_idx))
    plot_datapack(datapack,
                  ant_idx=ant_idx,
                  time_idx=time_idx,
                  dir_idx=dir_idx,
                  figname='{}/dobs'.format(output_folder),
                  vmin=vmin,
                  vmax=vmax)  #replace('hdf5','png'))
    ne_tci = create_initial_model(datapack,
                                  ant_idx=ant_idx,
                                  time_idx=time_idx,
                                  dir_idx=dir_idx,
                                  zmax=tmax,
                                  spacing=size_cell)
    #make uniform
    #ne_tci.m[:] = np.mean(ne_tci.m)
    ne_tci.save("{}/nePriori.hdf5".format(output_folder))
    rays = calc_rays(antennas, patches, times, array_center, fixtime, phase,
                     ne_tci, datapack.radio_array.frequency,
                     straight_line_approx, tmax, ne_tci.nz)
    m_tci = ne_tci.copy()
    K_ne = np.mean(m_tci.m)
    m_tci.m /= K_ne
    np.log(m_tci.m, out=m_tci.m)

    Nkernel = max(1, int(float(L_ne) / size_cell))
    sigma_m = np.log(
        10.
    )  #ne = K*exp(m+dm) = K*exp(m)*exp(dm), exp(dm) in (0.1,10) -> dm = (log(10) - log(0.1))/2.
    cov_obj = Covariance(m_tci, sigma_m, L_ne, 7. / 2.)
    #uvw = UVW(location = datapack.radio_array.get_center().earth_location,obstime = fixtime,phase = phase)
    #ants_uvw = antennas.transform_to(uvw).cartesian.xyz.to(au.km).value.transpose()
    #dirs_uvw = patches.transform_to(uvw).cartesian.xyz.value.transpose()
    F0 = precondition(ne_tci,
                      datapack,
                      ant_idx=ant_idx,
                      dir_idx=dir_idx,
                      time_idx=time_idx)
    #
    dsk = {}
    for n in range(int(N)):
        #g_n
        dsk['store_forwardEq{}'.format(n)] = (store_forwardEq, resettable,
                                              'output_folder', n,
                                              'template_datapack', 'ant_idx',
                                              'time_idx', 'dir_idx', 'rays',
                                              'K_ne', 'pull_m{}'.format(n),
                                              'i0')
        dsk['pull_forwardEq{}'.format(n)] = (pull_forwardEq, resettable,
                                             'store_forwardEq{}'.format(n),
                                             'ant_idx', 'time_idx', 'dir_idx')
        #gradient
        dsk['store_gamma{}'.format(n)] = (store_gamma, resettable,
                                          'output_folder', n, 'rays',
                                          'pull_forwardEq{}'.format(n), 'dobs',
                                          'i0', 'K_ne', 'pull_m{}'.format(n),
                                          'mprior', 'CdCt', 'sigma_m',
                                          'Nkernel', 'size_cell', 'cov_obj')
        dsk['pull_gamma{}'.format(n)] = (pull_gamma, resettable,
                                         'store_gamma{}'.format(n))
        #m update
        dsk['store_m{}'.format(n + 1)] = (store_m, resettable, 'output_folder',
                                          n + 1, 'pull_m{}'.format(n),
                                          'pull_phi{}'.format(n), 'rays',
                                          'K_ne', 'i0',
                                          'pull_forwardEq{}'.format(n), 'dobs',
                                          'CdCt', 'state_file')
        dsk['pull_m{}'.format(n + 1)] = (pull_m, resettable,
                                         'store_m{}'.format(n + 1))
        dsk['plot_m{}'.format(n + 1)] = (plot_model, 'output_folder', n + 1,
                                         'pull_m{}'.format(n + 1), 'mprior',
                                         'K_ne')
        dsk['plot_gamma{}'.format(n)] = (plot_gamma, 'output_folder', n,
                                         'pull_gamma{}'.format(n))
        #phi
        dsk['pull_phi{}'.format(n)] = (pull_Fdot, resettable,
                                       'store_F{}(gamma{})'.format(n, n))
        dsk['store_F{}(gamma{})'.format(
            n + 1, n + 1)] = (store_Fdot, resettable, 'output_folder', n + 1,
                              n + 1, 'pull_F{}(gamma{})'.format(n, n + 1),
                              'pull_gamma{}'.format(n + 1), 'beta{}'.format(n),
                              'dm{}'.format(n), 'dgamma{}'.format(n),
                              'v{}'.format(n), 'sigma_m', 'L_m')
        for i in range(1, n + 1):
            dsk['store_F{}(gamma{})'.format(
                i, n + 1)] = (store_Fdot, resettable, 'output_folder', i,
                              n + 1, 'pull_F{}(gamma{})'.format(i - 1, n + 1),
                              'pull_gamma{}'.format(n + 1),
                              'beta{}'.format(i - 1), 'dm{}'.format(i - 1),
                              'dgamma{}'.format(i - 1), 'v{}'.format(i - 1),
                              'sigma_m', 'L_m')
            dsk['pull_F{}(gamma{})'.format(
                i, n + 1)] = (pull_Fdot, resettable,
                              'store_F{}(gamma{})'.format(i, n + 1))
        #should replace for n=0
        dsk['store_F0(gamma{})'.format(n)] = (store_F0dot, resettable,
                                              'output_folder', n, 'pull_F0',
                                              'pull_gamma{}'.format(n))
        dsk['pull_F0(gamma{})'.format(n)] = (pull_Fdot, resettable,
                                             'store_F0(gamma{})'.format(n))
        #         #epsilon_n
        #         dsk['ep{}'.format(n)] = (calc_epsilon,n,'pull_phi{}'.format(n),'pull_m{}'.format(n),'rays',
        #                                     'K_ne','i0','pull_forwardEq{}'.format(n),'dobs','CdCt')
        #
        dsk['beta{}'.format(n)] = (calcBeta, 'dgamma{}'.format(n),
                                   'v{}'.format(n), 'dm{}'.format(n),
                                   'sigma_m', 'L_m')
        dsk['dgamma{}'.format(n)] = (diffTCI, 'pull_gamma{}'.format(n + 1),
                                     'pull_gamma{}'.format(n))
        dsk['dm{}'.format(n)] = (diffTCI, 'pull_m{}'.format(n + 1),
                                 'pull_m{}'.format(n))
        dsk['v{}'.format(n)] = (diffTCI, 'pull_F{}(gamma{})'.format(n, n + 1),
                                'pull_phi{}'.format(n))
    dsk['pull_F0'] = F0
    dsk['template_datapack'] = datapack
    dsk['ant_idx'] = ant_idx
    dsk['time_idx'] = time_idx
    dsk['dir_idx'] = dir_idx
    dsk['pull_m0'] = 'mprior'
    dsk['i0'] = i0
    dsk['K_ne'] = K_ne
    dsk['dobs'] = dobs
    dsk['mprior'] = m_tci
    dsk['CdCt'] = CdCt
    dsk['sigma_m'] = sigma_m
    dsk['Nkernel'] = Nkernel
    dsk['L_m'] = L_ne
    dsk['size_cell'] = size_cell
    dsk['cov_obj'] = cov_obj
    #calc rays
    #dsk['rays'] = (calc_rays_dask,'antennas','patches','times', 'array_center', 'fixtime', 'phase', 'ne_tci', 'frequency',  'straight_line_approx','tmax')
    dsk['rays'] = rays
    dsk['output_folder'] = output_folder
    dsk['resettable'] = resettable
    dsk['state_file'] = state_file

    return dsk
 def __init__(self, eval_fun, relative_precision = 1.0E-15, **params):
     Covariance.__init__(self, eval_fun, relative_precision, rank_limit=0, **params)
#Upper and lower bounds in frequency-space.
k_low = 0.001
k_high = 5.0
#Cutoff harmonic mode.
l_max = 10
#Maximum radius and number of radial samples (uniform grid).
r_max = 10.0
r_step = r_max / 10

#=================Sampler Options===============#
nubar = 1.0
nfields = 8
nsamples = 10

#===============Compute Covariance==============#
cov = Covariance()
if compute_cov == True:
    cov.ComputeCovariances(spectrum_filename, k_low, k_high, l_max, r_max,
                           r_step)
    cov.Save("covariances")

#===============Sample 00 Phi Mode==============#
cov.Load("covariances.npz")
samp = Sampler(cov)
print "===============Sampling Phi00=============="
samps = samp.GetSamples(nubar, nfields, nsamples)

#==============Compute mean w/droop=============#
print "===================Computing Mean=================="
#Recompute the rho splines.
#Ideally we would store the splines, but we can't