Skip to content

Commit 015f81a

Browse files
author
ibegleris
committed
first public appearance of the repository
1 parent 82115c8 commit 015f81a

32 files changed

+3476
-0
lines changed

Conversion_efficiency_post_proc.ipynb

Lines changed: 1011 additions & 0 deletions
Large diffs are not rendered by default.

Conversion_efficiency_post_proc.py

Lines changed: 747 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SM-FOPO
2+
3+
The repository holds the model of a unidirectional single mode FOPO based upon the system shown in.
4+
There is now a build script that downloads and installs miniconda with all the equilavent packadges needed. Beware to have sudo now for MPICH if not already installed.
5+
6+
<p align="center">
7+
<img src="https://github.com/ibegleris/strict-SM-FOPO/blob/master/build_data/FOPO.jpg">
8+
</p>

build_data/.conda_intel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
channels:
2+
- intel

build_data/.condarc_default

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
channels:
2+
- defaults

build_data/.condarc_intel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
channels:
2+
-defaults

build_data/FOPO.jpg

46.5 KB
Loading

build_intall.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
2+
bash miniconda.sh -b -p $HOME/miniconda
3+
rm minconda.sh
4+
export PATH="$HOME/miniconda/bin:$PATH"
5+
hash -r
6+
conda config --set always_yes yes --set changeps1 no
7+
conda update conda -y
8+
conda config --add channels intel
9+
conda create -n intel intelpython3_core python=3
10+
source activate intel
11+
conda install cython numpy scipy matplotlib pandas h5py pytables jupyter joblib numba pytest nose -y
12+
source deactivate
13+
rm -rf ../.condarc
14+
mv build_data/.condarc_default ../.condarc
15+
mv build_data/.condarc_default ~/miniconda/envs/intel/.condarc
16+
conda update conda -y
17+
conda install numpy scipy matplotlib jupyter pandas h5py pytables jupyter numba pytest nose -y
18+
conda install python=3.6 -y
19+
if [ "$1" != 'cluster' ]; then
20+
sudo apt-get update
21+
sudo apt-get install mpich -y
22+
fi
23+
echo 'export PATH="/home/$USER/miniconda/bin:$PATH"' >> ~/.bashrc
24+
source activate intel
25+
git clone https://github.com/mpi4py/mpi4py.git
26+
cd mpi4py
27+
python setup.py build
28+
python setup.py install
29+
cd ..
30+
rm -rf mpi4py
31+
pytest unittesting_scripts.py

data_plotters_animators.py

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
import matplotlib as mpl
2+
mpl.use('Agg')
3+
import matplotlib.pyplot as plt
4+
import numpy as np
5+
import os
6+
from scipy.constants import c
7+
import h5py
8+
9+
def w2dbm(W, floor=-100):
10+
"""This function converts a power given in W to a power given in dBm.
11+
Inputs::
12+
W(float): power in units of W
13+
Returns::
14+
Power in units of dBm(float)
15+
"""
16+
if type(W) != np.ndarray:
17+
if W > 0:
18+
return 10. * np.log10(W) + 30
19+
elif W == 0:
20+
return floor
21+
else:
22+
print(W)
23+
raise(ZeroDivisionError)
24+
a = 10. * (np.ma.log10(W)).filled(floor/10-3) + 30
25+
return a
26+
27+
plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
28+
plt.gca().get_xaxis().get_major_formatter().set_useOffset(False)
29+
30+
31+
def plotter_dbm(index, nm, sim_wind, u, U, P0_p, P0_s, f_p, f_s, which,ro, pump_wave = '',filename=None, title=None, im=0, plots = True):
32+
#u, U = np.reshape(u,(np.shape(u)[-1], np.shape(u)[0])), np.reshape(u,(np.shape(U)[-1], np.shape(U)[0]))
33+
if plots == True:
34+
fig = plt.figure(figsize=(20.0, 10.0))
35+
36+
plt.plot(1e-3*c/sim_wind.fv,
37+
w2dbm(np.abs(U[:,which])**2), '-*')
38+
#plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
39+
#plt.gca().get_xaxis().get_major_formatter().set_useOffset(False)
40+
plt.xlabel(r'$\lambda (nm)$', fontsize=18)
41+
plt.ylabel(r'$Spectrum (a.u.)$', fontsize=18)
42+
plt.ylim([-80, 100])
43+
plt.xlim([np.min(sim_wind.lv), np.max(sim_wind.lv)])
44+
plt.xlim([900, 1250])
45+
plt.title(title)
46+
plt.grid()
47+
if type(im) != int:
48+
newax = fig.add_axes([0.8, 0.8, 0.2, 0.2], anchor='NE')
49+
newax.imshow(im)
50+
newax.axis('off')
51+
if filename == None:
52+
plt.show()
53+
else:
54+
plt.savefig('output'+pump_wave+'/output'+str(index)+'/figures/wavelength/'+filename, bbox_inched='tight')
55+
56+
plt.close(fig)
57+
58+
fig = plt.figure(figsize=(20.0, 10.0))
59+
plt.plot(sim_wind.fv, w2dbm(np.abs(U[:,which])**2), '-*')
60+
#plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
61+
#plt.gca().get_xaxis().get_major_formatter().set_useOffset(False)
62+
plt.xlabel(r'$f (THz)$', fontsize=18)
63+
plt.ylabel(r'$Spectrum (a.u.)$', fontsize=18)
64+
#plt.xlim([np.min(sim_wind.fv), np.max(sim_wind.fv)])
65+
plt.ylim([-20, 120])
66+
#plt.xlim(270,300)
67+
plt.title(str(f_p)+' ' +str(f_s))
68+
plt.grid()
69+
if type(im) != int:
70+
newax = fig.add_axes([0.8, 0.8, 0.2, 0.2], anchor='NE')
71+
newax.imshow(im)
72+
newax.axis('off')
73+
if filename == None:
74+
plt.show()
75+
else:
76+
plt.savefig('output'+pump_wave+'/output'+str(index)+'/figures/freequency/'+filename, bbox_inched='tight')
77+
plt.close(fig)
78+
79+
fig = plt.figure(figsize=(20.0, 10.0))
80+
81+
plt.plot(sim_wind.t,np.abs(u[:, which])**2, '*-')
82+
#plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
83+
plt.title('time space')
84+
#plt.ylim([0, 160])
85+
plt.grid()
86+
plt.xlabel(r'$t(ps)$')
87+
plt.ylabel(r'$Spectrum$')
88+
if type(im) != int:
89+
newax = fig.add_axes([0.8, 0.8, 0.2, 0.2], anchor='NE')
90+
newax.imshow(im)
91+
newax.axis('off')
92+
93+
if filename == None:
94+
plt.show()
95+
else:
96+
97+
plt.savefig('output'+pump_wave+'/output'+str(index)+'/figures/time/'+filename)
98+
plt.close(fig)
99+
100+
101+
if filename is not(None):
102+
if filename[:4] != 'port':
103+
layer = filename[-1]+'/'+filename[:-1]
104+
else:
105+
layer = filename
106+
try:
107+
108+
save_variables('data_large', layer, filepath='output'+pump_wave+'/output'+str(index)+'/data/', U = U[:,which], t=sim_wind.t, u=u[:,which],
109+
fv=sim_wind.fv, lv=sim_wind.lv,
110+
which=which, nm=nm, P0_p=P0_p, P0_s=P0_s, f_p=f_p, f_s=f_s, ro = ro)
111+
except RuntimeError:
112+
os.system('rm output'+pump_wave+'/output'+str(index)+'/data/data_large.hdf5')
113+
save_variables('data_large', layer, filepath='output'+pump_wave+'/output'+str(index)+'/data/', U=U[:,which], t=sim_wind.t, u=u[:,which],
114+
fv=sim_wind.fv, lv=sim_wind.lv,
115+
which=which, nm=nm, P0_p=P0_p, P0_s=P0_s, f_p=f_p, f_s=f_s, ro = ro)
116+
pass
117+
118+
return 0
119+
120+
121+
def plotter_dbm_load():
122+
# class sim_window(object):
123+
plotter_dbm(nm, sim_wind, Uabs, u, which)
124+
return None
125+
126+
127+
128+
def animator_pdf_maker(rounds, pump_index):
129+
"""
130+
Creates the animation and pdf of the FOPO at different parts of the FOPO
131+
using convert from imagemagic. Also removes the pngs so be carefull
132+
133+
"""
134+
print("making pdf's and animations.")
135+
space = ('wavelength', 'freequency', 'time')
136+
for sp in space:
137+
file_loc = 'output/output'+str(pump_index)+'/figures/'+sp+'/'
138+
strings_large = ['convert '+file_loc+'00.png ']
139+
for i in range(4):
140+
strings_large.append('convert ')
141+
for ro in range(rounds):
142+
for i in range(4):
143+
strings_large[i+1] += file_loc+str(ro)+str(i+1)+'.png '
144+
for w in range(1, 4):
145+
if i == 5:
146+
break
147+
strings_large[0] += file_loc+str(ro)+str(w)+'.png '
148+
for i in range(4):
149+
os.system(strings_large[i]+file_loc+str(i)+'.pdf')
150+
151+
file_loca = file_loc+'portA/'
152+
file_locb = file_loc+'portB/'
153+
string_porta = 'convert '
154+
string_portb = 'convert '
155+
for i in range(rounds):
156+
string_porta += file_loca + str(i) + '.png '
157+
string_portb += file_locb + str(i) + '.png '
158+
159+
string_porta += file_loca+'porta.pdf '
160+
string_portb += file_locb+'portb.pdf '
161+
os.system(string_porta)
162+
os.system(string_portb)
163+
164+
for i in range(4):
165+
os.system(
166+
'convert -delay 30 '+file_loc+str(i)+'.pdf '+file_loc+str(i)+'.mp4')
167+
os.system('convert -delay 30 ' + file_loca +
168+
'porta.pdf ' + file_loca+'porta.mp4 ')
169+
os.system('convert -delay 30 ' + file_locb +
170+
'portb.pdf ' + file_locb+'portb.mp4 ')
171+
172+
for i in (file_loc, file_loca, file_locb):
173+
print('rm ' + i + '*.png')
174+
os.system('rm ' + i + '*.png')
175+
os.system('sleep 5')
176+
return None
177+
178+
179+
def read_variables(filename, layer, filepath=''):
180+
with h5py.File(filepath+str(filename)+'.hdf5', 'r') as f:
181+
D = {}
182+
for i in f.get(layer).keys():
183+
try:
184+
D[str(i)] = f.get(layer + '/' + str(i)).value
185+
except AttributeError:
186+
pass
187+
return D
188+
189+
190+
def save_variables(filename, layers, filepath='', **variables):
191+
with h5py.File(filepath + filename + '.hdf5', 'a') as f:
192+
for i in (variables):
193+
f.create_dataset(layers+'/'+str(i), data=variables[i])
194+
return None

fft_module.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import numpy as np
2+
import scipy.fftpack as scifft
3+
"""
4+
This file was made to test the speed of the fft's before they are used. After
5+
Intel released their own Scipy it became obsulete since intel scipy is always faster
6+
"""
7+
sfft, isfft = scifft.fft, scifft.ifft
8+
nfft,infft = np.fft.fft, np.fft.ifft
9+
from time import time
10+
try:
11+
import accelerate.mkl.fftpack as mklfft
12+
mfft, imfft = mklfft.fft, mklfft.ifft
13+
import accelerate
14+
complex128 = accelerate.numba.complex128
15+
vectorize = accelerate.numba.vectorize
16+
def timing(N, nm,times):
17+
a = np.random.rand(2**N, nm)*100 + 1j*np.random.rand(2**N, nm)*100
18+
dt = []
19+
method_names = ('scipy','mklfft','numpy')
20+
methods = (scifft.ifft,mklfft.ifft,np.fft.ifft)
21+
dt_average = []
22+
for method in methods:
23+
dt = []
24+
for i in range(times):
25+
t = time()
26+
test = method(a.T).T
27+
t = time() - t
28+
29+
dt.append(t)
30+
dt_average.append(np.average(dt))
31+
32+
33+
top = np.argsort(dt_average)
34+
method_sorted = [method_names[i] for i in top]
35+
dt_average_sorted = [dt_average[i] for i in top]
36+
return method_sorted ,dt_average_sorted
37+
38+
39+
def pick(N,nm,times,num_cores):
40+
if num_cores != 1:
41+
a = timing(N, nm, times)[0][0]
42+
else:
43+
a = 'scipy'
44+
45+
if a == 'scipy':
46+
fft, ifft = sfft, isfft
47+
elif a == 'mklfft':
48+
fft, ifft = mfft, imfft
49+
else:
50+
fft, ifft = nfft,infft
51+
print(fft, ifft)
52+
return fft,ifft,a
53+
54+
55+
except ImportError:
56+
#print("You dont have accelerate on this system, defaulting to scipy")
57+
def pick(N,nm,times,num_cores):
58+
59+
fft, ifft = sfft, isfft
60+
61+
return fft, ifft,'scipy'
62+
63+
64+
65+
66+
if __name__ == '__main__':
67+
import matplotlib.pyplot as plt
68+
points = []
69+
start = 100
70+
time1 = []
71+
time2 = []
72+
time3 = []
73+
for i in range(1,start,1):
74+
points.append(i)
75+
a ,b = timing(12,1,i)
76+
time1.append(b[0])
77+
time2.append(b[1])
78+
79+
time3.append(b[2])
80+
names = a
81+
plt.plot(points, time1, label= names[0])
82+
plt.plot(points, time2, label= names[1])
83+
84+
plt.plot(points, time3, label= names[2])
85+
plt.legend()
86+
plt.show()

0 commit comments

Comments
 (0)