def addMaterialToStack(self, material): '''Function adds material to stack''' modifyName = True if self.name == '-'.join(self.layers) else False self.layers.append(material.name) if modifyName: self.name = '-'.join(self.layers) if is_number(material.standard_thickness): self.thickness.append(material.standard_thickness) material.actual_thickness = material.standard_thickness else: self.thickness.append(0) #self.material.fitStatus = False self.material.append(material) #TRA from DB #self.T =[] #self.R =[] #self.A =[] #TRA from design self.designT = [] self.designR = [] self.designA = [] #Splines TRA from design self.spline_designT = None self.spline_designR = None self.spline_designA = None
def storeFitParameters(self, e): for layer in self.ui.stack.material: #technically for statement is redundant, but leavingit in here as precaution. if layer.editMode: row = self.ui.fitTableWidget.currentItem().row() column = self.ui.fitTableWidget.currentItem().column() text = self.ui.fitTableWidget.currentItem().text() mat = self.ui.stack.material[column] #Status change handled in: storeFitStatus if row == 4: #Actual Height change t = getThicknessFromString(text) if not t == None: mat.actual_thickness = t elif is_number(text) and float(text) > 0: if row == 5: #de mat.de = float(text) elif row == 6: #wO_U mat.w0_U = float(text) elif row == 7: #wO_P mat.wp_U = float(text) elif row == 8: #gamma_U mat.gamma_U = float(text) elif row == 9: #wO_D mat.w0_D = float(text) elif row == 10: #wO_D mat.wp_D = float(text) elif row == 11: #gamma_D mat.gamma_D = float(text) mat.create_NKspline() #Disable modification event before updating the FitTable. try: self.ui.fitTableWidget.itemChanged.disconnect( self.storeFitParameters) except TypeError: pass self.loadFitParameters(self.ui.stack) self.ui.fitTableWidget.itemChanged.connect(self.storeFitParameters) self.updateFitGraph(self.ui.stack) self.updateFitColorDataToTable(self.ui.stack)
def plot_fitGraph(self, x, stack, settings, refresh=True): from helperFunctions import is_number self.axes.clear() error_string = 'Error: -' refresh = True if not x == None: xmin = min(settings.standard_wave_list) xmax = max(settings.standard_wave_list) if not stack.isEmpty() and not len(stack.fitT) == 0: if is_number(stack.RMSerror): error_string = 'Error: {:5.3f}'.format(stack.RMSerror) if refresh: self.fitT, = self.axes.plot(x, stack.fitT, color='C0', linewidth=2, linestyle="-", label="$T_{fit}$") self.fitR, = self.axes.plot(x, stack.fitR, color='C1', linewidth=2, linestyle="-", label="$R_{fit}$") if settings.display_absorbCurve: self.fitA, = self.axes.plot(x, stack.fitA, color='C2', linewidth=2, linestyle="-", label="$A_{fit}$") xmin = min(x) xmax = max(x) else: self.fitT.set_ydata(stack.fitT) self.fitR.set_ydata(stack.fitR) if settings.display_absorbCurve: self.fitA.set_ydata(stack.fitA) if stack.online and not len(stack.measureT) == 0: if refresh or not hasattr(self, 'measureT'): self.measureT, = self.axes.plot(stack.measure_wvl, stack.measureT, color='C0', linewidth=2, linestyle="--", label="$T_{online}$") self.measureR, = self.axes.plot(stack.measure_wvl, stack.measureR, color='C1', linewidth=2, linestyle="--", label="$R_{online}$") if settings.display_absorbCurve: self.measureA, = self.axes.plot( stack.measure_wvl, stack.measureA, color='C2', linewidth=2, linestyle="--", label="$A_{online}$") else: self.measureT.set_ydata(stack.measureT) self.measureR.set_ydata(stack.measureR) if settings.display_absorbCurve: self.measureA.set_ydata(stack.measureA) if settings.display_designCurvesInFit: if not (stack.designT == None or len(stack.designT) == 0): if refresh: self.designT, = self.axes.plot( stack.fit_wvl, stack.designT, color='C0', linewidth=2, linestyle=":", label="$T_{design}$") self.designR, = self.axes.plot( stack.fit_wvl, stack.designR, color='C1', linewidth=2, linestyle=":", label="$R_{design}$") if settings.display_absorbCurve: self.designA, = self.axes.plot( stack.fit_wvl, stack.designA, color='C2', linewidth=2, linestyle=":", label="$A_{design}$") else: self.designT.set_ydata(stack.designT) self.designR.set_ydata(stack.designR) if settings.display_absorbCurve: self.designA.set_ydata(stack.designA) if refresh: self.axes.set_xlim(xmin, xmax) self.axes.set_ylim(0, 1) self.axes.set_xlabel('$Wavelength (nm)$') self.axes.set_ylabel('Ratio') #print error string in plot: arg1 and 2 are x,y, transform indicates coordinates are indicated from 0,0 to 1,1. self.axes.xmargin = 0 self.axes.ymargin = 0 #if title != None: # self.axes.set_title(title) system_time_string = 'Sys time: ' + datetime.datetime.now( ).strftime("%Y-%m-%d %H:%M:%S") db_time_string = 'DB time: ' + str(stack.measuredTime) txt_error = self.axes.text(0.007, 1.02, error_string, transform=self.axes.transAxes, weight='bold', fontsize=12) txt_time = self.axes.text(0.207, 1.02, system_time_string, transform=self.axes.transAxes, weight='bold', fontsize=12) txt_msr = self.axes.text(0.407, 1.02, db_time_string, transform=self.axes.transAxes, weight='bold', fontsize=12) if refresh: self.axes.legend(loc="upper right", prop={'size': 14}) self.canvas.draw() else: self.axes.draw_artist(self.axes.patch) self.axes.draw_artist(self.fitT) self.axes.draw_artist(self.fitR) self.axes.draw_artist(self.measureT) self.axes.draw_artist(self.measureR) if settings.display_designCurvesInFit: self.axes.draw_artist(self.designT) self.axes.draw_artist(self.designR) self.axes.draw_artist(txt_error) self.axes.draw_artist(txt_time) self.axes.draw_artist(txt_msr) if settings.display_absorbCurve: self.axes.draw_artist(self.fitA) self.axes.draw_artist(self.measureA) if settings.display_designCurvesInFit: self.axes.draw_artist(self.designA) self.fig.canvas.update() self.fig.canvas.flush_events()
def save(self): import os from helperFunctions import is_number #Perform all checks filePath = self.excelDBFilePathLineEdit.text() if not os.path.isfile(filePath): self.raiseWarningMessage( 'Error', 'Invalid default DB file name or location detected. Settings not saved.' ) return False waves = self.standardWaveTextEdit.toPlainText() waves = waves.replace(" ", "") standard_wave_list = waves.split("\n") if standard_wave_list[0] == '': standard_wave_list = [] for wave in standard_wave_list: if not is_number(wave): self.raiseWarningMessage( 'Error', 'Invalid entry detected in Standard Wave List. Settings not saved.' ) return False standard_wave_list = [float(i) for i in standard_wave_list] text = self.includedWaveTextEdit.toPlainText() text = text.replace(" ", "") domain_list = text.split("\n") domain_min_wvl = [] domain_max_wvl = [] if not domain_list[0] == '': for domain in domain_list: d = domain.split("-") if not len(d) == 2: self.raiseWarningMessage( 'Error', 'Invalid entry detected in Domains. Settings not saved.' ) return False elif (not is_number(d[0])) or (not is_number(d[1])): self.raiseWarningMessage( 'Error', 'Invalid entry detected in Domains. Settings not saved.' ) return False elif float(d[0]) > float(d[1]): self.raiseWarningMessage( 'Error', 'Invalid entry detected in Domains. Settings not saved.' ) return False domain_min_wvl.append(float(d[0])) domain_max_wvl.append(float(d[1])) standard_wave_list_mod = self.calculateStandardWaveListModified( standard_wave_list, domain_min_wvl, domain_max_wvl) if len(standard_wave_list_mod) < 3: self.raiseWarningMessage( 'Error', 'Total wavelengths in domain have to be more than 2. Settings not saved.' ) return False else: standard_wave_list_mod = self.settings.standard_wave_list #Save self.settings.defaultFile = filePath self.settings.standard_wave_list = standard_wave_list self.settings.standard_wave_list_mod = standard_wave_list_mod self.settings.domain_min_wvl = domain_min_wvl self.settings.domain_max_wvl = domain_max_wvl self.settings.incident_angle = self.incidentAngleSpinBox.value() self.settings.incoherence_factor = self.incoherenceFactorSpinBox.value( ) self.settings.display_absorbCurve = self.absorbCheckBox.isChecked() self.settings.display_designCurvesInFit = self.fitModelCurveCheckBox.isChecked( ) #Write settings to file self.settings.saveSettings() return True
def plot_designGraph(self, x, stack, settings, refresh=True): from helperFunctions import is_number self.axes.clear() error_string = 'Error: -' self.annot = self.axes.annotate("", xy=(0, 0), xytext=(-20, 20), textcoords="offset points", bbox=dict(boxstyle="round", fc="w"), arrowprops=dict(arrowstyle="->")) self.annot.set_visible(False) if not x == None: xmin = min(settings.standard_wave_list) xmax = max(settings.standard_wave_list) if not stack.isEmpty() and not len(stack.designT) == 0: if is_number(stack.RMSerror): error_string = 'Error: {:5.3f}'.format(stack.RMSerror) self.designT, = self.axes.plot(x, stack.designT, color='C0', linewidth=2, linestyle="-", label="$T_{design}$") self.designR, = self.axes.plot(x, stack.designR, color='C1', linewidth=2, linestyle="-", label="$R_{design}$") if settings.display_absorbCurve: self.designA, = self.axes.plot(x, stack.designA, color='C2', linewidth=2, linestyle="-", label="$A_{design}$") xmin = min(x) xmax = max(x) if not len(stack.excelT) == 0: self.excelT, = self.axes.plot(stack.excel_wvl, stack.excelT, color='C0', linewidth=2, linestyle="--", label="$T_{excel}$") self.excelR, = self.axes.plot(stack.excel_wvl, stack.excelR, color='C1', linewidth=2, linestyle="--", label="$R_{excel}$") if settings.display_absorbCurve: self.excelA, = self.axes.plot(stack.excel_wvl, stack.excelA, color='C2', linewidth=2, linestyle="--", label="$A_{excel}$") if min(x) > min(stack.excel_wvl): xmin = min(stack.excel_wvl) if max(x) < max(stack.excel_wvl): xmax = max(stack.excel_wvl) self.axes.legend(loc="upper right", prop={'size': 14}) if self.cid == None: self.cid = self.canvas.mpl_connect("motion_notify_event", self.hover_design) else: self.canvas.mpl_disconnect(self.cid) self.cid = None self.axes.set_xlim(xmin, xmax) self.axes.set_ylim(0, 1) self.axes.set_xlabel('$Wavelength (nm)$') self.axes.set_ylabel('Ratio') #print error string in plot: arg1 and 2 are x,y, transform indicates coordinates are indicated from 0,0 to 1,1. self.axes.xmargin = 0 self.axes.ymargin = 0 self.canvas.draw()