コード例 #1
0
ファイル: findorientations.py プロジェクト: johnkit/hexrd
def generate_eta_ome_maps(cfg, hkls=None, save=True):
    """
    Generates the eta-omega maps specified in the input config.
    """
    # extract PlaneData from config and set active hkls
    plane_data = cfg.material.plane_data

    # handle logic for active hkl spec
    # !!!: default to all hkls defined for material,
    #      override with
    #        1) hkls from config, if specified; or
    #        2) hkls from kwarg, if specified
    available_hkls = plane_data.hkls.T
    active_hkls = range(len(available_hkls))
    temp = cfg.find_orientations.orientation_maps.active_hkls
    active_hkls = active_hkls if temp == 'all' else temp
    active_hkls = hkls if hkls is not None else active_hkls

    # logging output
    hklseedstr = ', '.join([str(available_hkls[i]) for i in active_hkls])

    logger.info("building eta_ome maps using hkls: %s", hklseedstr)

    # grad imageseries dict from cfg
    imsd = cfg.image_series

    # handle omega period
    ome_period, _ = _process_omegas(imsd)

    start = timeit.default_timer()

    # make eta_ome maps
    eta_ome = instrument.GenerateEtaOmeMaps(
        imsd,
        cfg.instrument.hedm,
        plane_data,
        active_hkls=active_hkls,
        threshold=cfg.find_orientations.orientation_maps.threshold,
        ome_period=ome_period)

    logger.info("\t\t...took %f seconds", timeit.default_timer() - start)

    if save:
        # save maps
        # ???: should perhaps set default maps name at module level
        map_fname = cfg.find_orientations.orientation_maps.file \
            or '_'.join([cfg.analysis_id, "eta-ome_maps.npz"])

        if not os.path.exists(cfg.working_dir):
            os.mkdir(cfg.working_dir)

        fn = os.path.join(cfg.working_dir, map_fname)

        eta_ome.save(fn)

        logger.info('saved eta/ome orientation maps to "%s"', fn)

    return eta_ome
コード例 #2
0
ファイル: utils.py プロジェクト: hsheng94/hexrd-1
def get_eta_ome(cfg, clean=False):
    """Return eta-omega maps"""
    # make eta_ome maps
    imsd = cfg.image_series
    instr = cfg.instrument.hedm
    plane_data = cfg.material.plane_data
    active_hkls = cfg.find_orientations.orientation_maps.active_hkls
    build_map_threshold = cfg.find_orientations.orientation_maps.threshold
    ome_period = np.radians(cfg.find_orientations.omega.period)

    # Use existing ones if available
    maps_fname = cfg.find_orientations.orientation_maps.file
    if maps_fname is None:
        maps_fname = "_".join(
            [analysis_id(cfg),
             "t" + str(build_map_threshold),
             "maps.npz"]
        )
    if os.path.exists(maps_fname) and not clean:
        print("INFO: loading existing eta_ome maps")
        eta_ome = EtaOmeMaps(maps_fname)
        return eta_ome

    print("INFO: building eta_ome maps")
    start = timeit.default_timer()

    # trim plane_data to only use active hkls
    if active_hkls is not None:
        excl = np.ones_like(plane_data.exclusions, dtype=bool)
        excl[active_hkls] = False
        plane_data.exclusions = excl
        
    eta_ome = instrument.GenerateEtaOmeMaps(
        imsd, instr, plane_data,
        active_hkls=active_hkls,
        threshold=build_map_threshold,
        ome_period=cfg.find_orientations.omega.period
    )

    print("INFO:  ...took %f seconds" % (timeit.default_timer() - start))

    # save them
    eta_ome.save(maps_fname)

    return eta_ome
コード例 #3
0
ファイル: findorientations.py プロジェクト: rachelelim/hexrd
def generate_eta_ome_maps(cfg, hkls=None):
    # extract PlaneData from config and set active hkls
    plane_data = cfg.material.plane_data

    # handle logicl for active hkl spec
    # !!!: default to all hkls defined for material,
    #      override with
    #        1) hkls from config, if specified; or
    #        2) hkls from kwarg, if specified
    available_hkls = plane_data.hkls.T
    active_hkls = range(len(available_hkls))
    temp = cfg.find_orientations.orientation_maps.active_hkls
    active_hkls = active_hkls if temp == 'all' else temp
    active_hkls = hkls if hkls is not None else active_hkls

    # logging output
    hklseedstr = ', '.join(
        [str(available_hkls[i]) for i in active_hkls]
        )
    logger.info(
        "building eta_ome maps using hkls: %s",
        hklseedstr
        )

    # make eta_ome maps
    eta_ome = instrument.GenerateEtaOmeMaps(
        cfg.image_series, cfg.instrument.hedm, plane_data,
        active_hkls=active_hkls,
        threshold=cfg.find_orientations.orientation_maps.threshold,
        ome_period=cfg.find_orientations.omega.period)

    map_fname = cfg.find_orientations.orientation_maps.file \
        or '_'.join(cfg.analysis_id, 'maps.npz')
    fn = os.path.join(
        cfg.working_dir,
        map_fname
    )
    fd = os.path.split(fn)[0]
    if not os.path.isdir(fd):
        os.makedirs(fd)
    eta_ome.save(fn)
    logger.info('saved eta/ome orientation maps to "%s"', fn)
    return eta_ome
コード例 #4
0
det_keys = instr.detectors.keys()

imsd = dict.fromkeys(det_keys)
for det_key in det_keys:
    fc_file = sorted(
        glob.glob(os.path.join(data_dir, fc_stem % det_key.lower())))
    if len(fc_file) != 1:
        raise (RuntimeError, 'cache file not found, or multiple found')
    else:
        ims = load_images(fc_file[0])
        imsd[det_key] = OmegaImageSeries(ims)

eta_ome = instrument.GenerateEtaOmeMaps(
    imsd,
    instr,
    pd,
    active_hkls=active_hkls,
    threshold=cfg.find_orientations.orientation_maps.threshold,
    ome_period=cfg.find_orientations.omega.period)

grains_data = np.loadtxt(ref_grains_out)
expmaps = grains_data[:, 3:6]
quats = rot.quatOfExpMap(expmaps.T)

#%%

for i in range(0, len(expmaps)):
    this_quat = quats[:, i]
    qball = quaternion_ball(this_quat, mis_thresh)
    test_compl = test_GOE(cfg, qball, eta_ome, eta_tol=0.25)
    GOE, compl = thresh_GOE(qball, test_compl, comp_thresh)
コード例 #5
0
                      max_frames_output_name,
                      'hdf5',
                      path='/imageseries')
#%%

# note that here maps are only used for quaternion generation
active_hkls = fiber_seeds

# omega period...
# QUESTION: necessary???
ome_period = np.radians(cfg.find_orientations.omega.period)

# make eta_ome maps
eta_ome = instrument.GenerateEtaOmeMaps(imsd,
                                        instr,
                                        pd,
                                        active_hkls=active_hkls,
                                        threshold=map_threshold)

#%%
cmap = plt.cm.hot
cmap.set_under('b')

fig, ax = plt.subplots()
i_ring = 0
this_map_f = -ndimage.filters.gaussian_laplace(
    eta_ome.dataStore[i_ring],
    1.0,
)
ax.imshow(this_map_f, interpolation='nearest', vmin=0.1, vmax=1.0, cmap=cmap)
labels, num_spots = ndimage.label(this_map_f > 0,
コード例 #6
0
                      'hdf5',
                      path='/imageseries')
# %%

maps_fname = analysis_id + "_maps.npz"
if os.path.exists(maps_fname) and not clobber_maps:
    eta_ome = EtaOmeMaps(maps_fname)
else:
    print("INFO:\tbuilding eta_ome maps")
    start = timeit.default_timer()

    # make eta_ome maps
    eta_ome = instrument.GenerateEtaOmeMaps(
        imsd,
        instr,
        plane_data,
        active_hkls=active_hkls,
        threshold=build_map_threshold,
        ome_period=cfg.find_orientations.omega.period)

    print("INFO:\t\t...took %f seconds" % (timeit.default_timer() - start))

    # save them
    eta_ome.save(maps_fname)

# %%
# =============================================================================
# OPTINAL PLOTTING
# =============================================================================
if show_maps:
    cmap = plt.cm.hot