Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Dec 13, 2023

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from adophobr December 13, 2023 18:15
Comment on lines +165 to +171
# check that all the pitches are the same!
l = S.asarray([self.multilayer[i].pitch for i in idx])
if S.all(l == l[0]):
return l[0]

else:
# check that all the pitches are the same!
l = S.asarray([self.multilayer[i].pitch for i in idx])
if not S.all(l == l[0]):
raise ValueError("All the BinaryGratings must have the same pitch.")
else:
return l[0]
raise ValueError("All the BinaryGratings must have the same pitch.")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RCWA.get_pitch refactored with the following changes:

Comment on lines -988 to +997
Hs = []
for K, neff, l1, l2 in zip(self.Ks, self.neffs, self.l1s, self.l2s):
Hs.append(
composeTMlist(
[
Line(self.wl, neff, 0.0, neff, l1).TM(wl),
K.TM(wl),
Line(self.wl, neff, 0.0, neff, l2).TM(wl),
]
)
Hs = [
composeTMlist(
[
Line(self.wl, neff, 0.0, neff, l1).TM(wl),
K.TM(wl),
Line(self.wl, neff, 0.0, neff, l2).TM(wl),
]
)
for K, neff, l1, l2 in zip(self.Ks, self.neffs, self.l1s, self.l2s)
]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function NRR.CM refactored with the following changes:

Comment on lines -1333 to -1334
elif (self.w, self.T) == (400, 225):
pf = SWG.pf400_225
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SWG.solve refactored with the following changes:

return numpy.polyval(self.__data, T)
else:
return 0.0
return numpy.polyval(self.__data, T) if self.__data is not None else 0.0
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ThermalOpticCoefficient.TOC refactored with the following changes:

Comment on lines -216 to +213
return self.name + ", isotropic"
return f"{self.name}, isotropic"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function IsotropicMaterial.__str__ refactored with the following changes:

Comment on lines -1182 to +1184
if idxFWHM <= 0:
xFWHM_1 = x[0]
else:
xFWHM_1 = roots[idxFWHM - 1]
if idxFWHM >= len(roots):
xFWHM_2 = x[-1]
else:
xFWHM_2 = roots[idxFWHM]

xFWHM_1 = x[0] if idxFWHM <= 0 else roots[idxFWHM - 1]
xFWHM_2 = x[-1] if idxFWHM >= len(roots) else roots[idxFWHM]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function find_peaks refactored with the following changes:

Comment on lines -1262 to +1254
print("WARNING --- {}".format(s))
print(f"WARNING --- {s}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function warning refactored with the following changes:

Comment on lines -1292 to +1285
if newAmount < self.min:
newAmount = self.min
if newAmount > self.max:
newAmount = self.max
newAmount = max(newAmount, self.min)
newAmount = min(newAmount, self.max)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ProgressBar.updateAmount refactored with the following changes:

eps = numpy.c_[eps[:, 0:1], eps, eps[:, -1:]]
eps = numpy.r_[eps[0:1, :], eps, eps[-1:, :]]
return eps
return numpy.r_[eps[0:1, :], eps, eps[-1:, :]]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SVFDModeSolver._get_eps refactored with the following changes:

Comment on lines -263 to +262
A = coo_matrix((V, (I, J))).tocsr()

return A
return coo_matrix((V, (I, J))).tocsr()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SVFDModeSolver.build_matrix refactored with the following changes:

Comment on lines -289 to +293
tmp = []
for i in idx:
tmp.append(phi[i])

if self.method == "scalar":
self.phi = tmp
elif self.method == "Ex":
tmp = [phi[i] for i in idx]
if self.method == "Ex":
self.Ex = tmp
if self.method == "Ey":
elif self.method == "Ey":
self.Ey = tmp

elif self.method == "scalar":
self.phi = tmp
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SVFDModeSolver.solve refactored with the following changes:

  • Convert for loop into list comprehension (list-comprehension)
  • Simplify conditional into switch-like form [×2] (switch)

Comment on lines -303 to -306
descr = (
"Semi-Vectorial Finite Difference Modesolver\n\tmethod: %s\n" % self.method
return (
"Semi-Vectorial Finite Difference Modesolver\n\tmethod: %s\n"
% self.method
)
return descr
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SVFDModeSolver.__str__ refactored with the following changes:

self.yleft,
self.yright,
)
return f"xleft = {self.xleft}, xright = {self.xright}, yleft = {self.yleft}, yright = {self.yright}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Boundary.__str__ refactored with the following changes:

Comment on lines -292 to +288
if x_ is None:
x = self.get_x()
else:
x = numpy.atleast_1d(x_)
if y_ is None:
y = self.get_y()
else:
y = numpy.atleast_1d(y_)

x = self.get_x() if x_ is None else numpy.atleast_1d(x_)
y = self.get_y() if y_ is None else numpy.atleast_1d(y_)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FMMMode2d.eval refactored with the following changes:

Comment on lines -504 to +492
cSz = 0.5 * (Ex * numpy.conj(cBy) - Ey * numpy.conj(cBx))
return cSz
return 0.5 * (Ex * numpy.conj(cBy) - Ey * numpy.conj(cBx))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FMMMode2d.intensity refactored with the following changes:

Comment on lines -1210 to +1205
if k:
GaAs = GaAs_interp(wl, k=True)
AlAs = AlAs_interp(wl, k=True)
return GaAs - (GaAs - AlAs) * x
else:
if not k:
return GaAs_interp(wl) - (GaAs_interp(wl) - AlAs_interp(wl)) * x
GaAs = GaAs_interp(wl, k=True)
AlAs = AlAs_interp(wl, k=True)
return GaAs - (GaAs - AlAs) * x
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AlGaAs_interp refactored with the following changes:

Comment on lines -128 to +129
f = open(filename, "w")
f.write(self.__str__())
f.close()
with open(filename, "w") as f:
f.write(self.__str__())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Input.tofile refactored with the following changes:

data = field
pylab.plot(self.t, data)
data = 20 * numpy.log10(1e-20 + numpy.abs(field)) if logplot else field
pylab.plot(self.t, data)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TimeSensor.__plot_field refactored with the following changes:

Comment on lines -269 to +270
os.system(
"scp -C bollalo001@pico:" + remote_dir + "/" + input_file + " " + directory
)
os.system(f"scp -C bollalo001@pico:{remote_dir}/{input_file} {directory}")
# param file
os.system(
"scp -C bollalo001@pico:" + remote_dir + "/" + param_file + " " + directory
)
os.system(f"scp -C bollalo001@pico:{remote_dir}/{param_file} {directory}")
# fieldslices, flux and time sensors
os.system(
"scp -C bollalo001@pico:" + remote_dir + "/[EHeh]*_*" + " " + directory
)
os.system(f"scp -C bollalo001@pico:{remote_dir}/[EHeh]*_* {directory}")
# dielslices
os.system("scp -C bollalo001@pico:" + remote_dir + "/diel*" + " " + directory)
os.system(f"scp -C bollalo001@pico:{remote_dir}/diel* {directory}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FDTD.fetch_data refactored with the following changes:

Comment on lines -287 to +278
os.system("scp -C" + directory + input_file + " bollalo001@pico:" + remote_dir)
os.system(f"scp -C{directory}{input_file} bollalo001@pico:{remote_dir}")
# .dat modesolver's files
os.system("scp -C" + directory + "*.dat bollalo001@pico:" + remote_dir)
os.system(f"scp -C{directory}*.dat bollalo001@pico:{remote_dir}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FDTD.put_data refactored with the following changes:

Comment on lines -339 to +385
for i in range(ndielslices):
inp.dielslices.append(
numpy.fromstring(strip_comment(f.readline()), sep=" ")
)

inp.dielslices.extend(
numpy.fromstring(strip_comment(f.readline()), sep=" ")
for _ in range(ndielslices)
)
# fieldslices
nfieldslices = numpy.fromstring(strip_comment(f.readline()), sep=" ")
inp.fieldslices = []
for i in range(nfieldslices):
inp.fieldslices.append(
numpy.fromstring(strip_comment(f.readline()), sep=" ")
)

inp.fieldslices.extend(
numpy.fromstring(strip_comment(f.readline()), sep=" ")
for _ in range(nfieldslices)
)
# dielobjs
(ndielobjs, inp.bgrix, inp.bgsigma) = numpy.fromstring(
strip_comment(f.readline()), sep=" "
)
inp.dielobjs = []
for i in range(int(ndielobjs)):
inp.dielobjs.append(
(strip_comment(f.readline()), strip_comment(f.readline()))
)
inp.dielobjs.extend(
(strip_comment(f.readline()), strip_comment(f.readline()))
for _ in range(int(ndielobjs))
)
inp.smoothing_method = numpy.fromstring(strip_comment(f.readline()), sep=" ")

# sources
nsources = numpy.fromstring(strip_comment(f.readline()), dtype=int, sep=" ")
inp.sources = []
# (inp.time_dependence, inp.wls, inp.pwidth, inp.shift) = numpy.fromstring(strip_comment(f.readline()), sep = ' ')
for i in range(nsources):
inp.sources.append(
(
strip_comment(f.readline()),
strip_comment(f.readline()),
strip_comment(f.readline()),
strip_comment(f.readline()),
)
inp.sources.extend(
(
strip_comment(f.readline()),
strip_comment(f.readline()),
strip_comment(f.readline()),
strip_comment(f.readline()),
)

for _ in range(nsources)
)
# dft monitors
(inp.lambdamin, inp.lambdamax, inp.dlambda) = numpy.fromstring(
strip_comment(f.readline()), sep=" "
)
ndftmonitors = numpy.fromstring(strip_comment(f.readline()), dtype=int, sep=" ")
inp.dftmonitors = []
for i in range(ndftmonitors):
inp.dftmonitors.append(
(
numpy.fromstring(strip_comment(f.readline()), sep=" "),
numpy.fromstring(strip_comment(f.readline()), sep=" "),
)
inp.dftmonitors.extend(
(
numpy.fromstring(strip_comment(f.readline()), sep=" "),
numpy.fromstring(strip_comment(f.readline()), sep=" "),
)

for _ in range(ndftmonitors)
)
# time monitors
ntimemonitors = numpy.fromstring(strip_comment(f.readline()), sep=" ")
inp.timemonitors_time_interval = numpy.fromstring(
strip_comment(f.readline()), sep=" "
)
inp.timemonitors = []
for i in range(ntimemonitors):
inp.timemonitors.append(
numpy.fromstring(strip_comment(f.readline()), sep=" ")
)

inp.timemonitors.extend(
numpy.fromstring(strip_comment(f.readline()), sep=" ")
for _ in range(ntimemonitors)
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FDTD.load_input_file refactored with the following changes:

Comment on lines -414 to +398
param.dx, param.dy, param.dz, param.dt = data[0:4]
param.dx, param.dy, param.dz, param.dt = data[:4]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FDTD.load_param refactored with the following changes:

Comment on lines -470 to +457
tmp.E1 = tmp.E1[0::2] + 1j * tmp.E1[1::2]
tmp.H1 = tmp.H1[0::2] + 1j * tmp.H1[1::2]
tmp.E2 = tmp.E2[0::2] + 1j * tmp.E2[1::2]
tmp.H2 = tmp.H2[0::2] + 1j * tmp.H2[1::2]
tmp.E1 = tmp.E1[::2] + 1j * tmp.E1[1::2]
tmp.H1 = tmp.H1[::2] + 1j * tmp.H1[1::2]
tmp.E2 = tmp.E2[::2] + 1j * tmp.E2[1::2]
tmp.H2 = tmp.H2[::2] + 1j * tmp.H2[1::2]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FDTD.load_sensors refactored with the following changes:

Comment on lines -552 to +537
pylab.xlabel(x1label + " /um")
pylab.ylabel(x2label + " /um")
pylab.xlabel(f"{x1label} /um")
pylab.ylabel(f"{x2label} /um")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FDTD.viz2D refactored with the following changes:

Comment on lines -649 to +633
cmd = 'ssh pico "' + cmd + '"'
cmd = f'ssh pico "{cmd}"'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FDTD.run refactored with the following changes:

Comment on lines -678 to +662
if idx != -1:
return line[:idx].strip()
return line
return line[:idx].strip() if idx != -1 else line
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function strip_comment refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant