Beispiel #1
0
def OpenG2M1s(froot, expt_idx=None, roi_idx=None):
    res = []
    filter_str = ''
    if roi_idx is not None:
        filter_str += '_' + ROI_PREFIX + str(roi_idx).zfill(ROI_IDXLEN)
    if expt_idx is not None:
        filter_str += '_' + EXP_PREFIX + +str(expt_idx).zfill(EXP_IDXLEN)
    fnames_list = sf.FindFileNames(froot,
                                   Prefix=G2M1_PREFIX,
                                   Ext='.dat',
                                   FilterString=filter_str,
                                   Sort='ASC')
    ROI_list = [sf.FirstIntInStr(name) for name in fnames_list]
    exptime_list = [sf.LastIntInStr(name) for name in fnames_list]
    lagtimes = []
    imgtimes = []
    for i, fname in enumerate(fnames_list):
        res_g2m1, res_hdr = sf.LoadResFile(os.path.join(froot, fname),
                                           delimiter=TXT_DELIMITER,
                                           comments=TXT_COMMENT,
                                           readHeader=True,
                                           isolateFirst=0)
        res.append(res_g2m1[:, 1::2].T)
        lagtimes.append(res_g2m1[:, ::2].T)
        imgtimes.append(
            np.asarray([
                sf.FirstFloatInStr(res_hdr[j])
                for j in range(1, len(res_hdr), 2)
            ]))
    return res, lagtimes, imgtimes, ROI_list, exptime_list
Beispiel #2
0
 def ReadCIfile(self, fname):
     roi_idx = sf.FirstIntInStr(fname)
     exp_idx = sf.LastIntInStr(fname)
     cur_cI = np.loadtxt(os.path.join(self.outFolder, fname),
                         **self.loadtxt_kwargs)
     cur_times = cur_cI[:, 0]
     cur_cI = cur_cI[:, 1:]  # skip first row with image times
     if (cur_cI.shape != (self.NumTimes(), self.NumLagtimes())):
         logging.warning(
             'cI result file {0} potentially corrupted: shape {1} does not match expected {2}'
             .format(fname, cur_cI.shape,
                     (self.NumTimes(), self.NumLagtimes())))
     return cur_cI, cur_times, roi_idx, exp_idx
Beispiel #3
0
def OpenCIs(froot):
    res = []
    fnames_list = sf.FindFileNames(froot,
                                   Prefix=CI_PREFIX + '_',
                                   Ext='.dat',
                                   Sort='ASC')
    ROI_list = [sf.FirstIntInStr(name) for name in fnames_list]
    exptime_list = [sf.LastIntInStr(name) for name in fnames_list]
    lagtimes = []
    imgtimes = []
    for i, fname in enumerate(fnames_list):
        res_cI, res_hdr, col_times = sf.LoadResFile(os.path.join(froot, fname),
                                                    delimiter=TXT_DELIMITER,
                                                    comments=TXT_COMMENT,
                                                    readHeader=True,
                                                    isolateFirst=1)
        res.append(res_cI)
        lagtimes.append(np.asarray([sf.FirstIntInStr(hdr) for hdr in res_hdr]))
        imgtimes.append(col_times)
    return res, imgtimes, lagtimes, ROI_list, exptime_list
Beispiel #4
0
 def LoadFiles(self,
               mi_fnames,
               metadata_section='MIfile',
               open_mifiles=True,
               replace_previous=False):
     """Load list of filenames
     
     Parameters
     ----------
     mi_fnames        : list of filenames (full path, str)
     open_mifiles     : if True, open each MIfile for reading
     replace_previous : if True, replace eventual preexisting list of MIfile
     """
     if (replace_previous or self.MIfiles is None):
         self.MIfiles = []
         self.IdxList = []
     for i in range(len(mi_fnames)):
         self.IdxList.append(sf.LastIntInStr(mi_fnames[i]))
         self.MIfiles.append(
             MI.MIfile(mi_fnames[i],
                       self.MetaData.ToDict(section=metadata_section)))
         if open_mifiles:
             self.MIfiles[-1].OpenForReading()
     self._loaded = True
Beispiel #5
0
    def GetCorrMaps(self,
                    openMIfiles=True,
                    getAutocorr=True,
                    check_lagtimes=False):
        """Searches for MIfile correlation maps
        
        Parameters
        ----------
        openMIfiles: if true, it opens all MIfiles for reading.
        getAutocorr: if True, returns d0 in the list of correlation maps
                    otherwise, returns None instead of the autocorrelation map
        check_lagtimes: if true, checks that the lagtimes extracted from the filenames match with self.lagList
        
        Returns
        -------
        corr_config: configuration file for correlation maps
        corr_mifiles: list of correlation maps, one per time delay
        lag_list: list of lagtimes
        """

        if not self._corrmaps_loaded:

            assert os.path.isdir(
                self.outFolder), 'Correlation map folder ' + str(
                    self.outFolder) + ' not found.'
            config_fname = os.path.join(self.outFolder, 'CorrMapsConfig.ini')
            assert os.path.isfile(config_fname), 'Configuration file ' + str(
                config_fname) + ' not found'
            self.conf_cmaps = cf.Config(config_fname)

            all_cmap_fnames = sf.FindFileNames(self.outFolder,
                                               Prefix='CorrMap_d',
                                               Ext='.dat',
                                               Sort='ASC',
                                               AppendFolder=True)
            self.cmap_mifiles = []
            self.all_lagtimes = []
            for i in range(len(all_cmap_fnames)):
                cur_lag = sf.LastIntInStr(all_cmap_fnames[i])
                self.all_lagtimes.append(cur_lag)
                self.cmap_mifiles.append(
                    MI.MIfile(
                        all_cmap_fnames[i],
                        self.conf_cmaps.ToDict(section='corrmap_metadata')))
                self.cmap_mifiles[-1].OpenForReading()

            # Check lagtimes for consistency
            if (check_lagtimes):
                print(
                    'These are all lagtimes. They should be already sorted and not contain 0:'
                )
                print(self.all_lagtimes)
                for cur_lag in self.lagList:
                    if (cur_lag not in self.all_lagtimes):
                        print(
                            'WARNING: no correlation map found for lagtime ' +
                            str(cur_lag))

            self._corrmaps_loaded = True

        if (self.all_lagtimes[0] == 0 and getAutocorr == False):
            return self.conf_cmaps, [
                None
            ] + self.cmap_mifiles[1:], self.all_lagtimes
        else:
            return self.conf_cmaps, self.cmap_mifiles, self.all_lagtimes