コード例 #1
0
    def __init__(self, _filesimul='default.ini'):
        self.filesimul = _filesimul
        self.config = ConfigParser.ConfigParser()
        self.config.add_section("files")
        self.config.add_section("frequency")
        self.config.add_section("waveform")
        self.config.add_section("output")

        self.dtang = {}
        self.drang = {}
        self.dtauk = {}
        self.dfield = {}
        self.dcir = {}
        self.output = {}

        #
        # Here was a nasty bug : Rule for the future
        #    "Always precise the key value of the passed argument"
        #
        # Mal nommer les choses, c'est ajouter au malheur du monde ( Albert Camus )
        #
        self.tx = RadioNode(
            name='',
            typ='tx',
            _fileini='radiotx.ini',
            _fileant='defant.vsh3',
        )

        self.rx = RadioNode(
            name='',
            typ='rx',
            _fileini='radiorx.ini',
            _fileant='defant.vsh3',
        )

        self.filefreq = "def.freq"

        self.progress = -1  # simulation not loaded

        self.filetang = []
        self.filerang = []
        self.filetauk = []
        self.filefield = []

        self.fileconf = "project.conf"
        self.cfield = []
        self.fGHz = np.linspace(2, 11, 181, endpoint=True)
        self.wav = wvf.Waveform()
        self.load(_filesimul)
コード例 #2
0
 def Ab(self,Ant):
     position = self.b
     rot = self.Tb
     self.rx = RadioNode(name = '',
                         typ = 'rx',
                         _fileini = 'radiorx.ini',
                         )
     self._Ab = Ant
     #to be removed when radionode will be updated
     self.b = position
     self.Tb = rot
     self.initfreq()
コード例 #3
0
 def Aa(self,Ant):
     position = self.a
     rot = self.Ta
     self.tx = RadioNode(name = '',
                         typ = 'tx',
                         _fileini = 'radiotx.ini',
                         )
     self._Aa = Ant
     #to be removed when radionode will be updated
     self.a = position
     self.Ta = rot
     self.initfreq()
コード例 #4
0
    def __init__(self, **kwargs):
        """ deterministic link evaluation

        Parameters
        ----------

        L : Layout
            Layout to be used
        a : np.ndarray (3,)
            position of a device dev_a
        b : np.ndarray (3,)
            position of a device dev_b
        Aa : Antenna
            Antenna of device dev_a
        Ab : Antenna
            Antenna of device dev_b
        Ta : np.ndarray (3,3)
            Rotation matrice of Antenna of device dev_a relative to global Layout scene
        Tb : np.ndarray (3,3)
            Rotation matrice of Antenna of device dev_b relative to global Layout scene
        fGHz : np.ndarray (Nf,)
            frequency range of Nf points used for evaluation of channel
        wav : Waveform
            Waveform to be applied on the channel
        save_idx : int
            number to identify the h5 file generated

        Advanced (change only if you really know what you do !)

        save_opt : list (['sig','ray','Ct','H'])
            information to be saved in the Links h5 file. Should never be Modified !

        force_create : Boolean (False)
            forcecreating the h5py file (if already exist, will be erased)


        Notes
        -----

        All simulations are stored into a unique file in your <PyProject>/output directory
        using the following convention:

        Links_<save_idx>_<LayoutFilename>.h5

        where
            <save_idx> is an integer number to distinguish different links simulations
        and <LayoutFilename> is the Layout used for the link simulation.



        Dataset organisation:

        Links_<idx>_<Layout_name>.h5
            |
            |/sig/si_ID#0/
            |    /si_ID#1/
            |    ...
            |
            |/ray/ray_ID#0/
            |    /ray_ID#1/
            |    ...
            |
            |/Ct/Ct_ID#0/
            |   /Ct_ID#1/
            |    ...
            |
            |/H/H_ID#0/
            |  /H_ID#1/
            |    ...
            |
            |
            |p_map
            |c_map
            |f_map
            |A_map
            |T_map



        Roots Dataset :

        c_map : Cycles (Nc x 3)
        p_map : Positions (Np x 3)
        f_map : Frequency (Nf x 3)
        T_map : Rotation matrices (Nt x 3)
        A_map : Antenna name (Na x 3)

        Groups and subgroups:


            Signature identifier (si_ID#N):
                ca_cb_cutoff

            Ray identifier (ray_ID#N):
                cutoff_ua_ub

            Ctilde identifier (Ct_ID#N):
                ua_ub_uf

            H identifier (H_ID#N):
                ua_ub_uf_uTa_uTb_uAa_uAb

            with
            ca : cycle number of a
            cb : cycle number of b
            cutoff : signature.run cutoff
            ua : indice of a position in 'p_map' position dataset
            ub : indice of a position in 'p_map' position dataset
            uf : indice of freq position in 'f_map' frequency dataset
            uTa : indice of a position in 'T_map' Rotation dataset
            uTb : indice of a position in 'T_map' Rotation dataset
            uAa : indice of a position in 'A_map' Antenna name dataset
            uAb : indice of b position in 'A_map' Antenna name dataset



        Examples
        --------

        >>> from pylayers.simul.link import *
        >>> L = DLink(verbose=False)
        >>> aktk = L.eval()


        """


        Link.__init__(self)

        defaults={ 'L':Layout(),
                   'a':np.array(()),
                   'b':np.array(()),
                   'Aa':Antenna(typ='Omni'),
                   'Ab':Antenna(typ='Omni'),
                   'Ta':np.eye(3),
                   'Tb':np.eye(3),
                   'fGHz':[],
                   'wav':wvf.Waveform(),
                   'cutoff':3,
                   'save_opt':['sig','ray','Ct','H'],
                   'save_idx':0,
                   'force_create':False,
                   'verbose':True,
                   'graph':'tcvirw'
                }

        self._ca=-1
        self._cb=-1
        specset = ['a','b','Aa','Ab','Ta','Tb','L','fGHz','wav']

        # set default attribute
        for key, value in defaults.items():
            if key not in kwargs:
                if key in specset :
                    setattr(self,'_'+key,value)
                else :
                    setattr(self,key,value)
            else :
                if key in specset :
                    setattr(self,'_'+key,kwargs[key])
                else :
                    setattr(self,key,kwargs[key])

        force=self.force_create
        delattr(self,'force_create')

        if self.fGHz == []:
            self.initfreq()
        else :
            pass

        try:
            self._Lname = self._L.filename
        except:
            self._L=Layout(self._L)
            self._Lname = self._L.filename

        ###########
        # Transmitter and Receiver positions
        ###########

        self.tx = RadioNode(name = '',
                            typ = 'tx',
                            _fileini = 'radiotx.ini',
                            )

        self.rx = RadioNode(name = '',
                            typ = 'rx',
                            _fileini = 'radiorx.ini',
                            )



        self.filename = 'Links_' + str(self.save_idx) + '_' + self._Lname + '.h5'
        filenameh5 = pyu.getlong(self.filename,pstruc['DIRLNK'])
        # check if save file alreasdy exists
        if not os.path.exists(filenameh5) or force:
            print 'Links save file for ' + self.L.filename + ' does not exist.'
            print 'Creating file. You\'ll see this message only once per Layout'
            self.save_init(filenameh5)

        # dictionnary data exists
        self.dexist={'sig':{'exist':False,'grpname':''},
                     'ray':{'exist':False,'grpname':''},
                     'Ct':{'exist':False,'grpname':''},
                     'H':{'exist':False,'grpname':''}
                    }



        try:
            self.L.dumpr()
        except:
            print('This is the first time the Layout is used. Graphs have to be built. Please Wait')
            self.L.build(graph=self.graph)
            self.L.dumpw()
        #self.L.build()

        ###########
        # init pos & cycles
        #
        # If a and b are not specified
        #  they are chosen as center of gravity of cycle 0
        #
        ###########
        if len(self.a)==0:
            self.ca = 1
            # self.a = self.L.cy2pt(self.ca)
        else:
            if len(kwargs['a']) ==2:
                a=np.r_[kwargs['a'],1.0]
            else:
                a=kwargs['a']
            self.a = a
            # self.ca = self.L.pt2cy(self.a)

        if len(self.b)==0:
            if len(self.L.Gt.node)>2:
                self.cb = 2
            else:
                self.cb = 1
            # self.b = self.L.cy2pt(self.cb)
        else:
            if len(kwargs['b']) ==2:
                b=np.r_[kwargs['b'],1.0]
            else:
                b=kwargs['b']
            self.b = b
            # self.cb = self.L.pt2cy(self.b)


        ###########
        # init freq
        # TODO Check where it is used redundant with fGHz
        ###########
        #self.fmin  = self.fGHz[0]
        #self.fmax  = self.fGHz[-1]
        #self.fstep = self.fGHz[1]-self.fGHz[0]


        self.Si = Signatures(self.L,self.ca,self.cb,cutoff=self.cutoff)
        self.R = Rays(self.a,self.b)
        self.C = Ctilde()
        self.H = Tchannel()
コード例 #5
0
    def load(self, _filesimul):
        """ load a simulation configuration file

         each transmiter simulation results in the creation of an .ini file
         with the following sections
         related to the results obtained for different receivers

        Parameters
        ----------

        _filesimul   : file in the simul directory of the Project

        """

        self.filesimul = _filesimul
        filesimul = pyu.getlong(self.filesimul, "ini")

        self.config.read(filesimul)

        sections = self.config.sections()
        try:
            _filetx = self.config.get("files", "tx")
        except:
            raise NameError('Error in section tx from ' + _filesimul)

        try:
            _filerx = self.config.get("files", "rx")
        except:
            raise NameError('Error in section rx from ' + _filesimul)

        try:
            _fileini = self.config.get("files", "struc")
        except:
            raise NameError('Error in section struc from ' + _fileini)

        try:
            _fileanttx = self.config.get("files", "txant")
        except:
            raise NameError('Error in section txant from ' + _filesimul)

        try:
            _fileantrx = self.config.get("files", "rxant")
        except:
            raise NameError('Error in section rxant from ' + _filesimul)

        try:
            self.tx = RadioNode(name='',
                                typ='tx',
                                _fileini=_filetx,
                                _fileant=_fileanttx)

            self.rx = RadioNode(name='',
                                typ='rx',
                                _fileini=_filerx,
                                _fileant=_fileantrx)
        except:
            raise NameError('Error during Radionode load')
#
# Load Layout
#
        try:
            self.L = Layout(_fileini)
        except:
            raise NameError('Layout load error')

#
# Frequency base
#
        if "frequency" in sections:
            try:
                self.fGHz = np.linspace(
                    float(self.config.getfloat("frequency", "fghzmin")),
                    float(self.config.getfloat("frequency", "fghzmax")),
                    int(self.config.getint("frequency", "nf")),
                    endpoint=True)
            except:
                raise NameError('Error in section frequency from ' +
                                _filesimul)
            # update .freq file in tud directory

            filefreq = pyu.getlong(self.filefreq, pstruc['DIRTUD'])
            fd = open(filefreq, "w")
            chaine = self.config.get("frequency", "fghzmin") + ' ' + \
                self.config.get("frequency", "fghzmax") + ' ' + \
                self.config.get("frequency", "nf")
            fd.write(chaine)
            fd.close
#
# Simulation Progress
#
#        self.output = {}
#        if "output" in sections:
#            for itx in self.config.options("output"):
#                _filename  =  self.config.get("output", itx)
#                self.dout[int(itx)] = _filename
#                filename = pyu.getlong(_filename, "output")
#                output = ConfigParser.ConfigParser()
#                output.read(filename)
#                secout = output.sections()
#                self.dtra[int(itx)] = {}
#                self.dtud[int(itx)] = {}
#                self.dtang[int(itx)] = {}
#                self.drang[int(itx)] = {}
#                self.dtauk[int(itx)] = {}
#                self.dfield[int(itx)] = {}
#                self.dcir[int(itx)] = {}
#                if "launch" in secout:
#                    self.progress = 1
#                    keys_launch = output.options("launch")
#                    for kl in keys_launch:
#                        self.dlch[int(kl)] = output.get("launch", kl)
#                if "trace" in secout:
#                    self.progress = 2
#                    keys_tra = output.options("trace")
#                    for kt in keys_tra:
#                        self.dtra[int(itx)][int(kt)] = output.get("trace", kt)
#
#                if "tang" in secout:
#                    self.progress = 3
#                    keys_tang = output.options("tang")
#                    for kt in keys_tang:
#                        self.dtang[int(itx)][int(kt)] = output.get("tang", kt)
#                        self.drang[int(itx)][int(kt)] = output.get("rang", kt)
#                        self.dtud[int(itx)][int(kt)] = output.get("tud", kt)
#                if "field" in secout:
#                    self.progress = 4
#                    keys_field = output.options("field")
#                    for kt in keys_field:
#                        self.dfield[int(itx)][int(kt)] = output.get(
#                            "field", kt)
#                        self.dtauk[int(itx)][int(kt)] = output.get("tauk", kt)
#                if "cir" in secout:
#                    self.progress = 5
#                    keys_cir = output.options("cir")
#                    for kt in keys_cir:
#                        self.dcir[int(itx)][int(kt)] = output.get("cir", kt)
#
#                self.output[int(itx)] = output
#
# Waveform section
#
        self.wav = wvf.Waveform()
        self.wav.read(self.config)