Beispiel #1
0
    def fitToParameters(self):

        #Populate param for lmfit.
        param = Parameters()
        #self.def_param.add('A1', value=1.0, min=0,max=1.0, vary=False)
        for art in self.param:

            if self.param[art]['to_show'] == True and self.param[art][
                    'calc'] == False:

                param.add(art,
                          value=float(self.param[art]['value']),
                          min=float(self.param[art]['minv']),
                          max=float(self.param[art]['maxv']),
                          vary=self.param[art]['vary'])

        #Find the index of the nearest point in the scale.

        data = np.array(self.autoNorm).astype(np.float64).reshape(-1)

        scale = np.array(self.autotime).astype(np.float64).reshape(-1)
        self.indx_L = int(np.argmin(np.abs(scale - self.parentFn.dr.xpos)))
        self.indx_R = int(np.argmin(np.abs(scale - self.parentFn.dr1.xpos)))

        print('idxl', self.indx_L, self.indx_R)

        if self.parentFn.bootstrap_enable_toggle == True:
            num_of_straps = self.parentFn.bootstrap_samples.value()
            aver_data = {}

            lim_scale = scale[self.indx_L:self.indx_R + 1].astype(np.float64)
            lim_data = data[self.indx_L:self.indx_R + 1].astype(np.float64)

            #Populate a container which will store our output variables from the bootstrap.
            for art in self.param:
                if self.param[art]['to_show'] == True and self.param[art][
                        'calc'] == False:
                    aver_data[art] = []

            for i in range(0, num_of_straps):
                #Bootstrap our sample, but remove duplicates.
                boot_ind = np.random.choice(np.arange(0, lim_data.shape[0]),
                                            size=lim_data.shape[0],
                                            replace=True)

                #boot_ind = np.arange(0,lim_data.shape[0])#np.sort(boot_ind)
                boot_scale = lim_scale[boot_ind]
                boot_data = lim_data[boot_ind]

                res = minimize(self.residual,
                               param,
                               args=(boot_scale, boot_data,
                                     self.parentFn.def_options))
                for art in self.param:

                    if self.param[art]['to_show'] == True and self.param[art][
                            'calc'] == False:
                        aver_data[art].append(res.params[art].value)

            for art in self.param:

                if self.param[art]['to_show'] == True and self.param[art][
                        'calc'] == False:
                    self.param[art]['value'] = np.average(aver_data[art])
                    self.param[art]['stderr'] = np.std(aver_data[art])

        #Run the fitting.
        if self.parentFn.bootstrap_enable_toggle == False:

            res = minimize(self.residual,
                           param,
                           args=(scale[self.indx_L:self.indx_R + 1],
                                 data[self.indx_L:self.indx_R + 1],
                                 self.parentFn.def_options))
            #Repopulate the parameter object.

            for art in self.param:

                if self.param[art]['to_show'] == True and self.param[art][
                        'calc'] == False:

                    self.param[art]['value'] = res.params[art].value

                    self.param[art]['stderr'] = res.params[art].stderr

        #Extra parameters, which are not fit or inherited.
        #self.param['N_FCS']['value'] = np.round(1/self.param['GN0']['value'],4)

        #Populate param for the plotting. Would like to use same method as
        plot_param = Parameters()
        #self.def_param.add('A1', value=1.0, min=0,max=1.0, vary=False)
        for art in self.param:

            if self.param[art]['to_show'] == True and self.param[art][
                    'calc'] == False:

                plot_param.add(art,
                               value=float(self.param[art]['value']),
                               min=float(self.param[art]['minv']),
                               max=float(self.param[art]['maxv']),
                               vary=self.param[art]['vary'])

        #Display fitted equation.

        if self.parentFn.def_options['Diff_eq'] == 5:
            self.model_autoNorm = PB.equation_(
                plot_param, scale[self.indx_L:self.indx_R + 1],
                self.parentFn.def_options)
        elif self.parentFn.def_options['Diff_eq'] == 4:
            self.model_autoNorm = VD.equation_(
                plot_param, scale[self.indx_L:self.indx_R + 1],
                self.parentFn.def_options)
        elif self.parentFn.def_options['Diff_eq'] == 3:
            self.model_autoNorm = GS.equation_(
                plot_param, scale[self.indx_L:self.indx_R + 1],
                self.parentFn.def_options)
        else:
            self.model_autoNorm = SE.equation_(
                plot_param, scale[self.indx_L:self.indx_R + 1],
                self.parentFn.def_options)
        self.model_autotime = scale[self.indx_L:self.indx_R + 1]

        if self.parentFn.bootstrap_enable_toggle == False:
            self.residualVar = res.residual
        else:
            self.residualVar = self.model_autoNorm - data[self.
                                                          indx_L:self.indx_R +
                                                          1].astype(np.float64)

        output = fit_report(res.params)

        if (res.chisqr > self.parentFn.chisqr):
            print('CAUTION DATA DID NOT FIT WELL CHI^2 >',
                  self.parentFn.chisqr, ' ', res.chisqr)
            self.goodFit = False
        else:
            self.goodFit = True
        self.fitted = True
        self.chisqr = res.chisqr

        self.localTime = time.asctime(time.localtime(time.time()))

        #Update the displayed options.

        if self.parentFn.def_options['Diff_eq'] == 5:
            PB.calc_param_fcs(self.parentFn, self)
        elif self.parentFn.def_options['Diff_eq'] == 4:
            VD.calc_param_fcs(self.parentFn, self)
        elif self.parentFn.def_options['Diff_eq'] == 3:
            GS.calc_param_fcs(self.parentFn, self)
        else:
            SE.calc_param_fcs(self.parentFn, self)
Beispiel #2
0
def csv_import_method(fit_obj, file_path, feed=None):
    if feed == None:
        r_obj = csv.reader(open(str(file_path), 'r'))
    else:
        r_obj = csv.reader(feed.split('\n'), delimiter=',')

    line_one = next(r_obj)
    if line_one.__len__() > 1:

        if float(line_one[1]) == 2:

            version = 2
        else:
            print('version not known:', line_one[1])

    else:
        version = 1

    corrObj1 = corrObject(file_path, fit_obj)

    if version == 1:
        fit_obj.objIdArr.append(corrObj1)

        c = 0

        tscale = []
        tdata = []

        for line in csv.reader(open(file_path, 'r')):
            if (c > 0):
                tscale.append(line[0])
                tdata.append(line[1])
            c += 1

        corrObj1.autoNorm = np.array(tdata).astype(np.float64).reshape(-1)
        corrObj1.autotime = np.array(tscale).astype(np.float64).reshape(-1)
        corrObj1.max = np.max(corrObj1.autoNorm)
        corrObj1.min = np.min(corrObj1.autoNorm)
        corrObj1.calculate_suitability()
        corrObj1.name = corrObj1.name + '-CH' + str(0)
        corrObj1.ch_type = 0
        corrObj1.datalen = len(tdata)

        corrObj1.param = copy.deepcopy(fit_obj.def_param)
        fit_obj.fill_series_list()
    if version >= 2:

        numOfCH = float(next(r_obj)[1])

        if numOfCH == 1:
            fit_obj.objIdArr.append(corrObj1)
            corrObj1.type = str(next(r_obj)[1])
            corrObj1.ch_type = int(next(r_obj)[1])
            corrObj1.name = corrObj1.name + '-CH' + str(corrObj1.ch_type)
            corrObj1.parent_name = 'no name'
            corrObj1.parent_uqid = '0'

            line = next(r_obj)

            while line[0][:4] != 'Time':
                if line[0] == 'kcount':
                    corrObj1.kcount = float(line[1])
                if line[0] == 'numberNandB':
                    corrObj1.numberNandB = float(line[1])
                if line[0] == 'brightnessNandB':
                    corrObj1.brightnessNandB = float(line[1])
                if line[0] == 'CV':
                    corrObj1.CV = float(line[1])
                if line[0] == 'carpet pos':
                    carpet = int(line[1])
                if line[0] == 'pc':
                    pc_text = int(line[1])
                if line[0] == 'pbc_f0':
                    corrObj1.pbc_f0 = float(line[1])
                if line[0] == 'pbc_tb':
                    corrObj1.pbc_tb = float(line[1])
                if line[0] == 'parent_name':
                    corrObj1.parent_name = str(line[1])
                if line[0] == 'parent_uqid':
                    corrObj1.parent_uqid = str(line[1])

                line = next(r_obj)

            if pc_text != False:
                corrObj1.name = corrObj1.name + '_pc_m' + str(pc_text)

            tscale = []
            tdata = []

            #null = next(r_obj)

            line = next(r_obj)

            while line[0] != 'end':

                tscale.append(line[0])
                tdata.append(line[1])
                line = next(r_obj)

            corrObj1.autoNorm = np.array(tdata).astype(np.float64).reshape(-1)
            corrObj1.autotime = np.array(tscale).astype(np.float64).reshape(-1)
            corrObj1.max = np.max(corrObj1.autoNorm)
            corrObj1.min = np.min(corrObj1.autoNorm)
            corrObj1.tmax = np.max(corrObj1.autotime)
            corrObj1.tmin = np.min(corrObj1.autotime)

            corrObj1.siblings = None
            corrObj1.param = copy.deepcopy(fit_obj.def_param)

        elif numOfCH == 2:
            corrObj2 = corrObject(file_path, fit_obj)
            corrObj3 = corrObject(file_path, fit_obj)

            fit_obj.objIdArr.append(corrObj1)
            fit_obj.objIdArr.append(corrObj2)
            fit_obj.objIdArr.append(corrObj3)

            corrObj1.parent_name = 'no name'
            corrObj1.parent_uqid = '0'
            corrObj2.parent_name = 'no name'
            corrObj2.parent_uqid = '0'
            corrObj3.parent_name = 'no name'
            corrObj3.parent_uqid = '0'

            line_type = next(r_obj)
            corrObj1.type = str(line_type[1])
            corrObj2.type = str(line_type[1])
            corrObj3.type = str(line_type[1])

            line_ch = next(r_obj)
            corrObj1.ch_type = int(line_ch[1])
            corrObj2.ch_type = int(line_ch[2])
            corrObj3.ch_type = int(line_ch[3])

            corrObj1.name = corrObj1.name + '-CH' + str(corrObj1.ch_type)
            corrObj2.name = corrObj2.name + '-CH' + str(corrObj2.ch_type)
            corrObj3.name = corrObj3.name + '-CH' + str(corrObj3.ch_type)

            line = next(r_obj)
            while line[0][:4] != 'Time':
                if line[0] == 'kcount':
                    corrObj1.kcount = float(line[1])
                    corrObj2.kcount = float(line[2])
                if line[0] == 'numberNandB':
                    corrObj1.numberNandB = float(line[1])
                    corrObj2.numberNandB = float(line[2])
                if line[0] == 'brightnessNandB':
                    corrObj1.brightnessNandB = float(line[1])
                    corrObj2.brightnessNandB = float(line[2])
                if line[0] == 'CV':
                    corrObj1.CV = float(line[1])
                    corrObj2.CV = float(line[2])
                    corrObj3.CV = float(line[3])
                if line[0] == 'carpet pos':
                    corrObj1.carpet_position = int(line[1])
                if line[0] == 'pc':
                    pc_text = int(line[1])
                if line[0] == 'pbc_f0':
                    corrObj1.pbc_f0 = float(line[1])
                    corrObj2.pbc_f0 = float(line[2])
                if line[0] == 'pbc_tb':
                    corrObj1.pbc_tb = float(line[1])
                    corrObj2.pbc_tb = float(line[2])
                if line[0] == 'parent_name':
                    corrObj1.parent_name = str(line[1])
                    corrObj2.parent_name = str(line[1])
                    corrObj3.parent_name = str(line[1])
                if line[0] == 'parent_uqid':
                    corrObj1.parent_uqid = str(line[1])
                    corrObj2.parent_uqid = str(line[1])
                    corrObj3.parent_uqid = str(line[1])

                line = next(r_obj)

            if pc_text != False:
                corrObj1.name = corrObj1.name + '_pc_m' + str(pc_text)
                corrObj2.name = corrObj2.name + '_pc_m' + str(pc_text)
                corrObj3.name = corrObj3.name + '_pc_m' + str(pc_text)

            #null = next(r_obj)
            line = next(r_obj)
            tscale = []
            tdata0 = []
            tdata1 = []
            tdata2 = []
            while line[0] != 'end':

                tscale.append(line[0])
                tdata0.append(line[1])
                tdata1.append(line[2])
                tdata2.append(line[3])
                line = next(r_obj)

            corrObj1.autotime = np.array(tscale).astype(np.float64).reshape(-1)
            corrObj2.autotime = np.array(tscale).astype(np.float64).reshape(-1)
            corrObj3.autotime = np.array(tscale).astype(np.float64).reshape(-1)

            corrObj1.autoNorm = np.array(tdata0).astype(np.float64).reshape(-1)
            corrObj2.autoNorm = np.array(tdata1).astype(np.float64).reshape(-1)
            corrObj3.autoNorm = np.array(tdata2).astype(np.float64).reshape(-1)

            corrObj1.max = np.max(corrObj1.autoNorm)
            corrObj1.min = np.min(corrObj1.autoNorm)
            corrObj2.max = np.max(corrObj2.autoNorm)
            corrObj2.min = np.min(corrObj2.autoNorm)
            corrObj3.max = np.max(corrObj3.autoNorm)
            corrObj3.min = np.min(corrObj3.autoNorm)

            corrObj1.tmax = np.max(corrObj1.autotime)
            corrObj1.tmin = np.min(corrObj1.autotime)
            corrObj2.tmax = np.max(corrObj2.autotime)
            corrObj2.tmin = np.min(corrObj2.autotime)
            corrObj3.tmax = np.max(corrObj3.autotime)
            corrObj3.tmin = np.min(corrObj3.autotime)

            corrObj1.siblings = [corrObj2, corrObj3]
            corrObj2.siblings = [corrObj1, corrObj3]
            corrObj3.siblings = [corrObj1, corrObj2]

            corrObj1.param = copy.deepcopy(fit_obj.def_param)
            corrObj2.param = copy.deepcopy(fit_obj.def_param)
            corrObj3.param = copy.deepcopy(fit_obj.def_param)

            corrObj1.calculate_suitability()
            corrObj2.calculate_suitability()
            corrObj3.calculate_suitability()

            SE.calc_param_fcs(fit_obj, corrObj1)
Beispiel #3
0
def fcs_import_method(fit_obj, file_path, feed=None):

    if feed == None:
        #f.read().decode('UTF-8','replace')
        file = open(str(file_path), 'rb').read()
        fileo = file.decode('UTF-8', 'replace').replace("\t", "").split('\n')
        r_obj = csv.reader(fileo)
    else:
        r_obj = csv.reader(feed.replace("\t", "").split('\n'))

    version = next(r_obj)
    print(version)
    null = next(r_obj)
    name = next(r_obj)[0].split(' = ')[1]

    version_num = float(version[0].split("-")[2].split(" ")[2])
    if version_num != 3.0:
        print("Version of .fcs file:", version_num,
              " must be 3.0 to continue. Please email Dominic with file.")
        return False

    read = True
    ind = 0
    channelnum = 0

    tdata_arr = []
    tscale_arr = []
    cdata_arr = []
    cscale_arr = []

    #Main loop which ends once all file is read.
    while read == True:

        text = next(r_obj)

        while True:
            if text[0].split(' = ')[0] == 'Name':
                name2 = text[0].split(' = ')[1]
                #print('text',name2,tscale_arr.__len__())

            if text[0].split(' = ')[0] == 'Channel':
                channel_str = text[0].split(' = ')[1]
            text = next(r_obj)
            if text == []:
                read = False
                break
            if text[0].split(' = ')[0] == 'CountRateArray':
                break

        if read == False or text == []:
            break
        #text = next(r_obj)

        dimensions = text[0].split(' = ')[1]
        len_of_seq = int(dimensions.split(' ')[0])
        if len_of_seq > 0:
            cdata = []
            cscale = []
            text = next(r_obj)[0].split(" ")
            for v in range(0, len_of_seq):

                if text.__len__() > 1:
                    cscale.append(float(text[0]))
                    cdata.append(float(text[1]))

                text = next(r_obj)[0].split(" ")
            cdata_arr.append(cdata)
            cscale_arr.append(cscale)
            print("cscale_arr", cscale.__len__())
        #Reads to first correlation array text.
        while text[0].split(' = ')[0] != 'CorrelationArray':
            text = next(r_obj)

        dimensions = text[0].split(' = ')[1]
        len_of_seq = int(dimensions.split(' ')[0])
        if len_of_seq > 0:
            tdata = []
            tscale = []
            text = next(r_obj)[0].split(" ")
            for v in range(0, len_of_seq):

                #print(text)
                if text.__len__() > 1:
                    tscale.append(float(text[0]))
                    tdata.append(float(text[1]))

                text = next(r_obj)[0].split(" ")
            tdata_arr.append(tdata)
            tscale_arr.append(tscale)
        #This is where we find-out how many channels. Unhelpfully after the raw data.
        while text[0].split(' = ')[0] != 'Channels':
            text = next(r_obj)

        num_of_channels = int(text[0].split(' = ')[1])

        #Which channel is it. Found by matching string found earlier?? The only way I saw to do it.
        for i in range(num_of_channels):
            text = next(r_obj)[0].split(' = ')[1]
            if text == channel_str:
                this_is_ch = i

        if len_of_seq > 0:
            print('num_of_channels', num_of_channels)
            #If a four channel file we want to skip until we have collected all channels.
            if num_of_channels == 4 and tdata_arr.__len__() != 4:
                continue

            corrObj1 = corrObject(file_path, fit_obj)
            corrObj1.siblings = None
            corrObj1.autoNorm = np.array(tdata_arr[0]).astype(
                np.float64).reshape(-1)
            corrObj1.autotime = np.array(tscale_arr[0]).astype(
                np.float64).reshape(-1) * 1000

            corrObj1.name = name + '-CH0'
            corrObj1.parent_name = '.fcs files'
            corrObj1.parent_uqid = '0'

            corrObj1.ch_type = 0

            if cscale_arr != []:
                #Average counts per bin. Apparently they are normalised to time.
                unit = cscale_arr[0][-1] / (cscale_arr[0].__len__() - 1)
                #And to be in kHz we divide by 1000.
                corrObj1.kcount = np.average(
                    np.array(cdata_arr[0]) / unit) / 1000
            corrObj1.param = copy.deepcopy(fit_obj.def_param)
            corrObj1.calculate_suitability()
            corrObj1.max = np.max(corrObj1.autoNorm)
            corrObj1.min = np.min(corrObj1.autoNorm)
            corrObj1.tmax = np.max(corrObj1.autotime)
            corrObj1.tmin = np.min(corrObj1.autotime)

            if fit_obj.def_options['Diff_eq'] == 4:
                VD.calc_param_fcs(fit_obj, corrObj1)
            elif fit_obj.def_options['Diff_eq'] == 3:
                GS.calc_param_fcs(fit_obj, corrObj1)
            else:
                SE.calc_param_fcs(fit_obj, corrObj1)

            fit_obj.objIdArr.append(corrObj1)

            if num_of_channels == 1:
                tscale_arr = []
                tdata_arr = []
                cscale_arr = []
                cdata_arr = []
                continue

            if num_of_channels == 4 and tdata_arr.__len__() == 4:

                corrObj2 = corrObject(file_path, fit_obj)
                corrObj2.autoNorm = np.array(tdata_arr[1]).astype(
                    np.float64).reshape(-1)
                corrObj2.autotime = np.array(tscale_arr[1]).astype(
                    np.float64).reshape(-1) * 1000

                corrObj2.name = name + '-CH1'
                corrObj2.parent_name = '.fcs files'
                corrObj2.parent_uqid = '0'
                corrObj2.ch_type = 1

                #And to be in kHz we divide by 1000.
                if cscale_arr != []:
                    corrObj2.kcount = np.average(
                        np.array(cdata_arr[1]) / unit) / 1000

                corrObj2.param = copy.deepcopy(fit_obj.def_param)

                corrObj1.siblings = [corrObj2]
                corrObj2.siblings = [corrObj1]

                corrObj2.calculate_suitability()
                corrObj2.max = np.max(corrObj2.autoNorm)
                corrObj2.min = np.min(corrObj2.autoNorm)
                corrObj2.tmax = np.max(corrObj2.autotime)
                corrObj2.tmin = np.min(corrObj2.autotime)

                if fit_obj.def_options['Diff_eq'] == 4:
                    VD.calc_param_fcs(fit_obj, corrObj2)
                elif fit_obj.def_options['Diff_eq'] == 3:
                    GS.calc_param_fcs(fit_obj, corrObj2)
                else:
                    SE.calc_param_fcs(fit_obj, corrObj2)

                fit_obj.objIdArr.append(corrObj2)

                corrObj3 = corrObject(file_path, fit_obj)
                corrObj3.autoNorm = np.array(tdata_arr[2]).astype(
                    np.float64).reshape(-1)
                corrObj3.autotime = np.array(tscale_arr[2]).astype(
                    np.float64).reshape(-1) * 1000

                corrObj3.ch_type = 2
                corrObj3.name = name + '-CH01'
                corrObj3.parent_name = '.fcs files'
                corrObj3.parent_uqid = '0'

                #And to be in kHz we divide by 1000.
                #corrObj3.kcount = np.average(np.array(int_tdata3)/unit)/1000
                corrObj3.param = copy.deepcopy(fit_obj.def_param)

                corrObj1.siblings = [corrObj2, corrObj3]
                corrObj2.siblings = [corrObj1, corrObj3]
                corrObj3.siblings = [corrObj1, corrObj2]

                corrObj3.calculate_suitability()
                corrObj3.max = np.max(corrObj3.autoNorm)
                corrObj3.min = np.min(corrObj3.autoNorm)
                corrObj3.tmax = np.max(corrObj3.autotime)
                corrObj3.tmin = np.min(corrObj3.autotime)
                if fit_obj.def_options['Diff_eq'] == 4:
                    VD.calc_param_fcs(fit_obj, corrObj3)
                elif fit_obj.def_options['Diff_eq'] == 3:
                    GS.calc_param_fcs(fit_obj, corrObj3)
                else:
                    SE.calc_param_fcs(fit_obj, corrObj3)
                fit_obj.objIdArr.append(corrObj3)

                corrObj4 = corrObject(file_path, fit_obj)
                corrObj4.autoNorm = np.array(tdata_arr[3]).astype(
                    np.float64).reshape(-1)
                corrObj4.autotime = np.array(tscale_arr[3]).astype(
                    np.float64).reshape(-1) * 1000

                corrObj4.ch_type = 3
                corrObj4.name = name + '-CH10'
                corrObj4.parent_name = '.fcs files'
                corrObj4.parent_uqid = '0'

                #And to be in kHz we divide by 1000.
                #corrObj4.kcount = np.average(np.array(int_tdata4)/unit)/1000
                corrObj4.param = copy.deepcopy(fit_obj.def_param)

                corrObj1.siblings = [corrObj2, corrObj3, corrObj4]
                corrObj2.siblings = [corrObj1, corrObj3, corrObj4]
                corrObj3.siblings = [corrObj1, corrObj2, corrObj4]
                corrObj4.siblings = [corrObj1, corrObj2, corrObj3]

                corrObj4.calculate_suitability()
                corrObj4.max = np.max(corrObj4.autoNorm)
                corrObj4.min = np.min(corrObj4.autoNorm)
                corrObj4.tmax = np.max(corrObj4.autotime)
                corrObj4.tmin = np.min(corrObj4.autotime)

                if fit_obj.def_options['Diff_eq'] == 4:
                    VD.calc_param_fcs(fit_obj, corrObj4)
                elif fit_obj.def_options['Diff_eq'] == 3:
                    GS.calc_param_fcs(fit_obj, corrObj4)
                else:
                    SE.calc_param_fcs(fit_obj, corrObj4)
                fit_obj.objIdArr.append(corrObj4)

                tscale_arr = []
                tdata_arr = []
                cscale_arr = []
                cdata_arr = []
Beispiel #4
0
def sin_import_method(fit_obj, file_path, feed=None):

    if feed == None:
        r_obj = csv.reader(open(str(file_path)), delimiter='\t')
    else:
        r_obj = csv.reader(feed.split('\n'), delimiter='\t')
    tscale = []
    tdata = []
    tdata2 = []
    tdata3 = []
    tdata4 = []
    int_tscale = []
    int_tdata = []
    int_tdata2 = []

    proceed = False

    for line in r_obj:

        if proceed == 'correlated':
            if line == []:
                proceed = False
            else:
                tscale.append(float(line[0]))
                tdata.append(float(line[1]))
                if line.__len__() > 2:
                    tdata2.append(float(line[2]))
                if line.__len__() > 3:
                    tdata3.append(float(line[3]))
                if line.__len__() > 4:
                    tdata4.append(float(line[4]))
        if proceed == 'intensity':

            if line == []:
                proceed = False
            elif line.__len__() > 1:

                int_tscale.append(float(line[0]))
                int_tdata.append(float(line[1]))
                if line.__len__() > 2:
                    int_tdata2.append(float(line[2]))

        if (str(line) == "[\'[CorrelationFunction]\']"):
            proceed = 'correlated'
        elif (str(line) == "[\'[IntensityHistory]\']"):
            proceed = 'intensity'

    corrObj1 = corrObject(file_path, fit_obj)
    corrObj1.siblings = None
    corrObj1.autoNorm = np.array(tdata).astype(np.float64).reshape(-1)
    corrObj1.autotime = np.array(tscale).astype(np.float64).reshape(-1) * 1000

    corrObj1.name = corrObj1.name + '-CH0'
    corrObj1.parent_name = '.sin files'
    corrObj1.parent_uqid = '0'

    corrObj1.ch_type = 0
    #Average counts per bin. Apparently they are normalised to time.
    unit = int_tscale[-1] / (int_tscale.__len__() - 1)
    #And to be in kHz we divide by 1000.
    corrObj1.kcount = np.average(np.array(int_tdata)) / 1000
    corrObj1.param = copy.deepcopy(fit_obj.def_param)
    corrObj1.calculate_suitability()
    corrObj1.max = np.max(corrObj1.autoNorm)
    corrObj1.min = np.min(corrObj1.autoNorm)
    corrObj1.tmax = np.max(corrObj1.autotime)
    corrObj1.tmin = np.min(corrObj1.autotime)

    if fit_obj.def_options['Diff_eq'] == 4:
        VD.calc_param_fcs(fit_obj, corrObj1)
    elif fit_obj.def_options['Diff_eq'] == 3:
        GS.calc_param_fcs(fit_obj, corrObj1)
    else:
        SE.calc_param_fcs(fit_obj, corrObj1)

    fit_obj.objIdArr.append(corrObj1)

    #Basic
    if tdata2 != []:
        corrObj2 = corrObject(file_path, fit_obj)
        corrObj2.autoNorm = np.array(tdata2).astype(np.float64).reshape(-1)
        corrObj2.autotime = np.array(tscale).astype(
            np.float64).reshape(-1) * 1000

        corrObj2.name = corrObj2.name + '-CH1'
        corrObj2.parent_name = '.sin files'
        corrObj2.parent_uqid = '0'
        corrObj2.ch_type = 1

        #And to be in kHz we divide by 1000.
        corrObj2.kcount = np.average(np.array(int_tdata2)) / 1000
        corrObj2.param = copy.deepcopy(fit_obj.def_param)

        corrObj1.siblings = [corrObj2]
        corrObj2.siblings = [corrObj1]

        corrObj2.calculate_suitability()
        corrObj2.max = np.max(corrObj2.autoNorm)
        corrObj2.min = np.min(corrObj2.autoNorm)
        corrObj2.tmax = np.max(corrObj2.autotime)
        corrObj2.tmin = np.min(corrObj2.autotime)
        if fit_obj.def_options['Diff_eq'] == 4:
            VD.calc_param_fcs(fit_obj, corrObj2)
        elif fit_obj.def_options['Diff_eq'] == 3:
            GS.calc_param_fcs(fit_obj, corrObj2)
        else:
            SE.calc_param_fcs(fit_obj, corrObj2)
        fit_obj.objIdArr.append(corrObj2)
    if tdata3 != []:
        corrObj3 = corrObject(file_path, fit_obj)
        corrObj3.autoNorm = np.array(tdata3).astype(np.float64).reshape(-1)
        corrObj3.autotime = np.array(tscale).astype(
            np.float64).reshape(-1) * 1000

        corrObj3.ch_type = 2
        corrObj3.name = corrObj3.name + '-CH01'
        corrObj3.parent_name = '.sin files'
        corrObj3.parent_uqid = '0'

        #And to be in kHz we divide by 1000.
        #corrObj3.kcount = np.average(np.array(int_tdata3)/unit)/1000
        corrObj3.param = copy.deepcopy(fit_obj.def_param)

        corrObj1.siblings = [corrObj2, corrObj3]
        corrObj2.siblings = [corrObj1, corrObj3]
        corrObj3.siblings = [corrObj1, corrObj2]

        corrObj3.calculate_suitability()
        corrObj3.max = np.max(corrObj3.autoNorm)
        corrObj3.min = np.min(corrObj3.autoNorm)
        corrObj3.tmax = np.max(corrObj3.autotime)
        corrObj3.tmin = np.min(corrObj3.autotime)
        if fit_obj.def_options['Diff_eq'] == 4:
            VD.calc_param_fcs(fit_obj, corrObj3)
        elif fit_obj.def_options['Diff_eq'] == 3:
            GS.calc_param_fcs(fit_obj, corrObj3)
        else:
            SE.calc_param_fcs(fit_obj, corrObj3)
        fit_obj.objIdArr.append(corrObj3)
    if tdata4 != []:
        corrObj4 = corrObject(file_path, fit_obj)
        corrObj4.autoNorm = np.array(tdata4).astype(np.float64).reshape(-1)
        corrObj4.autotime = np.array(tscale).astype(
            np.float64).reshape(-1) * 1000

        corrObj4.ch_type = 3
        corrObj4.name = corrObj4.name + '-CH10'
        corrObj4.parent_name = '.sin files'
        corrObj4.parent_uqid = '0'

        #And to be in kHz we divide by 1000.
        #corrObj4.kcount = np.average(np.array(int_tdata4)/unit)/1000
        corrObj4.param = copy.deepcopy(fit_obj.def_param)

        corrObj1.siblings = [corrObj2, corrObj3, corrObj4]
        corrObj2.siblings = [corrObj1, corrObj3, corrObj4]
        corrObj3.siblings = [corrObj1, corrObj2, corrObj4]
        corrObj4.siblings = [corrObj1, corrObj2, corrObj3]

        corrObj4.calculate_suitability()
        corrObj4.max = np.max(corrObj4.autoNorm)
        corrObj4.min = np.min(corrObj4.autoNorm)
        corrObj4.tmax = np.max(corrObj4.autotime)
        corrObj4.tmin = np.min(corrObj4.autotime)
        if fit_obj.def_options['Diff_eq'] == 4:
            VD.calc_param_fcs(fit_obj, corrObj4)
        elif fit_obj.def_options['Diff_eq'] == 3:
            GS.calc_param_fcs(fit_obj, corrObj4)
        else:
            SE.calc_param_fcs(fit_obj, corrObj4)
        fit_obj.objIdArr.append(corrObj4)