コード例 #1
0
def test_energy():
    energy = Accelerator(energy=300e3)

    assert energy.energy == 300e3
    assert np.isclose(energy.wavelength, energy2wavelength(300e3))

    energy.energy = 200e3

    assert np.isclose(energy.wavelength, energy2wavelength(200e3))
コード例 #2
0
    def __init__(self,
                 expansion_cutoff: float,
                 interpolation: int = 1,
                 ctf: CTF = None,
                 extent: Union[float, Sequence[float]] = None,
                 gpts: Union[int, Sequence[int]] = None,
                 sampling: Union[float, Sequence[float]] = None,
                 energy: float = None,
                 device: str = 'cpu',
                 storage: str = None):

        if not isinstance(interpolation, int):
            raise ValueError('Interpolation factor must be int')

        self._interpolation = interpolation
        self._expansion_cutoff = expansion_cutoff
        self._ctf = ctf

        self._grid = Grid(extent=extent, gpts=gpts, sampling=sampling)
        self._accelerator = Accelerator(energy=energy)

        self._device = device
        if storage is None:
            storage = device

        self._storage = storage
コード例 #3
0
    def __init__(self,
                 array: np.ndarray,
                 expansion_cutoff: float,
                 interpolation: int,
                 k: Tuple[np.ndarray, np.ndarray],
                 ctf: CTF = None,
                 extent: Union[float, Sequence[float]] = None,
                 sampling: Union[float, Sequence[float]] = None,
                 energy: float = None,
                 device='cpu'):

        self._array = array
        self._interpolation = interpolation
        self._expansion_cutoff = expansion_cutoff
        self._k = k
        self._grid = Grid(extent=extent,
                          gpts=array.shape[1:],
                          sampling=sampling,
                          lock_gpts=True)

        self._accelerator = Accelerator(energy=energy)

        if ctf is None:
            ctf = CTF(semiangle_cutoff=expansion_cutoff, rolloff=.1)

        self.set_ctf(ctf)

        self._device = device
コード例 #4
0
 def __init__(self,
              array: np.ndarray,
              slice_thicknesses: Union[float, Sequence],
              extent: np.ndarray = None,
              sampling: np.ndarray = None,
              energy: float = None):
     self._accelerator = Accelerator(energy=energy)
     super().__init__(array, slice_thicknesses, extent, sampling)
コード例 #5
0
 def __init__(self,
              extent: Union[float, Sequence[float]] = None,
              gpts: Union[int, Sequence[int]] = None,
              sampling: Union[float, Sequence[float]] = None,
              energy: float = None,
              device: str = 'cpu'):
     self._grid = Grid(extent=extent, gpts=gpts, sampling=sampling)
     self._accelerator = Accelerator(energy=energy)
     self._device = device
コード例 #6
0
ファイル: transfer.py プロジェクト: nzaker/abTEM
    def __init__(self,
                 semiangle_cutoff: float = np.inf,
                 rolloff: float = 0.,
                 focal_spread: float = 0.,
                 angular_spread: float = 0.,
                 gaussian_spread: float = 0.,
                 energy: float = None,
                 parameters: Mapping[str, float] = None,
                 **kwargs):

        for key in kwargs.keys():
            if ((key not in polar_symbols)
                    and (key not in polar_aliases.keys())):
                raise ValueError('{} not a recognized parameter'.format(key))

        self.changed = Event()

        self._accelerator = Accelerator(energy=energy)
        self._semiangle_cutoff = semiangle_cutoff
        self._rolloff = rolloff
        self._focal_spread = focal_spread
        self._angular_spread = angular_spread
        self._gaussian_spread = gaussian_spread
        self._parameters = dict(zip(polar_symbols, [0.] * len(polar_symbols)))

        if parameters is None:
            parameters = {}

        parameters.update(kwargs)
        self.set_parameters(parameters)

        def parametrization_property(key):
            def getter(self):
                return self._parameters[key]

            def setter(self, value):
                old = getattr(self, key)
                self._parameters[key] = value
                self.changed.notify(**{
                    'notifier': self,
                    'property_name': key,
                    'change': old != value
                })

            return property(getter, setter)

        for symbol in polar_symbols:
            setattr(self.__class__, symbol, parametrization_property(symbol))

        for key, value in polar_aliases.items():
            if key != 'defocus':
                setattr(self.__class__, key, parametrization_property(value))
コード例 #7
0
    def __init__(self,
                 array: np.ndarray,
                 extent: Union[float, Sequence[float]] = None,
                 sampling: Union[float, Sequence[float]] = None,
                 energy: float = None):

        if len(array.shape) < 2:
            raise RuntimeError(
                'Wave function array should be have 2 dimensions or more')

        self._array = array
        self._grid = Grid(extent=extent,
                          gpts=array.shape[-2:],
                          sampling=sampling,
                          lock_gpts=True)
        self._accelerator = Accelerator(energy=energy)
コード例 #8
0
def test_accelerator_event():
    accelerator = Accelerator(300e3)

    accelerator.energy = 200e3
    assert accelerator.changed._notify_count == 1
コード例 #9
0
def test_energy_raises():
    accelerator1 = Accelerator(300e3)
    accelerator2 = Accelerator()

    with pytest.raises(RuntimeError):
        accelerator2.check_is_defined()

    accelerator2.energy = 200e3
    with pytest.raises(RuntimeError):
        accelerator1.check_match(accelerator2)

    accelerator2.energy = accelerator1.energy
    accelerator1.check_match(accelerator2)