示例#1
0
    def load_ftir_file(self):
        persist = PersistentStorage()
    
        try:
            last_path_used = persist.get_value("ftir_spectra_dir")
        except KeyError:
            last_path_used = ""

        #get filename to open
        spectrum_file = wx.FileSelector("Choose spectrum file to open", 
                                        default_path=last_path_used)
        if spectrum_file == "":
            return None
        
        persist.set_value("ftir_spectra_dir", os.path.dirname(spectrum_file))
        
        reader = csv.reader(open(spectrum_file, "rb"), dialect="excel") 
        
        wavenumber = []
        absorbance = []
    
        for line in reader:
             wavenumber.append(float(line[0]))
             absorbance.append(float(line[1]))        
        
        try:        
            return wavenumber, absorbance, spectrum_file
        #TODO see return above
        except Exception,e:
            print e.args
            wx.MessageBox("Unable to load spectrum file \'%s\'. "
                          "Unrecognised file format."%spectrum_file, 
                          "AvoPlot", wx.ICON_ERROR)
            return None
示例#2
0
    def load_file(self):
        persist = PersistentStorage()

        try:
            last_path_used = persist.get_value("fit_spectra_dir")
        except KeyError:
            last_path_used = ""

        #get filename to open
        spectrum_file = wx.FileSelector("Choose spectrum file to open",
                                        default_path=last_path_used)
        if spectrum_file == "":
            return None, None

        persist.set_value("fit_spectra_dir", os.path.dirname(spectrum_file))

        with open(spectrum_file, 'rU') as csvfile:
            reader = csv.reader(csvfile, delimiter='\t')

            #reader = csv.reader(open(spectrum_file, "rU"), dialect=csv.excel)

            col_data = []

            count = 0
            while count < 29:
                next(reader)
                count += 1
            #Skip the first 29 lines, which are header

            col_headers = next(reader)

            ncols = len(col_headers)

            for i in range(ncols):
                col_data.append(([float(x[i]) for x in reader]))
                csvfile.seek(0)
                count = 0
                while count < 30:
                    next(reader)
                    count += 1
            #now col_data is a list of lists of column data

            #Make col_data accessible to the rest of the class without needing to call the load_uvvis_file method
            self.col_data = col_data

        try:
            return col_data, spectrum_file, col_headers

        except Exception, e:
            print e.args
            wx.MessageBox(
                "Unable to load spectrum file \'%s\'. "
                "Unrecognised file format." % spectrum_file, "AvoPlot",
                wx.ICON_ERROR)
            return None
示例#3
0
文件: fitting.py 项目: drjvnv/avoplot
    def load_file(self):
        persist = PersistentStorage()
    
        try:
            last_path_used = persist.get_value("fit_spectra_dir")
        except KeyError:
            last_path_used = ""

        #get filename to open
        spectrum_file = wx.FileSelector("Choose spectrum file to open", 
                                        default_path=last_path_used)
        if spectrum_file == "":
            return None, None
        
        persist.set_value("fit_spectra_dir", os.path.dirname(spectrum_file))
        
        with open(spectrum_file, 'rU') as csvfile:
            reader = csv.reader(csvfile, delimiter='\t')
            
        #reader = csv.reader(open(spectrum_file, "rU"), dialect=csv.excel) 
      
            col_data = []
            
            count = 0
            while count<29:
                next(reader)
                count += 1
            #Skip the first 29 lines, which are header
            
            col_headers = next(reader)
            
            ncols = len(col_headers)
        
            for i in range(ncols):
                col_data.append(([float(x[i]) for x in reader]))
                csvfile.seek(0)
                count = 0
                while count<30:
                    next(reader)
                    count += 1
            #now col_data is a list of lists of column data  
            
            #Make col_data accessible to the rest of the class without needing to call the load_uvvis_file method
            self.col_data = col_data
        
        try:        
            return col_data, spectrum_file, col_headers

        except Exception,e:
            print e.args
            wx.MessageBox("Unable to load spectrum file \'%s\'. "
                          "Unrecognised file format."%spectrum_file, 
                          "AvoPlot", wx.ICON_ERROR)
            return None
示例#4
0
    def export(self):
        """
        Exports the selected data series. Called when user right clicks on the data series (see nav_panel.py).
        """
        persistant_storage = PersistentStorage()

        try:
            last_path_used = persistant_storage.get_value(
                "series_export_last_dir_used")
        except KeyError:
            last_path_used = ""

        export_dialog = wx.FileDialog(None,
                                      message="Export data series as...",
                                      defaultDir=last_path_used,
                                      defaultFile="AvoPlot Series.txt",
                                      style=wx.SAVE | wx.FD_OVERWRITE_PROMPT,
                                      wildcard="TXT files (*.txt)|*.txt")

        if export_dialog.ShowModal() == wx.ID_OK:
            path = export_dialog.GetPath()
            persistant_storage.set_value("series_export_last_dir_used",
                                         os.path.dirname(path))
            xdata, ydata = self.get_data()

            with open(path, 'w') as fp:

                if isinstance(xdata[0], datetime):
                    if isinstance(ydata[0], datetime):
                        for i in range(len(xdata)):
                            fp.write("%s\t%s\n" %
                                     (str(xdata[i]), str(ydata[i])))

                    else:
                        for i in range(len(xdata)):
                            fp.write("%s\t%f\n" % (str(xdata[i]), ydata[i]))

                else:
                    if isinstance(ydata[0], datetime):
                        for i in range(len(xdata)):
                            fp.write("%f\t%s\n" % (xdata[i], str(ydata[i])))

                    else:
                        for i in range(len(xdata)):
                            fp.write("%f\t%f\n" % (xdata[i], ydata[i]))

        export_dialog.Destroy()
示例#5
0
文件: series.py 项目: drjvnv/avoplot
    def export(self):
        """
        Exports the selected data series. Called when user right clicks on the data series (see nav_panel.py).
        """
        persistant_storage = PersistentStorage()
        
        try:
            last_path_used = persistant_storage.get_value("series_export_last_dir_used")
        except KeyError:
            last_path_used = ""
            
        export_dialog = wx.FileDialog(None, message="Export data series as...",
                                       defaultDir=last_path_used, defaultFile="AvoPlot Series.txt",
                                       style=wx.SAVE|wx.FD_OVERWRITE_PROMPT, wildcard = "TXT files (*.txt)|*.txt")
        
        if export_dialog.ShowModal() == wx.ID_OK:
            path = export_dialog.GetPath()
            persistant_storage.set_value("series_export_last_dir_used", os.path.dirname(path))
            xdata, ydata = self.get_data()
            
            with open(path, 'w') as fp:
                
                if isinstance(xdata[0], datetime):
                    if isinstance(ydata[0], datetime):
                        for i in range(len(xdata)):                   
                            fp.write("%s\t%s\n" %(str(xdata[i]), str(ydata[i])))
                        
                    else:
                        for i in range(len(xdata)):                   
                            fp.write("%s\t%f\n" %(str(xdata[i]), ydata[i]))
                
                else:
                    if isinstance(ydata[0], datetime):
                        for i in range(len(xdata)):                 
                            fp.write("%f\t%s\n" %(xdata[i], str(ydata[i])))

                    else:
                        for i in range(len(xdata)): 
                            fp.write("%f\t%f\n" %(xdata[i], ydata[i]))

        
        export_dialog.Destroy()            
示例#6
0
 def get_data_series(self):
     persistant_storage = PersistentStorage()
     
     try:
         last_path_used = persistant_storage.get_value("fromfile_last_dir_used")
     except KeyError:
         last_path_used = ""
     
     #get filename to open
     file_to_open = wx.FileSelector("Choose file to open", default_path=last_path_used)
     if file_to_open == "":
         return
     
     persistant_storage.set_value("fromfile_last_dir_used", os.path.dirname(file_to_open))
     
     wx.BeginBusyCursor()
     try:
         contents = loader.load_file(file_to_open)
         series_select_dialog = TxtFileDataSeriesSelectFrame(self.get_parent(), contents)
     finally:
         wx.EndBusyCursor()
     
     if series_select_dialog.ShowModal() == wx.ID_OK:
         return series_select_dialog.get_series()
示例#7
0
    def load_uvvis_file(self):
        persist = PersistentStorage()

        try:
            last_path_used = persist.get_value("uvvis_spectra_dir")
        except KeyError:
            last_path_used = ""

        # get filename to open
        spectrum_file = wx.FileSelector("Choose spectrum file to open", default_path=last_path_used)
        if spectrum_file == "":
            return None, None

        persist.set_value("uvvis_spectra_dir", os.path.dirname(spectrum_file))

        with open(spectrum_file, "rU") as csvfile:
            dialect = csv.Sniffer().sniff(csvfile.read(1024))
            csvfile.seek(0)
            reader = csv.reader(csvfile, dialect)

            # reader = csv.reader(open(spectrum_file, "rU"), dialect=csv.excel)

            col_data = []
            col_name = []
            col_name_and_data = []

            next(reader)
            next(reader)
            next(reader)
            next(reader)
            # Skip the first 4 lines, which are header

            ncols = len(next(reader))
            # This reads the 5th line, assigns its length to ncols & moves to the 6th line.

            for i in range(ncols):
                col_data.append(([float(x[i]) for x in reader]))
                csvfile.seek(0)
                next(reader)
                next(reader)
                next(reader)
                next(reader)
                next(reader)
            # now col_data is a list of lists of column data

            # TODO - NAME EACH SUBPLOT WITH ITS COLUMN HEADING
            for i in range(ncols):
                csvfile.seek(0)
                next(reader)
                next(reader)
                col_name_and_data.append(([str(x[i]) for x in reader]))
                col_name.append(col_name_and_data[i][0])

            col_name.pop(0)

            # Make col_data and col_name accessible to the rest of the class without needing to call the load_uvvis_file method
            self.col_data = col_data
            self.col_name = col_name

        try:
            return col_data, col_name, spectrum_file

        except Exception, e:
            print e.args
            wx.MessageBox(
                "Unable to load spectrum file '%s'. " "Unrecognised file format." % spectrum_file,
                "AvoPlot",
                wx.ICON_ERROR,
            )
            return None
示例#8
0
    def load_uvvis_file(self):
        persist = PersistentStorage()
    
        try:
            last_path_used = persist.get_value("uvvis_spectra_dir")
        except KeyError:
            last_path_used = ""

        #get filename to open
        spectrum_file = wx.FileSelector("Choose spectrum file to open", 
                                        default_path=last_path_used)
        if spectrum_file == "":
            return None, None
        
        persist.set_value("uvvis_spectra_dir", os.path.dirname(spectrum_file))
        
        with open(spectrum_file, 'rU') as csvfile:
            dialect = csv.Sniffer().sniff(csvfile.read(1024))
            csvfile.seek(0)
            reader = csv.reader(csvfile, dialect)
            
        #reader = csv.reader(open(spectrum_file, "rU"), dialect=csv.excel) 
      
            col_data = []
            col_name = []
            col_name_and_data = []
        
            next(reader)
            next(reader)
            next(reader)
            next(reader)
            #Skip the first 4 lines, which are header
        
            ncols = len(next(reader))
            #This reads the 5th line, assigns its length to ncols & moves to the 6th line.
        
            for i in range(ncols):
                col_data.append(([float(x[i]) for x in reader]))
                csvfile.seek(0)
                next(reader)
                next(reader)
                next(reader)
                next(reader)
                next(reader)
            #now col_data is a list of lists of column data  
            
            #TODO - NAME EACH SUBPLOT WITH ITS COLUMN HEADING
            for i in range(ncols):
                csvfile.seek(0)
                next(reader)
                next(reader)
                col_name_and_data.append(([str(x[i]) for x in reader]))
                col_name.append(col_name_and_data[i][0])
                
            col_name.pop(0)
            
            #Make col_data and col_name accessible to the rest of the class without needing to call the load_uvvis_file method
            self.col_data = col_data
            self.col_name = col_name
        
        try:        
            return col_data, col_name, spectrum_file

        except Exception,e:
            print e.args
            wx.MessageBox("Unable to load spectrum file \'%s\'. "
                          "Unrecognised file format."%spectrum_file, 
                          "AvoPlot", wx.ICON_ERROR)
            return None