Skip to content

Commit

Permalink
first public appearance of the repository
Browse files Browse the repository at this point in the history
  • Loading branch information
ibegleris committed Sep 25, 2017
1 parent 82115c8 commit 015f81a
Show file tree
Hide file tree
Showing 32 changed files with 3,476 additions and 0 deletions.
1,011 changes: 1,011 additions & 0 deletions Conversion_efficiency_post_proc.ipynb

Large diffs are not rendered by default.

747 changes: 747 additions & 0 deletions Conversion_efficiency_post_proc.py

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SM-FOPO

The repository holds the model of a unidirectional single mode FOPO based upon the system shown in.
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.

<p align="center">
<img src="https://github.com/ibegleris/strict-SM-FOPO/blob/master/build_data/FOPO.jpg">
</p>
2 changes: 2 additions & 0 deletions build_data/.conda_intel
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
channels:
- intel
2 changes: 2 additions & 0 deletions build_data/.condarc_default
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
channels:
- defaults
2 changes: 2 additions & 0 deletions build_data/.condarc_intel
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
channels:
-defaults
Binary file added build_data/FOPO.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions build_intall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
bash miniconda.sh -b -p $HOME/miniconda
rm minconda.sh
export PATH="$HOME/miniconda/bin:$PATH"
hash -r
conda config --set always_yes yes --set changeps1 no
conda update conda -y
conda config --add channels intel
conda create -n intel intelpython3_core python=3
source activate intel
conda install cython numpy scipy matplotlib pandas h5py pytables jupyter joblib numba pytest nose -y
source deactivate
rm -rf ../.condarc
mv build_data/.condarc_default ../.condarc
mv build_data/.condarc_default ~/miniconda/envs/intel/.condarc
conda update conda -y
conda install numpy scipy matplotlib jupyter pandas h5py pytables jupyter numba pytest nose -y
conda install python=3.6 -y
if [ "$1" != 'cluster' ]; then
sudo apt-get update
sudo apt-get install mpich -y
fi
echo 'export PATH="/home/$USER/miniconda/bin:$PATH"' >> ~/.bashrc
source activate intel
git clone https://github.com/mpi4py/mpi4py.git
cd mpi4py
python setup.py build
python setup.py install
cd ..
rm -rf mpi4py
pytest unittesting_scripts.py
194 changes: 194 additions & 0 deletions data_plotters_animators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import os
from scipy.constants import c
import h5py

def w2dbm(W, floor=-100):
"""This function converts a power given in W to a power given in dBm.
Inputs::
W(float): power in units of W
Returns::
Power in units of dBm(float)
"""
if type(W) != np.ndarray:
if W > 0:
return 10. * np.log10(W) + 30
elif W == 0:
return floor
else:
print(W)
raise(ZeroDivisionError)
a = 10. * (np.ma.log10(W)).filled(floor/10-3) + 30
return a

plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
plt.gca().get_xaxis().get_major_formatter().set_useOffset(False)


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):
#u, U = np.reshape(u,(np.shape(u)[-1], np.shape(u)[0])), np.reshape(u,(np.shape(U)[-1], np.shape(U)[0]))
if plots == True:
fig = plt.figure(figsize=(20.0, 10.0))

plt.plot(1e-3*c/sim_wind.fv,
w2dbm(np.abs(U[:,which])**2), '-*')
#plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
#plt.gca().get_xaxis().get_major_formatter().set_useOffset(False)
plt.xlabel(r'$\lambda (nm)$', fontsize=18)
plt.ylabel(r'$Spectrum (a.u.)$', fontsize=18)
plt.ylim([-80, 100])
plt.xlim([np.min(sim_wind.lv), np.max(sim_wind.lv)])
plt.xlim([900, 1250])
plt.title(title)
plt.grid()
if type(im) != int:
newax = fig.add_axes([0.8, 0.8, 0.2, 0.2], anchor='NE')
newax.imshow(im)
newax.axis('off')
if filename == None:
plt.show()
else:
plt.savefig('output'+pump_wave+'/output'+str(index)+'/figures/wavelength/'+filename, bbox_inched='tight')

plt.close(fig)

fig = plt.figure(figsize=(20.0, 10.0))
plt.plot(sim_wind.fv, w2dbm(np.abs(U[:,which])**2), '-*')
#plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
#plt.gca().get_xaxis().get_major_formatter().set_useOffset(False)
plt.xlabel(r'$f (THz)$', fontsize=18)
plt.ylabel(r'$Spectrum (a.u.)$', fontsize=18)
#plt.xlim([np.min(sim_wind.fv), np.max(sim_wind.fv)])
plt.ylim([-20, 120])
#plt.xlim(270,300)
plt.title(str(f_p)+' ' +str(f_s))
plt.grid()
if type(im) != int:
newax = fig.add_axes([0.8, 0.8, 0.2, 0.2], anchor='NE')
newax.imshow(im)
newax.axis('off')
if filename == None:
plt.show()
else:
plt.savefig('output'+pump_wave+'/output'+str(index)+'/figures/freequency/'+filename, bbox_inched='tight')
plt.close(fig)

fig = plt.figure(figsize=(20.0, 10.0))

plt.plot(sim_wind.t,np.abs(u[:, which])**2, '*-')
#plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
plt.title('time space')
#plt.ylim([0, 160])
plt.grid()
plt.xlabel(r'$t(ps)$')
plt.ylabel(r'$Spectrum$')
if type(im) != int:
newax = fig.add_axes([0.8, 0.8, 0.2, 0.2], anchor='NE')
newax.imshow(im)
newax.axis('off')

if filename == None:
plt.show()
else:

plt.savefig('output'+pump_wave+'/output'+str(index)+'/figures/time/'+filename)
plt.close(fig)


if filename is not(None):
if filename[:4] != 'port':
layer = filename[-1]+'/'+filename[:-1]
else:
layer = filename
try:

save_variables('data_large', layer, filepath='output'+pump_wave+'/output'+str(index)+'/data/', U = U[:,which], t=sim_wind.t, u=u[:,which],
fv=sim_wind.fv, lv=sim_wind.lv,
which=which, nm=nm, P0_p=P0_p, P0_s=P0_s, f_p=f_p, f_s=f_s, ro = ro)
except RuntimeError:
os.system('rm output'+pump_wave+'/output'+str(index)+'/data/data_large.hdf5')
save_variables('data_large', layer, filepath='output'+pump_wave+'/output'+str(index)+'/data/', U=U[:,which], t=sim_wind.t, u=u[:,which],
fv=sim_wind.fv, lv=sim_wind.lv,
which=which, nm=nm, P0_p=P0_p, P0_s=P0_s, f_p=f_p, f_s=f_s, ro = ro)
pass

return 0


def plotter_dbm_load():
# class sim_window(object):
plotter_dbm(nm, sim_wind, Uabs, u, which)
return None



def animator_pdf_maker(rounds, pump_index):
"""
Creates the animation and pdf of the FOPO at different parts of the FOPO
using convert from imagemagic. Also removes the pngs so be carefull
"""
print("making pdf's and animations.")
space = ('wavelength', 'freequency', 'time')
for sp in space:
file_loc = 'output/output'+str(pump_index)+'/figures/'+sp+'/'
strings_large = ['convert '+file_loc+'00.png ']
for i in range(4):
strings_large.append('convert ')
for ro in range(rounds):
for i in range(4):
strings_large[i+1] += file_loc+str(ro)+str(i+1)+'.png '
for w in range(1, 4):
if i == 5:
break
strings_large[0] += file_loc+str(ro)+str(w)+'.png '
for i in range(4):
os.system(strings_large[i]+file_loc+str(i)+'.pdf')

file_loca = file_loc+'portA/'
file_locb = file_loc+'portB/'
string_porta = 'convert '
string_portb = 'convert '
for i in range(rounds):
string_porta += file_loca + str(i) + '.png '
string_portb += file_locb + str(i) + '.png '

string_porta += file_loca+'porta.pdf '
string_portb += file_locb+'portb.pdf '
os.system(string_porta)
os.system(string_portb)

for i in range(4):
os.system(
'convert -delay 30 '+file_loc+str(i)+'.pdf '+file_loc+str(i)+'.mp4')
os.system('convert -delay 30 ' + file_loca +
'porta.pdf ' + file_loca+'porta.mp4 ')
os.system('convert -delay 30 ' + file_locb +
'portb.pdf ' + file_locb+'portb.mp4 ')

for i in (file_loc, file_loca, file_locb):
print('rm ' + i + '*.png')
os.system('rm ' + i + '*.png')
os.system('sleep 5')
return None


def read_variables(filename, layer, filepath=''):
with h5py.File(filepath+str(filename)+'.hdf5', 'r') as f:
D = {}
for i in f.get(layer).keys():
try:
D[str(i)] = f.get(layer + '/' + str(i)).value
except AttributeError:
pass
return D


def save_variables(filename, layers, filepath='', **variables):
with h5py.File(filepath + filename + '.hdf5', 'a') as f:
for i in (variables):
f.create_dataset(layers+'/'+str(i), data=variables[i])
return None
86 changes: 86 additions & 0 deletions fft_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import numpy as np
import scipy.fftpack as scifft
"""
This file was made to test the speed of the fft's before they are used. After
Intel released their own Scipy it became obsulete since intel scipy is always faster
"""
sfft, isfft = scifft.fft, scifft.ifft
nfft,infft = np.fft.fft, np.fft.ifft
from time import time
try:
import accelerate.mkl.fftpack as mklfft
mfft, imfft = mklfft.fft, mklfft.ifft
import accelerate
complex128 = accelerate.numba.complex128
vectorize = accelerate.numba.vectorize
def timing(N, nm,times):
a = np.random.rand(2**N, nm)*100 + 1j*np.random.rand(2**N, nm)*100
dt = []
method_names = ('scipy','mklfft','numpy')
methods = (scifft.ifft,mklfft.ifft,np.fft.ifft)
dt_average = []
for method in methods:
dt = []
for i in range(times):
t = time()
test = method(a.T).T
t = time() - t

dt.append(t)
dt_average.append(np.average(dt))


top = np.argsort(dt_average)
method_sorted = [method_names[i] for i in top]
dt_average_sorted = [dt_average[i] for i in top]
return method_sorted ,dt_average_sorted


def pick(N,nm,times,num_cores):
if num_cores != 1:
a = timing(N, nm, times)[0][0]
else:
a = 'scipy'

if a == 'scipy':
fft, ifft = sfft, isfft
elif a == 'mklfft':
fft, ifft = mfft, imfft
else:
fft, ifft = nfft,infft
print(fft, ifft)
return fft,ifft,a


except ImportError:
#print("You dont have accelerate on this system, defaulting to scipy")
def pick(N,nm,times,num_cores):

fft, ifft = sfft, isfft

return fft, ifft,'scipy'




if __name__ == '__main__':
import matplotlib.pyplot as plt
points = []
start = 100
time1 = []
time2 = []
time3 = []
for i in range(1,start,1):
points.append(i)
a ,b = timing(12,1,i)
time1.append(b[0])
time2.append(b[1])

time3.append(b[2])
names = a
plt.plot(points, time1, label= names[0])
plt.plot(points, time2, label= names[1])

plt.plot(points, time3, label= names[2])
plt.legend()
plt.show()
Loading

0 comments on commit 015f81a

Please sign in to comment.