In [1]:
from pylayers.antprop.rays import *
from pylayers.gis.layout import *
from pylayers.antprop.signature import *
import pylayers.signal.bsignal as bs
import pylayers.signal.waveform as wvf
from pylayers.simul.simulem import *
import matplotlib.pyplot as plt
import time
In [2]:
print "======================="
print " start test_rays.py (Ray Tracing numpy) "
print "======================="
S = Simul()
filestr = 'defstr'
S.layout(filestr+'.ini','matDB.ini','slabDB.ini')
S.L.Gs.node[1]['ss_name']=['WOOD','AIR','METAL']
S.L.build()
# first case
tx=array([759,1114,1.0])
rx=array([767,1114,1.5])
S.tx.clear()
S.rx.clear()
S.tx.point(tx)
S.rx.point(rx)
Ctx = S.L.pt2cy(S.tx.position[:,0])
Crx = S.L.pt2cy(S.rx.position[:,0])
fGHz=np.arange(2,11,0.1)
wav = wvf.Waveform(fcGHz=5,bandGHz=3)
We start by building a first set of rays.
In [41]:
Si1 = Signatures(S.L,Ctx,Crx)
Si1.run4(cutoff=5,algo='old')
r2d = Si1.rays(tx,rx)
r3d1 = r2d.to3D(S.L)
r3d1.locbas(S.L)
r3d1.fillinter(S.L)
C1 = r3d1.eval(fGHz)
sc1 = C1.prop2tran(a='theta',b='theta',Friis=False)
cir1 = sc1.applywavB(wav.sfg)
In [42]:
r3d1.show3(S.L)
In [43]:
r2d2 = r2d.reciprocal()
# get new reciprocal r3d
r3d2 = r2d2.to3D(S.L)
r3d2.locbas(S.L)
r3d2.fillinter(S.L)
C2=r3d2.eval(fGHz)
sc2=C2.prop2tran(a='theta',b='theta',Friis=False)
cir2 = sc2.applywavB(wav.sfg)
In [44]:
r3d1.check_reciprocity(r3d2)
In [46]:
cir1.plot(typ='v')
Out[46]:
In [47]:
cir2.plot(typ='v')
Out[47]:
In [48]:
C1.Ctt.show()
Out[48]:
In [9]:
C2.show(mode='dB')
Out[9]:
In [10]:
dsig1 = {}
for l in r3d1.keys():
tsig = r3d1[l]['sig']
nr = np.shape(tsig)[2]
for r in range(nr):
sig = tsig[:,:,r]
dsig1[str(sig)]=(l,r)
dsig2 = {}
for l in r3d2.keys():
tsig = r3d2[l]['sig']
nr = np.shape(tsig)[2]
for r in range(nr):
sig = tsig[:,::-1,r]
dsig2[str(sig)]=(l,r)
In [11]:
k1 = dsig1.keys()
k2 = dsig2.keys()
In [12]:
for s1 in k1:
if s1 not in k2:
l1,r1 = dsig1[s1]
iray1 = r3d1[l1]['rayidx'][r1]
print dsig1[s1],iray1,C1.tauk[iray1]
print "-----"
for s2 in k2:
if s2 not in k1:
l2,r2 = dsig2[s2]
iray2 = r3d2[l2]['rayidx'][r2]
print dsig2[s2],iray2,C2.tauk[iray2]
In [13]:
r134=r3d1.extract(3,4)
r134.show3(S.L)
r134[3]['pt'][:,:,0]
Out[13]:
In [18]:
r238=r3d2.extract(3,8)
r238.show3(S.L)
r238[3]['pt'][:,:,0]
Out[18]:
In [19]:
for s1 in k1:
if s1 in k2:
l1,r1 = dsig1[s1]
iray1 = r3d1[l1]['rayidx'][r1]
l2,r2 = dsig2[s1]
iray2 = r3d2[l2]['rayidx'][r2]
if abs(C1.tauk[iray1]-C2.tauk[iray2])>1e-7:
print C1.tauk[iray1]-C2.tauk[iray2]
In [20]:
k1[19] in k2
Out[20]:
In [21]:
print r3d1[2]['sig'][:,:,0]
print r3d2[2]['sig'][:,:,1]
In [22]:
S.L.sla[12]
Out[22]:
In [23]:
S.L.sla[10]
Out[23]:
In [24]:
S.L.lsss
Out[24]:
In [25]:
S.L.Gs.node[1]['ss_z']
Out[25]:
In [26]:
print r3d1[3]['pt'][:,:,4]- r3d2[3]['pt'][:,::-1,8]
In [27]:
r3d1.signature(2,1)
Out[27]:
In [28]:
r3d2.signature(2,0)
Out[28]:
In [29]:
print r3d1[2]['pt'][:,:,1]
In [30]:
print r3d2[2]['pt'][:,::-1,0]
In [31]:
idx1 = r3d1[2]['rayidx'][1]
idx2 = r3d1[2]['rayidx'][0]
print idx1
print idx2
In [15]:
Bi1 = r3d1[2]['Bi'][:,:,:,1]
BiN1 = r3d1[2]['BiN'][:,:,1]
Bo1 = r3d1[2]['Bo'][:,:,:,1]
Bo01 = r3d1[2]['Bo0'][:,:,1]
In [16]:
Bi2 = r3d2[2]['Bi'][:,:,:,0]
BiN2 = r3d2[2]['BiN'][:,:,0]
Bo2 = r3d2[2]['Bo'][:,:,:,0]
Bo02 = r3d2[2]['Bo0'][:,:,0]
In [17]:
print BiN1
In [18]:
print BiN2-Bo01
print BiN1-Bo02
In [20]:
TBi1 = np.concatenate((Bi1[:,1:,:], BiN1[:, 1:, np.newaxis]), axis=2)
TBo1 = np.concatenate((Bo01[:, 1:, np.newaxis], Bo1[:,1:,:]), axis=2)
TBi2 = np.concatenate((Bi2[:,1:,:], BiN2[:, 1:, np.newaxis]), axis=2)
TBo2 = np.concatenate((Bo02[:, 1:, np.newaxis], Bo2[:,1:,:]), axis=2)
In [21]:
B1=np.einsum('xv...,xw...->vw...', TBo1, TBi1)
B2=np.einsum('xv...,xw...->vw...', TBo2, TBi2)
In [22]:
print B1[:,:,2]
In [23]:
print B2[:,:,0]
In [24]:
r3d1[2]['B'][:,:,2,1]
Out[24]:
In [25]:
r3d2[2]['B'][:,:,0,0]
Out[25]:
In [26]:
np.shape(r3d1[2]['Bi'])
Out[26]:
In [27]:
r3d1[2].keys()
Out[27]:
In [28]:
r3d1[2]['Bi'][:,:,:,1]
Out[28]:
In [29]:
r3d1[2]['Bo'][:,:,:,1]
Out[29]:
In [30]:
r3d2[2]['Bo'][:,:,::-1,0]
Out[30]:
In [31]:
r3d2[2]['Bi'][:,:,::-1,0]
Out[31]:
In [37]:
r3d2[2]['Bi'][:,:,::-1,0]-r3d1[2]['Bo'][:,:,:,1]
Out[37]:
In [32]:
r3d2[2]['Bo'][:,:,::-1,0]-r3d1[2]['Bi'][:,:,:,1]
Out[32]:
In [33]:
np.shape(r3d1[2]['Bo'][:,:,:,1])
Out[33]:
In [34]:
r3d1[2]['B'][:,:,:,1]
Out[34]:
In [41]:
r3d2[2]['B'][:,:,::-1,0]
Out[41]:
In [49]:
cir1.plot()
Out[49]:
In [50]:
cir2.plot()
Out[50]:
In [44]:
print np.shape(r3d1[2]['Bi'])
print np.shape(r3d1[2]['pt'])
print r3d1[2]['pt']
In [45]:
G=geu.GeomVect()
G.geomBase(r3d1[2]['Bi'][:,:,0,0])
G.show3()
G.filename
Out[45]:
In [46]:
fGHz=np.arange(2,11,0.1)
wav = wvf.Waveform(fcGHz=5,bandGHz=3)
C1=r3d1.eval(fGHz)
sc1=C1.prop2tran(a='theta',b='theta')
cir1 = sc1.applywavB(wav.sfg)
In [47]:
rx=array([759,1114,1.0])
tx=array([767,1114,1.5])
S.tx.clear()
S.rx.clear()
S.tx.point(tx)
S.rx.point(rx)
Ctx = S.L.pt2cy(S.tx.position[:,0])
Crx = S.L.pt2cy(S.rx.position[:,0])
In [48]:
Si2 = Signatures(S.L,Ctx,Crx)
Si2.run4(cutoff=5,algo='old')
r2d2 = Si2.rays(tx,rx)
r3d2 = r2d2.to3D(S.L)
r3d2.locbas(S.L)
r3d2.fillinter(S.L)
In [49]:
fGHz=np.arange(2,11,0.1)
wav = wvf.Waveform(fcGHz=5,bandGHz=3)
C2=r3d2.eval(fGHz)
sc2=C2.prop2tran(a='theta',b='theta')
cir2 = sc2.applywavB(wav.sfg)
In [50]:
len(C2.tauk)
Out[50]:
In [51]:
r3d1.signature(3,3)
Out[51]:
In [52]:
r3d2.signature(3,7)
Out[52]:
In [53]:
r31 = r3d1.extract(3,3)
r32 = r3d2.extract(3,7)
In [54]:
r31.locbas(S.L)
r31.fillinter(S.L)
r31.nray=1
In [55]:
r32.locbas(S.L)
r32.fillinter(S.L)
r32.nray=1
In [56]:
C1 = r31.eval(fGHz)
C2 = r32.eval(fGHz)
In [57]:
sc1=C1.prop2tran(a='theta',b='theta')
cir1 = sc1.applywavB(wav.sfg)
sc2=C2.prop2tran(a='theta',b='theta')
cir2 = sc2.applywavB(wav.sfg)
In [58]:
cir1.plot(types='v')
cir2.plot(types='v')
In [ ]:
r2 = r2d.extract(2,1)
q2 = r2.reciprocal()
In [26]:
r2.show(S.L)
Out[26]:
In [27]:
q2.show(S.L)
Out[27]:
In [28]:
q2[2]
Out[28]:
In [29]:
r3 = r2.to3D(S.L)
r3.locbas(S.L)
r3.fillinter(S.L)
q3 = q2.to3D(S.L)
q3.locbas(S.L)
q3.fillinter(S.L)
In [30]:
r3
Out[30]:
In [31]:
q3
Out[31]:
In [32]:
Cr=r3.eval(fGHz)
Cr.sort()
scr=Cr.prop2tran(a='theta',b='theta')
Cq=q3.eval(fGHz)
Cq.sort()
scq=Cq.prop2tran(a='theta',b='theta')
In [33]:
scr
Out[33]:
In [34]:
scq
Out[34]:
In [35]:
scq.RSSI()
Out[35]:
In [36]:
scr.RSSI()
Out[36]:
In [37]:
print scr.doa
print scq.dod
In [38]:
print scr.dod
print scq.doa
In [39]:
-2.65738-0.47140627
Out[39]:
In [53]:
r3[2]
Out[53]:
In [40]:
print scr.tau0
print scq.tau0
In [41]:
r = 1
print Cr.Ctt.y[r,0],Cr.Ctp.y[r,0]
print Cr.Cpt.y[r,0],Cr.Cpp.y[r,0]
print "---"
print Cq.Ctt.y[r,0],Cq.Ctp.y[r,0]
print Cq.Cpt.y[r,0],Cq.Cpp.y[r,0]
Quand on parcours les bases locales à l'envers on n'observe pas de transposition !
In [42]:
print r3[4]['B'][:,:,1,0]
print q3[4]['B'][:,:,-2,0]
In [43]:
print r3[4]['sig'][:,:,0]
print q3[4]['sig'][:,::-1,0]
In [44]:
print r3[4]['sig'][:,:,0]
print q3[4]['sig'][:,::,0]
In [45]:
print r3.ray2nbi
print q3.ray2nbi
In [46]:
print r3.I.I[0,0]
print q3.I.I[0,0]
In [47]:
print r3.I.R.A[0,0,:,:]
print q3.I.R.A[0,0,:,:]
In [48]:
print r3.I.T.A[0,0,:,:]
print q3.I.T.A[0,0,:,:]
In [49]:
print r3.I.I[0,1]
print q3.I.I[0,-2]
In [104]:
i = 2
r = 0
a3=r3.extract(i,r)
In [105]:
a3.to3D(S.L)
b3 = a3.reciprocal()
b3.locbas(S.L)
In [106]:
np.shape(a3[i]['B'])
Out[106]:
In [117]:
a3.info(0)
In [108]:
a3r = a3[i]['B'].reshape(2,6,order='F')
plt.imshow(a3r,interpolation='nearest',cmap='PuOr')
colorbar()
Out[108]:
In [115]:
b3[i]['B']
Out[115]:
In [127]:
r3
Out[127]:
In [119]:
b3r = b3[i]['B'].reshape(2,6,order='F')
plt.imshow(b3r,interpolation='nearest',cmap='PuOr')
colorbar()
Out[119]:
In [125]:
import pylayers.util.geomutil as geu
pyu.getlong(S.L.filename,"geom")
Out[125]:
In [5]:
print np.shape(r3[3]['Bo'])
In [ ]:
def showBases(L=[],r3):
baselist = geu.Geomlist(bases,clear=True)
baselist.append("LIST\n")
if L!=[]:
filestruc = pyu.getlong(L.filename,"geom")
baselist.append('{<'+filestruc+'}\n')