diff --git a/.style.yapf b/.style.yapf index 1c9f7a913b1e117a75821ef5cd1af9bca2a58ea7..01194835fd81ee6300e82f398503619ffd9e1f04 100644 --- a/.style.yapf +++ b/.style.yapf @@ -1,4 +1,4 @@ [style] based_on_style = pep8 -column_limit = 80 +column_limit = 75 no_spaces_around_selected_binary_operators = "*,/" \ No newline at end of file diff --git a/Doc/FFCatalog/fig/ff2/bornplot.py b/Doc/FFCatalog/fig/ff2/bornplot.py index 27f3c1838a1db6aaa0e14c3e2cbfcd0d760c04eb..a48f916c362bc189a656456588fee108a325b3b1 100644 --- a/Doc/FFCatalog/fig/ff2/bornplot.py +++ b/Doc/FFCatalog/fig/ff2/bornplot.py @@ -19,10 +19,12 @@ class Result: self.data = data self.title = title + def rectangle(det): return (det.axis(0).lowerBound(), det.axis(0).upperBound(), det.axis(1).lowerBound(), det.axis(1).upperBound()) + def make_plot(results, det, name, nrow=1): """ Make a plot consisting of one detector image for each Result in results, @@ -66,13 +68,19 @@ def make_plot(results, det, name, nrow=1): # Plot the subfigures. for res in results: ax = axes[res.idx] - im = ax.imshow(res.data, norm=norm, extent=rectangle(det), aspect=1) + im = ax.imshow(res.data, + norm=norm, + extent=rectangle(det), + aspect=1) ax.set_xlabel(r'$\phi_{\rm f} (^{\circ})$', fontsize=fontsize) if res.idx % ncol == 0: - ax.set_ylabel(r'$\alpha_{\rm f} (^{\circ})$', fontsize=fontsize) + ax.set_ylabel(r'$\alpha_{\rm f} (^{\circ})$', + fontsize=fontsize) if res.title != "": ax.set_title(res.title, fontsize=fontsize) - ax.tick_params(axis='both', which='major', labelsize=fontsize*21/24) + ax.tick_params(axis='both', + which='major', + labelsize=fontsize*21/24) # Adjust whitespace around and between subfigures. plt.subplots_adjust(wspace=xskip, hspace=yskip, diff --git a/Doc/PhysicsManual/fig/drawing/Green.py b/Doc/PhysicsManual/fig/drawing/Green.py index c6ec918e20909f8a2ba3665ccaee7c939c64cd28..e2dd0ffd549719c591a4dca1f17575425a59d4de 100755 --- a/Doc/PhysicsManual/fig/drawing/Green.py +++ b/Doc/PhysicsManual/fig/drawing/Green.py @@ -59,8 +59,8 @@ for P in PP: DeltaPath.append(0) elif inside(y, -T[0], 0) and inside(yold, -T[0], 0): DeltaPath.append(DeltaLayer[0]) - elif inside(y, -T[0] - T[1], -T[0]) and inside(yold, -T[0] - T[1], - -T[0]): + elif inside(y, -T[0] - T[1], -T[0]) and inside( + yold, -T[0] - T[1], -T[0]): DeltaPath.append(DeltaLayer[1]) else: sys.stderr.write("Invalid input => layer ill defined\n") @@ -89,8 +89,10 @@ for P in PP: cmd1 += "st\n" cmd2 += "st\n" len1 = math.sqrt((xtot + x0 - x1)**2 + yd**2) - 8 - cmd1 += "%6.3g %6.3g %7.3g .8 %6.3g pfeiL\n" % (x1, y, 180*a0/math.pi, len1) - cmd2 += "%6.3g %6.3g %7.3g .8 %6.3g pfeiL\n" % (x2, y, 180*b0/math.pi, 7) + cmd1 += "%6.3g %6.3g %7.3g .8 %6.3g pfeiL\n" % (x1, y, 180*a0/math.pi, + len1) + cmd2 += "%6.3g %6.3g %7.3g .8 %6.3g pfeiL\n" % (x2, y, 180*b0/math.pi, + 7) cmd1 += "\n" cmd2 += "\n" #/pfeiL { % (arrow anchored at base) x y rot siz len diff --git a/Examples/fit52_Advanced/find_background.py b/Examples/fit52_Advanced/find_background.py index 05fe2b589dcd44e569aafcad15edd652de511550..b14487241e2d657bb92096551ea5b79e2743d2c8 100644 --- a/Examples/fit52_Advanced/find_background.py +++ b/Examples/fit52_Advanced/find_background.py @@ -48,8 +48,7 @@ def get_simulation(params): scale = params["scale"] simulation = ba.GISASSimulation() - simulation.setDetectorParameters(100, -1*deg, 1*deg, 100, 0, - 2*deg) + simulation.setDetectorParameters(100, -1*deg, 1*deg, 100, 0, 2*deg) simulation.setBeamParameters(1*angstrom, 0.2*deg, 0) simulation.beam().setIntensity(1e12*scale) simulation.setBackground(ba.ConstantBackground(background)) diff --git a/Examples/fit52_Advanced/fit_along_slices.py b/Examples/fit52_Advanced/fit_along_slices.py index 78242d985812101a164f3c50ec86eb6a2d99fb03..373f64ff46482bd01ebc77b1b16af3c808bbed12 100644 --- a/Examples/fit52_Advanced/fit_along_slices.py +++ b/Examples/fit52_Advanced/fit_along_slices.py @@ -43,8 +43,7 @@ def get_simulation(params, add_masks=True): Create and return GISAXS simulation with beam and detector defined """ simulation = ba.GISASSimulation() - simulation.setDetectorParameters(100, -1*deg, 1*deg, 100, 0, - 2*deg) + simulation.setDetectorParameters(100, -1*deg, 1*deg, 100, 0, 2*deg) simulation.setBeamParameters(1*angstrom, 0.2*deg, 0) simulation.beam().setIntensity(1e+08) simulation.setSample(get_sample(params)) @@ -115,7 +114,9 @@ class PlotObserver: """ plt.subplots_adjust(wspace=0.2, hspace=0.3) for label, slice in slices: - plt.semilogy(slice.binCenters(), slice.binValues(), label=label) + plt.semilogy(slice.binCenters(), + slice.binValues(), + label=label) plt.xlim(slice.getXmin(), slice.getXmax()) plt.ylim(1, slice.getMaximum()*10) plt.legend(loc='upper right') @@ -132,13 +133,14 @@ class PlotObserver: iteration_info = fit_objective.iterationInfo() plt.text( - 0.01, 0.85, - "Iterations " + '{:d}'.format(iteration_info.iterationCount())) + 0.01, 0.85, "Iterations " + + '{:d}'.format(iteration_info.iterationCount())) plt.text(0.01, 0.75, "Chi2 " + '{:8.4f}'.format(iteration_info.chi2())) for index, params in enumerate(iteration_info.parameters()): - plt.text(0.01, 0.55 - index*0.1, - '{:30.30s}: {:6.3f}'.format(params.name(), params.value)) + plt.text( + 0.01, 0.55 - index*0.1, + '{:30.30s}: {:6.3f}'.format(params.name(), params.value)) plt.tight_layout() plt.draw() @@ -168,7 +170,8 @@ class PlotObserver: # vertical slices slices = [("real", real_data.projectionY(phi_slice_value)), ("simul", simul_data.projectionY(phi_slice_value))] - title = "Vertical slice at phi =" + '{:3.1f}'.format(phi_slice_value) + title = "Vertical slice at phi =" + '{:3.1f}'.format( + phi_slice_value) plt.subplot(2, 2, 3) self.plot_slices(slices, title) diff --git a/Examples/fit52_Advanced/fit_with_masks.py b/Examples/fit52_Advanced/fit_with_masks.py index b8191e23801caebd3a55fe074aa09f5b76f08067..c9ec3794b9ffb3b0aeaa0f1c2823ed1e1ec53655 100644 --- a/Examples/fit52_Advanced/fit_with_masks.py +++ b/Examples/fit52_Advanced/fit_with_masks.py @@ -42,8 +42,7 @@ def get_simulation(params, add_masks=True): Create and return GISAXS simulation with beam and detector defined """ simulation = ba.GISASSimulation() - simulation.setDetectorParameters(100, -1*deg, 1*deg, 100, 0, - 2*deg) + simulation.setDetectorParameters(100, -1*deg, 1*deg, 100, 0, 2*deg) simulation.setBeamParameters(1*angstrom, 0.2*deg, 0) simulation.beam().setIntensity(1e+08) simulation.setSample(get_sample(params)) @@ -93,7 +92,8 @@ def add_mask_to_simulation(simulation): simulation.addMask(ba.Ellipse(0, 1*deg, 0.5*deg, 0.5*deg), False) # set mask for pacman's eye - simulation.addMask(ba.Ellipse(0.11*deg, 1.25*deg, 0.05*deg, 0.05*deg), True) + simulation.addMask(ba.Ellipse(0.11*deg, 1.25*deg, 0.05*deg, 0.05*deg), + True) # set mask for pacman's mouth points = [[0*deg, 1*deg], [0.5*deg, 1.2*deg], [0.5*deg, 0.8*deg], @@ -101,12 +101,12 @@ def add_mask_to_simulation(simulation): simulation.addMask(ba.Polygon(points), True) # giving pacman something to eat - simulation.addMask(ba.Rectangle(0.45*deg, 0.95*deg, 0.55*deg, 1.05*deg), - False) - simulation.addMask(ba.Rectangle(0.61*deg, 0.95*deg, 0.71*deg, 1.05*deg), - False) - simulation.addMask(ba.Rectangle(0.75*deg, 0.95*deg, 0.85*deg, 1.05*deg), - False) + simulation.addMask( + ba.Rectangle(0.45*deg, 0.95*deg, 0.55*deg, 1.05*deg), False) + simulation.addMask( + ba.Rectangle(0.61*deg, 0.95*deg, 0.71*deg, 1.05*deg), False) + simulation.addMask( + ba.Rectangle(0.75*deg, 0.95*deg, 0.85*deg, 1.05*deg), False) def run_fitting(): diff --git a/Examples/fit52_Advanced/multiple_datasets.py b/Examples/fit52_Advanced/multiple_datasets.py index 7180fce19a56bf0118e1cee93d736bcebd72db8c..1d73f5e95c4351473038fe87c7f7d4dceb1c11ce 100644 --- a/Examples/fit52_Advanced/multiple_datasets.py +++ b/Examples/fit52_Advanced/multiple_datasets.py @@ -45,8 +45,7 @@ def get_simulation(params): incident_angle = params["incident_angle"] simulation = ba.GISASSimulation() - simulation.setDetectorParameters(50, -1.5*deg, 1.5*deg, 50, 0, - 2*deg) + simulation.setDetectorParameters(50, -1.5*deg, 1.5*deg, 50, 0, 2*deg) simulation.setBeamParameters(1*angstrom, incident_angle, 0) simulation.beam().setIntensity(1e+08) simulation.setSample(get_sample(params)) @@ -110,13 +109,15 @@ class PlotObserver(): plt.subplot(canvas[i_dataset*3]) ba.plot_colormap(real_data, - title="\"Real\" data - #" + str(i_dataset + 1), + title="\"Real\" data - #" + + str(i_dataset + 1), zmin=1, zmax=zmax, zlabel="") plt.subplot(canvas[1 + i_dataset*3]) ba.plot_colormap(simul_data, - title="Simulated data - #" + str(i_dataset + 1), + title="Simulated data - #" + + str(i_dataset + 1), zmin=1, zmax=zmax, zlabel="") @@ -138,13 +139,14 @@ class PlotObserver(): iteration_info = fit_objective.iterationInfo() plt.text( - 0.01, 0.85, - "Iterations " + '{:d}'.format(iteration_info.iterationCount())) + 0.01, 0.85, "Iterations " + + '{:d}'.format(iteration_info.iterationCount())) plt.text(0.01, 0.75, "Chi2 " + '{:8.4f}'.format(iteration_info.chi2())) for index, params in enumerate(iteration_info.parameters()): - plt.text(0.01, 0.55 - index*0.1, - '{:30.30s}: {:6.3f}'.format(params.name(), params.value)) + plt.text( + 0.01, 0.55 - index*0.1, + '{:30.30s}: {:6.3f}'.format(params.name(), params.value)) @staticmethod def plot_fit_parameters(fit_objective): @@ -156,13 +158,14 @@ class PlotObserver(): iteration_info = fit_objective.iterationInfo() plt.text( - 0.01, 0.95, - "Iterations " + '{:d}'.format(iteration_info.iterationCount())) + 0.01, 0.95, "Iterations " + + '{:d}'.format(iteration_info.iterationCount())) plt.text(0.01, 0.70, "Chi2 " + '{:8.4f}'.format(iteration_info.chi2())) for index, params in enumerate(iteration_info.parameters()): - plt.text(0.01, 0.30 - index*0.3, - '{:30.30s}: {:6.3f}'.format(params.name(), params.value)) + plt.text( + 0.01, 0.30 - index*0.3, + '{:30.30s}: {:6.3f}'.format(params.name(), params.value)) def update(self, fit_objective): self.fig.clf() diff --git a/Examples/fit53_CustomObjective/custom_objective_function.py b/Examples/fit53_CustomObjective/custom_objective_function.py index 35179a58aec1040b30283e562b4a1df221976755..fdd53ac2324eb93f8b3d86bdb7f3fc38487b8f34 100644 --- a/Examples/fit53_CustomObjective/custom_objective_function.py +++ b/Examples/fit53_CustomObjective/custom_objective_function.py @@ -73,8 +73,7 @@ def get_simulation(params): Create and return GISAXS simulation with beam and detector defined. """ simulation = ba.GISASSimulation() - simulation.setDetectorParameters(100, -1*deg, 1*deg, 100, 0, - 2*deg) + simulation.setDetectorParameters(100, -1*deg, 1*deg, 100, 0, 2*deg) simulation.setBeamParameters(1*angstrom, 0.2*deg, 0) simulation.beam().setIntensity(1e+08) simulation.setSample(get_sample(params)) diff --git a/Examples/fit54_ExternalMinimizer/lmfit_basics.py b/Examples/fit54_ExternalMinimizer/lmfit_basics.py index 3a4c3a13f857e55af2b9bed6928f158754e6c8d0..db43da508518f774c6af3479b7b3682e5e6de0e4 100644 --- a/Examples/fit54_ExternalMinimizer/lmfit_basics.py +++ b/Examples/fit54_ExternalMinimizer/lmfit_basics.py @@ -47,8 +47,7 @@ def get_simulation(params): Create and return GISAXS simulation with beam and detector defined """ simulation = ba.GISASSimulation() - simulation.setDetectorParameters(100, -1*deg, 1*deg, 100, 0, - 2*deg) + simulation.setDetectorParameters(100, -1*deg, 1*deg, 100, 0, 2*deg) simulation.setBeamParameters(1*angstrom, 0.2*deg, 0) simulation.beam().setIntensity(1e+08) simulation.setSample(get_sample(params)) diff --git a/Examples/fit54_ExternalMinimizer/lmfit_with_plotting.py b/Examples/fit54_ExternalMinimizer/lmfit_with_plotting.py index 73d680d14af5aa2028d4a9f716c3a89d0074ba5b..a68e67899c9c03a5d0413732378e5f0c8642f951 100644 --- a/Examples/fit54_ExternalMinimizer/lmfit_with_plotting.py +++ b/Examples/fit54_ExternalMinimizer/lmfit_with_plotting.py @@ -48,8 +48,7 @@ def get_simulation(params): Create and return GISAXS simulation with beam and detector defined """ simulation = ba.GISASSimulation() - simulation.setDetectorParameters(100, -1*deg, 1*deg, 100, 0, - 2*deg) + simulation.setDetectorParameters(100, -1*deg, 1*deg, 100, 0, 2*deg) simulation.setBeamParameters(1*angstrom, 0.2*deg, 0) simulation.beam().setIntensity(1e+08) simulation.setSample(get_sample(params)) diff --git a/Examples/fit55_SpecularIntro/FitSpecularBasics.py b/Examples/fit55_SpecularIntro/FitSpecularBasics.py index 0d4f94f7e7856359bfa0d704d3b96758c0972fd8..54bb986cd05abb9167c02904b1db08538416ab2f 100644 --- a/Examples/fit55_SpecularIntro/FitSpecularBasics.py +++ b/Examples/fit55_SpecularIntro/FitSpecularBasics.py @@ -63,7 +63,8 @@ def get_real_data(): """ if not hasattr(get_real_data, "data"): filename = "genx_interchanging_layers.dat.gz" - filepath = path.join(path.dirname(path.realpath(__file__)), filename) + filepath = path.join(path.dirname(path.realpath(__file__)), + filename) real_data = np.loadtxt(filepath, usecols=(0, 1), skiprows=3) # translating axis values from double incident angle (degs) diff --git a/Examples/fit55_SpecularIntro/FitWithUncertainties.py b/Examples/fit55_SpecularIntro/FitWithUncertainties.py index 4d3142f2752bc415da01d1c16cea2e31f4347324..186bf12ccaa459ddf2fcdaf3e595f506ef69feba 100644 --- a/Examples/fit55_SpecularIntro/FitWithUncertainties.py +++ b/Examples/fit55_SpecularIntro/FitWithUncertainties.py @@ -67,7 +67,8 @@ def get_real_data(): """ if not hasattr(get_real_data, "data"): filename = "genx_interchanging_layers.dat.gz" - filepath = path.join(path.dirname(path.realpath(__file__)), filename) + filepath = path.join(path.dirname(path.realpath(__file__)), + filename) real_data = np.loadtxt(filepath, usecols=(0, 1), skiprows=3) # translating axis values from double incident angle (degs) @@ -117,7 +118,8 @@ def run_fitting(): uncertainties = real_data*0.5 fit_objective = ba.FitObjective() - fit_objective.addSimulationAndData(get_simulation, real_data, uncertainties) + fit_objective.addSimulationAndData(get_simulation, real_data, + uncertainties) plot_observer = ba_fitmonitor.PlotterSpecular(units=ba.Axes.RQ4) fit_objective.initPrint(10) diff --git a/Examples/fit55_SpecularIntro/PolarizedSpinAsymmetryFit.py b/Examples/fit55_SpecularIntro/PolarizedSpinAsymmetryFit.py index 4f60c1f3e5a9f4c28940cf32073ff50c995f278d..66330a72344f513f5040d4b36635cb0f89015f5c 100644 --- a/Examples/fit55_SpecularIntro/PolarizedSpinAsymmetryFit.py +++ b/Examples/fit55_SpecularIntro/PolarizedSpinAsymmetryFit.py @@ -53,8 +53,8 @@ def get_sample(params): magnetizationMagnitude*numpy.cos(angle*deg), 0) mat_vacuum = ba.MaterialBySLD("Vacuum", 0, 0) - mat_layer = ba.MaterialBySLD("(Mg,Al,Fe)3O4", params["rho_Mafo"]*1e-6, 0, - magnetizationVector) + mat_layer = ba.MaterialBySLD("(Mg,Al,Fe)3O4", params["rho_Mafo"]*1e-6, + 0, magnetizationVector) mat_substrate = ba.MaterialBySLD("MgAl2O4", *sldMao) ambient_layer = ba.Layer(mat_vacuum) @@ -174,7 +174,8 @@ def plotSpinAsymmetry(data_pp, data_mm, q, r_pp, r_mm, filename): fig = plt.figure() ax = fig.add_subplot(111) - ax.errorbar(data_pp[0], (data_pp[1] - data_mm[1])/(data_pp[1] + data_mm[1]), + ax.errorbar(data_pp[0], + (data_pp[1] - data_mm[1])/(data_pp[1] + data_mm[1]), xerr=data_pp[3], yerr=delta, fmt='.', @@ -232,7 +233,8 @@ def get_Experimental_data(qmin, qmax): data_pp = normalizeData(input_Data[0]) data_mm = normalizeData(input_Data[1]) - return (filterData(data_pp, qmin, qmax), filterData(data_mm, qmin, qmax)) + return (filterData(data_pp, qmin, + qmax), filterData(data_mm, qmin, qmax)) def downloadAndExtractData(): @@ -248,11 +250,11 @@ def downloadAndExtractData(): rawdata = zipfile.open("MAFO_Saturated.refl").read().decode("utf-8") table_pp = match( - r'.*# "polarization": "\+\+"\n#.*?\n# "units".*?\n(.*?)#.*', rawdata, - DOTALL).group(1) + r'.*# "polarization": "\+\+"\n#.*?\n# "units".*?\n(.*?)#.*', + rawdata, DOTALL).group(1) table_mm = match( - r'.*# "polarization": "\-\-"\n#.*?\n# "units".*?\n(.*?)#.*', rawdata, - DOTALL).group(1) + r'.*# "polarization": "\-\-"\n#.*?\n# "units".*?\n(.*?)#.*', + rawdata, DOTALL).group(1) data_pp = numpy.genfromtxt(BytesIO(table_pp.encode()), unpack=True) data_mm = numpy.genfromtxt(BytesIO(table_mm.encode()), unpack=True) @@ -265,7 +267,8 @@ def downloadAndExtractData(): #################################################################### -def run_fit_ba(q_axis, r_data, r_uncertainty, simulationFactory, startParams): +def run_fit_ba(q_axis, r_data, r_uncertainty, simulationFactory, + startParams): fit_objective = ba.FitObjective() fit_objective.setObjectiveMetric("chi2") @@ -368,8 +371,8 @@ if __name__ == '__main__': q_pp, r_pp = qr(run_Simulation_pp(qzs, fitResult)) q_mm, r_mm = qr(run_Simulation_mm(qzs, fitResult)) - plot([q_pp, q_mm], [r_pp, r_mm], [data_pp, data_mm], ["$++$", "$--$"], - f'MAFO_Saturated_fit.pdf') + plot([q_pp, q_mm], [r_pp, r_mm], [data_pp, data_mm], + ["$++$", "$--$"], f'MAFO_Saturated_fit.pdf') plotSpinAsymmetry(data_pp, data_mm, qzs, r_pp, r_mm, "MAFO_Saturated_spin_asymmetry_fit.pdf") diff --git a/Examples/fit55_SpecularIntro/RealLifeReflectometryFitting.py b/Examples/fit55_SpecularIntro/RealLifeReflectometryFitting.py index a96af5188c52c2bb4426319d977b56760e83bb61..e1ec8a7bde2d8bae719a97a53a595c2faaf1d499 100644 --- a/Examples/fit55_SpecularIntro/RealLifeReflectometryFitting.py +++ b/Examples/fit55_SpecularIntro/RealLifeReflectometryFitting.py @@ -46,7 +46,8 @@ def get_real_data(filename="mg6a_Merged.txt.gz"): and the third one being weights to restore intensity values from experiment """ if not hasattr(get_real_data, "data"): - filepath = path.join(path.dirname(path.realpath(__file__)), filename) + filepath = path.join(path.dirname(path.realpath(__file__)), + filename) real_data = np.loadtxt(filepath, usecols=(0, 1, 3), skiprows=1) # translating axis values from double incident angle (degs) @@ -111,9 +112,9 @@ def buildSample(arg_dict): """ # defining materials m_vacuum = ba.HomogeneousMaterial("Vacuum", 0, 0) - m_si_o2 = ba.HomogeneousMaterial("SiO2", - 8.57040868e-06*arg_dict["concentration"], - 1.11016654e-07*arg_dict["concentration"]) + m_si_o2 = ba.HomogeneousMaterial( + "SiO2", 8.57040868e-06*arg_dict["concentration"], + 1.11016654e-07*arg_dict["concentration"]) m_si = ba.HomogeneousMaterial("Si", 7.57211137e-06, 1.72728178e-07) # roughness @@ -193,7 +194,8 @@ def objective_fine(args, intensity, footprint_factor, divergence): bin_start = 404 # first bin in the experimental data to calculate bin_end = -1 # last bin in the experimental data to calculate - arg_dict = create_par_dict(intensity, footprint_factor, divergence, *args) + arg_dict = create_par_dict(intensity, footprint_factor, divergence, + *args) sim_result = run_simulation(arg_dict, bin_start, bin_end) sim_data = sim_result.array() @@ -237,7 +239,8 @@ def run_fitting(): preliminary_result.x[2] # beam divergence ) - print("\nStart fitting big incident angle part of experimental data:\n") + print( + "\nStart fitting big incident angle part of experimental data:\n") fine_tuning_result = differential_evolution(objective_fine, bounds, @@ -264,8 +267,8 @@ def plot_result(sim_result, ref_result, bin_start=0, bin_end=-1): plt.semilogy( get_real_data_axis(bin_start, bin_end)*180/np.pi, - get_real_data_values(bin_start, bin_end), sim_result.axis(), sim_data, - ref_result.axis(), ref_data) + get_real_data_values(bin_start, bin_end), sim_result.axis(), + sim_data, ref_result.axis(), ref_data) xlabel = ba.get_axes_labels(sim_result, ba.Axes.DEFAULT)[0] ylabel = "Intensity" diff --git a/Examples/fit56_SpecularAdvanced/Honeycomb_fit.py b/Examples/fit56_SpecularAdvanced/Honeycomb_fit.py index ac1a55b222523ef4a167faf14085ce702b518266..de7bc5854462dc87dc3583fee733dd837b3cc7c6 100644 --- a/Examples/fit56_SpecularAdvanced/Honeycomb_fit.py +++ b/Examples/fit56_SpecularAdvanced/Honeycomb_fit.py @@ -225,9 +225,10 @@ def get_Experimental_data(filename, qmin, qmax): if not hasattr(get_Experimental_data, "zipfile"): get_Experimental_data.zipfile = ZipFile("honeycomb_data.zip") - input_Data = numpy.genfromtxt(get_Experimental_data.zipfile.open(filename), - unpack=True, - usecols=(0, 2, 3)) + input_Data = numpy.genfromtxt( + get_Experimental_data.zipfile.open(filename), + unpack=True, + usecols=(0, 2, 3)) data = normalizeData(input_Data) minIndex = numpy.argmin(numpy.abs(data[0] - qmin)) @@ -270,7 +271,8 @@ class FitObjective: self._parameterNames = parameterNames def __call__(self, *args): - fitParameters = create_Parameter_dictionary(self._parameterNames, *args) + fitParameters = create_Parameter_dictionary(self._parameterNames, + *args) print(f"FitParamters = {fitParameters}") result_metric = 0 @@ -290,7 +292,8 @@ def run_fit_differential_evolution(q_axis, rdata, simulationFactory, parameterNames = [n for n, par in startParams.items()] print(f"Bounds = {bounds}") - objective = FitObjective(q_axis, rdata, simulationFactory, parameterNames) + objective = FitObjective(q_axis, rdata, simulationFactory, + parameterNames) chi2_initial = objective(parameters) @@ -302,7 +305,8 @@ def run_fit_differential_evolution(q_axis, rdata, simulationFactory, disp=True, tol=1e-2) - resultParameters = create_Parameter_dictionary(parameterNames, result.x) + resultParameters = create_Parameter_dictionary(parameterNames, + result.x) chi2_final = objective(resultParameters.values()) print(f"Initial chi2: {chi2_initial}") @@ -405,7 +409,8 @@ if __name__ == '__main__': data_150_p = get_Experimental_data("honeycomb_150_p.dat", qmin, qmax) data_150_m = get_Experimental_data("honeycomb_150_m.dat", qmin, qmax) - plot_sld_profile(paramsInitial, f"Honeycomb_Fit_sld_profile_initial.pdf") + plot_sld_profile(paramsInitial, + f"Honeycomb_Fit_sld_profile_initial.pdf") plot([q_300_p, q_300_m, q_150_p, q_150_m], [r_300_p, r_300_m, r_150_p, r_150_m], [data_300_p, data_300_m, data_150_p, data_150_m], [1, 1, 10, 10], @@ -422,7 +427,8 @@ if __name__ == '__main__': run_Simulation_150_p, run_Simulation_150_m ]] - fitResult = run_fit_differential_evolution(*dataSimTuple, startParams) + fitResult = run_fit_differential_evolution(*dataSimTuple, + startParams) print("Fit Result:") print(fitResult) @@ -435,7 +441,8 @@ if __name__ == '__main__': plot([q_300_p, q_300_m, q_150_p, q_150_m], [r_300_p, r_300_m, r_150_p, r_150_m], - [data_300_p, data_300_m, data_150_p, data_150_m], [1, 1, 10, 10], + [data_300_p, data_300_m, data_150_p, data_150_m], + [1, 1, 10, 10], ["300K $+$", "300K $-$", "150K $+$", "150K $-$"], f"Honeycomb_Fit_reflectivity_fit.pdf") diff --git a/Examples/fit56_SpecularAdvanced/Pt_layer_fit.py b/Examples/fit56_SpecularAdvanced/Pt_layer_fit.py index b2d0232e3f56fd53606968bad9e9cda4ccd03a66..a82dc971a4550e7d84293f51ee010710943065ae 100644 --- a/Examples/fit56_SpecularAdvanced/Pt_layer_fit.py +++ b/Examples/fit56_SpecularAdvanced/Pt_layer_fit.py @@ -171,14 +171,15 @@ def get_Experimental_data(qmin, qmax): #################################################################### -def run_fit_ba(q_axis, r_data, r_uncertainty, simulationFactory, startParams): +def run_fit_ba(q_axis, r_data, r_uncertainty, simulationFactory, + startParams): fit_objective = ba.FitObjective() fit_objective.setObjectiveMetric("chi2") fit_objective.addSimulationAndData( - lambda params: simulationFactory(q_axis, params), r_data, r_uncertainty, - 1) + lambda params: simulationFactory(q_axis, params), r_data, + r_uncertainty, 1) fit_objective.initPrint(10) @@ -247,4 +248,5 @@ if __name__ == '__main__': print(fitResult) q, r = qr(run_simulation(qzs, fitParams=fitResult)) - plot(q, r, data, f'PtLayerFit_fit.pdf', dict(fitResult, **fixedParams)) + plot(q, r, data, f'PtLayerFit_fit.pdf', + dict(fitResult, **fixedParams)) diff --git a/Examples/fit61_Galaxi/fit_galaxi_data.py b/Examples/fit61_Galaxi/fit_galaxi_data.py index 257eb0520e5bbd6ec1225fc806c1d7becda739c5..0cee8f191100526b53c567e6581d10755e0586f3 100644 --- a/Examples/fit61_Galaxi/fit_galaxi_data.py +++ b/Examples/fit61_Galaxi/fit_galaxi_data.py @@ -40,7 +40,8 @@ def create_simulation(params): simulation.setBeamParameters(wavelength, alpha_i, 0) simulation.beam().setIntensity(1.2e7) simulation.setRegionOfInterest(85, 70, 120, 92.) - simulation.addMask(ba.Rectangle(101.9, 82.1, 103.7, 85.2), True) # beamstop + simulation.addMask(ba.Rectangle(101.9, 82.1, 103.7, 85.2), + True) # beamstop sample_builder = SampleBuilder() sample = sample_builder.create_sample(params) diff --git a/Examples/fit61_Galaxi/sample_builder.py b/Examples/fit61_Galaxi/sample_builder.py index d9fe9b45b6407735fe5607275f2d7dc53ff8422f..6a18bfa9e94e5cfca4ea19be7cd5af1736e2521b 100755 --- a/Examples/fit61_Galaxi/sample_builder.py +++ b/Examples/fit61_Galaxi/sample_builder.py @@ -46,8 +46,10 @@ class SampleBuilder: m_vacuum = ba.HomogeneousMaterial("Vacuum", 0, 0) m_Si = ba.HomogeneousMaterial("Si", 5.78164736e-6, 1.02294578e-7) m_Ag = ba.HomogeneousMaterial("Ag", 2.24749529E-5, 1.61528396E-6) - m_PTFE = ba.HomogeneousMaterial("PTFE", 5.20508729E-6, 1.96944292E-8) - m_HMDSO = ba.HomogeneousMaterial("HMDSO", 2.0888308E-6, 1.32605651E-8) + m_PTFE = ba.HomogeneousMaterial("PTFE", 5.20508729E-6, + 1.96944292E-8) + m_HMDSO = ba.HomogeneousMaterial("HMDSO", 2.0888308E-6, + 1.32605651E-8) # collection of particles with size distribution nparticles = 20 diff --git a/Examples/scatter2d/BeamDivergence.py b/Examples/scatter2d/BeamDivergence.py index 0e9fed1d8bd54f03c96fe0ffdbc506333d1bf57a..18a6713cabd3484788eaf23addcf1e8f5755abcd 100644 --- a/Examples/scatter2d/BeamDivergence.py +++ b/Examples/scatter2d/BeamDivergence.py @@ -48,11 +48,11 @@ def get_simulation(sample): distr_1 = ba.DistributionLogNormal(0.1*nm, 0.1) simulation.addParameterDistribution("*/Beam/Wavelength", distr_1, 5, 0) distr_2 = ba.DistributionGaussian(0.2*deg, 0.1*deg) - simulation.addParameterDistribution("*/Beam/InclinationAngle", distr_2, 5, - 0) + simulation.addParameterDistribution("*/Beam/InclinationAngle", distr_2, + 5, 0) distr_3 = ba.DistributionGaussian(0, 0.1*deg) - simulation.addParameterDistribution("*/Beam/AzimuthalAngle", distr_3, 5, - 0) + simulation.addParameterDistribution("*/Beam/AzimuthalAngle", distr_3, + 5, 0) return simulation diff --git a/Examples/scatter2d/BuriedParticles.py b/Examples/scatter2d/BuriedParticles.py index 85ee794af1de9cd832b54a9db25c456fa59a1974..61908f5152542fab82107f581bc4655771633f74 100644 --- a/Examples/scatter2d/BuriedParticles.py +++ b/Examples/scatter2d/BuriedParticles.py @@ -16,7 +16,8 @@ def get_sample(): material_IntermLayer = ba.HomogeneousMaterial("IntermLayer", 3.45e-06, 5.24e-09) material_Particle = ba.HomogeneousMaterial("Particle", 0, 0) - material_Substrate = ba.HomogeneousMaterial("Substrate", 7.43e-06, 1.72e-07) + material_Substrate = ba.HomogeneousMaterial("Substrate", 7.43e-06, + 1.72e-07) material_Vacuum = ba.HomogeneousMaterial("Vacuum", 0, 0) # Define form factors diff --git a/Examples/scatter2d/CosineRipplesAtRectLattice.py b/Examples/scatter2d/CosineRipplesAtRectLattice.py index 3a7d251956f9eeb264a518842151ffb0b4087862..3beaea3123fafd0a43c3ffaee6ee53de0228b665 100644 --- a/Examples/scatter2d/CosineRipplesAtRectLattice.py +++ b/Examples/scatter2d/CosineRipplesAtRectLattice.py @@ -53,7 +53,8 @@ def get_sample(): def get_simulation(sample): beam = ba.Beam(1, 0.16*nm, ba.Direction(0.3*deg, 0)) - detector = ba.SphericalDetector(100, -1.5*deg, 1.5*deg, 100, 0, 2.5*deg) + detector = ba.SphericalDetector(100, -1.5*deg, 1.5*deg, 100, 0, + 2.5*deg) simulation = ba.GISASSimulation(beam, sample, detector) return simulation diff --git a/Examples/scatter2d/Cylinders.py b/Examples/scatter2d/Cylinders.py index 6006762bdfbe134271864af887ed36efc40e49a0..4ebc23eadc386cc8dba31470a41ed47d96def09d 100755 --- a/Examples/scatter2d/Cylinders.py +++ b/Examples/scatter2d/Cylinders.py @@ -42,7 +42,7 @@ def get_simulation(sample): beam = ba.Beam(1, wavelength, ba.Direction(alpha_i, 0)) # Define detector - nPix = 200 # pixels per direction + nPix = 200 # pixels per direction detector = ba.SphericalDetector(nPix, -2*deg, 2*deg, nPix, 0, 3*deg) return ba.GISASSimulation(beam, sample, detector) diff --git a/Examples/scatter2d/CylindersWithSizeDistribution.py b/Examples/scatter2d/CylindersWithSizeDistribution.py index ebf733b3f34a8f24da4ab0e8d46f0bd93dced5a9..976c0572e1bde5fccc90e91f24b83a6e38e9d783 100644 --- a/Examples/scatter2d/CylindersWithSizeDistribution.py +++ b/Examples/scatter2d/CylindersWithSizeDistribution.py @@ -24,8 +24,8 @@ def get_sample(): # Define particles with parameter following a distribution distr_1 = ba.DistributionGaussian(5*nm, 1*nm) - par_distr_1 = ba.ParameterDistribution("/Particle/Cylinder/Radius", distr_1, - 100, 2) + par_distr_1 = ba.ParameterDistribution("/Particle/Cylinder/Radius", + distr_1, 100, 2) particle_distrib = ba.ParticleDistribution(particle, par_distr_1) # Define particle layouts diff --git a/Examples/scatter2d/DodecahedraSAS.py b/Examples/scatter2d/DodecahedraSAS.py index d95abd1ff1a092a3531c1d9aad09a7ed60cf9e8f..da5cc69801a42b24599c6d8a2840a02ba81ea7c4 100755 --- a/Examples/scatter2d/DodecahedraSAS.py +++ b/Examples/scatter2d/DodecahedraSAS.py @@ -19,8 +19,8 @@ def get_sample(): layout = ba.ParticleLayout() layout.addParticle(particle) solution_layer = ba.Layer(m_solution, 1000*nm) - # TODO: make intensity proportional to thickness, - # https://github.com/scgmlz/BornAgain/issues/1222 + # TODO: make intensity proportional to thickness, + # https://github.com/scgmlz/BornAgain/issues/1222 solution_layer.addLayout(layout) # Flat sample layer sandwiched between semi-infinite vacuum layers: @@ -36,9 +36,9 @@ def get_simulation(sample): beam = ba.Beam(1, 0.4*nm, ba.Direction(90*deg, 0)) # Detector opposite to source: - detPos = 2000 # distance from sample center to detector in mm - detWid = 500 # detector width in mm - detPix = 200 # number of pixels per direction + detPos = 2000 # distance from sample center to detector in mm + detWid = 500 # detector width in mm + detPix = 200 # number of pixels per direction det = ba.RectangularDetector(detPix, detWid, detPix, detWid) det.setPerpendicularToDirectBeam(detPos, detWid/2, detWid/2) diff --git a/Examples/scatter2d/Interference2DLatticeSumOfRotated.py b/Examples/scatter2d/Interference2DLatticeSumOfRotated.py index 7b087346fc5e10ecf07d47908b4619b81645bfb7..c6dda65aa8875daefb406ccda6c70b50cb5a7370 100644 --- a/Examples/scatter2d/Interference2DLatticeSumOfRotated.py +++ b/Examples/scatter2d/Interference2DLatticeSumOfRotated.py @@ -41,7 +41,8 @@ def get_simulation(sample): detector = ba.SphericalDetector(100, 2*deg, 1*deg, 1*deg) simulation = ba.GISASSimulation(beam, sample, detector) distr_1 = ba.DistributionGate(0, 240*deg) - simulation.addParameterDistribution("*/SquareLattice2D/Xi", distr_1, 3, 0) + simulation.addParameterDistribution("*/SquareLattice2D/Xi", distr_1, 3, + 0) return simulation diff --git a/Examples/scatter2d/Interference2DRotatedSquareLattice.py b/Examples/scatter2d/Interference2DRotatedSquareLattice.py index 6e83cae2931801c0cdf3f15b795b12bbe9d74703..860438958963aab69b0a6f48ecd1ea839829fed4 100644 --- a/Examples/scatter2d/Interference2DRotatedSquareLattice.py +++ b/Examples/scatter2d/Interference2DRotatedSquareLattice.py @@ -27,8 +27,8 @@ def get_sample(): # Define interference functions iff = ba.InterferenceFunction2DLattice(lattice) - iff_pdf = ba.FTDecayFunction2DCauchy(47.7464829276*nm, 15.9154943092*nm, - 30*deg) + iff_pdf = ba.FTDecayFunction2DCauchy(47.7464829276*nm, + 15.9154943092*nm, 30*deg) iff.setDecayFunction(iff_pdf) # Define particle layouts diff --git a/Examples/scatter2d/MagneticSpheres.py b/Examples/scatter2d/MagneticSpheres.py index ac09edd7e0f897e2d051710b6f7879f1eb680667..47270df3829b5f92ba6806396bac22fc3d33e6b4 100644 --- a/Examples/scatter2d/MagneticSpheres.py +++ b/Examples/scatter2d/MagneticSpheres.py @@ -15,7 +15,8 @@ def get_sample(): magnetic_field = kvector_t(0, 0, 10000000) material_Particle = ba.HomogeneousMaterial("Particle", 2e-05, 4e-07, magnetic_field) - material_Substrate = ba.HomogeneousMaterial("Substrate", 7e-06, 1.8e-07) + material_Substrate = ba.HomogeneousMaterial("Substrate", 7e-06, + 1.8e-07) material_Vacuum = ba.HomogeneousMaterial("Vacuum", 0, 0) # Define form factors diff --git a/Examples/scatter2d/RectangularGrating.py b/Examples/scatter2d/RectangularGrating.py index 9fbe9f5a263704ffa08b8e562b24029aa341ff23..93693afebbb3f15812c6f4d521f1f0cc24eba337 100644 --- a/Examples/scatter2d/RectangularGrating.py +++ b/Examples/scatter2d/RectangularGrating.py @@ -55,7 +55,8 @@ def get_sample(lattice_rotation_angle=0*deg): def get_simulation(sample): beam = ba.Beam(100000000, 0.134*nm, ba.Direction(0.4*deg, 0)) - detector = ba.SphericalDetector(200, -0.5*deg, 0.5*deg, 200, 0, 0.6*deg) + detector = ba.SphericalDetector(200, -0.5*deg, 0.5*deg, 200, 0, + 0.6*deg) simulation = ba.GISASSimulation(beam, sample, detector) simulation.getOptions().setMonteCarloIntegration(True, 100) return simulation diff --git a/Examples/scatter2d/TriangularRipple.py b/Examples/scatter2d/TriangularRipple.py index dbc832090f50895854048a4cca4ab372b59a61be..3087b065b6d9debc0a225beac10f24f4e91c3e0c 100644 --- a/Examples/scatter2d/TriangularRipple.py +++ b/Examples/scatter2d/TriangularRipple.py @@ -54,7 +54,8 @@ def get_sample(): def get_simulation(sample): beam = ba.Beam(1, 0.16*nm, ba.Direction(0.3*deg, 0)) - detector = ba.SphericalDetector(200, -1.5*deg, 1.5*deg, 200, 0, 2.5*deg) + detector = ba.SphericalDetector(200, -1.5*deg, 1.5*deg, 200, 0, + 2.5*deg) simulation = ba.GISASSimulation(beam, sample, detector) return simulation diff --git a/Examples/specular/BeamAngularDivergence.py b/Examples/specular/BeamAngularDivergence.py index 8c6a75c04b01758559eeb8e05b3b4324c1cb5598..41190fd742fb89729428e14e16e04e09bb70436c 100755 --- a/Examples/specular/BeamAngularDivergence.py +++ b/Examples/specular/BeamAngularDivergence.py @@ -11,7 +11,7 @@ from matplotlib import pyplot as plt # input parameters wavelength = 1.54*angstrom -alpha_i_min = 0 # min incident angle, deg +alpha_i_min = 0 # min incident angle, deg alpha_i_max = 2*deg # max incident angle, rad beam_sample_ratio = 0.01 # beam-to-sample size ratio @@ -76,7 +76,8 @@ def get_simulation(sample, scan_size=500): footprint = ba.FootprintSquare(beam_sample_ratio) alpha_distr = ba.RangedDistributionGaussian(n_points, n_sig) - scan = ba.AngularSpecScan(wavelength, scan_size, alpha_i_min, alpha_i_max) + scan = ba.AngularSpecScan(wavelength, scan_size, alpha_i_min, + alpha_i_max) scan.setFootprintFactor(footprint) scan.setAbsoluteAngularResolution(alpha_distr, d_ang) diff --git a/Examples/specular/BeamFullDivergence.py b/Examples/specular/BeamFullDivergence.py index 382342164b215be0c67ecae95da3a6bd939c8068..79a342412cc2e4f4c64d5cb3932f3036203a6ac7 100755 --- a/Examples/specular/BeamFullDivergence.py +++ b/Examples/specular/BeamFullDivergence.py @@ -8,8 +8,8 @@ from bornagain import angstrom, deg # input parameters wavelength = 1.54*angstrom -alpha_i_min = 0 # min incident angle, deg -alpha_i_max = 2*deg # max incident angle, rad +alpha_i_min = 0 # min incident angle, deg +alpha_i_max = 2*deg # max incident angle, rad # convolution parameters d_wl = 0.01*wavelength # spread width for wavelength @@ -59,7 +59,8 @@ def get_simulation(sample, scan_size=500): alpha_distr = ba.RangedDistributionGaussian(n_points, n_sig) wavelength_distr = ba.RangedDistributionGaussian(n_points, n_sig) - scan = ba.AngularSpecScan(wavelength, scan_size, alpha_i_min, alpha_i_max) + scan = ba.AngularSpecScan(wavelength, scan_size, alpha_i_min, + alpha_i_max) scan.setAbsoluteAngularResolution(alpha_distr, d_ang) scan.setAbsoluteWavelengthResolution(wavelength_distr, d_wl) diff --git a/Examples/varia/AxesInDifferentUnits.py b/Examples/varia/AxesInDifferentUnits.py index b6ea0eb5ab69f377f640b19ad6a78379abea23f5..db767965c5d82541bb95bfb62a06560a72c048e7 100644 --- a/Examples/varia/AxesInDifferentUnits.py +++ b/Examples/varia/AxesInDifferentUnits.py @@ -54,7 +54,8 @@ def get_simulation(sample): pilatus_npx, pilatus_npy = 981, 1043 # number of pixels width = pilatus_npx*pilatus_pixel_size height = pilatus_npy*pilatus_pixel_size - detector = ba.RectangularDetector(pilatus_npx, width, pilatus_npy, height) + detector = ba.RectangularDetector(pilatus_npx, width, pilatus_npy, + height) detector.setPerpendicularToSampleX(detector_distance, width/2., 0) simulation = ba.GISASSimulation(beam, sample, detector) @@ -110,7 +111,11 @@ def plot(result): ylabel=r'$Q_{z} [1/nm]$', zlabel=None) - plt.subplots_adjust(left=0.07, right=0.97, top=0.9, bottom=0.1, hspace=0.25) + plt.subplots_adjust(left=0.07, + right=0.97, + top=0.9, + bottom=0.1, + hspace=0.25) plt.show() diff --git a/Examples/varia/BasicPolarizedReflectometry.py b/Examples/varia/BasicPolarizedReflectometry.py index 7c40e593ac065044382a10f9c549ce6669edecc2..db9ea9c179a4aaceed08650f3f73a87f4ff5d665 100644 --- a/Examples/varia/BasicPolarizedReflectometry.py +++ b/Examples/varia/BasicPolarizedReflectometry.py @@ -18,7 +18,8 @@ def get_sample(): # Define materials material_Ambient = ba.MaterialBySLD("Ambient", 0, 0) magnetic_field = kvector_t(0, 100000000, 0) - material_Layer = ba.MaterialBySLD("Layer", 0.0001, 1e-08, magnetic_field) + material_Layer = ba.MaterialBySLD("Layer", 0.0001, 1e-08, + magnetic_field) material_Substrate = ba.MaterialBySLD("Substrate", 7e-05, 2e-06) # Define layers @@ -80,6 +81,8 @@ def plot(data, labels): if __name__ == '__main__': - results_pp = run_simulation(ba.kvector_t(0, 1, 0), ba.kvector_t(0, 1, 0)) - results_mm = run_simulation(ba.kvector_t(0, -1, 0), ba.kvector_t(0, -1, 0)) + results_pp = run_simulation(ba.kvector_t(0, 1, 0), + ba.kvector_t(0, 1, 0)) + results_mm = run_simulation(ba.kvector_t(0, -1, 0), + ba.kvector_t(0, -1, 0)) plot([results_pp, results_mm], ["$++$", "$--$"]) diff --git a/Examples/varia/DepthProbe.py b/Examples/varia/DepthProbe.py index bc6224776f0231e4b614254ea47b07ef3823815a..3b2914bea93ff30df19f8d18b1c398a5c15dd711 100644 --- a/Examples/varia/DepthProbe.py +++ b/Examples/varia/DepthProbe.py @@ -92,8 +92,8 @@ def get_simulation(sample): simulation = ba.DepthProbeSimulation() simulation.setBeamParameters(wl, n_ai_bins, ai_min, ai_max, footprint) simulation.setZSpan(n_z_bins, z_min, z_max) - simulation.addParameterDistribution("*/Beam/InclinationAngle", alpha_distr, - n_points, n_sig) + simulation.addParameterDistribution("*/Beam/InclinationAngle", + alpha_distr, n_points, n_sig) simulation.setSample(sample) return simulation diff --git a/Examples/varia/LargeParticlesFormFactor.py b/Examples/varia/LargeParticlesFormFactor.py index da2d80b000eaa9a2d359a4c1328bcf9a63858bdc..7604ec12bd41ae4e06a0c54c605d3863170042ae 100644 --- a/Examples/varia/LargeParticlesFormFactor.py +++ b/Examples/varia/LargeParticlesFormFactor.py @@ -107,7 +107,9 @@ def simulate_and_plot(): zmin = condition['zmin'] zmax = condition['zmax'] - ba_plot.plot_colormap(result, intensity_min=zmin, intensity_max=zmax) + ba_plot.plot_colormap(result, + intensity_min=zmin, + intensity_max=zmax) plt.text(0, 2.1, diff --git a/Examples/varia/PolarizedNoAnalyzer.py b/Examples/varia/PolarizedNoAnalyzer.py index 143518cca37d97ec0fcb2f7339d6f4b42b45c5ef..ea19f15aad87d00ba808f3a712595127b501ce01 100644 --- a/Examples/varia/PolarizedNoAnalyzer.py +++ b/Examples/varia/PolarizedNoAnalyzer.py @@ -18,7 +18,8 @@ def get_sample(): # Define materials material_Ambient = ba.MaterialBySLD("Ambient", 0, 0) magnetic_field = kvector_t(50000000, 86602540.3784, 0) - material_Layer = ba.MaterialBySLD("Layer", 0.0001, 1e-08, magnetic_field) + material_Layer = ba.MaterialBySLD("Layer", 0.0001, 1e-08, + magnetic_field) material_Substrate = ba.MaterialBySLD("Substrate", 7e-05, 2e-06) # Define layers @@ -80,7 +81,8 @@ def plot(axis, data, labels): if __name__ == '__main__': - q, results_pp = run_simulation(ba.kvector_t(0, 1, 0), ba.kvector_t(0, 1, 0)) + q, results_pp = run_simulation(ba.kvector_t(0, 1, 0), + ba.kvector_t(0, 1, 0)) q, results_mm = run_simulation(ba.kvector_t(0, -1, 0), ba.kvector_t(0, -1, 0)) diff --git a/Examples/varia/PolarizedNonperfectAnalyzerPolarizer.py b/Examples/varia/PolarizedNonperfectAnalyzerPolarizer.py index a22a3f0cca7ab141d8881c721564012e0d366247..8a9c670e8a5ec5b9a8f3f3ea4a4f512854782f6a 100644 --- a/Examples/varia/PolarizedNonperfectAnalyzerPolarizer.py +++ b/Examples/varia/PolarizedNonperfectAnalyzerPolarizer.py @@ -16,9 +16,9 @@ sldMgO = (5.9803e-06, 9.3996e-12) magnetizationMagnitude = 1.6e6 angle = 0 -magnetizationVector = ba.kvector_t(magnetizationMagnitude*numpy.sin(angle*deg), - magnetizationMagnitude*numpy.cos(angle*deg), - 0) +magnetizationVector = ba.kvector_t( + magnetizationMagnitude*numpy.sin(angle*deg), + magnetizationMagnitude*numpy.cos(angle*deg), 0) def get_sample(*, magnetization=magnetizationVector): @@ -83,8 +83,8 @@ def run_simulation(*, simulation = get_simulation(sample) simulation.beam().setPolarization(polarization*polarizer_efficiency) - simulation.detector().setAnalyzerProperties(analyzer, analyzer_efficiency, - 0.5) + simulation.detector().setAnalyzerProperties(analyzer, + analyzer_efficiency, 0.5) simulation.setBackground(ba.ConstantBackground(1e-7)) diff --git a/Examples/varia/PolarizedSANS.py b/Examples/varia/PolarizedSANS.py index 0dfbdbfdf0e452a687f163f093461a52a3593039..f4ad3defd97c68a4ac5be2e92ff3c711beb69570 100644 --- a/Examples/varia/PolarizedSANS.py +++ b/Examples/varia/PolarizedSANS.py @@ -18,7 +18,8 @@ def get_sample(): # Define materials magnetic_field = kvector_t(0, 0, 10000000) - material_Core = ba.HomogeneousMaterial("Core", 6e-06, 2e-08, magnetic_field) + material_Core = ba.HomogeneousMaterial("Core", 6e-06, 2e-08, + magnetic_field) material_Shell = ba.HomogeneousMaterial("Shell", 1e-07, 2e-08) material_Solvent = ba.HomogeneousMaterial("Solvent", 5e-06, 0) @@ -59,7 +60,8 @@ def get_simulation(sample): simulation = ba.GISASSimulation() # Defining detector - simulation.setDetectorParameters(200, -3*deg, 3*deg, 200, -3*deg, 3*deg) + simulation.setDetectorParameters(200, -3*deg, 3*deg, 200, -3*deg, + 3*deg) # Defining beam parameters simulation.setBeamParameters(0.5*nm, 0, 0) diff --git a/Examples/varia/PolarizedSpinAsymmetry.py b/Examples/varia/PolarizedSpinAsymmetry.py index 5caeac35afbc5c8ac8b3f253dcdd3dcf58432ddd..0b5a89dcf3451eedcbbc4e88565d2ec597b65c5a 100644 --- a/Examples/varia/PolarizedSpinAsymmetry.py +++ b/Examples/varia/PolarizedSpinAsymmetry.py @@ -53,8 +53,8 @@ def get_sample(params): magnetizationMagnitude*numpy.cos(angle*deg), 0) mat_vacuum = ba.MaterialBySLD("Vacuum", 0, 0) - mat_layer = ba.MaterialBySLD("(Mg,Al,Fe)3O4", params["rho_Mafo"]*1e-6, 0, - magnetizationVector) + mat_layer = ba.MaterialBySLD("(Mg,Al,Fe)3O4", params["rho_Mafo"]*1e-6, + 0, magnetizationVector) mat_substrate = ba.MaterialBySLD("MgAl2O4", *sldMao) ambient_layer = ba.Layer(mat_vacuum) @@ -174,7 +174,8 @@ def plotSpinAsymmetry(data_pp, data_mm, q, r_pp, r_mm, filename): fig = plt.figure() ax = fig.add_subplot(111) - ax.errorbar(data_pp[0], (data_pp[1] - data_mm[1])/(data_pp[1] + data_mm[1]), + ax.errorbar(data_pp[0], + (data_pp[1] - data_mm[1])/(data_pp[1] + data_mm[1]), xerr=data_pp[3], yerr=delta, fmt='.', @@ -241,7 +242,8 @@ def get_Experimental_data(qmin, qmax): get_Experimental_data.data_mm = data_mm get_Experimental_data.raw_data = True - return (filterData(data_pp, qmin, qmax), filterData(data_mm, qmin, qmax)) + return (filterData(data_pp, qmin, + qmax), filterData(data_mm, qmin, qmax)) def downloadAndExtractData(): @@ -257,11 +259,11 @@ def downloadAndExtractData(): read().decode("utf-8") table_pp = match( - r'.*# "polarization": "\+\+"\n#.*?\n# "units".*?\n(.*?)#.*', rawdata, - DOTALL).group(1) + r'.*# "polarization": "\+\+"\n#.*?\n# "units".*?\n(.*?)#.*', + rawdata, DOTALL).group(1) table_mm = match( - r'.*# "polarization": "\-\-"\n#.*?\n# "units".*?\n(.*?)#.*', rawdata, - DOTALL).group(1) + r'.*# "polarization": "\-\-"\n#.*?\n# "units".*?\n(.*?)#.*', + rawdata, DOTALL).group(1) data_pp = numpy.genfromtxt(BytesIO(table_pp.encode()), unpack=True) data_mm = numpy.genfromtxt(BytesIO(table_mm.encode()), unpack=True) diff --git a/Examples/varia/PolarizedSpinFlip.py b/Examples/varia/PolarizedSpinFlip.py index b86334c0fa5fa6d33c8d253bff1dd40a682483b9..203c91145aa7888e87bfb79900cf1ae740c46114 100644 --- a/Examples/varia/PolarizedSpinFlip.py +++ b/Examples/varia/PolarizedSpinFlip.py @@ -17,7 +17,8 @@ def get_sample(): # Define materials material_Ambient = ba.MaterialBySLD("Ambient", 0, 0) magnetic_field = kvector_t(50000000, 86602540.3784, 0) - material_Layer = ba.MaterialBySLD("Layer", 0.0001, 1e-08, magnetic_field) + material_Layer = ba.MaterialBySLD("Layer", 0.0001, 1e-08, + magnetic_field) material_Substrate = ba.MaterialBySLD("Substrate", 7e-05, 2e-06) # Define layers @@ -79,11 +80,15 @@ def plot(data, labels): if __name__ == '__main__': - results_pp = run_simulation(ba.kvector_t(0, 1, 0), ba.kvector_t(0, 1, 0)) - results_mm = run_simulation(ba.kvector_t(0, -1, 0), ba.kvector_t(0, -1, 0)) - - results_pm = run_simulation(ba.kvector_t(0, 1, 0), ba.kvector_t(0, -1, 0)) - results_mp = run_simulation(ba.kvector_t(0, -1, 0), ba.kvector_t(0, 1, 0)) + results_pp = run_simulation(ba.kvector_t(0, 1, 0), + ba.kvector_t(0, 1, 0)) + results_mm = run_simulation(ba.kvector_t(0, -1, 0), + ba.kvector_t(0, -1, 0)) + + results_pm = run_simulation(ba.kvector_t(0, 1, 0), + ba.kvector_t(0, -1, 0)) + results_mp = run_simulation(ba.kvector_t(0, -1, 0), + ba.kvector_t(0, 1, 0)) plot([results_pp, results_mm, results_pm, results_mp], ["$++$", "$--$", "$+-$", "$-+$"]) diff --git a/Tests/Functional/PyCore/histogram2d.py b/Tests/Functional/PyCore/histogram2d.py index 54cf54b97f8b90047714c61a0c4ca7e0ead4f50a..060ee3d0f7f8fb903c193340b1b53b39fda1bcc3 100644 --- a/Tests/Functional/PyCore/histogram2d.py +++ b/Tests/Functional/PyCore/histogram2d.py @@ -34,9 +34,9 @@ class Histogram2DTest(unittest.TestCase): """ Testing construction of 2D histogram from numpy array """ - arr = numpy.array( - [[1, 2, 3, 4, 5.0], [6, 7, 8, 9, 10.0], [11, 12, 13, 14, 15.0]], - dtype=numpy.float64) + arr = numpy.array([[1, 2, 3, 4, 5.0], [6, 7, 8, 9, 10.0], + [11, 12, 13, 14, 15.0]], + dtype=numpy.float64) hist = ba.Histogram2D(arr) self.assertEqual(hist.getNbinsX(), 5) @@ -76,9 +76,9 @@ class Histogram2DTest(unittest.TestCase): """ Adding to the histogram content from numpy array """ - arr = numpy.array( - [[1, 2, 3, 4, 5.0], [6, 7, 8, 9, 10.0], [11, 12, 13, 14, 15.0]], - dtype=numpy.float64) + arr = numpy.array([[1, 2, 3, 4, 5.0], [6, 7, 8, 9, 10.0], + [11, 12, 13, 14, 15.0]], + dtype=numpy.float64) hist = ba.Histogram2D(arr) # adding same content once again hist.addContent(arr) @@ -110,9 +110,9 @@ class Histogram2DTest(unittest.TestCase): """ Testing newly create object """ - arr = numpy.array( - [[1, 2, 3, 4, 5.0], [6, 7, 8, 9, 10.0], [11, 12, 13, 14, 15.0]], - dtype=numpy.float64) + arr = numpy.array([[1, 2, 3, 4, 5.0], [6, 7, 8, 9, 10.0], + [11, 12, 13, 14, 15.0]], + dtype=numpy.float64) hist = self.create_histogram(arr) arr_from_hist = hist.getArray() diff --git a/Tests/Functional/PyCore/intensitydata_io.py b/Tests/Functional/PyCore/intensitydata_io.py index a58b9a5344117a18655243648bc30a305b5f384b..922fea8ea79e122e6d07d7e466e7ec34e9cbb72a 100644 --- a/Tests/Functional/PyCore/intensitydata_io.py +++ b/Tests/Functional/PyCore/intensitydata_io.py @@ -77,8 +77,9 @@ class OutputDataIOTest(unittest.TestCase): def test_04_VariableBinAxis_1D(self): data = ba.IntensityData() data.addAxis( - ba.VariableBinAxis("axis0", 10, - get_boundaries_flat_in_sin(10, -5*deg, 5*deg))) + ba.VariableBinAxis( + "axis0", 10, get_boundaries_flat_in_sin(10, -5*deg, + 5*deg))) fill_data(data) ba.IntensityDataIOFactory.writeOutputData(data, "tmp.int") newdata = ba.IntensityDataIOFactory.readOutputData("tmp.int") @@ -87,8 +88,9 @@ class OutputDataIOTest(unittest.TestCase): def test_05_VariableBinAxis_2D(self): data = ba.IntensityData() data.addAxis( - ba.VariableBinAxis("axis0", 10, - get_boundaries_flat_in_sin(10, -5*deg, 5*deg))) + ba.VariableBinAxis( + "axis0", 10, get_boundaries_flat_in_sin(10, -5*deg, + 5*deg))) data.addAxis( ba.VariableBinAxis("axis1", 3, get_boundaries_flat_in_sin(3, 0, 2*deg))) @@ -155,13 +157,15 @@ class OutputDataIOTest(unittest.TestCase): self.assertTrue(is_the_same_data(data, newdata)) def test_SaveNumpyArray_ReadOutputData(self): - arr = numpy.array([[0, 1, 2, 3.0], [4, 5, 6, 7.0], [8, 9, 10, 11.0]]) + arr = numpy.array([[0, 1, 2, 3.0], [4, 5, 6, 7.0], + [8, 9, 10, 11.0]]) numpy.savetxt('tmp.txt', arr) newdata = ba.IntensityDataIOFactory.readOutputData("tmp.txt") self.assertTrue(numpy.array_equal(newdata.getArray(), arr)) def test_SaveNumpyArray_ReadRawDataVector(self): - arr = numpy.array([[0, 1, 2, 3.0], [4, 5, 6, 7.0], [8, 9, 10, 11.0]]) + arr = numpy.array([[0, 1, 2, 3.0], [4, 5, 6, 7.0], + [8, 9, 10, 11.0]]) numpy.savetxt('tmp.txt', arr) newdata = numpy.array( ba.IntensityDataIOFactory.readOutputData( diff --git a/Tests/Functional/PyCore/mesocrystal1.py b/Tests/Functional/PyCore/mesocrystal1.py index f59d36e8b3879513dd78cb2397ba9627e15f4838..68fc2d2824bb34f14d8562580ef05fe15bf1f961 100644 --- a/Tests/Functional/PyCore/mesocrystal1.py +++ b/Tests/Functional/PyCore/mesocrystal1.py @@ -33,20 +33,23 @@ class MySampleBuilder(ISampleBuilder): "lattice_length_c", ctypes.addressof( self.lattice_length_c)).setUnit("nm").setNonnegative() self.registerParameter( - "nanoparticle_radius", ctypes.addressof( + "nanoparticle_radius", + ctypes.addressof( self.nanoparticle_radius)).setUnit("nm").setNonnegative() self.registerParameter( "sigma_nanoparticle_radius", - ctypes.addressof( - self.sigma_nanoparticle_radius)).setUnit("nm").setNonnegative() - self.registerParameter("meso_height", ctypes.addressof( - self.meso_height)).setUnit("nm").setNonnegative() - self.registerParameter("meso_radius", ctypes.addressof( - self.meso_radius)).setUnit("nm").setNonnegative() + ctypes.addressof(self.sigma_nanoparticle_radius)).setUnit( + "nm").setNonnegative() + self.registerParameter( + "meso_height", ctypes.addressof( + self.meso_height)).setUnit("nm").setNonnegative() + self.registerParameter( + "meso_radius", ctypes.addressof( + self.meso_radius)).setUnit("nm").setNonnegative() self.registerParameter( "sigma_lattice_length_a", - ctypes.addressof( - self.sigma_lattice_length_a)).setUnit("nm").setNonnegative() + ctypes.addressof(self.sigma_lattice_length_a)).setUnit( + "nm").setNonnegative() self.registerParameter( "surface_filling_ratio", ctypes.addressof(self.surface_filling_ratio)).setNonnegative() @@ -61,11 +64,13 @@ class MySampleBuilder(ISampleBuilder): n_particle = complex(1.0 - 2.84e-5, 4.7e-7) avg_n_squared_meso = complex(0.7886*n_particle*n_particle + 0.2114) n_avg = complex( - numpy.sqrt(self.surface_filling_ratio.value*avg_n_squared_meso + - 1.0 - self.surface_filling_ratio.value)) + numpy.sqrt(self.surface_filling_ratio.value* + avg_n_squared_meso + 1.0 - + self.surface_filling_ratio.value)) n_particle_adapted = complex( numpy.sqrt(n_avg*n_avg + n_particle*n_particle - 1)) - ff = FormFactorCylinder(self.meso_radius.value, self.meso_height.value) + ff = FormFactorCylinder(self.meso_radius.value, + self.meso_height.value) # Create multilayer p_multi_layer = MultiLayer() @@ -73,8 +78,10 @@ class MySampleBuilder(ISampleBuilder): n_substrate = complex(1.0 - 7.57e-6, 1.73e-7) p_vacuum_material = HomogeneousMaterial("Vacuum", n_air) - p_average_layer_material = HomogeneousMaterial("Averagelayer", n_avg) - p_substrate_material = HomogeneousMaterial("Substrate", n_substrate) + p_average_layer_material = HomogeneousMaterial( + "Averagelayer", n_avg) + p_substrate_material = HomogeneousMaterial("Substrate", + n_substrate) vacuum_layer = Layer(p_vacuum_material) avg_layer = Layer(p_average_layer_material, self.meso_height.value) substrate_layer = Layer(p_substrate_material) @@ -144,7 +151,8 @@ class MySampleBuilder(ISampleBuilder): # create lattice # ------------------------------------------------------------------------- def createLattice(self, stacking_radius_a, stacking_radius_c): - result = HexagonalLattice(stacking_radius_a*2, stacking_radius_c*2*2.3) + result = HexagonalLattice(stacking_radius_a*2, + stacking_radius_c*2*2.3) result.setSelectionRule(SimpleSelectionRule(-1, 1, 1, 3)) return result diff --git a/Tests/Functional/PyCore/parameterpool.py b/Tests/Functional/PyCore/parameterpool.py index b85d3851c0748581b3041461ebc72dbb5b5953ec..c49ab84b92032711cc1d9cfe8f0f8bb6d93d9577 100644 --- a/Tests/Functional/PyCore/parameterpool.py +++ b/Tests/Functional/PyCore/parameterpool.py @@ -18,8 +18,9 @@ class ParameterPoolTest(unittest.TestCase): pool = particle.parameterPool() self.assertEqual(pool.size(), 4) - self.assertEqual(pool.parameterNames(), - ('Abundance', 'PositionX', 'PositionY', 'PositionZ')) + self.assertEqual( + pool.parameterNames(), + ('Abundance', 'PositionX', 'PositionY', 'PositionZ')) expected = { 'Abundance': 1, diff --git a/Tests/Functional/PyCore/polmagcylinders1.py b/Tests/Functional/PyCore/polmagcylinders1.py index f86c25e9a99b77d62c715778a9e115e8e00aa1c3..c5c9fb0746786239ad8148b50bb8b6702ba31fad 100644 --- a/Tests/Functional/PyCore/polmagcylinders1.py +++ b/Tests/Functional/PyCore/polmagcylinders1.py @@ -53,7 +53,8 @@ def run_test(): result = runSimulation() # ba.IntensityDataIOFactory.writeIntensityData(result, 'polmagcylinders1_reference.int') - reference = utils.get_reference_data('polmagcylinders1_reference.int.gz') + reference = utils.get_reference_data( + 'polmagcylinders1_reference.int.gz') diff = utils.get_difference(result.array(), reference.getArray()) diff --git a/Tests/Functional/PyCore/polmagcylinders2.py b/Tests/Functional/PyCore/polmagcylinders2.py index 454870959e829d6207c3b81fd28274e81a7e32e0..9a94fd39dce7f8acb788608b155e34cf3f503acd 100644 --- a/Tests/Functional/PyCore/polmagcylinders2.py +++ b/Tests/Functional/PyCore/polmagcylinders2.py @@ -20,7 +20,8 @@ def getSimulationIntensity(rho_beam, efficiency): magnetization = kvector_t(0, 1e6, 0) - magParticle = HomogeneousMaterial("magParticle", 5e-6, 0, magnetization) + magParticle = HomogeneousMaterial("magParticle", 5e-6, 0, + magnetization) # collection of particles cylinder_ff = FormFactorCylinder(5*nm, 5*nm) cylinder = Particle(magParticle, cylinder_ff) @@ -79,16 +80,20 @@ def run_test(): diff = 0.0 diff += get_difference( getSimulationIntensity(zplus, 1).array(), - get_reference_data('polmagcylinders2_reference_00.int.gz').getArray()) + get_reference_data( + 'polmagcylinders2_reference_00.int.gz').getArray()) diff += get_difference( getSimulationIntensity(zplus, -1).array(), - get_reference_data('polmagcylinders2_reference_01.int.gz').getArray()) + get_reference_data( + 'polmagcylinders2_reference_01.int.gz').getArray()) diff += get_difference( getSimulationIntensity(zmin, 1).array(), - get_reference_data('polmagcylinders2_reference_10.int.gz').getArray()) + get_reference_data( + 'polmagcylinders2_reference_10.int.gz').getArray()) diff += get_difference( getSimulationIntensity(zmin, -1).array(), - get_reference_data('polmagcylinders2_reference_11.int.gz').getArray()) + get_reference_data( + 'polmagcylinders2_reference_11.int.gz').getArray()) diff /= 4.0 status = "OK" diff --git a/Tests/Functional/PyCore/samplebuilder.py b/Tests/Functional/PyCore/samplebuilder.py index 104516a04fb92b33b0405fdfe4de54614e9890d2..e2be45ea8c3fcd1385278b2bb6bbef5d4fd3323f 100644 --- a/Tests/Functional/PyCore/samplebuilder.py +++ b/Tests/Functional/PyCore/samplebuilder.py @@ -49,10 +49,11 @@ class BuilderPrototype(ba.ISampleBuilder): " in given class") # defining the name for new ctype variable and creating dynamic attribute wrapper_key = "wrapper_" + var_key - setattr(self, wrapper_key, ctypes.c_double(self.__dict__.get(var_key))) + setattr(self, wrapper_key, + ctypes.c_double(self.__dict__.get(var_key))) # registering new attribute in BornAgain - self.registerParameter(par_name, - ctypes.addressof(getattr(self, wrapper_key))) + self.registerParameter( + par_name, ctypes.addressof(getattr(self, wrapper_key))) class SampleBuilderTest(unittest.TestCase): diff --git a/Tests/Functional/PyCore/sliced_composition.py b/Tests/Functional/PyCore/sliced_composition.py index a6e1055ced71aab33ae84e7f9d93d8456d3f2aad..a882b1378f264aedd037f67e58cd02941b435a88 100644 --- a/Tests/Functional/PyCore/sliced_composition.py +++ b/Tests/Functional/PyCore/sliced_composition.py @@ -55,13 +55,13 @@ class SlicedSpheresTest(unittest.TestCase): topCup = ba.Particle( top_material, - ba.FormFactorTruncatedSphere(sphere_radius, - sphere_radius*2 - bottom_cup_height, - 0)) + ba.FormFactorTruncatedSphere( + sphere_radius, sphere_radius*2 - bottom_cup_height, 0)) bottomCup = ba.Particle( bottom_material, - ba.FormFactorTruncatedSphere(sphere_radius, sphere_radius*2, - sphere_radius*2 - bottom_cup_height)) + ba.FormFactorTruncatedSphere( + sphere_radius, sphere_radius*2, + sphere_radius*2 - bottom_cup_height)) # origin of resulting sphere will be at the bottom result = ba.ParticleComposition() @@ -79,12 +79,12 @@ class SlicedSpheresTest(unittest.TestCase): topCup = ba.Particle( top_material, - ba.FormFactorTruncatedSphere(sphere_radius, - sphere_radius*2 - bottom_cup_height, - 0)) + ba.FormFactorTruncatedSphere( + sphere_radius, sphere_radius*2 - bottom_cup_height, 0)) bottomCup = ba.Particle( bottom_material, - ba.FormFactorTruncatedSphere(sphere_radius, bottom_cup_height, 0)) + ba.FormFactorTruncatedSphere(sphere_radius, bottom_cup_height, + 0)) bottomCup.setRotation(ba.RotationX(180*deg)) # origin of resulting sphere will be at the bottom @@ -102,7 +102,8 @@ class SlicedSpheresTest(unittest.TestCase): """ # spherical particle - sphere = ba.Particle(mParticle, ba.FormFactorFullSphere(sphere_radius)) + sphere = ba.Particle(mParticle, + ba.FormFactorFullSphere(sphere_radius)) reference = self.get_result(sphere) # spherical composition @@ -164,7 +165,8 @@ class SlicedSpheresTest(unittest.TestCase): shift = 3*nm # spherical particle - sphere = ba.Particle(mParticle, ba.FormFactorFullSphere(sphere_radius)) + sphere = ba.Particle(mParticle, + ba.FormFactorFullSphere(sphere_radius)) sphere.setPosition(0, 0, -shift) reference = self.get_result(sphere) @@ -189,9 +191,8 @@ class SlicedSpheresTest(unittest.TestCase): # truncated sphere on top of substrate with height 16nm truncatedSphere = ba.Particle( mParticle, - ba.FormFactorTruncatedSphere(sphere_radius, - sphere_radius*2 - bottom_cup_height, - 0)) + ba.FormFactorTruncatedSphere( + sphere_radius, sphere_radius*2 - bottom_cup_height, 0)) reference = self.get_result(truncatedSphere) # Particle composition, top part made of same material, as particle. Bottom part made of same material as substrate. diff --git a/Tests/Functional/PyCore/sliced_spheres.py b/Tests/Functional/PyCore/sliced_spheres.py index 1e51b8d561ee886749c02b625f4111c771df0f5f..2116b4093636274e3f4c744809c4d3710195ab12 100644 --- a/Tests/Functional/PyCore/sliced_spheres.py +++ b/Tests/Functional/PyCore/sliced_spheres.py @@ -60,11 +60,13 @@ class SlicedSpheresTest(unittest.TestCase): truncatedSphere = ba.Particle( mSubstrate, ba.FormFactorTruncatedSphere(sphere_radius, - sphere_radius*2 - sphere_shift, 0)) + sphere_radius*2 - sphere_shift, + 0)) reference = self.get_result(truncatedSphere) # sphere crossing interface to look like truncated sphere above - sphere = ba.Particle(mSubstrate, ba.FormFactorFullSphere(sphere_radius)) + sphere = ba.Particle(mSubstrate, + ba.FormFactorFullSphere(sphere_radius)) sphere.setPosition(0, 0, -sphere_shift) data = self.get_result(sphere) @@ -90,7 +92,8 @@ class SlicedSpheresTest(unittest.TestCase): reference = self.get_result(truncatedSphere) # sphere crossing interface to look like truncated sphere above - sphere = ba.Particle(mAmbience, ba.FormFactorFullSphere(sphere_radius)) + sphere = ba.Particle(mAmbience, + ba.FormFactorFullSphere(sphere_radius)) sphere.setPosition(0, 0, -sphere_shift) data = self.get_result(sphere) @@ -111,12 +114,14 @@ class SlicedSpheresTest(unittest.TestCase): sphere_shift = 4.0 # shift beneath interface in absolute units # Sphere intended for vacuum layer and crossing interface - sphere1 = ba.Particle(mParticle, ba.FormFactorFullSphere(sphere_radius)) + sphere1 = ba.Particle(mParticle, + ba.FormFactorFullSphere(sphere_radius)) sphere1.setPosition(0, 0, -sphere_shift) reference = self.get_result(particle_to_air=sphere1) # Sphere intended for substrate layer and crossing interface - sphere2 = ba.Particle(mParticle, ba.FormFactorFullSphere(sphere_radius)) + sphere2 = ba.Particle(mParticle, + ba.FormFactorFullSphere(sphere_radius)) sphere2.setPosition(0, 0, -sphere_shift) data = self.get_result(particle_to_substrate=sphere2) diff --git a/Tests/Functional/PyCore/transform_BoxComposition.py b/Tests/Functional/PyCore/transform_BoxComposition.py index fc40e1d89954834ed31de07f800dfc7dfaac0e92..d9e528cc0a26b01e970bc3c68d0b4e25b81101ed 100644 --- a/Tests/Functional/PyCore/transform_BoxComposition.py +++ b/Tests/Functional/PyCore/transform_BoxComposition.py @@ -57,7 +57,8 @@ class TransformBoxCompositionTest(unittest.TestCase): height = 10.0 particle = Particle(particle_material, FormFactorBox(length, width, height)) - particle.setPosition(kvector_t(0, 0, -layer_thickness/2.0 - height/2)) + particle.setPosition( + kvector_t(0, 0, -layer_thickness/2.0 - height/2)) reference_data = self.get_result(particle) #IntensityDataIOFactory.writeIntensityData(reference_data, "ref_BoxComposition.int") @@ -89,7 +90,8 @@ class TransformBoxCompositionTest(unittest.TestCase): height = 20.0 particle = Particle(particle_material, FormFactorBox(length, width, height)) - particle.setPosition(kvector_t(0, 0, -layer_thickness/2.0 - height/2)) + particle.setPosition( + kvector_t(0, 0, -layer_thickness/2.0 - height/2)) reference_data = self.get_result(particle) #IntensityDataIOFactory.writeIntensityData(reference_data, "ref_BoxCompositionRotateX.int") @@ -120,7 +122,8 @@ class TransformBoxCompositionTest(unittest.TestCase): height = 50.0 particle = Particle(particle_material, FormFactorBox(length, width, height)) - particle.setPosition(kvector_t(0, 0, -layer_thickness/2.0 - height/2)) + particle.setPosition( + kvector_t(0, 0, -layer_thickness/2.0 - height/2)) reference_data = self.get_result(particle) #IntensityDataIOFactory.writeIntensityData(reference_data, "ref_BoxCompositionRotateY.int") @@ -152,7 +155,8 @@ class TransformBoxCompositionTest(unittest.TestCase): height = 10.0 particle = Particle(particle_material, FormFactorBox(length, width, height)) - particle.setPosition(kvector_t(0, 0, -layer_thickness/2.0 - height/2)) + particle.setPosition( + kvector_t(0, 0, -layer_thickness/2.0 - height/2)) reference_data = self.get_result(particle) #IntensityDataIOFactory.writeIntensityData(reference_data, "ref_BoxCompositionRotateZ.int") @@ -184,7 +188,8 @@ class TransformBoxCompositionTest(unittest.TestCase): height = 20.0 particle = Particle(particle_material, FormFactorBox(length, width, height)) - particle.setPosition(kvector_t(0, 0, -layer_thickness/2.0 - height/2)) + particle.setPosition( + kvector_t(0, 0, -layer_thickness/2.0 - height/2)) reference_data = self.get_result(particle) #IntensityDataIOFactory.writeIntensityData(reference_data, "ref_BoxCompositionRotateZandY.int") @@ -216,7 +221,8 @@ class TransformBoxCompositionTest(unittest.TestCase): height = 50.0 particle = Particle(particle_material, FormFactorBox(length, width, height)) - particle.setPosition(kvector_t(0, 0, -layer_thickness/2.0 - height/2)) + particle.setPosition( + kvector_t(0, 0, -layer_thickness/2.0 - height/2)) reference_data = self.get_result(particle) #IntensityDataIOFactory.writeIntensityData(reference_data, "ref_BoxStackComposition.int") @@ -227,16 +233,18 @@ class TransformBoxCompositionTest(unittest.TestCase): box1_length = 20.0 box1_width = 50.0 box1_height = 5.0 - box1 = Particle(particle_material, - FormFactorBox(box1_length, box1_width, box1_height)) + box1 = Particle( + particle_material, + FormFactorBox(box1_length, box1_width, box1_height)) box1.setRotation(RotationZ(90*deg)) # box2 (5,20,50), rotatedY box2_length = 5.0 box2_width = 20.0 box2_height = 50.0 - box2 = Particle(particle_material, - FormFactorBox(box2_length, box2_width, box2_height)) + box2 = Particle( + particle_material, + FormFactorBox(box2_length, box2_width, box2_height)) box2.setRotation(RotationY(90*deg)) box2.setPosition(kvector_t(-box2_height/2, 0, box2_length/2)) diff --git a/Tests/Functional/PyCore/transform_CoreShellBox.py b/Tests/Functional/PyCore/transform_CoreShellBox.py index 3bc46c3e25d8c056255bab2a2a9bd68578bcdcd2..dc37f876a40ed37b7629deb149e2ccf209e65e41 100644 --- a/Tests/Functional/PyCore/transform_CoreShellBox.py +++ b/Tests/Functional/PyCore/transform_CoreShellBox.py @@ -61,10 +61,10 @@ class TransformCoreShellBoxTest(unittest.TestCase): core_length = shell_length/2.0 core_width = shell_width/2.0 core_height = shell_height/2.0 - shell = Particle(mCore, - FormFactorBox(shell_length, shell_width, shell_height)) - core = Particle(mCore, - FormFactorBox(core_length, core_width, core_height)) + shell = Particle( + mCore, FormFactorBox(shell_length, shell_width, shell_height)) + core = Particle( + mCore, FormFactorBox(core_length, core_width, core_height)) coreshell = ParticleCoreShell( shell, core, kvector_t(0, 0, (shell_height - core_height)/2)) coreshell.setPosition( @@ -93,17 +93,16 @@ class TransformCoreShellBoxTest(unittest.TestCase): core_width = shell_width/2.0 core_height = shell_height/2.0 - core_ref = Particle(mCore, - FormFactorBox(core_length, core_width, core_height)) + core_ref = Particle( + mCore, FormFactorBox(core_length, core_width, core_height)) shell_ref = Particle( mShell, FormFactorBox(shell_length, shell_width, shell_height)) coreshell_ref = ParticleCoreShell( - shell_ref, core_ref, kvector_t(0, 0, - (shell_height - core_height)/2)) + shell_ref, core_ref, + kvector_t(0, 0, (shell_height - core_height)/2)) coreshell_ref.setPosition( - kvector_t( - 0, 0, -layer_thickness/2.0 - - shell_height/2)) # center of coreshell in center of the layer + kvector_t(0, 0, -layer_thickness/2.0 - shell_height/ + 2)) # center of coreshell in center of the layer reference_data = self.get_result(coreshell_ref) @@ -115,17 +114,16 @@ class TransformCoreShellBoxTest(unittest.TestCase): core_width = shell_width/2.0 core_height = shell_height/2.0 - core = Particle(mCore, - FormFactorBox(core_length, core_width, core_height)) - shell = Particle(mShell, - FormFactorBox(shell_length, shell_width, shell_height)) + core = Particle( + mCore, FormFactorBox(core_length, core_width, core_height)) + shell = Particle( + mShell, FormFactorBox(shell_length, shell_width, shell_height)) coreshell = ParticleCoreShell( shell, core, kvector_t(0, 0, (shell_height - core_height)/2)) coreshell.setRotation(RotationZ(90*deg)) coreshell.setPosition( - kvector_t( - 0, 0, -layer_thickness/2.0 - - shell_height/2)) # center of coreshell in center of the layer + kvector_t(0, 0, -layer_thickness/2.0 - shell_height/ + 2)) # center of coreshell in center of the layer data = self.get_result(coreshell) @@ -150,17 +148,16 @@ class TransformCoreShellBoxTest(unittest.TestCase): core_width = shell_width/2.0 core_height = shell_height/2.0 - core_ref = Particle(mCore, - FormFactorBox(core_length, core_width, core_height)) + core_ref = Particle( + mCore, FormFactorBox(core_length, core_width, core_height)) shell_ref = Particle( mShell, FormFactorBox(shell_length, shell_width, shell_height)) coreshell_ref = ParticleCoreShell( - shell_ref, core_ref, kvector_t(0, 0, - (shell_height - core_height)/2)) + shell_ref, core_ref, + kvector_t(0, 0, (shell_height - core_height)/2)) coreshell_ref.setPosition( - kvector_t( - 0, 0, -layer_thickness/2.0 - - shell_height/2)) # center of coreshell in center of the layer + kvector_t(0, 0, -layer_thickness/2.0 - shell_height/ + 2)) # center of coreshell in center of the layer reference_data = self.get_result(coreshell_ref) @@ -172,16 +169,16 @@ class TransformCoreShellBoxTest(unittest.TestCase): core_width = shell_width/2.0 core_height = shell_height/2.0 - core = Particle(mCore, - FormFactorBox(core_length, core_width, core_height)) - shell = Particle(mShell, - FormFactorBox(shell_length, shell_width, shell_height)) + core = Particle( + mCore, FormFactorBox(core_length, core_width, core_height)) + shell = Particle( + mShell, FormFactorBox(shell_length, shell_width, shell_height)) coreshell = ParticleCoreShell( shell, core, kvector_t(0, 0, (shell_height - core_height)/2)) coreshell.setRotation(RotationY(90.*deg)) - coreshell.setPosition(kvector_t( - 0, 0, - -layer_thickness/2)) # center of coreshell in center of the layer + coreshell.setPosition( + kvector_t(0, 0, -layer_thickness/ + 2)) # center of coreshell in center of the layer data = self.get_result(coreshell) @@ -206,17 +203,16 @@ class TransformCoreShellBoxTest(unittest.TestCase): core_width = shell_width/2.0 core_height = shell_height/2.0 - core_ref = Particle(mCore, - FormFactorBox(core_length, core_width, core_height)) + core_ref = Particle( + mCore, FormFactorBox(core_length, core_width, core_height)) shell_ref = Particle( mShell, FormFactorBox(shell_length, shell_width, shell_height)) coreshell_ref = ParticleCoreShell( - shell_ref, core_ref, kvector_t(0, 0, - (shell_height - core_height)/2)) + shell_ref, core_ref, + kvector_t(0, 0, (shell_height - core_height)/2)) coreshell_ref.setPosition( - kvector_t( - 0, 0, -layer_thickness/2.0 - - shell_height/2)) # center of coreshell in center of the layer + kvector_t(0, 0, -layer_thickness/2.0 - shell_height/ + 2)) # center of coreshell in center of the layer reference_data = self.get_result(coreshell_ref) #IntensityDataIOFactory.writeIntensityData(reference_data, "ref_CoreShellBoxRotateZandY.int") @@ -229,18 +225,18 @@ class TransformCoreShellBoxTest(unittest.TestCase): core_width = shell_width/2.0 core_height = shell_height/2.0 - core = Particle(mCore, - FormFactorBox(core_length, core_width, core_height)) - shell = Particle(mShell, - FormFactorBox(shell_length, shell_width, shell_height)) + core = Particle( + mCore, FormFactorBox(core_length, core_width, core_height)) + shell = Particle( + mShell, FormFactorBox(shell_length, shell_width, shell_height)) coreshell = ParticleCoreShell( shell, core, kvector_t(0, 0, (shell_height - core_height)/2)) coreshell.setRotation(RotationZ(90*deg)) coreshell.rotate(RotationY(90*deg)) # rotation changes reference point, which now coincide with center of the volume - coreshell.setPosition(kvector_t( - 0, 0, - -layer_thickness/2)) # center of coreshell in center of the layer + coreshell.setPosition( + kvector_t(0, 0, -layer_thickness/ + 2)) # center of coreshell in center of the layer data = self.get_result(coreshell) diff --git a/Tests/Functional/PyCore/transform_box.py b/Tests/Functional/PyCore/transform_box.py index 8f15e4b2cf905e7ba736b7cfe3f45d4cec795b64..655ee5a3f3b6cba37473ddfb06c9bccd40fe197a 100644 --- a/Tests/Functional/PyCore/transform_box.py +++ b/Tests/Functional/PyCore/transform_box.py @@ -18,7 +18,8 @@ class BoxTransformationsTest(unittest.TestCase): def get_sample(self, particle): mAmbience = ba.HomogeneousMaterial("Vacuum", 0, 0) mMiddle = ba.HomogeneousMaterial("Teflon", 2.900e-6, 6.019e-9) - mSubstrate = ba.HomogeneousMaterial("Substrate", 3.212e-6, 3.244e-8) + mSubstrate = ba.HomogeneousMaterial("Substrate", 3.212e-6, + 3.244e-8) layout = ba.ParticleLayout() layout.addParticle(particle) @@ -52,7 +53,8 @@ class BoxTransformationsTest(unittest.TestCase): width = 50 height = 20 - box = ba.Particle(mParticle, ba.FormFactorBox(length, width, height)) + box = ba.Particle(mParticle, + ba.FormFactorBox(length, width, height)) box.setPosition(kvector_t(0, 0, -layer_thickness/2 - height/2)) reference_data = self.get_result(box) #IntensityDataIOFactory.writeIntensityData(reference_data, "ref_TransformBox.int") @@ -61,7 +63,8 @@ class BoxTransformationsTest(unittest.TestCase): length = 50 width = 20 height = 10 - box = ba.Particle(mParticle, ba.FormFactorBox(length, width, height)) + box = ba.Particle(mParticle, + ba.FormFactorBox(length, width, height)) box.setRotation(ba.RotationZ(90*deg)) box.rotate(ba.RotationY(90*deg)) box.setPosition(kvector_t(0, 0, -layer_thickness/2)) diff --git a/Tests/Functional/PyCore/transform_cube.py b/Tests/Functional/PyCore/transform_cube.py index 73e9cb63c375c1592ee3489feaaec488f6f2dd80..df719a07b6137d4cea1591c090ad0ea5c3482bee 100644 --- a/Tests/Functional/PyCore/transform_cube.py +++ b/Tests/Functional/PyCore/transform_cube.py @@ -62,7 +62,8 @@ class RotationsCubeTest(unittest.TestCase): pos = data[2] layout_rot = data[3] layout_pos = data[4] - sample = self.get_sample(ff, rot, pos, layout_rot, layout_pos, add_to) + sample = self.get_sample(ff, rot, pos, layout_rot, layout_pos, + add_to) # simulation = self.get_simulation(sample) simulation = utils.get_simulation_MiniGISAS(sample) simulation.runSimulation() @@ -82,7 +83,8 @@ class RotationsCubeTest(unittest.TestCase): data_to_test = [ # ff rot pos layout_rot layout_pos (box, None, None, None, None), # reference - (box, RotationZ(90.*deg), None, None, None), # rotating particle + (box, RotationZ(90.*deg), None, None, + None), # rotating particle (box, RotationZ(-90.*deg), None, None, None), (box, RotationZ(180.*deg), None, None, None), (box, None, None, RotationZ(90.*deg), @@ -118,7 +120,8 @@ class RotationsCubeTest(unittest.TestCase): kvector_t(0, 0, 5)), # rotating and translating (box, RotationY(90.*deg), None, None, kvector_t(0, 0, 5)), # rotating and translating - (box, RotationY(45.*deg), kvector_t(0, 0, 0), RotationY(45.*deg), + (box, RotationY(45.*deg), kvector_t(0, 0, + 0), RotationY(45.*deg), kvector_t(0, 0, 5)), # rotating and translating ] @@ -149,7 +152,8 @@ class RotationsCubeTest(unittest.TestCase): kvector_t(0, 0, 5)), # rotating and translating (box, RotationX(90.*deg), None, None, kvector_t(0, 0, 5)), # rotating and translating - (box, RotationX(45.*deg), kvector_t(0, 0, 0), RotationX(45.*deg), + (box, RotationX(45.*deg), kvector_t(0, 0, + 0), RotationX(45.*deg), kvector_t(0, 0, 5)), # rotating and translating ] diff --git a/Tests/Functional/PyFit/fitobjective_api.py b/Tests/Functional/PyFit/fitobjective_api.py index 4526a6185c0de25a5353beb44d42f15b8b6a11c1..b3f2bbe5fd82d6b006e540905c041201145b4056 100644 --- a/Tests/Functional/PyFit/fitobjective_api.py +++ b/Tests/Functional/PyFit/fitobjective_api.py @@ -29,7 +29,8 @@ class SimulationBuilder: simulation = ba.GISASSimulation() simulation.setSample(ml) - simulation.setDetectorParameters(self.m_ncol, 0, 1, self.m_nrow, 0, 1) + simulation.setDetectorParameters(self.m_ncol, 0, 1, self.m_nrow, 0, + 1) return simulation def create_data(self): @@ -43,7 +44,8 @@ class FitObserver: def update(self, fit_objective): self.m_ncalls += 1 - self.m_iterations.append(fit_objective.iterationInfo().iterationCount()) + self.m_iterations.append( + fit_objective.iterationInfo().iterationCount()) class FitObjectiveAPITest(unittest.TestCase): @@ -78,7 +80,8 @@ class FitObjectiveAPITest(unittest.TestCase): expected_sim.append(0) expected_data.append(1) self.assertEqual(expected_sim, list(objective.simulation_array())) - self.assertEqual(expected_data, list(objective.experimental_array())) + self.assertEqual(expected_data, + list(objective.experimental_array())) def test_FittingObserver(self): """ diff --git a/Tests/Functional/PyFit/standalone_fits.py b/Tests/Functional/PyFit/standalone_fits.py index 33b8458b9c699ccc2918f4d6b9432250f5860cae..52c400f79657a9321964835b649424a085d5afa5 100644 --- a/Tests/Functional/PyFit/standalone_fits.py +++ b/Tests/Functional/PyFit/standalone_fits.py @@ -56,7 +56,8 @@ class StandaloneFitTest(unittest.TestCase): Testing fit of rosenbrock function """ params = ba.Parameters() - params.add(ba.Parameter("x", -1.2, ba.AttLimits.limited(-5, 5), 0.01)) + params.add( + ba.Parameter("x", -1.2, ba.AttLimits.limited(-5, 5), 0.01)) params.add(ba.Parameter("y", 1, ba.AttLimits.limited(-5, 5), 0.01)) model = Rosenbrock() @@ -77,7 +78,8 @@ class StandaloneFitTest(unittest.TestCase): params = ba.Parameters() params.add(ba.Parameter('amp', 1, ba.AttLimits.positive())) params.add(ba.Parameter('decay', 0.1, ba.AttLimits.positive())) - params.add(ba.Parameter('phase', 0.1, ba.AttLimits.limited(0, 3.1))) + params.add(ba.Parameter('phase', 0.1, ba.AttLimits.limited(0, + 3.1))) params.add(ba.Parameter('frequency', 1, ba.AttLimits.positive())) model = DecayingSin() diff --git a/Tests/Performance/Python/test_performance.py b/Tests/Performance/Python/test_performance.py index 1878642eeaada7a6e09f9a595c6f3416fe15dd6c..bcac6348ff4286ef8500b8ce8efeb22532405dbb 100755 --- a/Tests/Performance/Python/test_performance.py +++ b/Tests/Performance/Python/test_performance.py @@ -76,7 +76,8 @@ class CustomFormFactor(IBornFF): # class for performance test, constructed using sample factories class FactoryTest: - def __init__(self, name, simulation_name, sample_builder, nrepetitions): + def __init__(self, name, simulation_name, sample_builder, + nrepetitions): self.m_test_name = name self.m_simulation_name = simulation_name self.m_sample_builder_name = sample_builder @@ -185,8 +186,8 @@ class CustomTest(FactoryTest): """ simulation = GISASSimulation() simulation.getOptions().setNumberOfThreads(-1) - simulation.setDetectorParameters(100, phi_min*deg, phi_max*deg, 100, - alpha_min*deg, alpha_max*deg) + simulation.setDetectorParameters(100, phi_min*deg, phi_max*deg, + 100, alpha_min*deg, alpha_max*deg) simulation.setBeamParameters(1*angstrom, 0.2*deg, 0) return simulation @@ -201,17 +202,24 @@ class PerformanceTests: self.m_pyversion = "" self.m_filename = filename - self.add("MultiLayer", "MaxiGISAS", "MultiLayerWithRoughnessBuilder", 1) - self.add("CylindersInDWBA", "MaxiGISAS", "CylindersInDWBABuilder", 10) - self.add("RotatedPyramids", "MaxiGISAS", "RotatedPyramidsBuilder", 10) + self.add("MultiLayer", "MaxiGISAS", + "MultiLayerWithRoughnessBuilder", 1) + self.add("CylindersInDWBA", "MaxiGISAS", "CylindersInDWBABuilder", + 10) + self.add("RotatedPyramids", "MaxiGISAS", "RotatedPyramidsBuilder", + 10) self.add("CoreShell", "MaxiGISAS", "CoreShellParticleBuilder", 10) - self.add("SquareLattice2D", "MaxiGISAS", "SquareLattice2DBuilder", 10) - self.add("RadialParaCrystal", "MaxiGISAS", "RadialParaCrystalBuilder", + self.add("SquareLattice2D", "MaxiGISAS", "SquareLattice2DBuilder", + 10) + self.add("RadialParaCrystal", "MaxiGISAS", + "RadialParaCrystalBuilder", 10) + self.add("HexParaCrystal", "BasicGISAS", "HexParaCrystalBuilder", + 1) + self.add("SSCA", "MaxiGISAS", "SizeDistributionSSCAModelBuilder", 10) - self.add("HexParaCrystal", "BasicGISAS", "HexParaCrystalBuilder", 1) - self.add("SSCA", "MaxiGISAS", "SizeDistributionSSCAModelBuilder", 10) self.add("Mesocrystal", "MaxiGISAS", "MesoCrystalBuilder", 2) - self.add("PolMagCyl", "MaxiGISAS00", "MagneticCylindersBuilder", 10) + self.add("PolMagCyl", "MaxiGISAS00", "MagneticCylindersBuilder", + 10) # custom form factor is a special case since it's not in the registry self.m_tests.append(CustomTest("Custom FF", 10)) @@ -221,7 +229,8 @@ class PerformanceTests: def add(self, name, simulation_name, sample_builder, nrepetitions): self.m_tests.append( - FactoryTest(name, simulation_name, sample_builder, nrepetitions)) + FactoryTest(name, simulation_name, sample_builder, + nrepetitions)) # execute all performance tests def execute(self): @@ -279,7 +288,8 @@ class PerformanceTests: # determine platform, architecture, python version, etc. def init_sysinfo(self): - system, node, release, version, machine, processor = platform.uname() + system, node, release, version, machine, processor = platform.uname( + ) self.m_datime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') self.m_hostname = node diff --git a/Wrap/Python/ba_fitmonitor.py b/Wrap/Python/ba_fitmonitor.py index 4b01ec3c56624c4d38625df552002930e9be4042..6b5b11ad1ab18549689bbf875c275dd9ce8fedff 100644 --- a/Wrap/Python/ba_fitmonitor.py +++ b/Wrap/Python/ba_fitmonitor.py @@ -23,6 +23,7 @@ except Exception as e: label_fontsize = 16 + class Plotter: """ Draws fit progress. Base class for simulation-specific classes (PlotterGISAS etc). @@ -123,8 +124,8 @@ class PlotterGISAS(Plotter): iteration_info = fit_objective.iterationInfo() plt.text( - 0.01, 0.85, - "Iterations " + '{:d}'.format(iteration_info.iterationCount())) + 0.01, 0.85, "Iterations " + + '{:d}'.format(iteration_info.iterationCount())) plt.text(0.01, 0.75, "Chi2 " + '{:8.4f}'.format(iteration_info.chi2())) index = 0 @@ -175,7 +176,8 @@ class PlotterSpecular(Plotter): :param length: max non-truncated length :return: """ - return (token[:length - 2] + '..') if len(token) > length else token + return (token[:length - 2] + + '..') if len(token) > length else token def plot_table(self, fit_objective): @@ -222,10 +224,15 @@ class PlotterSpecular(Plotter): # data values sim_values = sim_data.array(self.units) real_values = real_data.array(self.units) - unc_values = None if unc_data is None else unc_data.array(self.units) + unc_values = None if unc_data is None else unc_data.array( + self.units) # default font properties dictionary to use - font = {'family': 'serif', 'weight': 'normal', 'size': label_fontsize} + font = { + 'family': 'serif', + 'weight': 'normal', + 'size': label_fontsize + } plt.subplot(self.gs[0]) plt.semilogy(sim_data.axis(), sim_values, 'b', real_data.axis(), diff --git a/Wrap/Python/ba_plot.py b/Wrap/Python/ba_plot.py index 7f884bd8c01456726ed7043d209a57df8edf2ec4..aae62b12463fc2a77f1a751a36d2f35a518cb0f4 100644 --- a/Wrap/Python/ba_plot.py +++ b/Wrap/Python/ba_plot.py @@ -108,7 +108,12 @@ def plot_array(array, axes_limits=None, **kwargs): aspect = kwargs.pop('aspect', 'equal') cmap = kwargs.pop('cmap', CMAP) - im = plt.imshow(array, cmap=cmap, norm=norm, aspect=aspect, extent=axes_limits, **kwargs) + im = plt.imshow(array, + cmap=cmap, + norm=norm, + aspect=aspect, + extent=axes_limits, + **kwargs) cb = plt.colorbar(im, pad=0.025) if xlabel: @@ -144,7 +149,10 @@ def plot_histogram(hist, **kwargs): title = kwargs.pop('title', None) - plot_array(hist.array(), title=title, axes_limits=axes_limits, **kwargs) + plot_array(hist.array(), + title=title, + axes_limits=axes_limits, + **kwargs) def plot_colormap(result, **kwargs): @@ -181,7 +189,8 @@ def plot_specular_simulation_result(result, **kwargs): x_axis = result.axis(units) ymax = kwargs.pop('intensity_max', np.amax(np.amax(intensity)*2)) - ymin = kwargs.pop('intensity_min', max(np.amin(intensity)*0.5, 1e-18*ymax)) + ymin = kwargs.pop('intensity_min', + max(np.amin(intensity)*0.5, 1e-18*ymax)) xlabel = kwargs.pop('xlabel', get_axes_labels(result, units)[0]) ylabel = kwargs.pop('ylabel', "Intensity") @@ -211,7 +220,8 @@ def plot_simulation_result(result, **kwargs): """ noshow = kwargs.pop('noshow', NOSHOW) - if len(result.array().shape) == 1: # 1D data, specular simulation assumed + if len(result.array().shape + ) == 1: # 1D data, specular simulation assumed plot_specular_simulation_result(result, **kwargs) else: plot_colormap(result, **kwargs) @@ -221,6 +231,7 @@ def plot_simulation_result(result, **kwargs): else: print("plot_simulation_result: noshow") + def run_and_plot(simulation, **kwargs): simulation.runSimulation() plot_simulation_result(simulation.result(), **kwargs) diff --git a/Wrap/Python/bornagain_python_install.py b/Wrap/Python/bornagain_python_install.py index 7743517fe3483a83cb0993f3d1671695a7542abd..6479f0cb6814a912844fdf9b6464c81fafbad64f 100644 --- a/Wrap/Python/bornagain_python_install.py +++ b/Wrap/Python/bornagain_python_install.py @@ -47,8 +47,9 @@ def python_version_string(): def add_rpath(newpath, filename): print("add_rpath ", newpath, filename) - p = subprocess.Popen(['install_name_tool', '-add_rpath', newpath, filename], - stdout=subprocess.PIPE) + p = subprocess.Popen( + ['install_name_tool', '-add_rpath', newpath, filename], + stdout=subprocess.PIPE) p.communicate() return @@ -90,8 +91,8 @@ def get_python_shared_library(): Returns full path to the python shared library on which current interpreter is relying """ prefix = sys.prefix - suffix = sysconfig.get_config_var('LDVERSION') or sysconfig.get_config_var( - 'VERSION') + suffix = sysconfig.get_config_var( + 'LDVERSION') or sysconfig.get_config_var('VERSION') result = sys.prefix + "/lib/libpython" + suffix + ".dylib" return result @@ -113,10 +114,12 @@ def get_application_dir(): app_dir = sys.argv[1] else: script_dir = get_script_path() - app_dir = os.path.abspath(os.path.join(script_dir, "..", "..", "..")) + app_dir = os.path.abspath( + os.path.join(script_dir, "..", "..", "..")) # getting version number - lib_dir = glob.glob(os.path.join(app_dir, "Contents", "lib", "BornAgain-*")) + lib_dir = glob.glob( + os.path.join(app_dir, "Contents", "lib", "BornAgain-*")) if len(lib_dir) != 1: exit("Can't find BornAgain libraries in " + app_dir) @@ -192,7 +195,8 @@ setup(name='bornagain', def prepare_init_module(app_dir, bundle_dir): source_dir = os.path.join(app_dir, "Contents", "libexec") - libexec_dir = os.path.join(source_dir, "BornAgain-" + BORNAGAIN_VERSION, + libexec_dir = os.path.join(source_dir, + "BornAgain-" + BORNAGAIN_VERSION, "bornagain") package_dir = os.path.join(bundle_dir, "bornagain") print("--> Copying modules from '{0}' to '{1}'".format( @@ -216,7 +220,8 @@ def copy_libraries(app_dir, destination_dir): os.path.join(destination_dir, "BornAgain-" + BORNAGAIN_VERSION)) # cleaning unnecessary files - libfiles = glob.glob(os.path.join(destination_dir, '*/libBornAgainGUI*')) + libfiles = glob.glob( + os.path.join(destination_dir, '*/libBornAgainGUI*')) for f in libfiles: os.remove(f) pass @@ -227,8 +232,8 @@ def copy_libraries(app_dir, destination_dir): if not os.path.exists(frameworks_dest): os.makedirs(frameworks_dest) for lib in frameworks_libs: - shutil.copyfile(lib, os.path.join(frameworks_dest, - os.path.basename(lib))) + shutil.copyfile( + lib, os.path.join(frameworks_dest, os.path.basename(lib))) def patch_libraries(dir_name): @@ -296,8 +301,8 @@ def install_bundle(dir_name): os.chdir(bundle_dir) sys.argv = ['setup.py', 'install'] exec_full('setup.py') - print("\nBornAgain Python bundle is successfully installed in '{0}'".format( - get_python_lib())) + print("\nBornAgain Python bundle is successfully installed in '{0}'". + format(get_python_lib())) print("Congratulations!") @@ -316,7 +321,9 @@ if __name__ == '__main__': print("To :", get_python_lib()) print(" ") print("Possible options:") - print("[0] - Generate bundle with BornAgain libraries, do not install it.") + print( + "[0] - Generate bundle with BornAgain libraries, do not install it." + ) print( "[1] - Generate bundle and install it into site-packages of your Python." ) diff --git a/Wrap/Swig/doxy2swig.py b/Wrap/Swig/doxy2swig.py index 93c2aa5b175022d338203267c6c85102898fa96c..e2044194d4661263f101da3ca74bb5394375ad96 100755 --- a/Wrap/Swig/doxy2swig.py +++ b/Wrap/Swig/doxy2swig.py @@ -69,8 +69,9 @@ class Doxy2SWIG: 'innerclass', 'name', 'declname', 'incdepgraph', 'invincdepgraph', 'programlisting', 'type', 'references', 'referencedby', 'location', - 'collaborationgraph', 'reimplements', 'reimplementedby', - 'derivedcompoundref', 'basecompoundref') + 'collaborationgraph', 'reimplements', + 'reimplementedby', 'derivedcompoundref', + 'basecompoundref') #self.generics = [] def generate(self): @@ -188,8 +189,8 @@ class Doxy2SWIG: prot = node.attributes['prot'].value if prot != 'public': return - names = ('compoundname', 'briefdescription', 'detaileddescription', - 'includes') + names = ('compoundname', 'briefdescription', + 'detaileddescription', 'includes') first = self.get_specific_nodes(node, names) for n in names: #if first.has_key(n): diff --git a/cmake/pack/fix_apple_bundle.py b/cmake/pack/fix_apple_bundle.py index 7c5749866215da53a949eca43608032462deaa7f..9eb35f4edb7cca9c8b799b9df460ddcc3b85880d 100644 --- a/cmake/pack/fix_apple_bundle.py +++ b/cmake/pack/fix_apple_bundle.py @@ -53,8 +53,8 @@ def bundle_main_executables(): def bundle_python_library(): - return os.path.join("Python.framework", "Versions", python_version_string(), - "Python") + return os.path.join("Python.framework", "Versions", + python_version_string(), "Python") def qtlibs_path(): @@ -75,7 +75,8 @@ def bundle_plugins(): def bornagain_binaries(): - return bundle_main_executables() + bundle_libraries() + bundle_plugins() + return bundle_main_executables() + bundle_libraries() + bundle_plugins( + ) def get_list_of_files(dirname): @@ -121,7 +122,8 @@ def otool(filename): """ Parses dependencies of given binary file """ - p = subprocess.Popen(['otool', '-XL', filename], stdout=subprocess.PIPE) + p = subprocess.Popen(['otool', '-XL', filename], + stdout=subprocess.PIPE) # return iter(p.stdout.readline, b'') for line in iter(p.stdout.readline, b''): if is_python3(): @@ -145,8 +147,9 @@ def fixDependency(filename, old, new): Replaces old dependency with new one for given binary file """ print(" fixDependency(filename, old, new)", filename, old, new) - p = subprocess.Popen(['install_name_tool', '-change', old, new, filename], - stdout=subprocess.PIPE) + p = subprocess.Popen( + ['install_name_tool', '-change', old, new, filename], + stdout=subprocess.PIPE) p.communicate() return @@ -253,7 +256,8 @@ def get_dependency_dest_location(dependency): libname = os.path.basename(dependency) if is_python_framework_dependency(dependency): - return os.path.join(bundle_frameworks_path(), bundle_python_library()) + return os.path.join(bundle_frameworks_path(), + bundle_python_library()) if is_qt_framework_dependency(dependency): libpath = os.path.join(libname + ".framework", "Versions", "5") @@ -269,7 +273,8 @@ def get_special_dependency_id(dependency): if is_python_framework_dependency(dependency): return "@rpath/" + bundle_python_library() - if is_qt_framework_dependency(dependency) and not "@rpath" in dependency: + if is_qt_framework_dependency( + dependency) and not "@rpath" in dependency: libname = os.path.basename(dependency) return "@rpath/" + libname + ".framework/Versions/5/" + libname return None @@ -288,8 +293,8 @@ def get_python_library_location(): # Let's try to find library directly prefix = sys.prefix - suffix = sysconfig.get_config_var('LDVERSION') or sysconfig.get_config_var( - 'VERSION') + suffix = sysconfig.get_config_var( + 'LDVERSION') or sysconfig.get_config_var('VERSION') result = sys.prefix + "/lib/libpython" + suffix + ".dylib" if os.path.exists(result): return result @@ -308,7 +313,8 @@ def copy_python_framework(): """ print("--> Copying Python framework") python_lib = get_python_library_location() - destfile = os.path.join(bundle_frameworks_path(), bundle_python_library()) + destfile = os.path.join(bundle_frameworks_path(), + bundle_python_library()) make_dir(os.path.dirname(destfile)) print(" From '{0}'\n To '{1}'".format(python_lib, destfile)) if not os.path.exists(destfile):