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)
def updcfg(self): """ update simulation .ini config file with values currently in use. """ self.config.set("files", "struc", self.filestr) self.config.set("files", "conf", self.fileconf) self.config.set("files", "txant", self.tx.fileant) self.config.set("files", "rxant", self.rx.fileant) self.config.set("files", "tx", self.tx.fileini) self.config.set("files", "rx", self.rx.fileini) self.config.set("files", "mat", self.filematini) self.config.set("files", "slab", self.fileslabini) self.config.set("tud", "purc", str(self.patud.purc)) self.config.set("tud", "nrmax", str(self.patud.nrmax)) self.config.set("tud", "num", str(self.patud.num)) # # frequency section # self.config.set("frequency", "fghzmin", self.fGHz[0]) self.config.set("frequency", "fghzmax", self.fGHz[-1]) self.config.set("frequency", "nf", str(len(self.fGHz))) # # waveform section # self.config.set("waveform", "tw", str(self.wav['twns'])) self.config.set("waveform", "band", str(self.wav['bandGHz'])) self.config.set("waveform", "fc", str(self.wav['fcGHz'])) self.config.set("waveform", "thresh", str(self.wav['threshdB'])) self.config.set("waveform", "type", str(self.wav['typ'])) self.config.set("waveform", "fe", str(self.wav['feGHz'])) # # output section # for k in self.output.keys(): self.config.set("output", str(k), self.dout[k]) # Initialize waveform self.wav = wvf.Waveform() # Update waveform self.wav.read(self.config) self.save()
S.tx.point(tx) S.rx.point(rx) Ctx = S.L.pt2cy(S.tx.position[:, 0]) Crx = S.L.pt2cy(S.rx.position[:, 0]) Si = Signatures(S.L, Ctx, Crx) Si.run1(cutoff=5) #Si.run2(cutoff=3,dcut=2) r2d = Si.rays(tx, rx) r3d = r2d.to3D(S.L) r3d.locbas(S.L) r3d.fillinter(S.L) pg = np.sum(S.L.pt, axis=1) / np.shape(S.L.pt)[1] pg = array([pg[0], pg[1], 0]).reshape(3, 1) #r3d.show3(strucname='defstr3',pg=pg) fGHz = np.arange(2, 11, 0.5) wav = wvf.Waveform(fcGHz=5, bandGHz=3) r3d.fillinter(S.L, append=True) Cair = r3d.eval(fGHz) scair = Cair.prop2tran(a='theta', b='theta') cirair = scair.applywavB(wav.sfg) S.L.Gs.node[1]['ss_name'] = ['WOOD', 'AIR', 'METAL'] S.L.g2npy() # graph to numpy Cwood = r3d.eval(fGHz) scwood = Cwood.prop2tran(a='theta', b='theta') cirwood = scwood.applywavB(wav.sfg) S.L.Gs.node[1]['ss_name'] = ['METAL', 'AIR', 'WOOD'] # graph to numpy S.L.g2npy()
ptt=[39, 10, 1.275], vec=[-1, 0, 0], mode='subst') ps = S.rx.position[:, -1] S.rx.linevect(npt=10, step=0.1, ptt=ps, vec=[0, -1, 0], mode='append') ps = S.rx.position[:, -1] S.rx.linevect(npt=250, step=0.1, ptt=ps, vec=[-1, 0, 0], mode='append') ps = S.rx.position[:, -1] S.rx.linevect(npt=30, step=0.1, ptt=ps, vec=[0, -1, 0], mode='append') ps = S.rx.position[:, -1] S.rx.linevect(npt=300, step=0.1, ptt=ps, vec=[1, 0, 0], mode='append') # Waveform wav = wvf.Waveform(typ='generic', bandGHz=2.559, fcGHz=4.9936, feGHz=100, threshdB=-10, twns=64) fig = plt.figure(figsize=(10, 10)) wav.show(fig=fig) #fGHz = wav.bandwidth(th_ratio=100,Npt=200) fGHz = np.linspace(2.5, 7.5, 60) L = Layout('TA-Office.ini') link = DLink(force=True, L=L, fGHz=fGHz, verbose=False) link.fGHz = fGHz link.a = S.tx.position[:, 1] link.b = S.rx.position[:, 22] print "eval ..."
import pdb import pickle import numpy as np import pylayers.signal.waveform as wvf #import matplotlib.pyplot as plt # Set the frequency range fGHz = np.arange(2,6,0.01) # Define the Layout L = Layout('DLR2.ini') # Create a link for the Layout S = DLink(L=L,fGHz=fGHz) ak,tauk=S.eval(force=['Ct','H']) #S._show3() S.H.plot() wav = wvf.Waveform(fcGHz=4,bandGHz=4) h = S.H.totime() ## applyu waveform #hw = S.H.applywav(wav.sfg) # #Nray = h.y.shape[0] #ir = 0 #it = 0 #plt.figure() #tEk1 = [] #tEk2 = [] #for k in range(Nray): # Ek = np.sum(h.y[k,ir,it,:]*h.y[k,ir,it,:]) # tEk1.append(Ek) #alpha=np.sqrt(tEk1)/max(np.sqrt(tEk1)) #for k in range(Nray):
r3d.locbas(L) r3d.fillinter(L) config = ConfigParser.ConfigParser() _filesimul = 'default.ini' filesimul = pyu.getlong(_filesimul, "ini") config.read(filesimul) fGHz = np.linspace(eval(config.get("frequency", "fghzmin")), eval(config.get("frequency", "fghzmax")), eval(config.get("frequency", "nf"))) Cn=r3d.eval(fGHz) Cn.freq=Cn.fGHz sco=Cn.prop2tran(a='theta',b='theta') wav = wvf.Waveform() ciro = sco.applywavB(wav.sfg) #raynumber = 4 #fig=plt.figure('Cpp') #f,ax=Cn.Cpp.plot(fig=fig,iy=np.array(([raynumber]))) #r3d.info(raynumber) # plt.show() #======= # #c11 = r3d.Ctilde[:,:,0,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()
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)