Skip to content

Commit

Permalink
Ruff format fixes
Browse files Browse the repository at this point in the history
"ruff format"
  • Loading branch information
lukasc-ubc committed Jul 29, 2024
1 parent 8b637c3 commit 1525cd1
Show file tree
Hide file tree
Showing 107 changed files with 22,964 additions and 16,426 deletions.
77 changes: 41 additions & 36 deletions klayout/EBeam/CDC_SM/MATLAB/matlabenginestart.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import time
import math
import numpy as np
#import matplotlib.pyplot as plt
# import matplotlib.pyplot as plt

#%% Parse data files
# %% Parse data files
os.chdir("C:/Users/Mustafa/Desktop")

contraDC_params_file = open("contraDC_params","r")
contraDC_params_file = open("contraDC_params", "r")
contraDC_params = (contraDC_params_file.read()).split(",")
gap = float(contraDC_params[0])
W_1 = float(contraDC_params[1])
Expand All @@ -27,60 +27,65 @@
contraDC_params_file.close()


contraDC_mode_file = open("contraDC_mode","r")
contraDC_mode = (contraDC_mode_file.read()).replace("[","").replace("]","").split(",")
contraDC_mode_file = open("contraDC_mode", "r")
contraDC_mode = (contraDC_mode_file.read()).replace("[", "").replace("]", "").split(",")
n_eff1_fit = [float(contraDC_mode[0]), float(contraDC_mode[1])]
n_eff2_fit = [float(contraDC_mode[2]), float(contraDC_mode[3])]
n_g1_fit = [float(contraDC_mode[4]), float(contraDC_mode[5])]
n_g2_fit = [float(contraDC_mode[6]), float(contraDC_mode[7])]
contraDC_mode_file.close()

contraDC_fdtd_file = open("contraDC_fdtd","r")
contraDC_fdtd = (contraDC_fdtd_file.read()).replace("[","").replace("]","").split(",")
contraDC_fdtd_file = open("contraDC_fdtd", "r")
contraDC_fdtd = (contraDC_fdtd_file.read()).replace("[", "").replace("]", "").split(",")
bandwidth = float(contraDC_fdtd[0])
lambda_0 = float(contraDC_fdtd[1])
contraDC_fdtd_file.close()

#%% Find the coupling coefficient
# %% Find the coupling coefficient

_lambda = np.linspace(1500,1600,10001)*1e-9
_lambda = np.linspace(1500, 1600, 10001) * 1e-9

n_eff1 = n_eff1_fit[0] + n_eff1_fit[1] * _lambda
n_eff2 = n_eff2_fit[0] + n_eff2_fit[1] * _lambda
n_g1 = n_g1_fit[0] + n_g1_fit[1] * _lambda
n_g2 = n_g2_fit[0] + n_g2_fit[1] * _lambda

n_eff1 = n_eff1_fit[0] + n_eff1_fit[1]*_lambda
n_eff2 = n_eff2_fit[0] + n_eff2_fit[1]*_lambda
n_g1 = n_g1_fit[0] + n_g1_fit[1]*_lambda
n_g2 = n_g2_fit[0] + n_g2_fit[1]*_lambda

def find_nearest(a, a0):
"Element in nd array `a` closest to the scalar value `a0`"
idx = np.abs(a - a0).argmin()
return idx


# find _lambda index nearest lambda_0
lambda_index = find_nearest(_lambda,float(lambda_0))
lambda_index = find_nearest(_lambda, float(lambda_0))

kappa = math.pi*((n_g1[lambda_index] + n_g2[lambda_index])/2) *(bandwidth / (lambda_0**2))
print("Contra-directional kappa = " + str(kappa) +"\n\n")
kappa = (
math.pi
* ((n_g1[lambda_index] + n_g2[lambda_index]) / 2)
* (bandwidth / (lambda_0**2))
)
print("Contra-directional kappa = " + str(kappa) + "\n\n")
print("SiEPIC TOOLS: Calling MATLAB engine Python API, please wait . . . \n\n")
#%% Call matlab
# %% Call matlab
if 1:
import matlab.engine as matlab

MATLABengine = matlab.start_matlab()

paath = 'C:/Users/Mustafa/Google Drive/UBC Files/MiNa/Simulations/MATLAB Scripts/CDC Simu/3_Matlab'

MATLABengine.cd(paath,nargout=0)

MATLABengine.workspace['n_eff1_fit1'] = n_eff1_fit[0]
MATLABengine.workspace['n_eff1_fit2'] = n_eff1_fit[1]
MATLABengine.workspace['n_eff2_fit1'] = n_eff2_fit[0]
MATLABengine.workspace['n_eff2_fit2'] = n_eff2_fit[1]
MATLABengine.workspace['contraDC_kappa'] = float(kappa)
MATLABengine.workspace['contraDC_period'] = period
MATLABengine.workspace['contraDC_a'] = float(a)
MATLABengine.workspace['contraDC_N'] = float(N)


MATLABengine.run('GratingPlotter',nargout=0)

time.sleep(10000)

paath = "C:/Users/Mustafa/Google Drive/UBC Files/MiNa/Simulations/MATLAB Scripts/CDC Simu/3_Matlab"

MATLABengine.cd(paath, nargout=0)

MATLABengine.workspace["n_eff1_fit1"] = n_eff1_fit[0]
MATLABengine.workspace["n_eff1_fit2"] = n_eff1_fit[1]
MATLABengine.workspace["n_eff2_fit1"] = n_eff2_fit[0]
MATLABengine.workspace["n_eff2_fit2"] = n_eff2_fit[1]
MATLABengine.workspace["contraDC_kappa"] = float(kappa)
MATLABengine.workspace["contraDC_period"] = period
MATLABengine.workspace["contraDC_a"] = float(a)
MATLABengine.workspace["contraDC_N"] = float(N)

MATLABengine.run("GratingPlotter", nargout=0)

time.sleep(10000)
Loading

0 comments on commit 1525cd1

Please sign in to comment.