Esempio n. 1
0
def Sdata_gen(cineFile, index):
    """

    Parameters
    ----------
    cineFile : string
               name of a cine file
    index : intege
            index is associated to a specific cine file
    Returns
    S : Sdata class object
    -------
    """
    failure = None
    # print(cineFile)
    base = browse.get_string(os.path.basename(cineFile), '', end='.cine')
    # find the file where exp. parameters are given

    fileDir = os.path.dirname(cineFile) + '/'

    fileList, n = browse.get_fileList(fileDir,
                                      'txt',
                                      root='Setup_file_Reference_',
                                      display=True,
                                      sort='date')

    file_param = os.path.dirname(cineFile) + '/' + 'Setup_file_Ref.txt'

    print '----Setup txt file(s)---'
    print fileList
    print '------------------------'

    for f in fileList:
        s = browse.get_string(f, 'Setup_file_Reference_', end='.txt')
        # print(base)
        # print('extract :'+s)
        if browse.contain(base, s):
            file_param = f
            print 'file_param: ' + file_param
            # input()
            #    file = os.path.dirname(cineFile)+'/References/Ref_'+base+'.txt'
            #    file = os.path.dirname(cineFile)+'/'+'Setup_file_Ref.txt' #/Volumes/labshared/Stephane_lab1/25015_09_22/References/Ref_PIV_sv_vp_zoom_Polymer_200ppm_X25mm_fps5000_n18000_beta500mu_H1180mm_S300mm.txt'
            #    print(file)
            # try:
    print '----Cine file being processed:----'
    print cineFile
    print '----------------------------'

    S = Sdata(fileCine=cineFile, index=index, fileParam=file_param)
    print '----------------------------'
    print 'Sdata class object S is created!'
    print 'Attributes of S are...'
    print dir(S)
    print 'Attributes of S.param are...'
    print dir(S.param)
    print '----------------------------'

    S.write()
    return S
Esempio n. 2
0
def find_dataType(S):
    s = browse.get_string(S.fileCine, '/PIV', '.cine')
    if not s == '':
        return '2D_PIVmovie'

    s = browse.get_string(S.fileCine, 'Bubbles', '.cine')
    if not s == '':
        return '2D_bubbles'

    return 'Unknown'
Esempio n. 3
0
    def get_fileList(self, display=False):
        """
        Return the list of PIV data (.txt files) associated to this measure
        """
        fileList, n = browse.get_fileList(self.dataDir + '/',
                                          self.frmt,
                                          display=display,
                                          sort='name')
        if n == 0:
            print("NO PIV files found locally at : " + self.dataDir)
            print("Look for other possible locations")

            rootDir = file_architecture.get_dir(self.Id.date)
            dataDir = browse.get_string(self.dataDir,
                                        self.Id.date,
                                        from_end=True)
            dataDir = rootDir + dataDir
            fileList, n = browse.get_fileList(dataDir + '/',
                                              self.frmt,
                                              display=display,
                                              sort='name')

            if n == 0:
                print("No PIV files found globally !")
            else:
                print("PIV files found at : " + rootDir)

        # print(n)
        return fileList, n
Esempio n. 4
0
def load_Mdata_serie(date, index=[], mindex=[], data=True):
    # list with the different Sdata files
    Mlist = []
    fileList = getloc(date, index, mindex)
    for file in fileList:
        index = int(browse.get_string(file, 'M_' + date + '_', '_'))

        try:
            M = load_Mdata_file(file, data=data)
            done = True
        except:
            # retrieve the Sdata associated to it
            S = Sdata_manip.load_Sdata(date, index)
            if S is not None:
                Measure_gen_serie(S)
                M = load_Mdata_file(file, data)
                done = True
            else:
                done = False
                #            for i,M in enumerate(Mlist):
                #                M_gen(S,dataDir,mindex,typ='Mdata')
        if done:
            Mlist.append(M)
        else:
            print("")
            print("unable to read Sdata for " + date)
            print("")

    return Mlist
Esempio n. 5
0
def draw_grid(M, ax, x0, y0, Mesh=50, Bar=10, H=10, N=5, facecolor='y', edgecolor='k', linewidth=2):
    """
    Draw the grid at the specified position.
    """
    file = M.Sdata.fileCine
    ind = browse.get_string(os.path.basename(file), '_M', end='mm')

    if M.Id.date == '2016_03_05':
        ind = 24

    if not ind == '':
        Bar = 4
        H = 8
        Mesh = int(ind)  # print(int(ind))
        N = 9
    else:
        Mesh = 50

    positions = [(i * Mesh + x0, y0) for i in range(-(N // 2), N // 2 + 1)]
    width = Bar
    height = H
    # grid = []
    for p in positions:
        square = patches.Rectangle(centered(p, width, height), width, height, facecolor=facecolor, edgecolor=edgecolor,
                                   linewidth=linewidth)
        ax.add_patch(square)
Esempio n. 6
0
def make_ref_file(cinefile, folder=''):
    keys = ['fx', 'im0', 'x0', 'y0', 'angle']
    List_info = [[0] for i in range(len(keys))]

    if folder == '':
        folder = os.path.dirname(cinefile)

    #generate an empty ref file associated to each cine file
    #Should be manually filled out from images measurements

    cinebase = browse.get_string(os.path.basename(cinefile), '', '.cine')
    name = folder + 'Ref_' + cinebase + '.txt'

    if not os.path.isfile(name):
        print(name)
        #check first if a Ref file exists already
        #    Ref_PIV_sv_vp_zoom_Polymer_200ppm_X25mm_fps5000_n18000_beta500mu_H1180mm_S300mm
        rw_data.write_dictionnary(name, keys, List_info)
    else:
        print('Reference file exists already')
        pass


#directory = '/Volumes/labshared3/Stephane/Experiments/Accelerated_grid/2015_03_24/'
#gen(directory)
Esempio n. 7
0
def make_movie(cinefile,
               nimage,
               start=0,
               stop=1,
               step=1,
               folder='',
               framerate=30,
               quality=50):
    #generate a folder with tiff images : it would be easier if a avi file is generated directly
    root = os.path.basename(cinefile)
    base = browse.get_string(root, '', end='.cine')

    if folder == '':
        folder = os.path.dirname(cinefile)

    folder = '/References'
    print(folder + base)

    cine2pic.cine2tiff(cinefile,
                       mode='Sample',
                       step=step,
                       ctime=2,
                       start=start,
                       stop=nimage * step + start,
                       folder=folder,
                       post=base)
Esempio n. 8
0
def saveDir(file, post=''):
    fileroot = browse.get_string(file, '', '.cine', 0)
    if not (fileroot == ''):
        Dir = fileroot + post + '/'
        root = 'im'
        if not os.path.isdir(Dir):
            os.makedirs(Dir)
    else:
        print('not a cine file')

    return Dir, root
Esempio n. 9
0
def make_timestep_files(fileList,Dt=args.imstep,starts=[],ends=[],Dt_list=[]):
    """
    Generate a timestep .txt file that will be used to process the data with the right time step
    INPUT
    -----
    fileList : list of filename to process
    Dt : int. Separation between image A and image B
    Optional variables (not implemented yet) : starts, ends and Dt_list to set a list of timestep for different instants in the movie.
    OUTPUT
    -----
    NONE
    """
    
    keys = ['start','end','Dt']
    
    for file in fileList[args.start:args.end]:
        
        n = str(browse.get_string(file,start = '_n',end='_'))
        try:
            int(n)
        except:
            n=''
        if n=='':
            #get the number of images from the cinefile
            try:
                c = cine.Cine(file)     
            except:
                print('Cine file temporary unavailable')
                return None
            c=cine.Cine(file)
            n=c.len()-1
            #print(n)
               
        values = [[0],[n],[Dt]]
        
        base = browse.get_string(os.path.basename(file),'','.cine')
        file_timestep = os.path.dirname(file) +'/PIV_timestep_'+base+'.txt'
        
        if not os.path.isfile(file_timestep):
            rw_data.write_dictionnary(file_timestep, keys, values)
Esempio n. 10
0
def get_parameters_isotropic(
        file):  ##use this method to get parameters for the isotropic data
    """

    Parameters
    ----------
    file

    Returns
    -------

    """
    List_key = ['zl', 'yl', 'xl', 't0', 'tl', 'y0', 'x0', 'z0']

    param = {}
    for k in List_key[:-1]:
        param[k] = int(
            browse.get_string(file, '_' + k + '_', end='_', display=False))
    k = List_key[-1]
    param[k] = int(
        browse.get_string(file, '_' + k + '_', end='/', display=False))

    return param
Esempio n. 11
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
Esempio n. 12
0
def get_parameters(file):
    """
    If the hdf5 file is named like "isotropic1024_zl_20_yl_20_xl_20_coarse_t0_0_tl_1_y0_0_x0_0_z0_0_",
    this method gets each parameter values.

    Parameters
    ----------
    file: str
        a definite path to the hdf5 file

    Returns
    -------
    param: dict
        parameter names and values read from the name of the hdf5 file
    """
    List_key = ['zl', 'yl', 'xl', 't0', 'tl', 'y0', 'x0', 'z0']

    param = {}
    for k in List_key:
        param[k] = int(
            browse.get_string(file, '_' + k + '_', end='_', display=False))
    k = List_key

    return param
Esempio n. 13
0
def make_result_folder(fileList,type_analysis='Sample',algo='PIVlab',W=32,ratio=None):
    """
    Create folders for storing the PIVlab Data (now processed in matlab)    
    INPUT
    -----	
    fileList : List of string
        filename List to be read
    type_analysis : string (default value 'Sample')
        Standard presaved types of analysis (Sample = 1/10 images processed, Full_single', every images, Full_double every pair of image (effective ratio = 2))
                Full_single : ratio = 1
                Full_double : ratio = 2
                Sample : ratio = 10
    algo : string (default value 'PIVlab')
        Name of the PIV algorithm used to processed the data
    W : int (default value = 32)
        Window size used for PIV processing.
    ratio : number of images / number of pair of images processed. default value = 10. Can be set to standard values using type_analysis
    OUTPUT
    ------
    None
    0	"""
    types = dict(Sample=ratio,Full_double=2,Full_single=1)
    if type_analysis in types.keys():
        ratio = types[type_analysis]
    else:
        #use the value given in argument for ratio
        pass
    
    for file in fileList[args.start:args.end]:
        Dir = os.path.dirname(file)
        rootDir = Dir +'/PIV_data'
        basename = browse.get_string(os.path.basename(file),'',end='.cine')
        foldername = rootDir+'/'+algo+'_ratio'+str(ratio)+'_W'+str(W)+'pix_'+basename

        if not os.path.isdir(foldername):
            os.makedirs(foldername)
Esempio n. 14
0
def title(M):
    date = M.Id.date
    typ = browse.get_string(M.dataDir, 'piston12mm_', end='_f5Hz')
    savedir = './Vortex_Turbulence/Vortex_propagation/' + date + '/' + typ + '/'
    print(savedir)
    return savedir
Esempio n. 15
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')
Esempio n. 16
0
 def set_date(self, file):
     # Date
     #        file=self.Sdata.fileCine
     self.date = browse.get_string(file, "/20", "/", -2)
Esempio n. 17
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()
Esempio n. 18
0
def compile(Mlist, V=None, method='circulation'):
    symbol = {'50': '^', '125': 'o', '250': 's'}
    color = {'circulation': 'r', 'vorticity': 'b', 'joseph': 'k'}
    labels = {key: color[method] + symbol[key] for key in symbol.keys()}
    if V == None:
        sub_labels = labels
        piston_v = None
    else:
        piston_v = str(V)
        sub_labels = {piston_v: labels[piston_v]}  # ,'125':'ro','250':'bs'}

    figs = {}

    for i, M in enumerate(Mlist):
        piston1 = browse.get_string(M.Sdata.fileCine,
                                    '_v',
                                    end='.cine',
                                    shift=0,
                                    display=False,
                                    from_end=True)
        piston2 = browse.get_string(M.Sdata.fileCine,
                                    '_v',
                                    end='_p30mum',
                                    shift=0,
                                    display=False,
                                    from_end=True)

        error = 0.25
        for piston in [piston1, piston2]:
            if piston in sub_labels.keys():
                print(M.dataDir)
                dx = np.mean(np.diff(M.x[0, :]))
                print('Spatial scale : ' + str(dx) + ' mm/box')
                lc, std_lc, Gamma, std_Gamma = compute(M,
                                                       method=method,
                                                       display=False,
                                                       fignum=(i + 1) * 2)

                #                print(piston,dx,lc,std_lc)
                if std_lc / lc < error:
                    graphes.errorbar(dx,
                                     lc, [0],
                                     std_lc,
                                     label=labels[piston],
                                     fignum=250)
                    figs.update(graphes.legende('mm/box', 'Core size (mm)',
                                                ''))
                    graphes.set_axis(0, 1.5, 0, 6.)

                    if method == 'circulation':
                        #   if np.abs(std_Gamma/Gamma)<error:
                        graphes.errorbar(dx,
                                         Gamma, [0],
                                         std_Gamma,
                                         label=labels[piston],
                                         fignum=251)
                        figs.update(
                            graphes.legende('mm/box', 'Circulation (mm^2/s)',
                                            ''))
                        graphes.set_axis(0, 1.5, -2 * 10**4, 0)
                # print(piston,dx,lc,std_lc
                print('')

    print('figure', figs)
    print(figs)
    graphes.save_figs(figs,
                      suffix='Compilation_method_' + method + '_v' + piston_v)