PEATDB/Ekin/IO.py
def do_import_data(self, filename=None):
        """Returns a list of new ekin datasets this functions requires the use of
           the vars from the dialog, so is not independently callable"""
        import string

        if not self.do_import:
            return
        s=self.separator.get()

        # Get a root name for the datatabs if data in rows

        if self.column_row.get() == 1:
            import tkSimpleDialog
            showname=tkSimpleDialog.askstring('Tab name',
                                       'Root name for datasets?',
                                       parent=self.ekin_win)
        datasets = {}

        # Data in rows?
        if self.column_row.get()==1:
            #All the work is done in dopreview,
            #here we just really need to create the ekin datasets
            x = [i for i in self.inrows_xdata]            
            for name in self.inrows_datasets.keys():
                y = [i for i in self.inrows_datasets[name]]
		datasets[name]=EkinDataset(xy=[x,y])
        else:
           #Data in Cols, do all files in file list
           for filename in self.file_list:               
               showname=os.path.split(filename)[1]
               showname=showname.replace('_','-')               
               showname=os.path.splitext(showname)[0]
               lines = self.get_lines(filename)
               importdata = []
               x=[]; y=[]
               xerrs=[]; yerrs=[]
               self.numrows = len(lines)
               for row in range(self.startnum, self.numrows):
                    line = string.strip(lines[row])
                    if lines[row].startswith('#'):
                        continue
                    if s == ' ':
                        data=string.split(line)
                    else:
                        data=string.split(line, s)

                    #now get chosen cols using checkboxes, may be multiple datasets created
                    temp=[]
                    for c in range(len(data)):
                        if c < len(self.colschosen) and self.colschosen[c].get() == 1:
                            temp.append(data[c])
                    importdata.append(temp)
               
               if self.multiple_tabs.get() == 1:
                   #we want to put all the cols into new datasets                   
                   for i in range(1,len(importdata)):
                       try:
                           x.append(float(importdata[i][0]))
                       except:
                           x.append(None)
                   cols = importdata[0]
                   for j in range(1,len(cols)): #iterate over each col
                       y=[]
                       for i in range(1,len(importdata)):
                           try:
                               y.append(float(importdata[i][j]))
                           except:
                               y.append(None)
                       name = cols[j]                      
		       datasets[name] = EkinDataset(xy=[x,y])

               else:
                   #otherwise just take the 1st 2 and ignore the rest
                   for i in range(len(importdata)):
                       try:
                           xval=float(importdata[i][0])
                           yval=float(importdata[i][1])
                           x.append(xval)
                           y.append(yval)
                       except:
                           pass
                  
                   if self.geterrorcols.get()==1:
                       for i in range(len(importdata)):          
                           if len(importdata[i])>2:
                               xerr=float(importdata[i][2])
                               xerrs.append(xerr)
                           if len(importdata[i])>3: 
                               yerr=float(importdata[i][3])                       
                               yerrs.append(yerr)
                       if len(xerrs)!=x: xerrs=[]        
                   else:
                       xerrs=[]; yerrs=[]
                   print xerrs, yerrs
		   datasets[showname] = EkinDataset(xy=[x,y],
                                                    xerrs=xerrs, yerrs=yerrs)
        #print 'datasets', datasets
        return datasets
Returns a list of new ekin datasets this functions requires the use of
           the vars from the dialog, so is not independently callable
Returns a list of new ekin datasets this functions requires the use of
the vars from the dialog, so is not independently callable
Returns a list of new ekin datasets this functions requires the use of the vars from the dialog so is not independently callable
def do_import_data(self, filename=None):
        import string
        if not self.do_import:
            return
        s=self.separator.get()
        if self.column_row.get() == 1:
            import tkSimpleDialog
            showname=tkSimpleDialog.askstring('Tab name',
                                       'Root name for datasets?',
                                       parent=self.ekin_win)
        datasets = {}
        if self.column_row.get()==1:
            x = [i for i in self.inrows_xdata]            
            for name in self.inrows_datasets.keys():
                y = [i for i in self.inrows_datasets[name]]
		datasets[name]=EkinDataset(xy=[x,y])
        else:
           for filename in self.file_list:               
               showname=os.path.split(filename)[1]
               showname=showname.replace('_','-')               
               showname=os.path.splitext(showname)[0]
               lines = self.get_lines(filename)
               importdata = []
               x=[]; y=[]
               xerrs=[]; yerrs=[]
               self.numrows = len(lines)
               for row in range(self.startnum, self.numrows):
                    line = string.strip(lines[row])
                    if lines[row].startswith('#'):
                        continue
                    if s == ' ':
                        data=string.split(line)
                    else:
                        data=string.split(line, s)
                    temp=[]
                    for c in range(len(data)):
                        if c < len(self.colschosen) and self.colschosen[c].get() == 1:
                            temp.append(data[c])
                    importdata.append(temp)
               if self.multiple_tabs.get() == 1:
                   for i in range(1,len(importdata)):
                       try:
                           x.append(float(importdata[i][0]))
                       except:
                           x.append(None)
                   cols = importdata[0]
                   for j in range(1,len(cols)): 
                       y=[]
                       for i in range(1,len(importdata)):
                           try:
                               y.append(float(importdata[i][j]))
                           except:
                               y.append(None)
                       name = cols[j]                      
		       datasets[name] = EkinDataset(xy=[x,y])
               else:
                   for i in range(len(importdata)):
                       try:
                           xval=float(importdata[i][0])
                           yval=float(importdata[i][1])
                           x.append(xval)
                           y.append(yval)
                       except:
                           pass
                   if self.geterrorcols.get()==1:
                       for i in range(len(importdata)):          
                           if len(importdata[i])>2:
                               xerr=float(importdata[i][2])
                               xerrs.append(xerr)
                           if len(importdata[i])>3: 
                               yerr=float(importdata[i][3])                       
                               yerrs.append(yerr)
                       if len(xerrs)!=x: xerrs=[]        
                   else:
                       xerrs=[]; yerrs=[]
                   print xerrs, yerrs
		   datasets[showname] = EkinDataset(xy=[x,y],
                                                    xerrs=xerrs, yerrs=yerrs)
        return datasets
def do_import_data ( self , filename = None ) : import string if not self . do_import : return s = self . separator . get ( ) if self . column_row . get ( ) == 1 : import tkSimpleDialog showname = tkSimpleDialog . askstring ( 'Tab name' , 'Root name for datasets?' , parent = self . ekin_win ) datasets = { } if self . column_row . get ( ) == 1 : x = [ i for i in self . inrows_xdata ] for name in self . inrows_datasets . keys ( ) : y = [ i for i in self . inrows_datasets [ name ] ] datasets [ name ] = EkinDataset ( xy = [ x , y ] ) else : for filename in self . file_list : showname = os . path . split ( filename ) [ 1 ] showname = showname . replace ( '_' , '-' ) showname = os . path . splitext ( showname ) [ 0 ] lines = self . get_lines ( filename ) importdata = [ ] x = [ ] ; y = [ ] xerrs = [ ] ; yerrs = [ ] self . numrows = len ( lines ) for row in range ( self . startnum , self . numrows ) : line = string . strip ( lines [ row ] ) if lines [ row ] . startswith ( '#' ) : continue if s == ' ' : data = string . split ( line ) else : data = string . split ( line , s ) temp = [ ] for c in range ( len ( data ) ) : if c < len ( self . colschosen ) and self . colschosen [ c ] . get ( ) == 1 : temp . append ( data [ c ] ) importdata . append ( temp ) if self . multiple_tabs . get ( ) == 1 : for i in range ( 1 , len ( importdata ) ) : try : x . append ( float ( importdata [ i ] [ 0 ] ) ) except : x . append ( None ) cols = importdata [ 0 ] for j in range ( 1 , len ( cols ) ) : y = [ ] for i in range ( 1 , len ( importdata ) ) : try : y . append ( float ( importdata [ i ] [ j ] ) ) except : y . append ( None ) name = cols [ j ] datasets [ name ] = EkinDataset ( xy = [ x , y ] ) else : for i in range ( len ( importdata ) ) : try : xval = float ( importdata [ i ] [ 0 ] ) yval = float ( importdata [ i ] [ 1 ] ) x . append ( xval ) y . append ( yval ) except : pass if self . geterrorcols . get ( ) == 1 : for i in range ( len ( importdata ) ) : if len ( importdata [ i ] ) > 2 : xerr = float ( importdata [ i ] [ 2 ] ) xerrs . append ( xerr ) if len ( importdata [ i ] ) > 3 : yerr = float ( importdata [ i ] [ 3 ] ) yerrs . append ( yerr ) if len ( xerrs ) != x : xerrs = [ ] else : xerrs = [ ] ; yerrs = [ ] print xerrs , yerrs datasets [ showname ] = EkinDataset ( xy = [ x , y ] , xerrs = xerrs , yerrs = yerrs ) return datasets
Returns a list of new ekin datasets this functions requires the use of
the vars from the dialog, so is not independently callable
Returns a list of new ekin datasets this functions requires the use of the vars from the dialog so is not independently callable
"""Returns a list of new ekin datasets this functions requires the use of
           the vars from the dialog, so is not independently callable""" # Get a root name for the datatabs if data in rows # Data in rows? #All the work is done in dopreview, #here we just really need to create the ekin datasets #Data in Cols, do all files in file list #now get chosen cols using checkboxes, may be multiple datasets created #we want to put all the cols into new datasets                    #iterate over each col #otherwise just take the 1st 2 and ignore the rest #print 'datasets', datasets
self
filename