예제 #1
0
    def __init__(self, x_prefix, y_prefix, z_prefix, z_offset, z_dir, E,
                 att_obj, lcls_obj=None, mono_obj=None, *args, path,
                 lens_set=None, **kwargs):

        self.path = path
        self.lens_pack = self.read_lens()

        if lens_set is None:
            # Defaulting this a the first set in the file for now
            lens_set = calcs.get_lens_set(1, self.path)

        super().__init__(
            x_prefix, y_prefix, z_prefix, lens_set, z_offset, z_dir, E,
            att_obj, *args, **kwargs
        )
예제 #2
0
    def set_lens_set(self, index):
        """
        Temporary method to get the set from the lens set file at the index.

        TODO: this method will obviously change when we know how we want to get
        the lens, for now it is merely choosing it manually.

        Parameters
        ----------
        index : int
            Index to indicate which set in the list to get.

        Examples
        --------
        >>> set_lens_set(2)
        """
        self.lens_set = calcs.get_lens_set(index, self.path)
예제 #3
0
    def read_lens(self, print_only=False):
        """
        Read the lens sets from file provided in the path.

        Parameters
        ----------
        print_only : bool
            To indicate if printing out the currents sets only. If `False`
            the `self.lens_pack` will be set to get the current file sets.

        Returns
        -------
        sets : list
            Pack of lens sets.
        """
        lens_pack = calcs.get_lens_set(None, self.path, get_all=True)
        if print_only:
            logger.info(lens_pack)
        else:
            self.lens_pack = lens_pack
            return self.lens_pack
예제 #4
0
def test_get_lens_set_no_file():
    be_lens_calcs.LENS_SET_FILE = None
    with pytest.raises(ValueError):
        be_lens_calcs.get_lens_set(1)
예제 #5
0
def test_get_lens_set():
    first_set = [3, 0.0001, 1, 0.0002]
    lens_set = be_lens_calcs.get_lens_set(1, PATH)
    logger.debug(f'result: {lens_set}')
    assert lens_set == first_set
예제 #6
0
def test_lens_file_with_multiple_sets():
    be_lens_calcs.set_lens_set_to_file(SETS_SAMPLE, PATH, False)
    lens_set = be_lens_calcs.get_lens_set(2, PATH)
    expected = [1, 0.0001, 1, 0.0003, 1, 0.0005]
    assert expected == lens_set
예제 #7
0
def test_get_lens_set_file_one_set():
    first_set = [3, 0.0001, 1, 0.0002]
    be_lens_calcs.set_lens_set_to_file(first_set, PATH, False)
    lens_set = be_lens_calcs.get_lens_set(1, PATH)
    logger.debug(f'result: {lens_set}')
    assert lens_set == first_set
예제 #8
0
def test_get_lens_set_with_empty_file():
    be_lens_calcs.set_lens_set_to_file("", PATH, False)
    # file should be empty
    with pytest.raises(ValueError):
        be_lens_calcs.get_lens_set(1, PATH)
예제 #9
0
def test_get_lens_set_with_bad_path():
    with pytest.raises(FileNotFoundError):
        be_lens_calcs.get_lens_set(1, BAD_PATH)