Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
    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.adv.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)

        page1.Chain(page2).Chain(page3).Chain(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
Ejemplo n.º 3
0
    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()
Ejemplo n.º 4
0
    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 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[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].extra_data_raw[
                'xe'] = load_array[:, self.xe_col]
            self.data[data_item_number].extra_commands['xe'] = 'xe'
            self.data[data_item_number].extra_data_raw[
                'ai'] = load_array[:, self.ai_col]
            self.data[data_item_number].extra_commands['ai'] = 'ai'
            # 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.SendUpdateDataEvent()
            self.UpdateDataList()
Ejemplo n.º 5
0
    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, 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]\
                    ],\
                     names = 'h, k, l, I, eI, LB, dL')
            # 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')
                self.data[-1].set_extra_data('LB', tmp['LB'], 'LB')
                self.data[-1].set_extra_data('dL', tmp['dL'], 'dL')
                # Increase the index
                i += len(tmp)

            # Update the data list
            self.UpdateDataList()
            # Send an update that new data has been loaded
            self.SendUpdateDataEvent()