Ejemplo n.º 1
0
    def load_ref(self):
        fileList, nt = self.get_fileList(False)
        self.ref_Header, Data1D = rw_data.read_dataFile(fileList[0], ',', ',')

        new_Data1D = self.switch_keys(Data1D)
        Data2D = self.rescale_data(new_Data1D)
        return Data2D
Ejemplo n.º 2
0
def sample_from_file(filename, step=1):
    #file must contain a list of starting and ending index, associated with a time step Dt
    # filename : name of the parameter file
    # step : optional time step between two successive pairs of images. If step=1, the step will be equal to Dt
    Header, data = rw_data.read_dataFile(filename, '\t', '\t')

    start = [int(p) for p in data['start']]
    end = [int(p) for p in data['end']]
    Dt = [int(p) for p in data['Dt']]

    return manual_sampling(start, end, Dt, step)
Ejemplo n.º 3
0
def read_time_step(file):
    # read time step that was used to analyse the movie
    # every units should be in ms
    Header, lines = rw_data.read_dataFile(file, '\t', '\t')

    t_s = np.asarray(lines['Start'])
    Dt = np.asarray(lines['Dt'])

    t0 = t_s[0]
    t_s = (t_s - t0) / 1000  # t in s
    print('t0 = ' + str(t0))

    return t_s, Dt
Ejemplo n.º 4
0
def get_data(fileList):
    dataList = []
    for name in fileList:
        W = browse.get_number(name, '_W', 'pix_')
        Dt = int(browse.get_string(name, 'pix_Dt_', '_'))
        Header, Data = rw_data.read_dataFile(name, ',', ',')
        #    indexA=browse.get_number(Header[1],'A: im','.tiff') #name of the image is localized on the second line of the ASCII file
        #    indexB=browse.get_number(Header[1],'B: im','.tiff')
        Data = pivlab.switch_keys(Data)
        dataList.append(Data)
        for key in ['u', 'v']:
            Data[key] = (cdata.rm_nans([np.asarray(Data[key])], d=1,
                                       rate=0.05))[0]

    return dataList
Ejemplo n.º 5
0
def recover(log_file):
    """
    From a log file containing the dset information to download, try again to download data
    """
    data_type = 'u'
    directory = os.path.dirname(log_file) + 'Data/'
    print(directory)

    Header, dset_list = rw_data.read_dataFile(log_file,
                                              Hdelimiter='\t',
                                              Ddelimiter='\t',
                                              Oneline=False)

    n = len(dset_list[dset_list.keys()[0]])

    for i in range(n):
        dset = {key: int(dset_list[key][i]) for key in dset_list.keys()}
        print(dset)

        dir_current = directory + convert_dict(dset) + '/'
        if not os.path.isdir(dir_current):
            os.makedirs(dir_current)
        name = dir_current + 'jhtdb_data_' + convert_dict(dset)  # + '.h5'

        get_cutout(t0=dset['t0'],
                   tl=dset['tl'],
                   x0=dset['x0'],
                   xl=dset['xl'],
                   y0=dset['y0'],
                   yl=dset['yl'],
                   z0=dset['z0'],
                   zl=dset['zl'],
                   data_set='isotropic1024coarse',
                   data_type=data_type,
                   filename=name)
        f0 = h5py.File('tst.h5', mode='r')
        print((data_type, f0['_contents'][:]))
        f0.close()
Ejemplo n.º 6
0
    def load_exp_parameters(self, fileParam=''):
        """
        Read experimental parameters from a setup file, or let user manually type them on the screen.
        The parameters are stored in a param class object, and this param class object is attributed to a Sdata class object.
        Parameters
        ----------
        opt : str, default: "w"
            option. If opt=="r", the filename becomes /path/to/.../CineFile_param   . (Extension is not included)
            Otherwise, the filename becomes /path/to/../CineFileDir/PIV_date_index_mindex_param

        Returns
        name : str
            "/.../CineFileDir/CineFile_param" or "/.../CineFileDir/PIV_date_index_mindex_param"
        -------
        """

        self.fileParam = self.fileParam + '.txt'
        self.im_ref = self.read_reference(
            ref=0
        )  #self.read_reference(ref=0) outputs spatial resolution of cine images. e.g.- (640, 1024) Note that this method uses the cine Class.
        # default value of fileParam :
        if True:  # fileParam == '':
            base = browse.get_string(os.path.basename(self.Sdata.fileCine),
                                     '',
                                     end='.cine')
            #   print(base)
            fileRef = os.path.dirname(
                self.Sdata.fileCine) + '/Setup_file_Reference*.txt'
            #   print(fileRef)
            fileList = glob.glob(
                fileRef)  # make a list of Setup_file_Reference*.txt files.

            #print(base)
            #print(fileList)
            for filename in fileList:
                pattern = browse.get_string(filename,
                                            'Setup_file_Reference',
                                            end='.txt')
                if pattern in base:  # if there is such a txt file with a filename which contains 'Setup_file_Reference', the file must be the one that cotains experimental parameters.
                    fileParam = filename

        # other name :
        print 'Experimental parameters may be stored here:'
        print fileParam
        print 'Does this file exist?'
        if os.path.isfile(fileParam):
            print '... Yes! Read experimental parameters from this file.'
            #Read the parameters from the param file
            Header, Data = rw_data.read_dataFile(fileParam,
                                                 Hdelimiter='\t',
                                                 Ddelimiter='\t')
            #            print Header
            print Data

            #Add the Data keys to attributes
            for i in Data.keys():
                setattr(self, i, Data[i][0])
            print 'Now, this param class object has new attributes which are named as same as the header of ' + fileParam

        else:
            print '... No. You specified to read ' + self.fileParam + ' if this is just ".txt", you did not specify the setup file. '
            print 'Does this file actually exist?'
            ######## If the argument "fileParam" is given,... read that file as a setup file.
            if os.path.isfile(self.fileParam):
                self.im_ref = self.read_reference(
                    ref=0
                )  #Read spatial resolution of cine images directory (i.e.- Open the target cine file, and grab the spatial resolution information)
                self.Sdata.read_param(
                )  # load parameters from the parameter file
            #######
            ####### If the algorithm above could not find the setuo file, manually input the experimental parameters.
            else:
                print '... No. '
                print 'We could not find the setup file. Please type experimental parameters now.'
                self.im_ref = self.read_reference(
                    ref=0
                )  #Read spatial resolution of cine images directory (i.e.- Open the target cine file, and grab the spatial resolution information)
                self.manual_input()
Ejemplo n.º 7
0
    def load_measure(self, rescale=True):
        self.fieldnames = {
            'x': 'x',
            'y': 'y',
            'ux': 'u',
            'uy': 'v'
        }  # Here is the attributes specific to a PIVlab measurement
        self.frmt = 'txt'

        self.im_indexA = []
        self.im_indexB = []

        self.get_PIVparams(self.dataDir)

        fileList, nt = self.get_fileList(True)
        self.nt = nt

        if nt == 0:
            return False

        # print("Set time axis")        #MaJ of the time axis
        self.t, self.Dt = self.time_axis()

        # print("Loading data ...")
        self.Ux = np.zeros(self.shape())
        self.Uy = np.zeros(self.shape())

        Dx = self.fx

        for i, name in enumerate(fileList):
            Header, Data = rw_data.read_dataFile(name, ',', ',')
            # print(Header)
            # Not useful anymore : the time axis and Dt serie is generated once at the beginning
            #   indexA=browse.get_number(Header[1],'A: im','.tiff') #name of the image is localized on the second line of the ASCII file
            #   indexB=browse.get_number(Header[1],'B: im','.tiff')
            # from the name of the image, get the time at which the frame was taken !!!
            ##### old _method (linear movie)
            # Dt=self.ft*(indexB-indexA)
            #    print(times)
            ###### from the time recorded in the cine file
            # Dt=times[indexB]-times[indexA]
            Dt = self.Dt[i]

            # print(self.im_indexA[i])
            new_Data = self.switch_keys(Data)  # use of standard keys

            Data2D = self.rescale_data(new_Data)

            if Data2D is not None:
                if rescale:
                    self.Ux[:, :, i] = Dx * Data2D['u'] / Dt
                    self.Uy[:, :, i] = Dx * Data2D['v'] / Dt
                else:
                    self.Ux[:, :, i] = Data2D['u']
                    self.Uy[:, :, i] = Data2D['v']
            else:
                print('Frame ' + str(i) + 'cannot be read')
            if nt > 100:
                if i % (nt // 100) == 0:
                    pass
                    # print('Dt = '+str(Dt*1000)+' ms, '+str(i*100//nt) + " %")
        # print("Data loaded")
        return True
Ejemplo n.º 8
0
def review():
    folder = '/Volumes/Stephane/Vortex_Turbulence/'

    folders = glob.glob(folder + '*')

    l_vortices = []

    D = {}
    D['v'] = []
    D['fx'] = []
    D['fps'] = []
    D['date'] = []
    D['index'] = []
    # D['Sdata_file']=[]
    D['cinefile'] = []

    for f in folders:
        # print(f)
        l = glob.glob(f + '/PIV*A0mm*.cine')
        l_vortices = l_vortices + l

    # print(l_vortices)

    for cinefile in l_vortices:
        s = browse.get_string(cinefile, '', '/PIV')
        date = s[-10:]

        filename = os.path.dirname(file_architecture.os_i(
            cinefile)) + '/Sdata_' + date + '/Cine_index_' + date + '.txt'
        if os.path.exists(filename):

            Header, data = rw_data.read_dataFile(filename,
                                                 Hdelimiter='\t',
                                                 Ddelimiter='\t')
            #  print(data)
            # print(data)
            # print("l : "+l)
            #    print(data['Names'])
            # print(file_architecture.os_i(cinefile))
            index = \
            np.where([file_architecture.os_i(cinefile) == file_architecture.os_i(name) for name in data['Names']])[0][0]
            index = int(data['Index'][index])

            v = browse.get_number(cinefile, '_v', 'mms')
            if v == -1:
                v = browse.get_number(cinefile, 'mm_v', 'mm')
            fps = browse.get_number(cinefile, '_fps', '_')

            S = Sdata_manip.load_Sdata(date, index)
            fx = S.param.fx

            D['date'].append(date)
            D['index'].append(index)
            D['v'].append(v)
            D['fps'].append(fps)
            D['fx'].append(fx)
            #        D['Sdata_file'].append(filename)

            D['cinefile'].append(cinefile)

    print(D['v'])

    filename = './Vortices/free_index_no_cine.txt'
    rw_data.write_a_dict(filename, D, delimiter='\t')