def test_get_th(self): b = B10.B10() config = b.configurations.get('10B4C 2.24g/cm3') assert B10.find_th(config.get('alpha94'), 200000) == 28000.0 assert B10.find_th(config.get('Li94'), 200000) == 11000.0 assert B10.find_th(config.get('alpha06'), 200000) == 37000.0 assert B10.find_th(config.get('Li06'), 200000) == 13000.0
def plot_eff_vs_wave_meta(self): """plots the efficiency for a set of wavelengths, Args: sigma: Full sigma calculation fo the detector ranges: Ranges calculation blades: detector blades result: Efficiency figure: figure to plot in Returns: plotted figure reference: figure 3.13 On Francesco's Thesis """ sigmalist = np.arange(0.0011, 20, 0.1) sigmaeq = [] for sigma in sigmalist: # transformation for meeting requirements of functions sigma = [[sigma], ] sigmaeq.append(B10.B10().full_sigma_calculation(sigma, self.angle)) ranges = self.calculate_ranges() blades = self.blades result = self.calculate_eff() wavelength = self.wavelength y = efftools.metadata_diffthick_vs_wave(sigmaeq, blades, ranges, len(blades)) self.metadata.update({'effVsWave': [sigmalist, y]}) print("plot_eff_vs_wave_meta")
def test_configurations(self): b = B10.B10() assert len(b.configurations) == 2 conf = b.configurations.get('10B4C 2.24g/cm3') assert len(conf) == 4 conf = b.configurations.get('10B4C 2.20g/cm3') assert len(conf) == 4
def test_read_cross_section(self): # to test floats I need an aproximation given by numpy :/ b = B10.B10() assert numpy.isclose(b.read_cross_section([[1.8, 100]])[0], [3844.3852472], rtol=1e-05, atol=1e-08, equal_nan=False)
def plot_eff_vs_wave(self): """plots the efficiency for a set of wavelengths, Args: sigma: Full sigma calculation fo the detector ranges: Ranges calculation blades: detector blades result: Efficiency figure: figure to plot in Returns: plotted figure reference: figure 3.13 On Francesco's Thesis """ sigmalist = np.arange(0.0011, 20, 0.1) sigmaeq = [] for sigma in sigmalist: # transformation for meeting requirements of functions sigma = [ [sigma], ] sigmaeq.append(B10.B10().full_sigma_calculation(sigma, self.angle)) ranges = self.calculate_ranges() blades = self.blades result = self.calculate_eff() wavelength = self.wavelength y = efftools.metadata_diffthick_vs_wave(sigmaeq, blades, ranges, len(blades)) cx = plt.figure(1) plt.subplot(111) self.metadata.update({'effVsWave': [sigmalist, y]}) plt.plot(sigmalist, np.array(y), color='g') if len(self.wavelength) == 1: if self.single: plt.plot([wavelength[0][0], wavelength[0][1]], [0, result[0][1]], '--', color='k') plt.plot([0, wavelength[0][0]], [result[0][1], result[0][1]], '--', color='k') else: plt.plot([wavelength[0][0], wavelength[0][0]], [0, np.array(result[1])], '--', color='k') plt.plot([0, wavelength[0][0]], [np.array(result[1]), np.array(result[1])], '--', color='k') plt.grid(True) plt.xlabel(r'Neutron wavelength ($\AA$)') plt.ylabel('Detector efficiency (%)') # ticks = cx.get_yticks() * 100 # cx.set_yticklabels(ticks) return cx
def __init__(self, name='Detector', angle=90, threshold=100, single=False): self.converter = B10.B10() self.name = name self.wavelength = [] self.angle = angle self.threshold = threshold self.single = single self.metadata = {} self.blades = [] self.converterConfiguration = ''
def test_full_sigma_calculation(self): b = B10.B10() sigma = b.full_sigma_calculation([[1.8, 100]], 90) assert numpy.isclose([sigma], [0.0398457257908], rtol=1e-05, atol=1e-08, equal_nan=False) sigma = b.full_sigma_calculation([[2, 100]], 3) assert numpy.isclose([sigma], [0.845952315849], rtol=1e-05, atol=1e-08, equal_nan=False)
def test_sigma_eq(self): b = B10.B10() sigmaeq = b.sigma_eq([0.0398457257908], 90) assert numpy.isclose([sigmaeq], [0.0398457257908], rtol=1e-05, atol=1e-08, equal_nan=False) sigmaeq = b.sigma_eq([0.0398457257908], 5) assert numpy.isclose([sigmaeq], [0.457178431789], rtol=1e-05, atol=1e-08, equal_nan=False)
def test_ranges(self): b = B10.B10() r1 = b.ranges(200, '10B4C 2.24g/cm3') r2 = b.ranges(100, '10B4C 2.24g/cm3') assert r1[0] == 2.8 assert r1[1] == 1.1 assert r1[2] == 3.7 assert r1[3] == 1.3 assert r2[0] == 3.1 assert r2[1] == 1.35 assert r2[2] == 4.0 assert r2[3] == 1.6
def test_mg_same_thick(self): b = B10.B10() sigma = b.full_sigma_calculation([[1.8, 100]], 5) r1 = b.ranges(200, '10B4C 2.24g/cm3') thick = 1 # check if mg with 1 blade and single blade gives the same value assert numpy.isclose( mg_same_thick(sigma[0], r1, thick, 1), [efficiency4boron(thick, r1[0], r1[1], r1[2], r1[3], sigma[0])[0]], rtol=1e-05, atol=1e-08, equal_nan=False) assert numpy.isclose(mg_same_thick(sigma[0], r1, thick, 20), [0.69218537268800717], rtol=1e-05, atol=1e-08, equal_nan=False)
def test_macro_sigma(self): b = B10.B10() assert numpy.isclose(b.macro_sigma([3844.3852472]), [0.0398457257908], rtol=1e-05, atol=1e-08, equal_nan=False)
def __init__(self, detector, action, parent = None): super(detectorDialog, self).__init__(parent) uic.loadUi(os.path.dirname(os.path.abspath(__file__))+"/detectorDialogTab.ui", self) self.state = 'venv' self.Boron = B10.B10() self.action = action self.detector = detector self.setWindowTitle("Detector configurator") if detector.converterConfiguration != '': if detector.converterConfiguration is not None: index = self.converterComboBox.findText(detector.converterConfiguration) self.converterComboBox.setCurrentIndex(index) self.detector.delete = False self.nameLineEdit.setText(detector.name) self.angleSpinBox.setValue(detector.angle) self.thresholdSpinBox.setValue(detector.threshold) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.waveTabWidget.hide() self.waveFormWidget.show() self.effWidget.hide() self.bladeTabWidget.show() self.bladePlotWidget.hide() self.thickVsEff = [] # Add plots layouts self.waveInfoFigure = matplotlib.figure.Figure() self.waveInfoCanvas = FigureCanvas(self.waveInfoFigure) self.wavePlotLayout.addWidget(self.waveInfoCanvas) self.bladeInfoFigure = matplotlib.figure.Figure() self.bladeInfoCanvas = FigureCanvas(self.bladeInfoFigure) self.bladePlotLayout.addWidget(self.bladeInfoCanvas) self.bladeEffFigure = matplotlib.figure.Figure() self.bladeEffCanvas = FigureCanvas(self.bladeEffFigure) self.bladeEfficiencyPlotLayout.addWidget(self.bladeEffCanvas) self.thickVsEffFigure = matplotlib.figure.Figure() self.thickVsEffCanvas = FigureCanvas(self.thickVsEffFigure) self.thickVsEffPlotLayout.addWidget(self.thickVsEffCanvas) self.waveVsEffFigure = matplotlib.figure.Figure() self.waveVsEffCanvas = FigureCanvas(self.waveVsEffFigure) self.waveVsEffPlotLayout.addWidget(self.waveVsEffCanvas) self.phsFigure = matplotlib.figure.Figure() self.phsCanvas = FigureCanvas(self.phsFigure) self.phsPlotLayout.addWidget(self.phsCanvas) #Interaction plot toolbars self.toolbar = NavigationToolbar(self.thickVsEffCanvas, self) self.toolbar2 = NavigationToolbar(self.waveVsEffCanvas, self) self.toolbar3 = NavigationToolbar(self.bladeEffCanvas, self) self.toolbar4 = NavigationToolbar(self.bladeInfoCanvas, self) self.toolbar5 = NavigationToolbar(self.waveInfoCanvas, self) self.thickToolLayout.addWidget(self.toolbar) self.waveToolLayout.addWidget(self.toolbar2) self.wavePlotLayout.addWidget(self.toolbar5) self.bladetoolPlotLayout.addWidget(self.toolbar4) self.effPlotHorizontalLayout.addWidget(self.toolbar3) self.BladeTableWidget.setColumnWidth(0, 70) self.BladeTableWidget.setColumnWidth(1, 85) self.BladeTableWidget.setColumnWidth(2, 115) self.BladeTableWidget.setColumnWidth(3, 75) self.verticalLayout_8.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop) self.verticalLayout.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop) self.substrateComboBox.setToolTip('') # self.toolbar.hide() if self.action == 'create': self.deleteButton.setEnabled(False) # List widget update if len(self.detector.blades) > 0: print ('loading blade') self.addBladeButton.setEnabled(False) try: c = 0 ax = self.bladeInfoFigure.add_subplot(111) ax.set_xlabel('Blade number') ax.set_ylabel('Blade thickness (micronm)') ax.set_ylim([0,8]) ax.plot(0, 0) ax.plot(len(self.detector.blades)+1, 0) for b in self.detector.blades: rowPosition = c self.BladeTableWidget.insertRow(rowPosition) # Note that the plot displayed is the backscattering thickness ax.plot(c+1, b.backscatter, 'd', color='black') item = QtWidgets.QTableWidgetItem('Blade N:'+str(c+1)) # execute the line below to every item you need locked item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.BladeTableWidget.setItem(rowPosition, 0, QtWidgets.QTableWidgetItem(item)) item = QtWidgets.QTableWidgetItem(str(b.backscatter)) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsEditable) self.BladeTableWidget.setItem(rowPosition, 1, item) # self.BladeTableWidget.setItem(rowPosition, 2, QtWidgets.QTableWidgetItem(str(b.transmission))) item = QtWidgets.QTableWidgetItem(str(b.substrate)) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsEditable) self.BladeTableWidget.setItem(rowPosition, 2, QtWidgets.QTableWidgetItem(item)) item = QtWidgets.QTableWidgetItem('unknown') item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.BladeTableWidget.setItem(rowPosition, 3, QtWidgets.QTableWidgetItem(item)) c += 1 ax.grid(True) if self.detector.single: self.bladeClassLabel.setText("Single coated blade") else: self.bladeClassLabel.setText("Multigrid with " + str(len(self.detector.blades)) + " blades") self.effWidget.show() self.bladePlotWidget.show() self.bladeTabWidget.hide() self.bladeInfoCanvas.draw() except IndexError: print ('no blades') else: self.deleteBladeButton.setEnabled(False) if len(self.detector.wavelength) > 0: print ('loading wavelength') try: c = 0 self.waveTabWidget.show() self.waveFormWidget.hide() if len(self.detector.wavelength) > 1: ax = self.waveInfoFigure.add_subplot(111) ax.set_xlabel('Wavelength ($\AA$)') ax.set_ylabel('weight (%)') # ax.set_xlim([0, len(wave)]) # a = [[1, 2], [3, 3], [4, 4], [5, 2]] # ax.plot(a, 'ro') # ax.plot(wave) ax.plot(self.detector.wavelength, color='b') ax.grid() else: ax = self.waveInfoFigure.add_subplot(111) ax.set_xlabel('Wavelength ($\AA$)') ax.set_ylabel('weight (%)') # a = [[1, 2], [3, 3], [4, 4], [5, 2]] # ax.plot(a, 'ro') # ax.plot(wave) x = self.wavePoliSpinBox.value() y = self.percentPoliSpinBox.value() ax.plot([x, x], [0, 100], color='b') ax.set_xlim([0, x + x]) ax.grid() for b in self.detector.wavelength: rowPosition = c self.lambdaTableWidget.insertRow(rowPosition) self.lambdaTableWidget.setItem(rowPosition, 0, QtWidgets.QTableWidgetItem(str(b[0]))) self.lambdaTableWidget.setItem(rowPosition, 1, QtWidgets.QTableWidgetItem(str(b[1]))) c += 1 except IndexError: print ('no wavelength') else: self.deleteWaveButton.setEnabled(False) #Button connections self.deleteWaveButton.clicked.connect(lambda: self.delete_wavelength()) self.addBladeButton.clicked.connect(lambda: self.add_blades()) self.addSingleBladeButton.clicked.connect(lambda: self.add_layer()) self.addPoliWavelengthButton.clicked.connect(lambda: self.add_poli_wavelength()) self.deleteBladeButton.clicked.connect(lambda: self.delete_blades()) self.deleteButton.clicked.connect(lambda: self.delete_detector()) self.calculateTotalEffButton.clicked.connect(lambda: self.calculate_total_efficiency()) self.optimizeThicknessSameButton.clicked.connect(lambda: self.optimize_thickness_same()) self.optimizeThicknessDiffButton.clicked.connect(lambda: self.optimize_thickness_diff()) self.exportButton.clicked.connect(lambda: self.export()) self.exportThickvseffButton.clicked.connect(lambda: self.export_plot_file('effvsthick')) self.exportEffVsDepthButton.clicked.connect(lambda: self.export_plot_file('effvsdepth')) self.exportEffVsWaveButton.clicked.connect(lambda: self.export_plot_file('effVsWave')) self.nameLineEdit.textChanged.connect(lambda: self.updateDetector()) self.importWaveButton.clicked.connect(lambda: self.importWave()) self.exportThickDepthButton.clicked.connect(lambda: self.export_plot_file('thickDepth')) #table edit signal self.BladeTableWidget.itemChanged.connect(self.tableEdited) #Button disable self.exportButton.setEnabled(False) self.calculateTotalEffButton.setDefault(True) self.exportThickvseffButton.setEnabled(False) self.exportEffVsWaveButton.setEnabled(False) self.optimizeThicknessDiffButton.setEnabled(False) #validation for name line edit reg_ex = QtCore.QRegExp("[A-Za-z0-9_]{0,255}") name_validator = QtGui.QRegExpValidator(reg_ex, self.nameLineEdit) self.nameLineEdit.setValidator(name_validator)
def __init__(self): self.b = B10.B10()
def get_th_test(self): config = self.b.configurations.get('10B4C 2.24g/cm3') assert B10.find_th(config.get('alpha94'), 200000) == 28000.0 assert B10.find_th(config.get('Li94'), 200000) == 11000.0 assert B10.find_th(config.get('alpha06'), 200000) == 37000.0 assert B10.find_th(config.get('Li06'), 200000) == 13000.0
def converter_list(self): self.Boron = B10.B10() self.converters.update(self.Boron.configurations)
import neutron_detector_eff_functions.Aluminium as Aluminium import neutron_detector_eff_functions.Converter as Converter import neutron_detector_eff_functions.efftools as efftools import neutron_detector_eff_functions.B10 as B10 import itertools import shutil import os import analysis_helper_functions as hf # ============================================================================== # DEFINE PARAMETERS # ============================================================================== # General parameters B10_object = B10.B10() al_sub = 500 # um inclination = 90 threshold = 120 ranges = B10_object.ranges(threshold, '10B4C 2.24g/cm3') wavelengths = np.linspace(0.7, 7, 100) coatings_ideal = np.concatenate( (np.ones(5) * 1, np.ones(10) * 1.25, np.ones(6) * 2)) # Blade positions relative to triple blade center (cm) middle_blade_1 = -7.325 middle_blade_2 = 7.325 upper_blade_1 = 7.925 upper_blade_2 = 22.575 lower_blade_1 = -22.575 lower_blade_2 = -7.925