Ejemplo n.º 1
0
    def getL(self,provis,obs,control):
#         print "================================================================================="
#         print "======    Calculate Misclosure L      ==========================================="
        
      
        
        count=obsCount(obs)
        L=numpy.zeros(shape=(count,1))
        Lnames=Points("L vector name pairs")
        i=0
        for sn1,station in obs.iteritems():
            for tn1,target in station.iteritems():
                tn2=tn1
                tn1=tn1[0:-2]
                if target.type=="direction":
                    if control.has_key(tn1):
                        if provis.has_key(sn1):
                            calc=provis[sn1].join(control[tn1])
                        elif control.has_key(sn1):
                            calc=control[sn1].join(control[tn1])
                    elif provis.has_key(tn1):
                        if provis.has_key(sn1):
                            calc=provis[sn1].join(provis[tn1])
                        elif control.has_key(sn1):
                            calc=control[sn1].join(provis[tn1])
                    else: 
                        print "error"
                        calc=0
                    observed=obs[sn1][tn2].direction
                    target.setMisclosure(observed-calc)
                    L[i][0]=(observed-calc)
                    
                    Lnames[sn1 + " to "+ tn1 + " direc"]=L[i][0]
                    i+=1
#                   
                    continue
                elif target.type == "distance":
                    if control.has_key(tn1):
                        if provis.has_key(sn1):
                            calc=provis[sn1].joinS(control[tn1])
                        elif control.has_key(sn1):
                            calc=control[sn1].joinS(control[tn1])
                    elif provis.has_key(tn1):
                        if provis.has_key(sn1):
                            calc=provis[sn1].joinS(provis[tn1])
                        elif control.has_key(sn1):
                            calc=control[sn1].joinS(provis[tn1])
                    else: print "error"
                    
                    observed=obs[sn1][tn2].distance
                    target.setMisclosure(observed-calc)
                    L[i][0]=round((observed-calc),3)
                    Lnames[sn1 + " to "+ tn1 + " distance"]=L[i][0]
                    i+=1   
        return L
Ejemplo n.º 2
0
    def getL(self, provis, obs, control):
        #         print "================================================================================="
        #         print "======    Calculate Misclosure L      ==========================================="

        count = obsCount(obs)
        L = numpy.zeros(shape=(count, 1))
        Lnames = Points("L vector name pairs")
        i = 0
        for sn1, station in obs.iteritems():
            for tn1, target in station.iteritems():
                tn2 = tn1
                tn1 = tn1[0:-2]
                if target.type == "direction":
                    if control.has_key(tn1):
                        if provis.has_key(sn1):
                            calc = provis[sn1].join(control[tn1])
                        elif control.has_key(sn1):
                            calc = control[sn1].join(control[tn1])
                    elif provis.has_key(tn1):
                        if provis.has_key(sn1):
                            calc = provis[sn1].join(provis[tn1])
                        elif control.has_key(sn1):
                            calc = control[sn1].join(provis[tn1])
                    else:
                        print "error"
                        calc = 0
                    observed = obs[sn1][tn2].direction
                    target.setMisclosure(observed - calc)
                    L[i][0] = (observed - calc)

                    Lnames[sn1 + " to " + tn1 + " direc"] = L[i][0]
                    i += 1
                    #
                    continue
                elif target.type == "distance":
                    if control.has_key(tn1):
                        if provis.has_key(sn1):
                            calc = provis[sn1].joinS(control[tn1])
                        elif control.has_key(sn1):
                            calc = control[sn1].joinS(control[tn1])
                    elif provis.has_key(tn1):
                        if provis.has_key(sn1):
                            calc = provis[sn1].joinS(provis[tn1])
                        elif control.has_key(sn1):
                            calc = control[sn1].joinS(provis[tn1])
                    else:
                        print "error"

                    observed = obs[sn1][tn2].distance
                    target.setMisclosure(observed - calc)
                    L[i][0] = round((observed - calc), 3)
                    Lnames[sn1 + " to " + tn1 + " distance"] = L[i][0]
                    i += 1
        return L
Ejemplo n.º 3
0
    def Iterate(self,provis,OBS,control,unknowns):
        count=obsCount(OBS)
        L=self.getL(provis, OBS, control)
#         print "==============        A Matrix        ========================================="
        
        A = numpy.zeros(shape=(count,len(unknowns)))
        A[0][0]=3
        i=0
        j=0
        for station_name,station in OBS.iteritems():
            
            if control.has_key(station_name):
                    current_station=control[station_name]
            elif provis.has_key(station_name):
                    current_station=provis[station_name]
                    
            for tname,target in station.iteritems():
                tname=tname[0:-2]
                j=0
#                 tname=tname[0:-2]
                if target.type=='direction' or target.type=='distance' :
                    for diff_wrt in unknowns:
                        
                        
                        if diff_wrt[-1]=='o':
                            if station_name==diff_wrt[0:-2]:
                                A[i][j]=-1.
                                j+=1
                                continue
                            else: 
                                A[i][j]=0
                                j+=1
                                continue
                        if not tname==diff_wrt[0:-2] and not station_name==diff_wrt[0:-2]: 
                            A[i][j]=0
                            j+=1
                            continue
                        
                        if control.has_key(tname):#if observing control
                                if target.type=="direction":
                                    A[i][j]=equations(current_station,control[tname],diff_wrt,'direction')
                                else :   
                                    A[i][j]=equations(current_station,control[tname],diff_wrt,'distance')
                                j+=1
                                continue
                            
                        else:#if observing provisional
                                if target.type=="direction":
                                    A[i][j]=equations(current_station,provis[tname],diff_wrt,'direction')
                                else:
                                    A[i][j]=equations(current_station,provis[tname],diff_wrt,'distance')
                                j+=1
                                continue
                else:
                    for diff_wrt in unknowns:
                        
                        if diff_wrt[-1]=='o':
                            if station_name==diff_wrt[0:-2]:
                                A[i][j]=-1.
                                j+=1
                                continue
                            else: 
                                A[i][j]=0
                                j+=1
                                continue
                        if not tname==diff_wrt[0:-2] and not station_name==diff_wrt[0:-2]:
                            A[i][j]=0
                            j+=1
                            continue
                        
                        if control.has_key(tname):#if observing control
                            
                                A[i][j]=equations(current_station,control[tname],diff_wrt,target.type)
                                j+=1
                            
                            
                        else:#if observing provisional
                                A[i][j]=equations(current_station,provis[tname],diff_wrt,target.type)
                                j+=1
                    
                    
                i+=1
        names=[]
        for name,ob in OBS.iteritems():
            for na,tar in ob.iteritems():
                if tar.type=="both":
                    names.append(name + "-" + na + "D")
                    names.append(name + "-" + na + "d")
                else:
                    names.append(name + "-" + na + "D")
    
                    
        row_labels = ['SUR09-T013', 'Y', 'N', 'W']
#         for row_label, row in zip(names, A):
#             print '%s [%s]' % (row_label, '      '.join('%01f' % i for i in row))          
   
#         print "==============        Calculating Least squares       ========================================="
        
        
        Pob= Weights()
        Pob.setDirectionWeight(1)
        Pob.setDistanceWeight(1)
        P=Pob.matrix(OBS,A)
        A=numpy.asmatrix(A)
        N= (((A.T)*A)**(-1))*A.T*L
        provUpdate=self.Provisional(N, provis, unknowns)
        Xtemp=Points("N correction pairs")
        i=0
        
        for name in unknowns:
            Xtemp[name]=float64(N[i])
            i+=1
                
        V=A*N-L
#         print A.T*V
        posteriori=float((V.T*P*V)/(count-size(unknowns)))
#         print posteriori
        covarience_mat= posteriori*(A.T*A)**(-1)
        precisions=Points("Precisions of Unknowns")
        i=0
        for name,value in Xtemp.iteritems():
            precisions[name]=sqrt(float(covarience_mat[i,i]))
            i+=1
            
#         print precisions    
#         
#         for i,j in finalX.iteritems():
#             print i + ": "
#             print("Y: %.2f" % j.y)
#             print("N: %.2f" % j.x)
#         print "Orientations :\n"
#         for i,ob in orientations.iteritems():
#             
#             print str.format("{0}   {1}", i, round(ob,1))
#     

        return A,Xtemp , provUpdate , OBS , control , unknowns, V,P
    
# if __name__ == '__main__':
#     Leas= LeastSqr()
#     A,Xdict,provis,OBS,control,unknowns,V,P=Leas.Read('control.csv','observations.csv')  
Ejemplo n.º 4
0
    def Iterate(self, provis, OBS, control, unknowns):
        count = obsCount(OBS)
        L = self.getL(provis, OBS, control)
        #         print "==============        A Matrix        ========================================="

        A = numpy.zeros(shape=(count, len(unknowns)))
        A[0][0] = 3
        i = 0
        j = 0
        for station_name, station in OBS.iteritems():

            if control.has_key(station_name):
                current_station = control[station_name]
            elif provis.has_key(station_name):
                current_station = provis[station_name]

            for tname, target in station.iteritems():
                tname = tname[0:-2]
                j = 0
                #                 tname=tname[0:-2]
                if target.type == 'direction' or target.type == 'distance':
                    for diff_wrt in unknowns:

                        if diff_wrt[-1] == 'o':
                            if station_name == diff_wrt[0:-2]:
                                A[i][j] = -1.
                                j += 1
                                continue
                            else:
                                A[i][j] = 0
                                j += 1
                                continue
                        if not tname == diff_wrt[
                                0:-2] and not station_name == diff_wrt[0:-2]:
                            A[i][j] = 0
                            j += 1
                            continue

                        if control.has_key(tname):  #if observing control
                            if target.type == "direction":
                                A[i][j] = equations(current_station,
                                                    control[tname], diff_wrt,
                                                    'direction')
                            else:
                                A[i][j] = equations(current_station,
                                                    control[tname], diff_wrt,
                                                    'distance')
                            j += 1
                            continue

                        else:  #if observing provisional
                            if target.type == "direction":
                                A[i][j] = equations(current_station,
                                                    provis[tname], diff_wrt,
                                                    'direction')
                            else:
                                A[i][j] = equations(current_station,
                                                    provis[tname], diff_wrt,
                                                    'distance')
                            j += 1
                            continue
                else:
                    for diff_wrt in unknowns:

                        if diff_wrt[-1] == 'o':
                            if station_name == diff_wrt[0:-2]:
                                A[i][j] = -1.
                                j += 1
                                continue
                            else:
                                A[i][j] = 0
                                j += 1
                                continue
                        if not tname == diff_wrt[
                                0:-2] and not station_name == diff_wrt[0:-2]:
                            A[i][j] = 0
                            j += 1
                            continue

                        if control.has_key(tname):  #if observing control

                            A[i][j] = equations(current_station,
                                                control[tname], diff_wrt,
                                                target.type)
                            j += 1

                        else:  #if observing provisional
                            A[i][j] = equations(current_station, provis[tname],
                                                diff_wrt, target.type)
                            j += 1

                i += 1
        names = []
        for name, ob in OBS.iteritems():
            for na, tar in ob.iteritems():
                if tar.type == "both":
                    names.append(name + "-" + na + "D")
                    names.append(name + "-" + na + "d")
                else:
                    names.append(name + "-" + na + "D")

        row_labels = ['SUR09-T013', 'Y', 'N', 'W']
        #         for row_label, row in zip(names, A):
        #             print '%s [%s]' % (row_label, '      '.join('%01f' % i for i in row))

        #         print "==============        Calculating Least squares       ========================================="

        Pob = Weights()
        Pob.setDirectionWeight(1)
        Pob.setDistanceWeight(1)
        P = Pob.matrix(OBS, A)
        A = numpy.asmatrix(A)
        N = (((A.T) * A)**(-1)) * A.T * L
        provUpdate = self.Provisional(N, provis, unknowns)
        Xtemp = Points("N correction pairs")
        i = 0

        for name in unknowns:
            Xtemp[name] = float64(N[i])
            i += 1

        V = A * N - L
        #         print A.T*V
        posteriori = float((V.T * P * V) / (count - size(unknowns)))
        #         print posteriori
        covarience_mat = posteriori * (A.T * A)**(-1)
        precisions = Points("Precisions of Unknowns")
        i = 0
        for name, value in Xtemp.iteritems():
            precisions[name] = sqrt(float(covarience_mat[i, i]))
            i += 1

#         print precisions
#
#         for i,j in finalX.iteritems():
#             print i + ": "
#             print("Y: %.2f" % j.y)
#             print("N: %.2f" % j.x)
#         print "Orientations :\n"
#         for i,ob in orientations.iteritems():
#
#             print str.format("{0}   {1}", i, round(ob,1))
#

        return A, Xtemp, provUpdate, OBS, control, unknowns, V, P


# if __name__ == '__main__':
#     Leas= LeastSqr()
#     A,Xdict,provis,OBS,control,unknowns,V,P=Leas.Read('control.csv','observations.csv')