Example #1
0
def main(overide={}):
    # get command line args and config
    sc  = 'make_whitefield'
 
    # search the current directory for *.ini files if not present in cxi directory
    config_dirs = [os.path.split(os.path.abspath(__file__))[0]]
    
    # extract the first paragraph from the doc string
    des = st.make_whitefield.__doc__.split('\n\n')[0]
    
    # now load the necessary data
    args, params = cmdline_config_cxi_reader.get_all(sc, des, config_dirs=config_dirs, roi=False)
    params = params['make_whitefield']

    # overide with input parameters (if any)
    params.update(overide)
    
    W = st.make_whitefield(params['data'], params['mask'])
    
    out = {'whitefield': W}
    cmdline_config_cxi_reader.write_all(params, args.filename, out, apply_roi=False)

    # output display for gui
    with open('.log', 'w') as f:
        print('display: '+params['h5_group']+'/whitefield', file=f)
def main(overide={}):
    # get command line args and config
    sc = 'guess_roi'

    # search the current directory for *.ini files if not present in cxi directory
    config_dirs = [os.path.split(os.path.abspath(__file__))[0]]

    # extract the first paragraph from the doc string
    des = st.guess_roi.__doc__.split('\n\n')[0]

    # now load the necessary data
    args, params = cmdline_config_cxi_reader.get_all(sc,
                                                     des,
                                                     config_dirs=config_dirs,
                                                     roi=False)
    params = params['guess_roi']

    # overide with input params (if any)
    params.update(overide)

    roi = st.guess_roi(params['whitefield'])

    out = {'roi': roi}
    cmdline_config_cxi_reader.write_all(params,
                                        args.filename,
                                        out,
                                        apply_roi=False)
Example #3
0
def main(overide={}):
    # get command line args and config
    sc = 'calculate_phase'

    # search the current directory for *.ini files if not present in cxi directory
    config_dirs = [os.path.split(os.path.abspath(__file__))[0]]

    # extract the first paragraph from the doc string
    des = st.calculate_phase.__doc__.split('\n\n')[0]

    # now load the necessary data
    args, params = cmdline_config_cxi_reader.get_all(sc,
                                                     des,
                                                     config_dirs=config_dirs,
                                                     roi=True)
    params = params[sc]

    # overide with input params (if any)
    params.update(overide)

    phase, angles, res = st.calculate_phase(
        params['pixel_map'], params['weight'], params['wavelength'],
        params['z'], params['x_pixel_size'], params['y_pixel_size'],
        params['dss'], params['dfs'], False, params['maxiter'])

    out = {'phase': phase, 'angles': angles}
    out.update(res)
    cmdline_config_cxi_reader.write_all(params,
                                        args.filename,
                                        out,
                                        apply_roi=True)

    # output display for gui
    with open('.log', 'w') as f:
        print('display: ' + params['h5_group'] + '/phase', file=f)
def main(overide={}):
    # get command line args and config
    sc = 'make_reference'

    # search the current directory for *.ini files if not present in cxi directory
    config_dirs = [os.path.split(os.path.abspath(__file__))[0]]

    # extract the first paragraph from the doc string
    des = st.make_object_map.__doc__.split('\n\n')[0]

    # now load the necessary data
    args, params = cmdline_config_cxi_reader.get_all(sc,
                                                     des,
                                                     config_dirs=config_dirs,
                                                     roi=True)
    params = params['make_reference']

    # overide with input params (if any)
    params.update(overide)

    O, n0, m0 = st.make_object_map(
        params['data'].astype(params['whitefield'].dtype), params['mask'],
        params['whitefield'], params['pixel_translations'],
        params['pixel_map'], params['ls'])

    out = {'reference_image': O, 'n0': n0, 'm0': m0}
    cmdline_config_cxi_reader.write_all(params,
                                        args.filename,
                                        out,
                                        apply_roi=True)

    # output display for gui
    with open('.log', 'w') as f:
        print('display: ' + params['h5_group'] + '/reference_image', file=f)
Example #5
0
def main(overide={}):
    # get command line args and config
    sc = 'defocus_sweep'

    # search the current directory for *.ini files if not present in cxi directory
    config_dirs = [os.path.split(os.path.abspath(__file__))[0]]

    # extract the first paragraph from the doc string
    des = defocus_sweep.__doc__.split('\n\n')[0]

    # now load the necessary data
    args, params = cmdline_config_cxi_reader.get_all(sc,
                                                     des,
                                                     config_dirs=config_dirs,
                                                     roi=True)
    params = params['defocus_sweep']

    # overide with input params (if any)
    params.update(overide)

    Os, z1 = defocus_sweep(params['z1_min'], params['z1_max'], params['n'],
                           params['z'], params['data'], params['mask'],
                           params['whitefield'], params['basis'],
                           params['x_pixel_size'], params['y_pixel_size'],
                           params['translations'], params['ls'])

    out = {'Os': Os, 'defocus': z1}
    cmdline_config_cxi_reader.write_all(params,
                                        args.filename,
                                        out,
                                        apply_roi=True)

    # output display for gui
    with open('.log', 'w') as f:
        print('display: /' + params['h5_group'] + '/Os', file=f)
Example #6
0
def main(overide={}):
    print('Running...')
    # get command line args and config
    sc = 'calc_error'

    # search the current directory for *.ini files if not present in cxi directory
    config_dirs = [os.path.split(os.path.abspath(__file__))[0]]

    # extract the first paragraph from the doc string
    des = st.calc_error.__doc__.split('\n\n')[0]

    # now load the necessary data
    args, params = cmdline_config_cxi_reader.get_all(sc,
                                                     des,
                                                     config_dirs=config_dirs,
                                                     roi=True)
    params = params['calc_error']

    # overide with input params (if any)
    params.update(overide)

    error_total, error_frame, error_pixel, error_residual, error_reference, norm, flux_correction, res = st.calc_error(
        params['data'],
        params['mask'],
        params['whitefield'],
        params['pixel_translations'],
        params['reference_image'],
        params['pixel_map'],
        params['n0'],
        params['m0'],
        subpixel=True,
        verbose=True)

    out = {
        'error_total': error_total,
        'error_frame': error_frame,
        'error_pixel': error_pixel,
        'error_residual': error_residual,
        'error_reference': error_reference,
        'error_norm': norm,
        'flux_correction': flux_correction
    }

    if '1d_data_vs_forward' in res:
        out['1d_data_vs_forward'] = res['1d_data_vs_forward']
    else:
        out['forward'] = res['forward']

    cmdline_config_cxi_reader.write_all(params,
                                        args.filename,
                                        out,
                                        apply_roi=True)

    # output display for gui
    with open('.log', 'w') as f:
        print('display: ' + params['h5_group'] + '/error_pixel', file=f)
Example #7
0
def main(overide={}):
    # get command line args and config
    sc = 'update_pixel_map'

    # search the current directory for *.ini files if not present in cxi directory
    config_dirs = [os.path.split(os.path.abspath(__file__))[0]]

    # extract the first paragraph from the doc string
    des = st.update_pixel_map.__doc__.split('\n\n')[0]

    # now load the necessary data
    args, params = cmdline_config_cxi_reader.get_all(sc,
                                                     des,
                                                     config_dirs=config_dirs,
                                                     roi=True)
    params = params[sc]

    # overide with input parameters (if any)
    params.update(overide)

    u, res = st.update_pixel_map(params['data'].astype(np.float32),
                                 params['mask'],
                                 params['whitefield'],
                                 params['reference_image'],
                                 params['pixel_map'],
                                 params['n0'],
                                 params['m0'],
                                 params['pixel_translations'],
                                 params['search_window'],
                                 None,
                                 None,
                                 params['subpixel'],
                                 params['subsample'],
                                 params['interpolate'],
                                 params['fill_bad_pix'],
                                 params['quadratic_refinement'],
                                 params['integrate'],
                                 params['clip'],
                                 params['filter'],
                                 verbose=True,
                                 guess=False)

    u0 = np.array(np.indices(params['data'].shape[1:]))
    du = u - u0
    out = {'pixel_map': u, 'pixel_map_residual': du}
    cmdline_config_cxi_reader.write_all(params,
                                        args.filename,
                                        out,
                                        apply_roi=True)

    # output display for gui
    with open('.log', 'w') as f:
        print('display: ' + params['h5_group'] + '/pixel_map_residual', file=f)
def main(overide={}):
    # get command line args and config
    sc = 'generate_pixel_map'

    # search the current directory for *.ini files if not present in cxi directory
    config_dirs = [os.path.split(os.path.abspath(__file__))[0]]

    # extract the first paragraph from the doc string
    des = st.generate_pixel_map.__doc__.split('\n\n')[0]

    # now load the necessary data
    args, params = cmdline_config_cxi_reader.get_all(sc,
                                                     des,
                                                     config_dirs=config_dirs,
                                                     roi=True)
    params = params[sc]

    # overide with input params (if any)
    params.update(overide)

    u, pixel_translations, res = st.generate_pixel_map(params['mask'].shape,
                                                       params['translations'],
                                                       params['basis'],
                                                       params['x_pixel_size'],
                                                       params['y_pixel_size'],
                                                       params['z'],
                                                       params['defocus_fs'],
                                                       params['defocus_ss'],
                                                       params['dss'],
                                                       params['dfs'],
                                                       verbose=True)

    # make the 'residual' pixel map for display
    u0 = np.array(np.indices(params['mask'].shape))
    du = u - u0

    out = {
        'pixel_map': u,
        'pixel_map_residual': du,
        'pixel_translations': pixel_translations
    }
    out.update(res)
    cmdline_config_cxi_reader.write_all(params,
                                        args.filename,
                                        out,
                                        apply_roi=True)

    # output display for gui
    with open('.log', 'w') as f:
        print('display: /' + params['h5_group'] + '/pixel_map_residual',
              file=f)
Example #9
0
def main(overide={}):
    # get command line args and config
    sc = 'update_translations'

    # search the current directory for *.ini files if not present in cxi directory
    config_dirs = [os.path.split(os.path.abspath(__file__))[0]]

    # extract the first paragraph from the doc string
    des = st.make_object_map.__doc__.split('\n\n')[0]

    # now load the necessary data
    args, params = cmdline_config_cxi_reader.get_all(sc,
                                                     des,
                                                     config_dirs=config_dirs,
                                                     roi=True)
    params = params[sc]

    # overide with input params (if any)
    params.update(overide)

    xy_pix, err = st.update_translations(
        params['data'].astype(np.float32), params['mask'],
        params['whitefield'], params['reference_image'], params['pixel_map'],
        params['n0'], params['m0'], params['pixel_translations'],
        params['search_window'], False, params['maxiters'], params['tol'],
        None)

    comp = np.array([xy_pix, params['pixel_translations']])

    out = {'pixel_translations': xy_pix, 'pixel_translations_comparison': comp}
    cmdline_config_cxi_reader.write_all(params,
                                        args.filename,
                                        out,
                                        apply_roi=True)

    # output display for gui
    with open('.log', 'w') as f:
        print('display: ' + params['h5_group'] +
              '/pixel_translations_comparison scatter',
              file=f)
def main(overide={}):
    # get command line args and config
    sc = 'fit_thon_rings'

    # search the current directory for *.ini files if not present in cxi directory
    config_dirs = [os.path.split(os.path.abspath(__file__))[0]]

    # extract the first paragraph from the doc string
    des = st.fit_thon_rings.__doc__.split('\n\n')[0]

    # now load the necessary data
    args, params = cmdline_config_cxi_reader.get_all(sc,
                                                     des,
                                                     config_dirs=config_dirs,
                                                     roi=True)
    params = params['fit_thon_rings']

    # overide with input params (if any)
    params.update(overide)

    z1, res = st.fit_thon_rings(params['data'], params['x_pixel_size'],
                                params['y_pixel_size'], params['distance'],
                                params['wavelength'], params['mask'],
                                params['whitefield'], None, None,
                                params['sigma'], params['edge_pix'],
                                params['window'], params['rad_range'])

    out = {'defocus': z1}
    out.update(res)

    cmdline_config_cxi_reader.write_all(params,
                                        args.filename,
                                        out,
                                        apply_roi=False)

    # output display for gui
    with open('.log', 'w') as f:
        print('display: ' + params['h5_group'] + '/thon_display', file=f)
Example #11
0
def main(overide={}):
    # get command line args and config
    sc = 'focus_profile'

    # search the current directory for *.ini files if not present in cxi directory
    config_dirs = [os.path.split(os.path.abspath(__file__))[0]]

    # extract the first paragraph from the doc string
    des = st.focus_profile.__doc__.split('\n\n')[0]

    # now load the necessary data
    args, params = cmdline_config_cxi_reader.get_all(sc,
                                                     des,
                                                     config_dirs=config_dirs,
                                                     roi=True)
    params = params[sc]

    # overide with input params (if any)
    params.update(overide)

    px, py, dx, dy, zstep = st.focus_profile(
        params['phase'], params['whitefield'], params['z'],
        params['wavelength'], params['x_pixel_size'], params['y_pixel_size'],
        params['zs'], params['subsamples'])

    out = {
        'profile_ss': px,
        'profile_fs': py,
        'xyz_voxel_size': np.array([dx, dy, zstep])
    }
    cmdline_config_cxi_reader.write_all(params,
                                        args.filename,
                                        out,
                                        apply_roi=True)

    # output display for gui
    with open('.log', 'w') as f:
        print('display: ' + params['h5_group'] + '/profile_ss', file=f)
def main(overide={}):
    # get command line args and config
    sc = 'calculate_sample_thickness'

    # search the current directory for *.ini files if not present in cxi directory
    config_dirs = [os.path.split(os.path.abspath(__file__))[0]]

    # extract the first paragraph from the doc string
    des = st.calculate_sample_thickness.__doc__.split('\n\n')[0]

    # now load the necessary data
    args, params = cmdline_config_cxi_reader.get_all(sc,
                                                     des,
                                                     config_dirs=config_dirs,
                                                     roi=False)
    params = params[sc]

    # overide with input params (if any)
    params.update(overide)

    t_pag, t_ctf = st.calculate_sample_thickness(
        params['delta'], params['beta'], params['distance'], params['defocus'],
        params['wavelength'], params['dss'], params['dfs'],
        params['reference_image'], params['reference_roi'],
        params['set_median_to_zero'], params['tol_ctf'], params['tol_tie'])

    out = {'sample_thickness_pag': t_pag, 'sample_thickness_ctf': t_ctf}
    cmdline_config_cxi_reader.write_all(params,
                                        args.filename,
                                        out,
                                        apply_roi=False)

    # output display for gui
    with open('.log', 'w') as f:
        print('display: /' + params['h5_group'] + '/sample_thickness_ctf',
              file=f)
Example #13
0
    # ----------------------------------
    z, z_poly, basis, basis_grid, y, x = calculate_Zernike_coeff(phase, params['mask'], 
                                                    params['orders'], dq, basis, basis_grid, y, x)
    
    # make the Zernike fit
    # ---------------------------------
    phase_zern = np.sum( [z[i] * basis_grid[i] for i in range(len(basis))], axis=0)
    
    # get the focus spot
    if params['whitefield'] is not None :
        print('\ncalculating focus...')
        pupil = params['whitefield'] * np.exp(1J * phase)
        P_focus = get_focus_probe(pupil)
        print('Real space pixel size   :', 1./ (np.array(P_focus.shape) * dq))
        print('Real space Field-of-view:', 1./ dq)

    
    # write the result 
    ##################
    out = {'probe_focus': P_focus, 
           'phase': phase, 
           'zernike_phase_fit' : phase_zern,
           'zernike_coefficients': z, 
           'zernike_rms': np.sqrt(np.sum(z**2)), 
           'zernike_basis_vectors': basis_grid}
    cmdline_config_cxi_reader.write_all(params, args.filename, out)
    
    # output display for gui
    with open('.log', 'w') as f:
        print('display: '+params['h5_group']+'/zernike_coefficients', file=f)
Example #14
0
                                                     des,
                                                     config_dirs=config_dirs,
                                                     roi=False)
    params = params['pixel_map_from_data']

    # Initialisation
    #---------------

    # make mask
    if str_compare(params['mask'], 'auto'):
        params['mask'] = st.make_mask(params['data'])

        # write to file
        out = {'mask': params['mask'], 'h5_group': params['h5_group']}
        cmdline_config_cxi_reader.write_all(out,
                                            args.filename,
                                            out,
                                            apply_roi=False)

        # output display for gui
        with open('.log', 'w') as f:
            print('display: /' + params['h5_group'] + '/mask', file=f)

    # make whitefield
    if str_compare(params['whitefield'], 'auto'):
        params['whitefield'] = st.make_whitefield(params['data'],
                                                  params['mask'])

        # write to file
        out = {
            'whitefield': params['whitefield'],
            'h5_group': params['h5_group']
Example #15
0
def main(overide={}):
    # get command line args and config
    sc = 'make_pixel_map_poly'

    # search the current directory for *.ini files if not present in cxi directory
    config_dirs = [os.path.split(os.path.abspath(__file__))[0]]

    # extract the first paragraph from the doc string
    #des = st.generate_pixel_map.__doc__.split('\n\n')[0]
    des = ""

    # now load the necessary data
    args, params = cmdline_config_cxi_reader.get_all(sc,
                                                     des,
                                                     config_dirs=config_dirs,
                                                     roi=True)
    params = params[sc]

    # overide with input params (if any)
    params.update(overide)

    # evaluate the polynomial expreesion for the pixel map
    y, x = np.indices(params['whitefield'].shape)
    ufs = eval(params['pixel_map_fs'])
    uss = eval(params['pixel_map_ss'])
    u = np.array([uss, ufs])
    u = np.clip(u, -1000, 1000)

    # generate the pixel translations
    M = params['z'] / params['defocus']
    dfs = params['x_pixel_size'] / M
    dss = params['y_pixel_size'] / M

    pixel_translations = st.make_pixel_translations(params['translations'],
                                                    params['basis'], dss, dfs)

    O, n0, m0 = st.make_object_map(
        params['data'].astype(params['whitefield'].dtype), params['mask'],
        params['whitefield'], pixel_translations,
        u.astype(params['whitefield'].dtype), params['ls'])

    u0 = np.array(np.indices(params['mask'].shape))
    du = u - u0

    out = {
        'reference_image': O,
        'n0': n0,
        'm0': m0,
        'pixel_map': u,
        'pixel_map_residual': du,
        'pixel_translations': pixel_translations,
        'dfs': dfs,
        'dss': dss
    }
    cmdline_config_cxi_reader.write_all(params,
                                        args.filename,
                                        out,
                                        apply_roi=True)

    # output display for gui
    with open('.log', 'w') as f:
        print('display: ' + params['h5_group'] + '/reference_image', file=f)