def load_two_theta(self): __file_name = utility.get_filename(io='open', caption='Load 2-theta data file') if not __file_name: return self.data_file = __file_name try: self.two_theta_data = np.loadtxt(self.data_file, unpack=False) except ValueError: _message = [ 'Error loading file!', 'Unable to load file.\nPlease check filename is correct and make sure header lines are commented (#)' ] self.error_msg = QMessageBox() self.error_msg.setIcon(QMessageBox.Warning) self.error_msg.setStandardButtons(QMessageBox.Ok) self.error_msg.setText(_message[0]) self.error_msg.setInformativeText((_message[1])) self.error_msg.setWindowTitle(__appname__ + ' v' + __version__) self.error_msg.adjustSize() self.error_msg.show() self.data_file = None self.two_theta_data = None return self.data_filename_lbl.setText(self.data_file.split('/')[-1]) __split_path = os.path.splitext(self.data_file) self.default_fname = __split_path[0] + '_qspace' + __split_path[1]
def load_bkg(self): __file_name = utility.get_filename(io='open', caption='Load Background File') if __file_name: self.bkg_file = __file_name else: return try: self.data['bkg_raw_x'], self.data['bkg_raw_y'] = np.loadtxt( self.bkg_file, unpack=True) if self.data_units: self.data['bkg_raw_x'] /= 10.0 except ValueError: self.bkg_file = None self.load_file_error() return try: self.rebin_data(bkg=1) except RuntimeWarning: self.oversize_file_error() self.bkg_file = None return self.bkg_config_widget.data_files_gb.bkg_filename_lbl.setText( self.bkg_file.split('/')[-1]) print(f'Background File: {self.bkg_file}')
def load_data(self): __file_name = utility.get_filename(io='open') if __file_name: self.data_file = __file_name else: return try: self.data['data_raw_x'], self.data['data_raw_y'] = np.loadtxt( self.data_file, unpack=True) # Convert to angstroms if data_units == 1 (nm) if self.data_units: self.data['data_raw_x'] /= 10.0 except ValueError: self.data_file = None self.load_file_error() return try: self.rebin_data(bkg=0) except RuntimeWarning: self.oversize_file_error() self.data_file = None return self.bkg_config_widget.data_files_gb.data_filename_lbl.setText( self.data_file.split('/')[-1]) print(f'Data file: {self.data_file}') self.file_name_changed.emit()
def save_sq(self): if not self.data['sq_y'].size: return # Base filename is the name of the input file (set in main_widget) __default_file_name = self.base_filename + '_SQ.dat' __file_name = utility.get_filename(io='save', directory=__default_file_name, caption='Save S(Q)') if not __file_name: return __header = ( f'Refined S(Q)\n' f'{__appname__} v{__version__}\n' f'See refinement_log for more info\n' f'Composition {{element: (Z, charge, n)}}: {self.data["composition"]}\n' f'Rho = {self.data["rho"]}\n' f'S(Q) formalism : {self.data["sq_method"]}\n' f'S(Q) = i(Q) + S_inf\n' f'S_inf = {np.str(self.data["S_inf"])}\n') if self.data['mod_func'] == 'None': __header += 'Q|S(Q)' __data = np.column_stack((self.data['sq_x'], self.data['sq_y'])) else: __header += f'M(Q) : {self.data["mod_func"]}\n' if self.data['mod_func'] == 'Cosine-window': __header += f'Window-start : {self.data["window_start"]}\n' __header += f'Q|S(Q)|i(Q)*M(Q)' __data = np.column_stack((self.data['sq_x'], self.data['sq_y'], self.data['mod_int_func'])) np.savetxt(__file_name, __data, header=__header, comments='#')
def save_q_space(self): if self.data_file is None or self.two_theta_data is None: return try: __lambda = np.float(self.lambda_input.text()) # Return if no wavelength set except ValueError: _message = ['No Wavelength Set!', 'Please set wavelength value'] self.error_msg = QMessageBox() self.error_msg.setIcon(QMessageBox.Warning) self.error_msg.setStandardButtons(QMessageBox.Ok) self.error_msg.setText(_message[0]) self.error_msg.setInformativeText((_message[1])) self.error_msg.setWindowTitle(__appname__ + ' v' + __version__) self.error_msg.adjustSize() self.error_msg.show() return try: # Get out filename self.convert_filename = utility.get_filename( io='save', caption='Save Q-space Data', directory=self.default_fname) except NameError: return if not self.convert_filename: return # Convert 2theta data __q_data = data_utils.convert_two_theta(self.two_theta_data[0], __lambda) __out_data = np.column_stack((__q_data, self.two_theta_data[1])) np.savetxt(self.convert_filename, __out_data) # Message user success self.success_msg = QMessageBox() self.success_msg.setIcon(QMessageBox.Information) self.success_msg.setStandardButtons(QMessageBox.Ok) self.success_msg.setText('Data converted to Q-Space!') self.success_msg.setInformativeText( ('Lambda: ' + str(__lambda) + '\nConverted data: ' + self.convert_filename)) self.success_msg.setWindowTitle(__appname__ + ' v' + __version__) self.success_msg.adjustSize() self.success_msg.show() # Clear variables del __lambda, __q_data, __out_data, self.convert_filename
def save_rdf(self): if not self.data['rdf_y'].size: return __default_file_name = self.base_filename + '_rdf.dat' __file_name = utility.get_filename(io='save', directory=__default_file_name, caption='Save RDF') if not __file_name: return __header = ( f'Refined rdf\n' f'{__appname__} v{__version__}\n' f'See refinement_log for more info\n' f'Composition {{element: (Z, charge, n)}}: {self.data["composition"]}\n' f'Rho = {self.data["rho"]}\n' f'r|rdf') __data = np.column_stack((self.data['rdf_x'], self.data['rdf_y'])) np.savetxt(__file_name, __data, header=__header, comments='#')