示例#1
0
    def __init__(self, 
                 stdevUseApriori=True,
                 confProb=0.95,
                 reliabProb=0.95,
                 #config=None,
                 duplicateFixId=DUPLICATE_ID.compare,
                 textTable=None):
        """
        stdevUseApriori: use apriori/aposteriori standard deviation
        confProb: confidence probability
        reliabProb: reliability probability
        config: project configuration file
        duplicateFixId: what to do with duplicate fixed points in epoch
        textTable: text table instance for epochPointList
        """

        self.numEpoch = 0 # the number of epoch added
        #self.epochList = []

        self.dateTimeList = [] # list of dates of epochs, datetime instances
        self.epochPointList = EpochPointList()
            # list of coordinates, displacements and test results
            # PointLocalGamaDisplTest instances
        
        self.pointListFix = PointList(textTable=gama_coor_table(), 
                                      duplicateId=duplicateFixId)
            # list of fixed points for all epochs

        self.coordSystemLocal = CoordSystemLocal2D()
            # definition of local geodetic system
        
        self.stdevList = []
            # list of StandardDeviation instances
            # handles degrees of freedom from GamaLocalData instance

        self._stdevUseApriori = stdevUseApriori

        self._confProb = confProb

        self.reliabProb = reliabProb

        self.testType = None

        if textTable is None:
            from gizela.stat.displ_test_text_table import displ_test_text_table
            self.textTable = displ_test_text_table()
        else:
            self.textTable = textTable
示例#2
0
    def __init__(self, 
                 coordSystemLocal,
                 stdevUseApriori=True,
                 confProb=0.95,
                 reliabProb=0.95,
                 testId=None,
                 duplicateIdFix=DUPLICATE_ID.compare,
                 duplicateIdAdj=DUPLICATE_ID.compare,
                 textTable=None):
        """
        stdevUseApriori: use apriori/aposteriori standard deviation
        confProb: confidence probability
        reliabProb: reliability probability
        testId: Ids of point for testing (currently only for output)
        duplicateFixId: what to do with duplicate fixed points in epoch
        textTable: text table instance for epochPointList
        """

        NetworkList.__init__(self, 
                             coordSystemLocal,
                             stdevUseApriori=stdevUseApriori,
                             confProb=confProb,
                             #reliabProb=reliabProb,
                             #duplicateIdFix=duplicateIdFix,
                             duplicateIdAdj=duplicateIdAdj)
        
        self.pointListAdj = PointList(textTable=gama_coor_table(), 
                                      duplicateId=duplicateIdFix)
            # list of fixed points for all epochs

        self.epochPointList = EpochPointList(idList=testId)
            # list of coordinates, displacements and test results
            # PointLocalGamaDisplTest instances

        self.stdevList = []
            # list of StandardDeviation instances
            # handles degrees of freedom from GamaLocalData instance

        ##self.testType = None

        if textTable is None:
            from gizela.stat.displ_test_text_table import displ_test_text_table
            self._textTable = displ_test_text_table()
        else:
            self._textTable = textTable

        self._reliabProb = reliabProb
示例#3
0
class EpochList(object):
    """
    list of Epoch instances
    like project
    """

    def __init__(self, 
                 stdevUseApriori=True,
                 confProb=0.95,
                 reliabProb=0.95,
                 #config=None,
                 duplicateFixId=DUPLICATE_ID.compare,
                 textTable=None):
        """
        stdevUseApriori: use apriori/aposteriori standard deviation
        confProb: confidence probability
        reliabProb: reliability probability
        config: project configuration file
        duplicateFixId: what to do with duplicate fixed points in epoch
        textTable: text table instance for epochPointList
        """

        self.numEpoch = 0 # the number of epoch added
        #self.epochList = []

        self.dateTimeList = [] # list of dates of epochs, datetime instances
        self.epochPointList = EpochPointList()
            # list of coordinates, displacements and test results
            # PointLocalGamaDisplTest instances
        
        self.pointListFix = PointList(textTable=gama_coor_table(), 
                                      duplicateId=duplicateFixId)
            # list of fixed points for all epochs

        self.coordSystemLocal = CoordSystemLocal2D()
            # definition of local geodetic system
        
        self.stdevList = []
            # list of StandardDeviation instances
            # handles degrees of freedom from GamaLocalData instance

        self._stdevUseApriori = stdevUseApriori

        self._confProb = confProb

        self.reliabProb = reliabProb

        self.testType = None

        if textTable is None:
            from gizela.stat.displ_test_text_table import displ_test_text_table
            self.textTable = displ_test_text_table()
        else:
            self.textTable = textTable

        #print self.textTable

        #self.id = self.epochPointList.index # just shorter name
        #self.axesOri = None # orientation of axes
        #self.coordSystem = None # system of coordinates
        #self.ellipsoid = None # ellipsoid instance

        #self.numPoint = 0 # the number of points in x, y and z lists
        #self.id = {} # dictionary of point ids and indexes in x, y, z lists
        #self.x = [] # list of lists of x coordinates
        #self.y = [] # list of lists of y coordinates
        #self.z = [] # list of lists of z coordinates
        #self.covmat = [] # list of covariance matrices of points

        # plots
        #self.displacementScale = 10.0 # scale factor for displacements
        #self.confScale1d = 1.0 # scale factor for confidence interval 
        #self.confScale2d = 1.0 # scale factor for confidence ellipse 
        #self.cmap = 'hsv'
        #self.pointStyleList = [] # properties for points in each epoch
                                 # PointStyleGama instances
        #self.errEllStyle = ErrEllStyle # properties for error ellipses
        #self.vecStyle = VecStyle # properties for vectors of displacements
        #self.dateStyle = DateStyle # properties for date plots
        #self.stdevStyle = StdevStyle # properties for standard deviation interval
        #if config is not None:
            # parsing configuration file
            #self.parse_config_file(config)

    
    def add_epoch(self, epoch, addCoordSystem=True):
        """adds GamaLocalData instance to list of epochs"""

        if not isinstance(epoch, Epoch):
            raise EpochListError, "Epoch instance expected"
        
        # add epoch
        self.numEpoch += 1
        #self.epochList.append(epoch)

        # stdev
        epoch.pointListAdj.covmat.useApriori = self._stdevUseApriori
        epoch.stdev.set_conf_prob(self._confProb)
        epoch.stdev.set_use(self._stdevUseApriori and "apriori" or
                                  "aposteriori")
        self.stdevList.append(epoch.stdev)


        # add epoch time and date
        self.dateTimeList.append(datetime.datetime(epoch.date.year,
                                                   epoch.date.month,
                                                   epoch.date.day,
                                                   epoch.time.hour,
                                                   epoch.time.minute,
                                                   epoch.time.second,
                                                   epoch.time.microsecond,
                                                   epoch.time.tzinfo))

        # change type of point
        pl = PointListCovMat(covmat=epoch.pointListAdj.covmat,
                             textTable=self.textTable)
        for p in epoch.pointListAdj:
            pp = PointLocalGamaDisplTest(p)
            pp.epochIndex = self.numEpoch - 1
            pl.add_point(pp)

        # compute differences - previous epoch
        #if self.numEpoch > 1:
        #    lastEpoch = self.epochPointList.get_epoch(-1)
        #    for p in pl:
        #        if p.id in lastEpoch:
        #            # compute displacement
        #            pd = p - lastEpoch.get_point(p.id)
        #            #print pd.id, pd.covmat.data
        #            # add displacement 
        #            p.set_displacement(pd)
        #from gizela.stat.displ_test_text_table import point_displ_text_table
        #pl.textTable = point_displ_text_table()
        #print pl

        for p in pl:
            # find point in "zero" epoch
            p0 = None
            if p.id in self.epochPointList.iter_id():
                for pp in self.epochPointList.iter_point(p.id):
                    if p.is_set_xyz() and pp.is_set_xyz():
                        p0 = pp
                        break
                    elif p.is_set_xy() and pp.is_set_xy():
                        p0 = pp
                        break
                    elif p.is_set_z() and pp.is_set_z():
                        p0 = pp
                        break
                if p0 is None:
                    # no point found
                    continue

                #print "type p", type(p)
                #print "minus", type((p - p0).covmat)
                #from gizela.data.point_text_table import gama_coor_var_table
                #print (p-p0).with_text_table(gama_coor_var_table())
                p.set_displacement(p - p0)

        # add adjusted points
        self.epochPointList.add_epoch(pl)
        #for p in self.epochPointList.get_epoch(-1):
        #    print p.id,"covmat", p.covmat.make_gama_xml()
        #    print p.id,"var", p.var

        # add fixed points
        self.pointListFix.extend(epoch.pointListFix)
        

    def get_epoch_point_list(self, index):
        return self.epochPointList.get_epoch(index)

    
    def plot_xy(self, figure, idAdj=None, idFix=None, plotTest=False):
        """
        plots figure with points and error ellipses and displacements

        figure: FigureLayoutBase instance or descendant
        idAdj: list of ids of adjusted points to be drawn
               for no adjusted points set idAdj = []
        idFix: plot fixed points
               for no fixed points set idFix = []

        """

        # id of points
        if idAdj is None:
            idAdj = [id for id in self.epochPointList.iter_id()]
        
        if idFix is None:
            idFix = [id for id in self.pointListFix.iter_id()]

        # plot adjusted
        if len(idAdj) > 0:
           self.plot_adj(figure, idAdj, plotErrorZ=False, plotTest=plotTest)
        
        # plot fixed
        if len(idFix) > 0:
            self.plot_fix(figure, idFix)

    def plot_xyz(self, figure, idAdj=None, idFix=None, plotTest=False):
        """
        plots figure with points, error ellipses, displacements
        and confidence interval of z along y axis

        figure: FigureLayoutBase instance or descendant
        idAdj: list of ids of adjusted points to be drawn
               for no adjusted points set idAdj = []
        idFix: plot fixed points
               for no fixed points set idFix = []

        """

        # id of points
        if idAdj is None:
            idAdj = [id for id in self.epochPointList.iter_id()]
        
        if idFix is None:
            idFix = [id for id in self.pointListFix.iter_id()]

        # plot adjusted
        if len(idAdj) > 0:
           self.plot_adj(figure, idAdj, plotErrorZ=True, plotTest=plotTest)
        
        # plot fixed
        if len(idFix) > 0:
            self.plot_fix(figure, idFix)

    
    def plot_z(self, figure, id, plotTest=False):
        """plot x coordinates of point id for all epochs with stdev

        self: EpochList isntance
        id: id or ids of point
        """

        if type(id) is not tuple and type(id) is not list:
            id = (id,)

        # set figure
        figure.set_color_style(self)
        figure.gca().xaxis_date()


        # plot points
        for idi in id:
            self._plot_epoch_list_displacement_z(figure, idi, plotTest)
            figure.reset_epoch_counter()
        
        # set free space around draw
        figure.set_free_space()

        #update
        figure.update_(self)
        

    def _plot_epoch_list_displacement_z(self, figure, id, plotTest): 
        """
        plot 2D graph of point z coordinates,
        confidence intervals of z coordinates and displacements for all epochs

        id: point id
        plotTest: plot results of test?
        """

        # point iterator
        pointIter = self.epochPointList.iter_point(id)
        # plot points and stdev
        z = [] # z coordinates of points
        for point, date in zip(pointIter, self.dateTimeList):
            point.plot_z(figure, date)
            if plotTest:
                if point.testPassed is not None: # point is tested
                    point.plot_z_stdev(figure, date)
            else:
                point.plot_z_stdev(figure, date)
                
            figure.next_point_dot_style()
            z.append(point.z)

        point0 = None
        for p, i in zip(self.epochPointList.iter_point(id), 
                        xrange(self.numEpoch)):
            if p.is_set_z():
                point0 = p
                i_epoch = i
                break

        # label point0
        if point0 is not None:
            point0.x = self.dateTimeList[i_epoch]
            point0.y = point.z
            point0.plot_label(figure)

        # plot vector
        figure.plot_vector_z(self.dateTimeList, z)

        # plot zero line
        if point0 is not None:
            z0 = [point0.z for t in self.dateTimeList]
            figure.plot_vector_z0(self.dateTimeList, z0)

    
    def plot_fix(self, figure, id):
        """
        plots 2D graph of fixed points
        """

        figure.set_aspect_equal()
        figure.update_(self) 

        for idi in id:
            self.pointListFix.plot_(figure)

        # set free space around draw
        figure.set_free_space()
        

    def plot_adj(self, figure, id, plotErrorZ, plotTest):
        """
        plots 2D graph of adjusted points, displacements and error ellipses

        figure: FigureLayoutBase instance
        id: id or ids of point
        plotErrorZ: plot confidence interval of z coordinate?
        plotTest: plot results of test?
        """

        if type(id) is not tuple and type(id) is not list:
            id = [id]

        # update figure 
        figure.set_aspect_equal()
        figure.update_(self)

        # plot points
        for idi in id:
            self._plot_epoch_list_displacement_xy(figure, idi, plotErrorZ,
                                                plotTest)
            figure.reset_epoch_counter()
        
        # set free space around draw
        figure.set_free_space()

    def _plot_epoch_list_displacement_xy(self, figure, id, 
                                          plotErrorZ, plotTest): 
        """
        plot 2D graph of point ,
        error ellipses and displacements for all epochs
        and optionally confidence interval of z coordinate along y axis

        id: point id
        plotErrorZ: plot confidence interval of z coordinate?
        plotTest: plot results of test?
        """
        
        # point iterator
        pointIter = self.epochPointList.iter_point(id)
        
        # find zero epoch for point
        # the first point with x!=None and y!=None
        point0 = None
        for p in pointIter:
            if p.x != None and p.y != None:
                point0 = p
                #x0, y0 = point0.x, point0.y
                break
        if point0 == None:
            return # no xy point available

        # point iterator
        pointIter = self.epochPointList.iter_point(id)
        
        # save coordinates of vector with scale
        pointScaled = [] # point list as normal list
        for p in pointIter:
            if plotTest:
                covmat = p.displ.get_point_cov_mat()
            else:
                covmat = p.get_point_cov_mat()
            ps = (p - point0)*figure.errScale + point0
            ps.covmat = covmat
            #print "epl:", type(ps)
            pointScaled.append(ps)

        # plot points and error ellipses
        for p in pointScaled:
            p.plot_(figure, plotLabel=False)
            figure.set_stdev(self) # sets StandardDeviation instance for epoch
            if plotTest:
                if p.testPassed is not None: # point is tested
                    p.plot_error_ellipse(figure)
            else:
                p.plot_error_ellipse(figure)
                
            figure.next_point_dot_style()

        # label point0
        point0.plot_label(figure)
        
        # plot vector
        figure.plot_vector_xy(pointScaled)

    def __str__(self):
        tt = TextTable([("epoch", "%5i"), ("date","%10s"), ("time","%8s")])
        str = [tt.make_table_head()]
        str.extend([tt.make_table_row(i, dt.date(), dt.time())\
                    for dt,i in zip(self.dateTimeList,
                                    xrange(len(self.dateTimeList)))])
        str.append(tt.make_table_foot())
        str.append("\n")
        str.append(self.epochPointList.__str__())

        return "".join(str)

    def get_epoch_table(self, index=None):
        "returns text table of displacements"
        str = []
        if index is None:
            for i, e in zip(xrange(self.epochPointList.get_num_epoch()),
                            self.epochPointList.iter_epoch()):
                str.append("Epoch %i:" % i)
                str.append(e.__str__())
        else:
                str.append("Epoch %i:" % index)
                str.append(self.epochPointList.get_epoch(index).__str__())

        return "\n".join(str)

    def set_stdev_use(self, use):
        """
        set which standart deviation to use
        """

        if use is "apriori":
            self._stdevUseApriori = True
            for pl in self.pointListAdj.iter_epoch():
                pl.covmat.useApriori = True
            for s in self.stdevList:
                s.set_stdev_use_apriori()
        elif use is "aposteriori":
            self._stdevUseApriori = False
            for pl in self.pointListAdj.iter_epoch():
                pl.covmat.useApriori = False
            for s in self.stdevList:
                s.set_stdev_use_aposteriori()
        else:
            raise EpochListError, "Unknown value of parameter use: %s" % use

    def set_stdev_use_apriori(self):
        self.set_stdev_use("apriori")
    
    def set_stdev_use_aposteriori(self):
        self.set_stdev_use("aposteriori")

    def get_stdev_use(self): 
        return self._stdevUseApriori and "apriori" or "aposteriori"


    #def parse_config_file(self, fileName):

    #    import ConfigParser
    #    configParser = ConfigParser.SafeConfigParser()
    #    configParser.optionxform = str # to make options case sensitive
 
    #    readed = configParser.read(fileName)
    #    
    #    print "Fonfiguration file(s) readed: %s" % ", ".join(readed)
    #    
    #    self.config = {}

    #    for sec in configParser.sections():
    #        self.config[sec] = {}
    #        for p,v in configParser.items(sec):
    #            print p, v
    #            try:
    #                v=float(v)
    #            except:
    #                pass
    #            self.config[sec][p]=v

    #    #print self.config
    #    
    #    from gizela.util.Converter import Converter as con

    #    # local system
    #    try:
    #        self.coordSystemLocal = CoordSystemLocal(\
    #           ellipsoidCode = self.config["localSystem"]["ellipsoid"],
    #           lat = con.deg2rad_(self.config["localSystem"]["latitude"]),
    #           lon = con.deg2rad_(self.config["localSystem"]["longitude"]),
    #                  height = self.config["localSystem"]["height"],
    #                       x = self.config["localSystem"]["x"],
    #                       y = self.config["localSystem"]["y"],
    #                       z = self.config["localSystem"]["z"],
    #                 axesOri = self.config["localSystem"]["axesOri"],
    #              bearingOri = self.config["localSystem"]["bearingOri"],
    #                    name = self.config["localSystem"]["name"],
    #             description = self.config["localSystem"]["description"]
    #        )
    #    except:
    #        import sys
    #        print >>sys.stderr, "Warning: Local system not set."

    #    # standard deviation
    #    try:
    #        if self.config["stdev"]["use"] is "apriori":
    #            self.set_stdev_use("apriori")
    #        elif self.config["stdev"]["use"] is "aposteriori":
    #            self.set_stdev_use("aposteriori")
    #    except:
    #        import sys
    #        print >>sys.stderr, "Warning: Use of standard deviation not set"


    def compute_displacement_test(self, pointId=None, testType=None):
        """
        computes test statistic for displacements of points
        pointId: ids of point to be tested
        testType: type of test see DisplacementTestType class
                  or None for testing according to point dimension
        """

        self.testType = testType
        from gizela.stat.DisplacementTest import DisplacementTest
        dtest = DisplacementTest(apriori=self._stdevUseApriori,
                                 confProb=self._confProb,
                                 reliabProb=self.reliabProb)
        dtest.compute_test(self.epochPointList, pointId, testType)

    def get_conf_prob(self):
        return self._confProb

    def set_conf_prob(sefl, confProb):
        self._confProb = confProb
        for s in self.stdevList:
            s.set_conf_prob(confProb)
示例#4
0
            print obs, "is a horizontal distance"
        if isinstance(obs, ObsZAngle):
            print obs, "is zenit angle"
        if isinstance(obs, ObsSDistance):
            print obs, "is slope distance"
    
    print "Making correction"
    from gizela.corr.ObsCorrSphere import ObsCorrSphere
    from gizela.util.Ellipsoid     import Ellipsoid
    from gizela.data.PointGeodetic import PointGeodetic
    from gizela.data.PointCart     import PointCart
    from gizela.data.PointList     import PointList
    from gizela.data.ObsClusterList import ObsClusterList

    pA = PointCart("AB", x=0, y=0, z=0)
    pl = PointList(textTable=pA.textTable)
    pl.add_point(pA)
    pl.add_point(PointCart("CD", x=1, y=1, z=1))
    print pl
    ocl = ObsClusterList()
    ocl.append_cluster(cl)

    corr = ObsCorrSphere(ellipsoid=Ellipsoid(), 
            centralPointGeo=PointGeodetic(id="c", lat=0, lon=0, height=0),
            centralPointLoc=PointCart(id="c", x=0, y=0, z=0),
            axesOri="ne",
            bearingOri="righ-handed",
            pointList=pl,
            obsClusterList=ocl)
    cl.compute_corr(corr)
    print cl
示例#5
0
    #    return "\n".join([point.make_gama_xml() for point in self.list])

    #def plot_point(self, figure, pointProp=PointProp):
    #    for point in self.list: point.plot_point(figure, pointProp)



if __name__ == "__main__":
    
    from gizela.data.PointCart import PointCart
    from gizela.data.PointList import PointList
    
    c1 = PointCart(id="C",x=1,y=2,z=3)
    c2 = PointCart(id="B",x=4,y=5,z=6)

    pl1=PointList() 
    pl2=PointList() 

    pl1.add_point(c1)
    pl1.add_point(c2)
    pl2.add_point(c2)
    
    print pl1
    print pl2

    el = EpochPointList()
    el.add_(pl1)
    el.add_(pl2)

    print el.index
    el.sortOutput = True
示例#6
0
    Main module doc
    """
    print "This is ObsCorrSphere class instance"
    
#    corr = ObsCorrSphere(ellipsoid, centralPointGeo, centralPointLoc, pointList)


    print "Making correction"
    from gizela.util.Ellipsoid     import Ellipsoid
    from gizela.data.PointGeodetic import PointGeodetic
    from gizela.data.PointCart     import PointCart
    from gizela.data.PointList     import PointList

    centralPointLoc = PointCart("99", 0, 0, 0)
    
    pointList = PointList(textTable=centralPointLoc.textTable)
    pointList.add_point(centralPointLoc)
    pointList.add_point(PointCart("999", 1000, 000, 0))
    pointList.add_point(PointCart("1", 2000, 0, 0))
    pointList.add_point(PointCart("2", 2000, 1000, 0))
    pointList.add_point(PointCart("3", 1000, 1000, 0))
    pointList.add_point(PointCart("4", 0, 1000, 0))
    pointList.add_point(PointCart("5", 0, 0, 0))
    pointList.add_point(PointCart("6", 0, -1000, 0))
    pointList.add_point(PointCart("7", 1000, -1000, 0))
    pointList.add_point(PointCart("8", 2000, -1000, 0))
    
    pointList.add_point(PointCart("11", 2000, 0, 1000))
    pointList.add_point(PointCart("12", 2000, 1000, 1000))
    pointList.add_point(PointCart("13", 1000, 1000, 1000))
    pointList.add_point(PointCart("14", 0, 1000, 1000))
示例#7
0
    #    return "\n".join([point.make_gama_xml() for point in self.list])

    #def plot_point(self, figure, pointProp=PointProp):
    #    for point in self.list: point.plot_point(figure, pointProp)



if __name__ == "__main__":
    
    from gizela.data.PointCart import PointCart
    from gizela.data.PointList import PointList
    
    c1 = PointCart(id="C",x=1,y=2,z=3)
    c2 = PointCart(id="B",x=4,y=5,z=6)

    pl1=PointList() 
    pl2=PointList() 

    pl1.add_point(c1)
    pl1.add_point(c2)
    pl2.add_point(c2)
    
    print pl1
    print pl2

    el = EpochPointList()
    el.add_epoch(pl1)
    el.add_epoch(pl2)

    print el.index
    el.sortOutput = True
示例#8
0
#
# point_status: adj_xy adj_xyz adj_z adj_XY adj_XYZ adj_Z adj_xyZ adj_XYz
#               fix_xy fix_xyz fix_z

pList = None
if opt.fileCoord is not None:

    from gizela.data.GamaCoordStatus import GamaCoordStatus
    from gizela.data.GamaCoordStatus import GamaCoordStatusError,\
                                            gama_coord_status_string,\
                                            gama_coord_status_dim,\
                                            gama_coord_status_attr
    from gizela.data.PointLocalGama import PointLocalGama
    from gizela.data.PointList import PointList

    pList = PointList()

    try:
        file = open(opt.fileCoord);
    except IOError:
        sys.exit("Cannot open file \"%s\"" % opt.fileCoord)

    line = file.readline()
    line_num = 1
    pointsId = []
    while line:
        line = line.strip()
        if len(line) == 0:
            line = file.readline()
            line_num+=1
            continue
示例#9
0
class NetworkAdjList(NetworkList):
    """
    list of Epoch instances
    like project
    """

    def __init__(self, 
                 coordSystemLocal,
                 stdevUseApriori=True,
                 confProb=0.95,
                 reliabProb=0.95,
                 testId=None,
                 duplicateIdFix=DUPLICATE_ID.compare,
                 duplicateIdAdj=DUPLICATE_ID.compare,
                 textTable=None):
        """
        stdevUseApriori: use apriori/aposteriori standard deviation
        confProb: confidence probability
        reliabProb: reliability probability
        testId: Ids of point for testing (currently only for output)
        duplicateFixId: what to do with duplicate fixed points in epoch
        textTable: text table instance for epochPointList
        """

        NetworkList.__init__(self, 
                             coordSystemLocal,
                             stdevUseApriori=stdevUseApriori,
                             confProb=confProb,
                             #reliabProb=reliabProb,
                             #duplicateIdFix=duplicateIdFix,
                             duplicateIdAdj=duplicateIdAdj)
        
        self.pointListAdj = PointList(textTable=gama_coor_table(), 
                                      duplicateId=duplicateIdFix)
            # list of fixed points for all epochs

        self.epochPointList = EpochPointList(idList=testId)
            # list of coordinates, displacements and test results
            # PointLocalGamaDisplTest instances

        self.stdevList = []
            # list of StandardDeviation instances
            # handles degrees of freedom from GamaLocalData instance

        ##self.testType = None

        if textTable is None:
            from gizela.stat.displ_test_text_table import displ_test_text_table
            self._textTable = displ_test_text_table()
        else:
            self._textTable = textTable

        self._reliabProb = reliabProb

    def _get_textTable(self):
        return self._textTable

    def _set_textTable(self, textTable):
        self._textTable = textTable
        for epoch in self.list:
            epoch.pointListAdjCovMat.textTable = textTable

    textTable = property(_get_textTable, _set_textTable)

    
    def append(self, net):
        """
        adds GamaLocalData instance to list of nets
        """

        if not isinstance(net, Network):
            raise NetworkAdjListError, "Network instance expected"

        NetworkList.append(self, net)

        # standard deviation
        net.stdev.set_use_apriori(self._stdevUseApriori)
        net.stdev.set_conf_prob(self._confProb)
        net.pointListAdjCovMat.covmat.useApriori = self._stdevUseApriori
        self.stdevList.append(net.stdev)

        # change textTable of pointList
        net.pointListAdjCovMat.textTable = self._textTable

        # compute displacements of net added
        #
        # compute differences from "zero" epoch
        for pp in net.pointListAdjCovMat:
            # change type of point
            p = PointLocalGamaDisplTest(pp)
            #p.epochIndex = len(self)# - 1
            p.epochIndex = len(self) - 1

            #import sys
            #from gizela.data.point_text_table import gama_coor_stdev_table
            #print >>sys.stderr, pp.with_text_table(gama_coor_stdev_table())
            #print >>sys.stderr, p.with_text_table(gama_coor_stdev_table())
            
            # find point in "zero" epoch
            
            p0 = None
            if p.id in self.epochPointList.iter_id():
                for pp in self.epochPointList.iter_point(p.id):
                    if p.is_set_xyz() and pp.is_set_xyz():
                        p0 = pp
                        break
                    elif p.is_set_xy() and pp.is_set_xy():
                        p0 = pp
                        break
                    elif p.is_set_z() and pp.is_set_z():
                        p0 = pp
                        break
                if p0 is not None:
                    #print "type p", type(p)
                    #print "minus", type((p - p0).covmat)
                    #from gizela.data.point_text_table import gama_coor_stdev_table
                    #print (p-p0).with_text_table(gama_coor_stdev_table())
                    p.set_displacement(p - p0)

            net.pointListAdjCovMat.replace_point(p)

        # compute differences - previous epoch
        #if self.numEpoch > 1:
        #    lastEpoch = self.epochPointList.get_epoch(-1)
        #    for p in pl:
        #        if p.id in lastEpoch:
        #            # compute displacement
        #            pd = p - lastEpoch.get_point(p.id)
        #            #print pd.id, pd.covmat.data
        #            # add displacement 
        #            p.set_displacement(pd)
        #from gizela.stat.displ_test_text_table import point_displ_text_table
        #pl.textTable = point_displ_text_table()
        #print pl


        # add adjusted points with displacements
        self.epochPointList.add_(net.pointListAdjCovMat)
        #for p in self.epochPointList.get_epoch(-1):
        #    print p.id,"covmat", p.covmat.make_gama_xml()
        #    print p.id,"var", p.var

        # add fixed points
        self.pointListAdj.extend(net.pointListAdj)


    def append_joined(self, data, reString, epochIndex, pointIndex):
        """
        separate data with joined epochs and add them

        data: Network instance with adjustment
        reString: regular expression with two groups - point id, 
                                                     - epoch index from 0
        epochIndex: index of epoch number (0 or 1) in regular expression groups
        pointIndex: index of point id (0 or 1) in regular expression groups
        """

        if not isinstance(data, Network):
            raise NetworkAdjList, "Network instance expected"

        # set text table
        data.pointListAdjCovMat.textTable = self._textTable

        # separate epochs
        self.epochPointList.add_joined(data.pointListAdjCovMat,
                                       reString, 
                                       epochIndex, pointIndex)

        # add epochs
        for i in xrange(self.epochPointList.get_num_epoch()):
            self.list.append(data)
        self.dateTimeList.extend(data.dateTimeList)

        # standard deviation
        data.stdev.set_use_apriori(self._stdevUseApriori)
        data.stdev.set_conf_prob(self._confProb)
        data.pointListAdjCovMat.covmat.useApriori = self._stdevUseApriori
        for i in xrange(self.epochPointList.get_num_epoch()):
            self.stdevList.append(data.stdev)
        
        # compute displacements
        #
        # change type of points
        for id, ind in self.epochPointList.index.items():
            #print id, ind
            for i, ii in enumerate(ind):
                if ii is not None:
                    pp = PointLocalGamaDisplTest(\
                                     self.epochPointList.list[i].list[ii])
                    pp.epochIndex = i
                    self.epochPointList.list[i].list[ii] = pp
                    #print self.epochPointList.list[i].list[ii]

        # add fixed points
        self.pointListAdj.extend(data.pointListAdj)

        # compute differences from "zero" epoch
        for id, ind in self.epochPointList.index.items():
            for i, ii in enumerate(ind):
                if ii is None:
                    continue
                p = self.epochPointList.list[i].list[ii]
                p0 = None
                for j, jj in enumerate(ind[:i]):
                    if jj is None:
                        continue
                    pp = self.epochPointList.list[j].list[jj]
                    if p.is_set_xyz() and pp.is_set_xyz():
                        p0 = pp
                        break
                    elif p.is_set_xy() and pp.is_set_xy():
                        p0 = pp
                        break
                    elif p.is_set_z() and pp.is_set_z():
                        p0 = pp
                        break
                if p0 is None:
                    # point in "zero" epoch not found
                    continue

                p.set_displacement(p - p0)
           

    def get_epoch_point_list(self, index):
        return self.epochPointList.get_epoch(index)


    def __str__(self):
        tt = TextTable([("epoch", "%5i"), ("date","%10s"), ("time","%8s")])
        str = [tt.make_table_head()]
        str.extend([tt.make_table_row(i, dt.date(), dt.time())\
                    for dt,i in zip(self.dateTimeList,
                                    xrange(len(self.dateTimeList)))])
        str.append(tt.make_table_foot())
        str.append("\n")
        str.append(self.epochPointList.__str__())

        return "".join(str)


    def get_epoch_table(self, index=None):
        """
        returns text table of displacements

        index: integer: index of epoch, None = all epoch
        """
        str = []
        if index is None:
            for i, e in enumerate(self.epochPointList.iter_epoch()):
                str.append("Epoch %i:" % i)
                str.append(e.__str__())
        else:
                str.append("Epoch %i:" % index)
                str.append(self.epochPointList.get_epoch(index).__str__())

        return "\n".join(str)

    def set_stdev_use(self, use):
        """
        set which standart deviation to use
        """

        if use is "apriori":
            self._stdevUseApriori = True
            for pl in self.epochPointList.iter_epoch():
                pl.covmat.useApriori = True
            for s in self.stdevList:
                s.set_stdev_use_apriori()
        elif use is "aposteriori":
            self._stdevUseApriori = False
            for pl in self.epochPointList.iter_epoch():
                pl.covmat.useApriori = False
            for s in self.stdevList:
                s.set_stdev_use_aposteriori()
        else:
            raise EpochListError, "Unknown value of parameter use: %s" % use

    def set_stdev_use_apriori(self):
        self.set_stdev_use("apriori")
    
    def set_stdev_use_aposteriori(self):
        self.set_stdev_use("aposteriori")

    def get_stdev_use(self): 
        return self._stdevUseApriori and "apriori" or "aposteriori"

    
    def plot_xy(self, figure, idAdj=None, idFix=None, plotTest=False):
        """
        plots figure with points and error ellipses and displacements

        figure: FigureLayoutBase instance or descendant
        idAdj: list of ids of adjusted points to be drawn
               for no adjusted points set idAdj = []
        idFix: plot fixed points
               for no fixed points set idFix = []
        """

        # id of points
        if idAdj is None:
            idAdj = [id for id in self.epochPointList.iter_id()]
        
        if idFix is None:
            idFix = [id for id in self.pointListAdj.iter_id()]

        # plot adjusted
        if len(idAdj) > 0:
           self.plot_adj(figure, idAdj, plotErrorZ=False, plotTest=plotTest)
        
        # plot fixed
        if len(idFix) > 0:
            self.plot_fix(figure, idFix)

    def plot_xyz(self, figure, idAdj=None, plotTest=False):
        """
        plots figure with points, error ellipses, displacements
        and confidence interval of z along y axis

        figure: FigureLayoutBase instance or descendant
        idAdj: list of ids of adjusted points to be drawn
               for no adjusted points set idAdj = []
        #idFix: plot fixed points
        #       for no fixed points set idFix = []

        """

        # id of points
        if idAdj is None:
            idAdj = [id for id in self.epochPointList.iter_id()]
        
        #if idFix is None:
        #    idFix = [id for id in self.pointListFix.iter_id()]

        # plot adjusted
        if len(idAdj) > 0:
           self.plot_adj(figure, idAdj, plotErrorZ=True, plotTest=plotTest)
        
        # plot fixed
        #if len(idFix) > 0:
        #    self.plot_fix(figure, idFix)

    
    def plot_z(self, figure, id, plotTest=False):
        """plot x coordinates of point id for all epochs with stdev

        self: EpochList isntance
        id: id or ids of point
        """

        if type(id) is not tuple and type(id) is not list:
            id = (id,)

        # set figure
        figure.set_color_style(self)
        figure.gca().xaxis_date()


        # plot points
        for idi in id:
            self._plot_epoch_list_displacement_z(figure, idi, plotTest)
            figure.reset_epoch_counter()
        
        # set free space around draw
        figure.set_free_space()

        #update
        figure.update_(self)
        

    def _plot_epoch_list_displacement_z(self, figure, id, plotTest): 
        """
        plot 2D graph of point z coordinates,
        confidence intervals of z coordinates and displacements for all epochs

        id: point id
        plotTest: plot results of test?
        """

        # point iterator
        pointIter = self.epochPointList.iter_point(id)
        # plot points and stdev
        z = [] # z coordinates of points
        for point, date in zip(pointIter, self.dateTimeList):
            point.plot_z(figure, date)
            if plotTest:
                if point.testPassed is not None: # point is tested
                    point.plot_z_stdev(figure, date)
            else:
                point.plot_z_stdev(figure, date)
                
            figure.next_point_dot_style()
            z.append(point.z)

        point0 = None
        for i, p in enumerate(self.epochPointList.iter_point(id)): 
            if p.is_set_z():
                point0 = p
                i_epoch = i
                break

        # label point0
        if point0 is not None:
            point0.x = self.dateTimeList[i_epoch]
            point0.y = point.z
            point0.plot_label(figure)

        # plot vector
        figure.plot_vector_z(self.dateTimeList, z)

        # plot zero line
        if point0 is not None:
            z0 = [point0.z for t in self.dateTimeList]
            figure.plot_vector_z0(self.dateTimeList, z0)

    
    def plot_fix(self, figure, id):
        """
        plots 2D graph of fixed points
        """

        figure.set_aspect_equal()
        figure.update_(self) 

        for idi in id:
            self.pointListAdj.plot_(figure)

        # set free space around draw
        figure.set_free_space()
        

    def plot_adj(self, figure, id, plotErrorZ, plotTest):
        """
        plots 2D graph of adjusted points, displacements and error ellipses

        figure: FigureLayoutBase instance
        id: id or ids of point
        plotErrorZ: plot confidence interval of z coordinate?
        plotTest: plot results of test?
        """

        if type(id) is not tuple and type(id) is not list:
            id = [id]

        # update figure 
        figure.set_aspect_equal()
        figure.update_(self)

        # plot points
        for idi in id:
            self._plot_epoch_list_displacement_xy(figure, idi, plotErrorZ,
                                                plotTest)
            figure.reset_epoch_counter()
        
        # set free space around draw
        figure.set_free_space()

    def _plot_epoch_list_displacement_xy(self, figure, id, 
                                          plotErrorZ, plotTest): 
        """
        plot 2D graph of point ,
        error ellipses and displacements for all epochs
        and optionally confidence interval of z coordinate along y axis

        id: point id
        plotErrorZ: plot confidence interval of z coordinate?
        plotTest: plot results of test?
        """
        
        # find zero epoch for point
        # the first point with x!=None and y!=None
        point0 = None
        for p in self.epochPointList.iter_point(id, withNone=False):
            if p.x != None and p.y != None:
                point0 = p
                #x0, y0 = point0.x, point0.y
                break
        if point0 == None:
            return # no xy point available

        # save coordinates of vector with scale
        pointScaled = [] # point list as normal list
        for p in self.epochPointList.iter_point(id, withNone=True):
            if plotTest and isinstance(p, PointLocalGamaDisplTest): 
                    covmat = p.displ.get_point_cov_mat()
            else:
                covmat = p.get_point_cov_mat()
            ps = (p - point0)*figure.errScale + point0
            ps.covmat = covmat
            #import sys
            #print >>sys.stderr, "Point: %s" % ps.id
            #print >>sys.stderr, "epl: %s" % type(ps)
            pointScaled.append(ps)

        # plot points and error ellipses
        for p in pointScaled:
            p.plot_(figure, plotLabel=False)
            figure.set_stdev(self) # sets StandardDeviation instance for epoch
            if plotTest and isinstance(p, PointLocalGamaDisplTest): 
                if p.testPassed is not None: # point is tested
                    p.plot_error_ellipse(figure)
            else:
                p.plot_error_ellipse(figure)
                
            figure.next_point_dot_style()

        # label point0
        point0_label = copy.deepcopy(point0)
        point0_label.id = id
        point0_label.plot_label(figure)
        
        # plot vector
        figure.plot_vector_xy(pointScaled)


    def compute_displacement_test(self, pointId=None, testType=None):
        """
        computes test statistic for displacements of points
        pointId: ids of point to be tested
        testType: type of test see DisplacementTestType class
                  or None for testing according to point dimension
        """

        #self.testType = testType
        from gizela.stat.DisplacementTest import DisplacementTest
        dtest = DisplacementTest(apriori=self._stdevUseApriori,
                                 confProb=self._confProb,
                                 reliabProb=self._reliabProb)
        dtest.compute_test(self.epochPointList, pointId, testType)

    def get_conf_prob(self):
        return self._confProb

    def set_conf_prob(sefl, confProb):
        self._confProb = confProb
        for s in self.stdevList:
            s.set_conf_prob(confProb)

    def _num_epoch(self): return len(self)

    numEpoch = property(_num_epoch)