示例#1
0
文件: spe.py 项目: msb002/mhdpy
def _lasertiming(filepaths):
    """generates a dataframe of intensities and timestamps from a list of spe filepaths"""
    #folderpath = os.path.split(filepaths[0])
    #filenames = [f for f in os.listdir(folderpath) if os.path.isfile(os.path.join(folderpath,f))]
    #filenames = [os.path.split(filepath) for filepath in filepaths if os.path.splitext(filepaths)[1] == '.spe']

    spe_files = sl.load_from_files(filepaths)
    if type(spe_files) != type(list()):
        spe_files = [spe_files]
    gatedelays = _get_gatedelays(spe_files[0])
    intensities = pd.DataFrame(index=gatedelays, columns=range(len(filepaths)))
    timestamps = pd.DataFrame(index=gatedelays, columns=range(len(filepaths)))
    i = 0
    for spe_file in spe_files:
        frames = spe_file.data
        intensity = list(map(lambda x: x[0].max(), frames))
        try:
            timestamps.iloc[:, i] = pd.Series(_get_starttimes(spe_file),
                                              index=timestamps.index)
            intensities.iloc[:, i] = pd.Series(intensity,
                                               index=intensities.index)
            i = i + 1
        except ValueError:  #comes up if there is an incomplete file.
            print(
                'A SPE file did not have correct number of data points. Note that first file must have correct number of data points'
            )
    intensities = intensities.truncate(after=i, axis='columns')
    timestamps = timestamps.truncate(after=i, axis='columns')
    return intensities, timestamps, gatedelays
示例#2
0
def SPEtoTDMS_seq(spefilepath,meastype):
    """convert a sequential SPE file (image or spectral) into a Tdms file. """
    if isinstance(spefilepath,bytes): #The labview addin passes a bytes instead of string. 
        spefilepath = spefilepath.decode("utf-8")
    
    folder = os.path.splitext(os.path.dirname(spefilepath))[0]
    base = os.path.splitext(os.path.basename(spefilepath))[0]
    tdmsfilepath = os.path.join(folder,base + ".tdms")

    spe_file = sl.load_from_files([spefilepath])

    frames  = spe_file.data   
    gatedelays = _get_gatedelays(spe_file)
    
    root_object = RootObject(properties={})    
    common_group_object = GroupObject("Common", properties={})
    
    with TdmsWriter(tdmsfilepath) as tdms_writer:   
        channel_object = ChannelObject("Common", "Gate Delays" ,gatedelays, properties={})
        tdms_writer.write_segment([root_object,common_group_object,channel_object])
    
    if(meastype == 0): 
        wavelength = spe_file.wavelength
        with TdmsWriter(tdmsfilepath, mode = 'a') as tdms_writer: 
            channel_object = ChannelObject("Common", "Wavelength" ,wavelength, properties={})
            tdms_writer.write_segment([root_object,common_group_object,channel_object])   
        write_spectra(tdmsfilepath, root_object, frames,wavelength )
    if(meastype == 1):
        write_image(tdmsfilepath, root_object, frames )
示例#3
0
 def open_file_callback(self):
     path_to_file = os.path.join(self.directory_input.value,
                                 self.file_view.value[0])
     if not os.path.isfile(path_to_file):
         return
     self.spe_file = spe_loader.load_from_files([path_to_file])
     self.full_sensor_data = self.spe_file.data[0][0]
     self.full_sensor_image_label.text = ''
     self.full_sensor_image.title.text = 'Source Data'
     self.update_full_sensor_image()
示例#4
0
 def _open_callback(self, event):
     # calls general observation load function
     root = tk.Tk()
     root.withdraw()
     filename = filedialog.askopenfilename()
     if filename is not '':
         self.spe_file = spe_loader.load_from_files([filename])
         self.full_sensor_data = self.spe_file.data[0][0]
         self._image_full_sensor_data()
     else:
         return
示例#5
0
def spe2df_spect(spefilepath, gatingtype='rep'):
    #convert a sequential spectral SPE file to a pandas dataframe with one axis wl and other axis gate delay.
    spe_file = sl.load_from_files([spefilepath])

    frames = spe_file.data
    gatedelays = _get_gatedelays(spe_file)
    wavelength = spe_file.wavelength

    datamatrix = np.zeros((len(wavelength), len(gatedelays)))

    for i, frame in enumerate(frames):
        datamatrix[:, i] = frame[0]
    if gatingtype == 'rep':
        spectraldf = pd.DataFrame(datamatrix, index=wavelength)
    elif gatingtype == 'seq':
        spectraldf = pd.DataFrame(datamatrix,
                                  index=wavelength,
                                  columns=gatedelays)

    return spectraldf