lib/transient.py
def import_file_csv(self, filepath):
        """
        Import data from a .txt file containing metadata in the header.

        Metadata should be coded as variable names from this class:
            material, date, pump_power, temperature, probe_polarization etc...
        Data expected is 4 couloms: raw_time, raw_trace, time, trace.

        filepath should full path to file as string.

        """
        # ---------- get metadata ----------

        # dictionary of attributes where to assign parameters
        attributes = self.__dict__
        parameters = []
        for attribute in attributes:  # use only non-data attributes
            if attribute not in self.DATA_ATTRIBUTES:
                parameters.append(attribute)

        with open(filepath, 'r') as f:
            n = 0
            for l in f:
                # search for the data coulomn header
                if 'raw_time' in l:
                    dataOffset = n + 1  # used for offset of data fetching, data starts from next line -> +1
                    columnHeaders = l.replace('\n', '').replace(' ', '').split(',')
                else:
                    n += 1
                # split each line from file into a list
                word = l[:-1:].split(': ')
                # if the first word corresponds to an attribute name
                if word[0] in parameters:
                    key = word[0]
                    value_string = word[1].replace(' ', '')
                    if self.get_unit(key):
                        # if parameter expects units, get only numbers,
                        value = float(re.findall("\d+\.\d+", value_string)[0])
                    else:  # otherwise get the whole string
                        value = value_string
                    # create/assign attribute from imported parameter
                    setattr(self, key, value)
        self.key_parameter_value = getattr(self, self.key_parameter)

        # ---------- get data ---------- using pandas! :)

        data = pd.read_csv(filepath, names=columnHeaders, skiprows=dataOffset)
        for col in data.columns:
            # make a list of float tipe data for each dataset found
            col_data = getattr(data, col).astype(float).tolist()
            data_list = []
            for i in col_data:
                if i != 'nan': data_list.append(i)

            setattr(self, col, data_list)

        Import data from a .txt file containing metadata in the header.

        Metadata should be coded as variable names from this class:
            material, date, pump_power, temperature, probe_polarization etc...
        Data expected is 4 couloms: raw_time, raw_trace, time, trace.

        filepath should full path to file as string.

        
Import data from a .txt file containing metadata in the header.
Metadata should be coded as variable names from this class:
material, date, pump_power, temperature, probe_polarization etc
Data expected is 4 couloms: raw_time, raw_trace, time, trace.

filepath should full path to file as string.
Import data from a . txt file containing metadata in the header . Metadata should be coded as variable names from this class : material date pump_power temperature probe_polarization etc Data expected is 4 couloms : raw_time raw_trace time trace . filepath should full path to file as string .
def import_file_csv(self, filepath):
        attributes = self.__dict__
        parameters = []
        for attribute in attributes:  
            if attribute not in self.DATA_ATTRIBUTES:
                parameters.append(attribute)
        with open(filepath, 'r') as f:
            n = 0
            for l in f:
                if 'raw_time' in l:
                    dataOffset = n + 1  
                    columnHeaders = l.replace('\n', '').replace(' ', '').split(',')
                else:
                    n += 1
                word = l[:-1:].split(': ')
                if word[0] in parameters:
                    key = word[0]
                    value_string = word[1].replace(' ', '')
                    if self.get_unit(key):
                        value = float(re.findall("\d+\.\d+", value_string)[0])
                    else:  
                        value = value_string
                    setattr(self, key, value)
        self.key_parameter_value = getattr(self, self.key_parameter)
        data = pd.read_csv(filepath, names=columnHeaders, skiprows=dataOffset)
        for col in data.columns:
            col_data = getattr(data, col).astype(float).tolist()
            data_list = []
            for i in col_data:
                if i != 'nan': data_list.append(i)
            setattr(self, col, data_list)
def import_file_csv ( self , filepath ) : attributes = self . __dict__ parameters = [ ] for attribute in attributes : if attribute not in self . DATA_ATTRIBUTES : parameters . append ( attribute ) with open ( filepath , 'r' ) as f : n = 0 for l in f : if 'raw_time' in l : dataOffset = n + 1 columnHeaders = l . replace ( '\n' , '' ) . replace ( ' ' , '' ) . split ( ',' ) else : n += 1 word = l [ : - 1 : ] . split ( ': ' ) if word [ 0 ] in parameters : key = word [ 0 ] value_string = word [ 1 ] . replace ( ' ' , '' ) if self . get_unit ( key ) : value = float ( re . findall ( "\d+\.\d+" , value_string ) [ 0 ] ) else : value = value_string setattr ( self , key , value ) self . key_parameter_value = getattr ( self , self . key_parameter ) data = pd . read_csv ( filepath , names = columnHeaders , skiprows = dataOffset ) for col in data . columns : col_data = getattr ( data , col ) . astype ( float ) . tolist ( ) data_list = [ ] for i in col_data : if i != 'nan' : data_list . append ( i ) setattr ( self , col , data_list )
Import data from a .txt file containing metadata in the header.
Import data from a . txt file containing metadata in the header .
"""
        Import data from a .txt file containing metadata in the header.

        Metadata should be coded as variable names from this class:
            material, date, pump_power, temperature, probe_polarization etc...
        Data expected is 4 couloms: raw_time, raw_trace, time, trace.

        filepath should full path to file as string.

        """ # ---------- get metadata ---------- # dictionary of attributes where to assign parameters # use only non-data attributes # search for the data coulomn header # used for offset of data fetching, data starts from next line -> +1 # split each line from file into a list # if the first word corresponds to an attribute name # if parameter expects units, get only numbers, # otherwise get the whole string # create/assign attribute from imported parameter # ---------- get data ---------- using pandas! :) # make a list of float tipe data for each dataset found
self
filepath