Commit 6dbf09f1 authored by Arne Striegler's avatar Arne Striegler 😁

Memory optimizations

parent d2173c31
...@@ -45,7 +45,7 @@ E = SSMF(E = E, D = D, l = z) ...@@ -45,7 +45,7 @@ E = SSMF(E = E, D = D, l = z)
# Plot Input and Output signal # Plot Input and Output signal
plt.figure(1) 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_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 # Get FWHM of the input signal E_Tx
......
...@@ -29,7 +29,7 @@ class pypho_bits(object): ...@@ -29,7 +29,7 @@ class pypho_bits(object):
self.nob = None self.nob = None
self.pattern = None self.pattern = None
self.set(nob,pattern) self.set(nob, pattern)
######################################################################## ########################################################################
def __call__(self, nob = None, pattern = None): def __call__(self, nob = None, pattern = None):
...@@ -44,55 +44,56 @@ class pypho_bits(object): ...@@ -44,55 +44,56 @@ class pypho_bits(object):
self.set(nob, pattern) self.set(nob, pattern)
if self.pattern == "singlepulse": if self.pattern == "singlepulse":
self.bits = np.zeros(self.nob, dtype=np.int) bits = np.zeros(self.nob, dtype=np.int)
self.bits[self.glova.nos/2] = 1 bits[self.glova.nos/2] = 1
elif self.pattern == "ones": 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": elif self.pattern == "random":
self.bits = self.rndm() bits = self.rndm()
elif self.pattern == "debruijn": elif self.pattern == "debruijn":
self.dbl = int(np.log2(self.nob)) bits =self.debruijn(2, int(np.log2(self.nob)))
self.a = [0] * self.dbl * 2
self.bits = []
self.db(1, 1)
else: else:
print ("ERROR: No valid pattern specified!") print ("ERROR: No valid pattern specified!")
sys.exit("PyPho stopped!") sys.exit("PyPho stopped!")
return self.bits return bits
### Create Random Bit Sequence ######################################### ### Create Random Bit Sequence #########################################
def rndm(self): def rndm(self):
self.value_rndn = np.ones(self.nob) value_rndn = np.ones(self.nob)
self.value_rndn[self.nob/2:] = 0 value_rndn[self.nob/2:] = 0
random.shuffle(self.value_rndn) random.shuffle(value_rndn)
self.value_rndn[0] = 1 value_rndn[0] = 1
self.value_rndn[-1] = 0 value_rndn[-1] = 0
self.bits = np.array(self.value_rndn)
return self.value_rndn return value_rndn
### Create De Bruijn Sequence ######################################### ### Create De Bruijn Sequence #########################################
def db(self, t, p): def debruijn(self, k, n):
a = [0] * k * n
if t > self.dbl: sequence = []
if self.dbl % p == 0: def db(t, p):
for j in range(1, p + 1): if t > n:
self.bits.append(self.a[j]) if n % p == 0:
else: for j in range(1, p + 1):
self.a[t] = self.a[t - p] sequence.append(a[j])
self.db(t + 1, p) else:
for j in range(self.a[t - p] + 1, 2): a[t] = a[t - p]
self.a[t] = j db(t + 1, p)
self.db(t + 1, t) 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): def set(self, nob = None, pattern = None):
......
...@@ -54,7 +54,7 @@ class pypho_cwlaser(object): ...@@ -54,7 +54,7 @@ class pypho_cwlaser(object):
if type(self.Df) != list: if type(self.Df) != list:
self.Df = [self.Df] self.Df = [self.Df]
self.E = []; E = [];
for Dfi in self.Df: for Dfi in self.Df:
Etmp = {} Etmp = {}
...@@ -69,9 +69,9 @@ class pypho_cwlaser(object): ...@@ -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) ) 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): ...@@ -56,7 +56,7 @@ class pypho_lasmod(object):
if type(self.Df) != list: if type(self.Df) != list:
self.Df = [self.Df] self.Df = [self.Df]
self.E = []; E = [];
for Dfi in self.Df: for Dfi in self.Df:
Etmp = {} Etmp = {}
...@@ -70,9 +70,9 @@ class pypho_lasmod(object): ...@@ -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 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): ...@@ -134,9 +134,7 @@ class pypho_optfi(object):
# ax.plot((self.glova.freqax-self.glova.f0)*1e-9, self.filfunc) # ax.plot((self.glova.freqax-self.glova.f0)*1e-9, self.filfunc)
# ax.set_ylim(-0.2, 1.2) # ax.set_ylim(-0.2, 1.2)
self.E = E return E
return self.E
######################################################################## ########################################################################
......
...@@ -50,24 +50,24 @@ class pypho_signalsrc(object): ...@@ -50,24 +50,24 @@ class pypho_signalsrc(object):
if self.pulseshape == "gauss_rz": if self.pulseshape == "gauss_rz":
self.tau = self.fwhm * 1/self.glova.symbolrate / 2.3582 self.tau = self.fwhm * 1/self.glova.symbolrate / 2.3582
self.E = self.gauss_rz() E = self.gauss_rz()
elif self.pulseshape == "gauss_nrz": elif self.pulseshape == "gauss_nrz":
self.tau = self.fwhm * 1/self.glova.symbolrate / 2.3582 self.tau = self.fwhm * 1/self.glova.symbolrate / 2.3582
self.E = self.gauss_nrz() E = self.gauss_nrz()
elif self.pulseshape == "sech_rz": elif self.pulseshape == "sech_rz":
self.tau = self.fwhm * 1/self.glova.symbolrate / 1.76 self.tau = self.fwhm * 1/self.glova.symbolrate / 1.76
self.E = self.sech_rz() E = self.sech_rz()
elif self.pulseshape == "rect": elif self.pulseshape == "rect":
self.tau = 0 self.tau = 0
self.E = self.rect() E = self.rect()
else: else:
print ("ERROR: No valid pulse shape") print ("ERROR: No valid pulse shape")
sys.exit("PyPho stopped!") sys.exit("PyPho stopped!")
return self.E return E
### Create Gauss RZ Pulse shape ######################################## ### 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