Commit 6dbf09f1 authored by hm-striegle's avatar hm-striegle

Memory optimizations

parent d2173c31
......@@ -45,7 +45,7 @@ E = SSMF(E = E, D = D, l = z)
# Plot Input and Output signal
plt.figure(1)
plt.plot(gp.timeax*1.0e12, np.abs(E_Tx[0]['E'][0]), 'r', label='$E(0, t)$')
plt.plot(gp.timeax*1.0e12, np.abs(E[0]['E'][0]), 'g', label= '$E(z='+ SSMF.l/1e3+ 'km, t)')
plt.plot(gp.timeax*1.0e12, np.abs(E[0]['E'][0]), 'g', label= '$E(z='+ str(SSMF.l/1e3)+ 'km, t)')
# Get FWHM of the input signal E_Tx
......
......@@ -29,7 +29,7 @@ class pypho_bits(object):
self.nob = None
self.pattern = None
self.set(nob,pattern)
self.set(nob, pattern)
########################################################################
def __call__(self, nob = None, pattern = None):
......@@ -44,55 +44,56 @@ class pypho_bits(object):
self.set(nob, pattern)
if self.pattern == "singlepulse":
self.bits = np.zeros(self.nob, dtype=np.int)
self.bits[self.glova.nos/2] = 1
bits = np.zeros(self.nob, dtype=np.int)
bits[self.glova.nos/2] = 1
elif self.pattern == "ones":
self.bits = np.ones(self.nob, dtype=np.int)
bits = np.ones(self.nob, dtype=np.int)
elif self.pattern == "random":
self.bits = self.rndm()
bits = self.rndm()
elif self.pattern == "debruijn":
self.dbl = int(np.log2(self.nob))
self.a = [0] * self.dbl * 2
self.bits = []
self.db(1, 1)
bits =self.debruijn(2, int(np.log2(self.nob)))
else:
print ("ERROR: No valid pattern specified!")
sys.exit("PyPho stopped!")
return self.bits
return bits
### Create Random Bit Sequence #########################################
def rndm(self):
self.value_rndn = np.ones(self.nob)
self.value_rndn[self.nob/2:] = 0
random.shuffle(self.value_rndn)
self.value_rndn[0] = 1
self.value_rndn[-1] = 0
self.bits = np.array(self.value_rndn)
value_rndn = np.ones(self.nob)
value_rndn[self.nob/2:] = 0
random.shuffle(value_rndn)
value_rndn[0] = 1
value_rndn[-1] = 0
return self.value_rndn
return value_rndn
### Create De Bruijn Sequence #########################################
def db(self, t, p):
if t > self.dbl:
if self.dbl % p == 0:
for j in range(1, p + 1):
self.bits.append(self.a[j])
else:
self.a[t] = self.a[t - p]
self.db(t + 1, p)
for j in range(self.a[t - p] + 1, 2):
self.a[t] = j
self.db(t + 1, t)
def debruijn(self, k, n):
a = [0] * k * n
sequence = []
def db(t, p):
if t > n:
if n % p == 0:
for j in range(1, p + 1):
sequence.append(a[j])
else:
a[t] = a[t - p]
db(t + 1, p)
for j in range(a[t - p] + 1, k):
a[t] = j
db(t + 1, t)
db(1, 1)
return sequence
########################################################################
def set(self, nob = None, pattern = None):
......
......@@ -54,7 +54,7 @@ class pypho_cwlaser(object):
if type(self.Df) != list:
self.Df = [self.Df]
self.E = [];
E = [];
for Dfi in self.Df:
Etmp = {}
......@@ -69,9 +69,9 @@ class pypho_cwlaser(object):
Etmp['noise'] = np.zeros(self.glova.nos * self.glova.sps) + np.mean(a) / 10**(5.0) * self.glova.fres / (0.1 * cv.lightspeed/(1550**2 *1e-9) )
self.E.append( Etmp )
E.append( Etmp )
return self.E
return E
......
......@@ -56,7 +56,7 @@ class pypho_lasmod(object):
if type(self.Df) != list:
self.Df = [self.Df]
self.E = [];
E = [];
for Dfi in self.Df:
Etmp = {}
......@@ -70,9 +70,9 @@ class pypho_lasmod(object):
Etmp['noise'] = np.zeros(self.glova.nos * self.glova.sps) + dbm2w( self.power ) / 10.0**(5.8) / 12.5e9 * self.glova.fres
self.E.append( Etmp )
E.append( Etmp )
return self.E
return E
########################################################################
......
......@@ -134,9 +134,7 @@ class pypho_optfi(object):
# ax.plot((self.glova.freqax-self.glova.f0)*1e-9, self.filfunc)
# ax.set_ylim(-0.2, 1.2)
self.E = E
return self.E
return E
########################################################################
......
......@@ -50,24 +50,24 @@ class pypho_signalsrc(object):
if self.pulseshape == "gauss_rz":
self.tau = self.fwhm * 1/self.glova.symbolrate / 2.3582
self.E = self.gauss_rz()
E = self.gauss_rz()
elif self.pulseshape == "gauss_nrz":
self.tau = self.fwhm * 1/self.glova.symbolrate / 2.3582
self.E = self.gauss_nrz()
E = self.gauss_nrz()
elif self.pulseshape == "sech_rz":
self.tau = self.fwhm * 1/self.glova.symbolrate / 1.76
self.E = self.sech_rz()
E = self.sech_rz()
elif self.pulseshape == "rect":
self.tau = 0
self.E = self.rect()
E = self.rect()
else:
print ("ERROR: No valid pulse shape")
sys.exit("PyPho stopped!")
return self.E
return E
### Create Gauss RZ Pulse shape ########################################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment