def run(self, data, output_dir, **run_args):
     
     results = {}
     
     infile = data.infile
     f = tools.Filename(infile)
     filepath, filename, filebase, ext = f.split()
     
     results['infile'] = infile
     results['filepath'] = filepath
     results['filename'] = filename
     results['filebase'] = filebase
     results['fileext'] = ext
     
     results['sample_name'] = data.name
     results['file_ctime'] = os.path.getctime(infile)
     results['file_modification_time'] = os.path.getmtime(infile)
     results['file_access_time'] = os.path.getatime(infile)
     results['file_size'] = os.path.getsize(infile)
     
     
     patterns = [
                 ['theta', '.+_th(\d+\.\d+)_.+'] ,
                 ['annealing_temperature', '.+_T(\d+\.\d\d\d)C_.+'] ,
                 ['annealing_time', '.+_(\d+\.\d)s_T.+'] ,
                 ['exposure_time', '.+_(\d+\.\d+)c_\d+_saxs.+'] ,
                 ['sequence_ID', '.+_(\d+)_saxs.+'] ,
                 ]
                 
     
     for pattern_name, pattern_string in patterns:
         pattern = re.compile(pattern_string)
         m = pattern.match(filename)
         if m:
             if run_args['verbosity']>=5:
                 print('  matched: {} = {}'.format(pattern_name, m.groups()[0]))
             results[pattern_name] = float(m.groups()[0])
     
     
     #outfile = self.get_outfile(data.name, output_dir)
     
     
     return results
Exemplo n.º 2
0
def plot_results(x_vals,
                 y_vals,
                 z_vals,
                 outfile,
                 plot2d=True,
                 plot3d=False,
                 grid=None,
                 dgrid=None,
                 title=None,
                 cmap='viridis',
                 alpha=1.0,
                 x_label='$x$',
                 y_label='$y$',
                 z_label=None,
                 interpolate_cyclic=None,
                 verbosity=3):

    if verbosity >= 3:
        print("Plotting for {}".format(outfile))
        val_stats(z_vals, name='z_vals')

    # Define grid for interpolation
    if grid is None:
        grid = [np.min(x_vals), np.max(x_vals), np.min(y_vals), np.max(y_vals)]
    if dgrid is None:
        dgrid = [(grid[1] - grid[0]) / 200, (grid[3] - grid[2]) / 200]
    if isinstance(dgrid, float):
        dgrid = [dgrid, dgrid]

    xi = np.arange(grid[0], grid[1] + dgrid[0], dgrid[0])
    yi = np.arange(grid[2], grid[3] + dgrid[1], dgrid[1])
    XI, YI = np.meshgrid(xi, yi)

    # Interpolation
    import scipy.interpolate
    POINTS = np.column_stack((x_vals, y_vals))
    VALUES = z_vals
    if verbosity >= 4:
        print("Interpolating {:,} points to {:,}×{:,} = {:,} points".format(
            len(VALUES), len(xi), len(yi),
            len(xi) * len(yi)))

    if interpolate_cyclic is not None:
        xlike = np.cos(VALUES * 2 * np.pi / interpolate_cyclic)
        ylike = np.sin(VALUES * 2 * np.pi / interpolate_cyclic)
        XLIKE = scipy.interpolate.griddata(POINTS,
                                           xlike, (XI, YI),
                                           method='linear')
        YLIKE = scipy.interpolate.griddata(POINTS,
                                           ylike, (XI, YI),
                                           method='linear')

        ZI = (np.arctan2(YLIKE, XLIKE) / (2 * np.pi)) * interpolate_cyclic
        ZI_mask = np.ma.masked_where(np.isnan(ZI), ZI)

    else:
        ZI = scipy.interpolate.griddata(
            POINTS, VALUES, (XI, YI),
            method='linear')  # method='nearest' 'linear' 'cubic'
        ZI_mask = np.ma.masked_where(np.isnan(ZI), ZI)

    if verbosity >= 4:
        val_stats(ZI, name='ZI')
        val_stats(ZI_mask, name='ZI_mask')

    d = Data2D_current()
    d.data = ZI_mask
    d.x_axis = xi
    d.y_axis = yi

    d.x_vals = x_vals
    d.y_vals = y_vals
    d.z_vals = z_vals

    d.set_z_display([None, None, 'linear', 1.0])
    d.x_rlabel = x_label
    d.y_rlabel = y_label
    d.z_rlabel = z_label

    if plot2d:
        d.plot_args['rcParams'] = {
            'axes.labelsize': 50,
            'xtick.labelsize': 40,
            'ytick.labelsize': 40,
        }
        d.alpha = alpha

        d.plot(save=outfile,
               show=False,
               cmap=cmap,
               zmin=zmin,
               zmax=zmax,
               title=title,
               plot_buffers=[0.21, 0.12, 0.18, 0.10],
               plot_range=grid,
               plot_2D_type='pcolormesh',
               dpi=150,
               transparent=False)

    if plot3d:
        d.plot_args['rcParams'] = {
            'axes.labelsize': 40,
            'xtick.labelsize': 20,
            'ytick.labelsize': 20,
        }
        d.X = XI
        d.Y = YI

        elev = 30
        azim = 30
        azim = 30 - 90

        #outfile = outfile[:-4]+'-3D.png'
        outfile = tools.Filename(outfile).path_append('3D')
        d.plot3D(save=outfile,
                 show=False,
                 cmap=cmap,
                 zmin=zmin,
                 zmax=zmax,
                 title=title,
                 plot_buffers=[0.05, 0.10, 0.05, 0.05],
                 plot_range=grid,
                 elev=elev,
                 azim=azim,
                 dpi=150,
                 transparent=False)
Exemplo n.º 3
0
    data_dir = 'LDRD_Meso_correlation/2015_10Oct-ref_patterns/21/'
    
    protocol = 'view'
    source_dir = root_dir+'data/'+data_dir
    output_dir = root_dir+'analysis/'+data_dir+'/'+protocol+'/'
    
    tools.make_dir(output_dir)
    
    infile = 'AgBH_22_master.h5'
    infile = 'Coral_porous_glass_0.3s_30_master.h5'
    infile = 'chip411_found_star_x-0.356_y13.468_922_master.h5'




f = tools.Filename(source_dir+infile)

if f.get_ext()=='.h5':

    # Check if this is a HDF5 data (as opposed to master) file
    m = re.compile('(.+)_data_\d{5,20}\.h5').match(f.get_filename())
    if m:
        # Switch to corresponding master file
        f = tools.Filename(f.get_path() + m.groups()[0] + '_master.h5')
    
    data = Data2DScattering(f.get_filepath())
    data.threshold_pixels(4294967295-1) # Eiger inter-module gaps
    data.set_z_display( [None, None, 'gamma', 0.3] )
    data.plot(show=True)