def LoadData(self, data_item_number, filename): '''LoadData(self, data_item_number, filename) --> none Loads the data from filename into the data_item_number. ''' # get scan number and polarization channel from filename name = '' fhandle = open(filename, 'r') fline = fhandle.readline() while not '[Data]' in fline: if 'Input file indices:' in fline: name += fline.split(':')[1].strip() if 'Extracted states:' in fline: name += ' (%s)' % (fline.split(':')[1].strip().split(' ')[0]) fline = fhandle.readline() if not fline: ShowWarningDialog( self.parent, 'Could not load the file: ' + filename + ' \nWrong format.\n') return try: load_array = np.loadtxt(fhandle, delimiter=self.delimiter, comments=self.comment, skiprows=self.skip_rows) except Exception, e: ShowWarningDialog( self.parent, 'Could not load the file: ' + filename + ' \nPlease check the format.\n\n numpy.loadtxt' + ' gave the following error:\n' + str(e)) return
def LoadData(self, data_item_number, filename): '''LoadData(self, data_item_number, filename) --> none Loads the data from filename into the data_item_number. ''' try: load_array = np.loadtxt(filename, delimiter=self.delimiter, comments=self.comment, skiprows=self.skip_rows) except Exception as e: ShowWarningDialog(self.parent, 'Could not load the file: ' +\ filename + ' \nPlease check the format.\n\n numpy.loadtxt'\ + ' gave the following error:\n' + str(e)) else: # For the freak case of only one data point if len(load_array.shape) < 2: load_array = np.array([load_array]) # Check so we have enough columns if load_array.shape[1] - 1 < max(self.x_col, self.y_col): ShowWarningDialog( self.parent, 'The data file does not contain enough number of columns. It has ' + str(load_array[1]) + ' columns. Rember that the column index start at zero!') self.SetStatusText('Could not load data - not enough columns') return # The data is set by the default Template.__init__ function # Know the loaded data goes into *_raw so that they are not # changed by the transforms self.data = self.parent.data_cont.get_data() self.data[data_item_number].x_raw = load_array[:, self.x_col] self.data[data_item_number].y_raw = load_array[:, self.y_col] # Check if we have errors in the data - if not handle it with nan's if load_array.shape[1] - 1 < self.e_col: self.data[ data_item_number].error_raw = load_array[:, self. y_col] * np.nan self.SetStatusText( 'Could not load error column - setting it to nan') else: self.data[data_item_number].error_raw = load_array[:, self.e_col] # Run the commands on the data - this also sets the x,y, error members of the data item. self.data[data_item_number].run_command() self.UpdateDataList() # Send an update that new data has been loaded self.SendUpdateDataEvent()
def LoadData(self, data_item_number, filename): """LoadData(self, data_item_number, filename) --> none Loads the data from filename into the data_item_number. """ try: datafile = Data(str(filename), debug=True) # does all the hard work here except Exception as e: ShowWarningDialog( self.parent, "Could not load the file: " + filename + " \nPlease check the format.\n\n Stoner.Data" + " gave the following error:\n" + str(e), ) else: # For the freak case of only one data point try: if datafile.setas.cols["axes"] == 0: self.x_col = datafile.find_col(self.x_col) self.y_col = datafile.find_col(self.y_col) self.e_col = datafile.find_col(self.e_col) datafile.etsas(x=self.x_col, y=self.y_col, e=self.e_col) else: self.x_col = datafile.setas.cols["xcol"] self.y_col = datafile.setas.cols["ycol"][0] if len(datafile.setas.cols["yerr"]) > 0: self.e_col = datafile.setas.cols["yerr"][0] else: datafile.add_column(np.ones(len(datafile))) datafile.setas[-1] = "e" except Exception as e: ShowWarningDialog( self.parent, "The data file does not contain" + "all the columns specified in the opions\n" + e.message, ) # Okay now we have showed a dialog lets bail out ... return # The data is set by the default Template.__init__ function, neat hu # Know the loaded data goes into *_raw so that they are not # changed by the transforms datafile.y = np.where(datafile.y == 0.0, 1e-8, datafile.y) self.data[data_item_number].x_raw = datafile.x self.data[data_item_number].y_raw = datafile.y self.data[data_item_number].error_raw = datafile.e # Run the commands on the data - this also sets the x,y, error memebers # of that data item. self.data[data_item_number].run_command() # Send an update that new data has been loaded self.SendUpdateDataEvent()
def LoadData(self, data_item_number, filename): '''LoadData(self, data_item_number, filename) --> none Loads the data from filename into the data_item_number. ''' # get scan number and polarization channel from filename name=os.path.basename(filename)[:-4] fhandle = open(filename, 'r') fline = fhandle.readline() while not 'q_z' in fline: if 'Input file indices:' in fline: name += fline.split(':')[1].strip() if 'Extracted states:' in fline: name += ' (%s)'%(fline.split(':')[1].strip().split(' ')[0]) fline = fhandle.readline() if not fline: ShowWarningDialog(self.parent, 'Could not load the file: ' + filename+' \nWrong format.\n') return try: load_array = np.loadtxt(fhandle, delimiter=self.delimiter, comments=self.comment, skiprows=self.skip_rows) except Exception as e: ShowWarningDialog(self.parent, 'Could not load the file: ' + filename + ' \nPlease check the format.\n\n numpy.loadtxt' + ' gave the following error:\n' + str(e)) return else: # For the freak case of only one data point if len(load_array.shape) < 2: load_array = np.array([load_array]) # Check so we have enough columns if load_array.shape[1] - 1 < max(self.x_col, self.y_col, self.e_col): ShowWarningDialog(self.parent, 'The data file does not contain' + 'enough number of columns. It has ' + str(load_array[1]) + ' columns. Rember that the column index start at zero!') # Okay now we have showed a dialog lets bail out ... return # The data is set by the default Template.__init__ function, neat hu # Know the loaded data goes into *_raw so that they are not # changed by the transforms self.data = self.parent.data_cont.get_data() self.data[data_item_number].x_raw=load_array[:, self.x_col] self.data[data_item_number].y_raw=load_array[:, self.y_col] self.data[data_item_number].error_raw=load_array[:, self.e_col] self.data[data_item_number].set_extra_data('res', load_array[:,self.xe_col], 'res') # Name the dataset accordign to file name self.data[data_item_number].name = name # Run the commands on the data - this also sets the x,y, error memebers # of that data item. self.data[data_item_number].run_command() # Send an update that new data has been loaded self.UpdateDataList() self.SendUpdateDataEvent()
def LoadDataFile(self, selected_items): ''' Called when GenX wants to load data''' if len(selected_items) == 0: ShowWarningDialog(self.parent, 'Please select a data set before trying to load a spec file.') return False old_data = self.datalist[selected_items[0]].copy() self.dataset = self.datalist[selected_items[0]] wizard = wx.wizard.Wizard(self.parent, -1, "Load Spec File", style = wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER) #page1 = TitledPage(wizard, "Page1") page1 = LoadSpecScanPage(wizard, self, default_filename = self.specfile_name) page2 = SelectCountersPage(wizard, self) page3 = CustomManipulationPage(wizard, self) page4 = SetNamePage(wizard, self) wx.wizard.WizardPageSimple_Chain(page1, page2) wx.wizard.WizardPageSimple_Chain(page2, page3) wx.wizard.WizardPageSimple_Chain(page3, page4) wizard.FitToPage(page1) #print dir(wizard) #print 'data: ', self.datalist[0].x if wizard.RunWizard(page1): return True else: self.datalist[selected_items[0]].safe_copy(old_data) return False
def LoadData(self, data_item_number, filename): '''LoadData(self, data_item_number, filename) --> none Loads the data from filename into the data_item_number. ''' try: load_array = np.loadtxt(filename, delimiter=self.delimiter, comments=self.comment, skiprows=self.skip_rows) except Exception as e: ShowWarningDialog(self.parent, 'Could not load the file: ' +\ filename + ' \nPlease check the format.\n\n numpy.loadtxt'\ + ' gave the following error:\n' + str(e)) else: # For the freak case of only one data point if len(load_array.shape) < 2: load_array = np.array([load_array]) # Check so we have enough columns if load_array.shape[1]-1 < max(self.q_col, self.res_col, \ self.I_col, self.eI_col): ShowWarningDialog(self.parent, 'The data file does not contain'\ + 'enough number of columns. It has ' + str(load_array.shape[1])\ + ' columns. Rember that the column index start at zero!') # Okay now we have showed a dialog lets bail out ... return # The data is set by the default Template.__init__ function, neat hu # Note that the loaded data goes into *_raw so that they are not # changed by the transforms #print load_array self.data[data_item_number].x_raw = load_array[:, self.q_col] self.data[data_item_number].y_raw = load_array[:, self.I_col] self.data[data_item_number].error_raw = load_array[:, self.eI_col] self.data[data_item_number].set_extra_data( 'res', load_array[:, self.res_col], 'res') self.data[data_item_number].res = load_array[:, self.res_col] * 1.0 # Run the commands on the data - this also sets the x,y, error memebers # of that data item. self.data[data_item_number].run_command() #print self.data[data_item_number].x # Send an update that new data has been loaded self.SendUpdateDataEvent()
def LoadData(self, data_item_number, filename): '''LoadData(self, data_item_number, filename) --> none Loads the data from filename into the data_item_number. ''' try: load_array = np.loadtxt(filename, delimiter = self.delimiter, comments = self.comment, skiprows = self.skip_rows) except Exception, e: ShowWarningDialog(self.parent, 'Could not load the file: ' +\ filename + ' \nPlease check the format.\n\n numpy.loadtxt'\ + ' gave the following error:\n' + str(e))
def LoadData(self, data_item_number, filename): '''LoadData(self, data_item_number, filename) --> none Loads the data from filename into the data_item_number. ''' try: datafile = SC.DataFile( str(filename)) # does all the hard work here except Exception, e: ShowWarningDialog(self.parent, 'Could not load the file: ' +\ filename + ' \nPlease check the format.\n\n Stoner.DataFile'\ + ' gave the following error:\n' + str(e))
delimiter=self.delimiter, comments=self.comment, skiprows=self.skip_rows) except Exception, e: ShowWarningDialog(self.parent, 'Could not load the file: ' +\ filename + ' \nPlease check the format.\n\n numpy.loadtxt'\ + ' gave the following error:\n' + str(e)) else: # For the freak case of only one data point if len(load_array.shape) < 2: load_array = np.array([load_array]) # Check so we have enough columns if load_array.shape[1]-1 < max(self.h_col, self.k_col,\ self.l_col, self.I_col, self.eI_col, self.LB_col, self.dL_col): ShowWarningDialog(self.parent, 'The data file does not contain'\ + 'enough number of columns. It has ' + str(load_array.shape[1])\ + ' columns. Rember that the column index start at zero!') # Okay now we have showed a dialog lets bail out ... return # The data is set by the default Template.__init__ function, neat hu # Note that the loaded data goes into *_raw so that they are not # changed by the transforms # Create an record array so we can sort the data properly data = np.rec.fromarrays([\ load_array[:,self.h_col].round().astype(type(1)),\ load_array[:,self.k_col].round().astype(type(1)),\ load_array[:,self.l_col], load_array[:,self.I_col],\ load_array[:,self.eI_col],\ load_array[:,self.LB_col], load_array[:,self.dL_col]\ ],\
''' try: datafile = SC.DataFile( str(filename)) # does all the hard work here except Exception, e: ShowWarningDialog(self.parent, 'Could not load the file: ' +\ filename + ' \nPlease check the format.\n\n Stoner.DataFile'\ + ' gave the following error:\n' + str(e)) else: # For the freak case of only one data point try: self.x_col = datafile.find_col(self.x_col) self.y_col = datafile.find_col(self.y_col) self.e_col = datafile.find_col(self.e_col) except KeyError: ShowWarningDialog(self.parent, 'The data file does not contain'\ + 'all the columns specified in the opions\n') # Okay now we have showed a dialog lets bail out ... return # The data is set by the default Template.__init__ function, neat hu # Know the loaded data goes into *_raw so that they are not # changed by the transforms datafile = SC.AnalyseFile(datafile) datafile = datafile.apply( lambda x: x1E - 8 if [self.y_col] == 0.0 else x[self.y_col], self.y_col, header=datafile.column_headers[self.y_col]) # clear out zeroes self.data[data_item_number].x_raw = datafile.column(self.x_col) self.data[data_item_number].y_raw = datafile.column(self.y_col) self.data[data_item_number].error_raw = datafile.column(self.e_col) # Run the commands on the data - this also sets the x,y, error memebers # of that data item.
def LoadData(self, data_item_number, filename): '''LoadData(self, data_item_number, filename) --> none Loads the data from filename into the data_item_number. ''' try: load_array = np.loadtxt(filename, delimiter=self.delimiter, comments=self.comment, skiprows=self.skip_rows) except Exception as e: ShowWarningDialog(self.parent, 'Could not load the file: ' +\ filename + ' \nPlease check the format.\n\n numpy.loadtxt'\ + ' gave the following error:\n' + str(e)) else: # For the freak case of only one data point if len(load_array.shape) < 2: load_array = np.array([load_array]) # Check so we have enough columns if load_array.shape[1]-1 < max(self.h_col, self.k_col, self.l_col,\ self.I_col, self.eI_col): ShowWarningDialog(self.parent, 'The data file does not contain'\ + 'enough number of columns. It has ' + str(load_array.shape[1])\ + ' columns. Rember that the column index start at zero!') # Okay now we have showed a dialog lets bail out ... return # The data is set by the default Template.__init__ function, neat hu # Note that the loaded data goes into *_raw so that they are not # changed by the transforms # Create an record array so we can sort the data properly data = np.rec.fromarrays([\ load_array[:,self.h_col].round().astype(type(1)),\ load_array[:,self.k_col].round().astype(type(1)),\ load_array[:,self.l_col], load_array[:,self.I_col],\ load_array[:,self.eI_col]\ ],\ names = 'h, k, l, I, eI') # Sort the data data.sort(order=('h', 'k', 'l')) i = 0 while i < len(data): # Find all the data for each rod tmp = data.compress(np.bitwise_and(data['h'] == data[i]['h'],\ data['k'] == data[i]['k'])) self.data.add_new('(%i, %i)' % (tmp['h'][0], tmp['k'][0])) self.data[-1].x_raw = tmp['l'] self.data[-1].y_raw = tmp['I'] self.data[-1].error_raw = tmp['eI'] # Run the commands on the data - this also sets the x,y, error memebers # of that data item. self.data[-1].run_command() self.data[-1].set_extra_data('h', tmp['h'], 'h') self.data[-1].set_extra_data('k', tmp['k'], 'k') # Increase the index i += len(tmp) # Update the data list self.UpdateDataList() # Send an update that new data has been loaded self.SendUpdateDataEvent()