Conversation
| # 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.") |
There was a problem hiding this comment.
Function RCWA.get_pitch refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else) - Swap if/else branches (
swap-if-else-branches)
| 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) | ||
| ] |
There was a problem hiding this comment.
Function NRR.CM refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| elif (self.w, self.T) == (400, 225): | ||
| pf = SWG.pf400_225 |
There was a problem hiding this comment.
Function SWG.solve refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if)
| 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 |
There was a problem hiding this comment.
Function ThermalOpticCoefficient.TOC refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| return self.name + ", isotropic" | ||
| return f"{self.name}, isotropic" |
There was a problem hiding this comment.
Function IsotropicMaterial.__str__ refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| 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] |
There was a problem hiding this comment.
Function find_peaks refactored with the following changes:
- Replace if statement with if expression [×3] (
assign-if-exp) - Lift code into else after jump in control flow (
reintroduce-else)
| print("WARNING --- {}".format(s)) | ||
| print(f"WARNING --- {s}") |
There was a problem hiding this comment.
Function warning refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| if newAmount < self.min: | ||
| newAmount = self.min | ||
| if newAmount > self.max: | ||
| newAmount = self.max | ||
| newAmount = max(newAmount, self.min) | ||
| newAmount = min(newAmount, self.max) |
There was a problem hiding this comment.
Function ProgressBar.updateAmount refactored with the following changes:
- Replace comparison with min/max call [×2] (
min-max-identity) - Replace interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation) - Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index) - Remove unnecessary calls to
str()from formatted values in f-strings (remove-str-from-fstring)
| 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:, :]] |
There was a problem hiding this comment.
Function SVFDModeSolver._get_eps refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| A = coo_matrix((V, (I, J))).tocsr() | ||
|
|
||
| return A | ||
| return coo_matrix((V, (I, J))).tocsr() |
There was a problem hiding this comment.
Function SVFDModeSolver.build_matrix refactored with the following changes:
- Simplify conditional into switch-like form (
switch) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| 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 |
There was a problem hiding this comment.
Function SVFDModeSolver.solve refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension) - Simplify conditional into switch-like form [×2] (
switch)
| 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 |
There was a problem hiding this comment.
Function SVFDModeSolver.__str__ refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| self.yleft, | ||
| self.yright, | ||
| ) | ||
| return f"xleft = {self.xleft}, xright = {self.xright}, yleft = {self.yleft}, yright = {self.yright}" |
There was a problem hiding this comment.
Function Boundary.__str__ refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| 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_) |
There was a problem hiding this comment.
Function FMMMode2d.eval refactored with the following changes:
- Replace if statement with if expression [×2] (
assign-if-exp)
| cSz = 0.5 * (Ex * numpy.conj(cBy) - Ey * numpy.conj(cBx)) | ||
| return cSz | ||
| return 0.5 * (Ex * numpy.conj(cBy) - Ey * numpy.conj(cBx)) |
There was a problem hiding this comment.
Function FMMMode2d.intensity refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| 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 |
There was a problem hiding this comment.
Function AlGaAs_interp refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| f = open(filename, "w") | ||
| f.write(self.__str__()) | ||
| f.close() | ||
| with open(filename, "w") as f: | ||
| f.write(self.__str__()) |
There was a problem hiding this comment.
Function Input.tofile refactored with the following changes:
- Use
withwhen opening file to ensure closure (ensure-file-closed)
| 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) |
There was a problem hiding this comment.
Function TimeSensor.__plot_field refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Hoist repeated code outside conditional statement (
hoist-statement-from-if)
| 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}") |
There was a problem hiding this comment.
Function FDTD.fetch_data refactored with the following changes:
- Use f-string instead of string concatenation [×18] (
use-fstring-for-concatenation)
| 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}") |
There was a problem hiding this comment.
Function FDTD.put_data refactored with the following changes:
- Use f-string instead of string concatenation [×7] (
use-fstring-for-concatenation)
| 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) | ||
| ) |
There was a problem hiding this comment.
Function FDTD.load_input_file refactored with the following changes:
- Replace unused for index with underscore [×6] (
for-index-underscore) - Replace a for append loop with list extend [×6] (
for-append-to-extend)
| param.dx, param.dy, param.dz, param.dt = data[0:4] | ||
| param.dx, param.dy, param.dz, param.dt = data[:4] |
There was a problem hiding this comment.
Function FDTD.load_param refactored with the following changes:
- Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index)
| 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] |
There was a problem hiding this comment.
Function FDTD.load_sensors refactored with the following changes:
- Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] [×4] (
remove-redundant-slice-index)
| pylab.xlabel(x1label + " /um") | ||
| pylab.ylabel(x2label + " /um") | ||
| pylab.xlabel(f"{x1label} /um") | ||
| pylab.ylabel(f"{x2label} /um") |
There was a problem hiding this comment.
Function FDTD.viz2D refactored with the following changes:
- Simplify conditional into switch-like form [×2] (
switch) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| cmd = 'ssh pico "' + cmd + '"' | ||
| cmd = f'ssh pico "{cmd}"' |
There was a problem hiding this comment.
Function FDTD.run refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| if idx != -1: | ||
| return line[:idx].strip() | ||
| return line | ||
| return line[:idx].strip() if idx != -1 else line |
There was a problem hiding this comment.
Function strip_comment refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
Branch
masterrefactored 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
masterbranch, then run:Help us improve this pull request!