Beispiel #1
0
 def test_refine_position_gaussian(self):
     signal = self.signal
     vector = ipf.find_dumbbell_vector(signal, 4)
     position_list = get_atom_positions(signal, separation=13)
     atom_lattice = ipf.make_atom_lattice_dumbbell_structure(
         signal, position_list, vector)
     atom_lattice.refine_position_gaussian()
Beispiel #2
0
 def test_find_number_of_columns(self):
     test_data = MakeTestData(50, 50)
     x, y = np.mgrid[5:48:5, 5:48:5]
     x, y = x.flatten(), y.flatten()
     test_data.add_atom_list(x, y)
     peaks = afr.get_atom_positions(test_data.signal, separation=3)
     assert len(peaks) == len(x)
Beispiel #3
0
 def test_simple_running(self):
     s = self.s
     vector = find_dumbbell_vector(s, 4)
     position_list = get_atom_positions(s, 14)
     dumbbell_array0, dumbbell_array1 = _get_dumbbell_arrays(
         s, position_list, vector)
     assert len(dumbbell_array0) == 100
     assert len(dumbbell_array1) == 100
Beispiel #4
0
 def test_simple_running(self):
     s = self.s
     vector = find_dumbbell_vector(s, 4)
     position_list = get_atom_positions(s, separation=13)
     atom_lattice = make_atom_lattice_dumbbell_structure(
         s, position_list, vector)
     assert len(atom_lattice.sublattice_list) == 2
     sublattice0 = atom_lattice.sublattice_list[0]
     sublattice1 = atom_lattice.sublattice_list[1]
     assert len(sublattice0.atom_list) == 100
     assert len(sublattice1.atom_list) == 100
Beispiel #5
0
def get_polarised_single_sublattice_rotated(image_noise=False, rotation=45):
    sublattice = get_polarised_single_sublattice(image_noise=image_noise)
    sig = sublattice.signal
    sig.map(scipy.ndimage.rotate, angle=rotation, reshape=False)
    # sig.plot()
    atom_positions = get_atom_positions(sig, separation=7)
    rot_sublattice = Sublattice(atom_positions, image=sig.data)
    rot_sublattice.find_nearest_neighbors()
    rot_sublattice.refine_atom_positions_using_center_of_mass()
    # rot_sublattice.plot()
    return rot_sublattice
Beispiel #6
0
    def setup_method(self):
        test_data = tt.MakeTestData(520, 520)
        x, y = np.mgrid[10:510:20j, 10:510:20j]
        x, y = x.flatten(), y.flatten()
        test_data.add_atom_list(x, y)
        s = test_data.signal

        atom_positions = afr.get_atom_positions(
            signal=s,
            separation=10,
            threshold_rel=0.02,
        )
        sublattice = Sublattice(atom_position_list=atom_positions,
                                image=s.data)
        sublattice.find_nearest_neighbors()
        self.sublattice = sublattice
Beispiel #7
0
    def setup_method(self):
        s_adf_filename = os.path.join(my_path, "datasets",
                                      "test_ADF_cropped.hdf5")
        peak_separation = 0.15

        s_adf = load(s_adf_filename)
        s_adf.change_dtype('float64')
        s_adf_modified = afr.subtract_average_background(s_adf)
        self.s_adf_modified = afr.do_pca_on_signal(s_adf_modified)
        self.pixel_size = s_adf.axes_manager[0].scale
        self.pixel_separation = peak_separation / self.pixel_size

        s_abf_filename = os.path.join(my_path, "datasets",
                                      "test_ABF_cropped.hdf5")
        s_abf = load(s_abf_filename)
        s_abf.change_dtype('float64')

        self.peaks = afr.get_atom_positions(self.s_adf_modified,
                                            self.pixel_separation)
Beispiel #8
0
    def test_manual_processing(self):
        s_adf_filename = os.path.join(my_path, "datasets",
                                      "test_ADF_cropped.hdf5")
        s = load(s_adf_filename)
        s.change_dtype('float32')
        atom_positions = afr.get_atom_positions(
            signal=s,
            separation=17,
            threshold_rel=0.02,
        )
        sublattice = Sublattice(atom_position_list=atom_positions,
                                image=s.data)
        sublattice.find_nearest_neighbors()
        sublattice.refine_atom_positions_using_center_of_mass(
            sublattice.image, percent_to_nn=0.4)
        sublattice.refine_atom_positions_using_2d_gaussian(sublattice.image,
                                                           percent_to_nn=0.4)

        Atom_Lattice(image=s.data, sublattice_list=[sublattice])
        sublattice.construct_zone_axes()
def find_dumbbell_vector(s, separation):
    """
    Find the vector between the atoms in structure with dumbbells.
    For example GaAs-(110).

    Parameters
    ----------
    s : HyperSpy 2D signal
    separation : int
        Pixel separation between the atoms in the dumbbells.

    Returns
    -------
    dumbbell_vector : tuple

    Examples
    --------
    >>> import temul.external.atomap_devel_012.api as am
    >>> from temul.external.atomap_devel_012.initial_position_finding import find_dumbbell_vector
    >>> s = am.dummy_data.get_dumbbell_signal()
    >>> dumbbell_vector = find_dumbbell_vector(s, 4)
    """
    position_list = get_atom_positions(s, separation=separation)
    test = _get_n_nearest_neighbors(position_list, 10, leafsize=100)
    fp = Fingerprinter()
    fp.fit(test)
    clusters = fp.cluster_centers_
    clusters_dist = (clusters[:, 0]**2 + clusters[:, 1]**2)**0.5
    sort_zip = zip(list(clusters_dist), clusters[:, 0], clusters[:, 1])
    cluster_dist, cluster_x, cluster_y = zip(
        *sorted(sort_zip, key=itemgetter(0)))
    vec0 = cluster_x[0], cluster_y[0]
    vec1 = cluster_x[1], cluster_y[1]

    if (abs(vec0[0] + vec1[0]) > 0.1) or (abs(vec0[1] + vec1[1]) > 0.1):
        raise ValueError(
            "Dumbbell vectors should be antiparallel, but are %r and %r"
            % (vec0, vec1))
    return(vec0)
Beispiel #10
0
def make_atom_lattice_from_image(s_image0,
                                 process_parameter=None,
                                 pixel_separation=None,
                                 s_image1=None,
                                 debug_plot=False):
    if s_image0.data.dtype == 'float16':
        raise ValueError(
            "s_image0 has the dtype float16, which is not supported. "
            "Convert it to something else, for example using "
            "s_image0.change_dtype('float64')")
    image0_filename = _get_signal_name(s_image0)

    name = image0_filename

    s_image0 = s_image0.deepcopy()
    s_image0_modified = run_image_filtering(s_image0)

    if process_parameter is None:
        process_parameter = pp.GenericStructure()

    image0_scale = s_image0.axes_manager[0].scale
    if pixel_separation is None:
        if process_parameter.peak_separation is None:
            raise ValueError("pixel_separation is not set.\
                    Either set it in the process_parameter.peak_separation\
                    or pixel_separation parameter")
        else:
            pixel_separation = process_parameter.peak_separation / image0_scale
    initial_atom_position_list = get_atom_positions(
        s_image0_modified, separation=pixel_separation)

    if s_image1 is not None:
        if s_image1.data.dtype == 'float16':
            raise ValueError(
                "s_image1 has the dtype float16, which is not supported. "
                "Convert it to something else, for example using "
                "s_image1.change_dtype('float64')")
        s_image1 = s_image1.deepcopy()
        s_image1.data = 1. / s_image1.data
        image1_data = s_image1.data

    #################################

    image0_data = s_image0.data
    image0_data_modified = s_image0_modified.data

    atom_lattice = Atom_Lattice(name=name)
    atom_lattice._original_filename = image0_filename
    atom_lattice.image0 = image0_data
    if s_image1 is not None:
        atom_lattice.image1 = image1_data
    atom_lattice._pixel_separation = pixel_separation

    for sublattice_index in range(process_parameter.number_of_sublattices):
        sublattice_para = process_parameter.get_sublattice_from_order(
            sublattice_index)

        if sublattice_para.image_type == 0:
            s_image = s_image0
            image_data = image0_data
            image_data_modified = image0_data_modified
        if sublattice_para.image_type == 1:
            if s_image1 is not None:
                s_image = s_image1
                image_data = image1_data
                image_data_modified = image1_data
            else:
                break

        if sublattice_para.sublattice_order == 0:
            sublattice = Sublattice(initial_atom_position_list,
                                    image_data_modified)
        else:
            temp_sublattice = atom_lattice.get_sublattice(
                sublattice_para.sublattice_position_sublattice)
            temp_zone_vector_index = temp_sublattice.get_zone_vector_index(
                sublattice_para.sublattice_position_zoneaxis)
            zone_vector = temp_sublattice.zones_axis_average_distances[
                temp_zone_vector_index]
            atom_list = temp_sublattice.find_missing_atoms_from_zone_vector(
                zone_vector)

            sublattice = Sublattice(atom_list, image_data)

        zone_axis_para_list = False
        if hasattr(sublattice_para, 'zone_axis_list'):
            zone_axis_para_list = sublattice_para.zone_axis_list

        sublattice._plot_color = sublattice_para.color
        sublattice.name = sublattice_para.name
        sublattice.pixel_size = s_image.axes_manager[0].scale
        sublattice._pixel_separation = pixel_separation
        sublattice.original_image = image_data
        atom_lattice.sublattice_list.append(sublattice)
        if debug_plot:
            sublattice.plot_atom_list_on_image_data(figname=sublattice.name +
                                                    "_initial_position.jpg")
        for atom in sublattice.atom_list:
            atom.sigma_x = sublattice._pixel_separation / 10.
            atom.sigma_y = sublattice._pixel_separation / 10.
        if not (sublattice_para.sublattice_order == 0):
            construct_zone_axes_from_sublattice(
                sublattice, zone_axis_para_list=zone_axis_para_list)
            atom_subtract_config = sublattice_para.atom_subtract_config
            image_data = sublattice.image
            for atom_subtract_para in atom_subtract_config:
                temp_sublattice = atom_lattice.get_sublattice(
                    atom_subtract_para['sublattice'])
                neighbor_distance = atom_subtract_para['neighbor_distance']
                image_data = remove_atoms_from_image_using_2d_gaussian(
                    image_data,
                    temp_sublattice,
                    percent_to_nn=neighbor_distance)
            sublattice.image = image_data
            sublattice.original_image = image_data

        refinement_config = sublattice_para.refinement_config
        refinement_neighbor_distance = refinement_config['neighbor_distance']
        refinement_steps = refinement_config['config']
        for refinement_step in refinement_steps:
            if refinement_step[0] == 'image_data':
                refinement_step[0] = sublattice.original_image
            elif refinement_step[0] == 'image_data_modified':
                refinement_step[0] = sublattice.image
            else:
                refinement_step[0] = sublattice.original_image

        refine_sublattice(sublattice, refinement_steps,
                          refinement_neighbor_distance)

        if sublattice_para.sublattice_order == 0:
            sublattice.construct_zone_axes(
                zone_axis_para_list=zone_axis_para_list)

    return (atom_lattice)
Beispiel #11
0
 def test_too_low_separation(self, separation):
     s = dd.get_simple_cubic_signal()
     with pytest.raises(ValueError):
         afr.get_atom_positions(s, separation)