Skip to content

States

Classes

Beam(tem)

Bases: State

Control for the beam blanker.

Source code in src/instamatic/microscope/components/states.py
37
38
39
40
41
def __init__(self, tem):
    super().__init__(tem=tem)
    self._setter = self._tem.setBeamBlank
    self._getter = self._tem.isBeamBlanked
    self._states = 'unblanked', 'blanked'

Attributes

is_blanked property

Return the status of the beam blanker as a bool

state property

Return the status of the beam blanker as a str (on/off)

Methods:

blank(delay=0.0)

Turn the beamblank on, optionally wait for delay in ms to allow the beam to settle.

Source code in src/instamatic/microscope/components/states.py
53
54
55
56
57
58
def blank(self, delay: float = 0.0) -> None:
    """Turn the beamblank on, optionally wait for `delay` in ms to allow
    the beam to settle."""
    self._setter(True)
    if delay:
        time.sleep(delay)
blanked(condition=True, delay=0.0)

Temporarily blank the beam using a with blanked statement.

Source code in src/instamatic/microscope/components/states.py
67
68
69
70
71
72
73
74
75
76
77
@contextmanager
def blanked(self, condition=True, delay: float = 0.0) -> ContextManager[None]:
    """Temporarily blank the beam using a `with blanked` statement."""
    was_blanked_before = self.is_blanked
    try:
        if condition and not was_blanked_before:
            self.blank(delay=delay)
        yield
    finally:
        if condition and not was_blanked_before:
            self.unblank(delay=delay)
get()

Get current state of the beam.

Source code in src/instamatic/microscope/components/states.py
97
98
99
def get(self) -> str:
    """Get current state of the beam."""
    return self._states[self.is_blanked]
set(state, delay=0.0)

Set state of the beam, with optional delay in ms.

Source code in src/instamatic/microscope/components/states.py
91
92
93
94
95
def set(self, state: str, delay: float = 0.0):
    """Set state of the beam, with optional delay in ms."""
    index = self._states.index(state)
    f = (self.unblank, self.blank)[index]
    f(delay=delay)
unblank(delay=0.0)

Turn the beamblank off, optionally wait for delay in ms to allow the beam to settle.

Source code in src/instamatic/microscope/components/states.py
60
61
62
63
64
65
def unblank(self, delay: float = 0.0) -> None:
    """Turn the beamblank off, optionally wait for `delay` in ms to allow
    the beam to settle."""
    self._setter(False)
    if delay:
        time.sleep(delay)
unblanked(condition=True, delay=0.0)

Temporarily unblank the beam using a with unblanked statement.

Source code in src/instamatic/microscope/components/states.py
79
80
81
82
83
84
85
86
87
88
89
@contextmanager
def unblanked(self, condition=True, delay: float = 0.0) -> ContextManager[None]:
    """Temporarily unblank the beam using a `with unblanked` statement."""
    was_blanked_before = self.is_blanked
    try:
        if condition and was_blanked_before:
            self.unblank(delay=delay)
        yield
    finally:
        if condition and was_blanked_before:
            self.blank(delay=delay)

Mode(tem)

Bases: State

Control for the magnification mode.

Source code in src/instamatic/microscope/components/states.py
105
106
107
108
def __init__(self, tem):
    super().__init__(tem=tem)
    self._setter = self._tem.setFunctionMode
    self._getter = self._tem.getFunctionMode

Attributes

state property

Return magnification mode.

Methods:

get()

Returns the function mode.

Source code in src/instamatic/microscope/components/states.py
119
120
121
def get(self) -> str:
    """Returns the function mode."""
    return self._getter()
set(mode)

Set the function mode.

Source code in src/instamatic/microscope/components/states.py
115
116
117
def set(self, mode: str) -> None:
    """Set the function mode."""
    self._setter(mode)

Screen(tem)

Bases: State

Control for the fluorescence screen.

Source code in src/instamatic/microscope/components/states.py
127
128
129
130
131
132
def __init__(self, tem):
    super().__init__(tem=tem)
    self._setter = self._tem.setScreenPosition
    self._getter = self._tem.getScreenPosition
    self._DOWN = 'down'
    self._UP = 'up'

Attributes

is_up property

Return the position of the screen as a bool

state property

Return the position of the screen as a str

Methods:

down()

Lower the fluorescence screen.

Source code in src/instamatic/microscope/components/states.py
148
149
150
def down(self) -> None:
    """Lower the fluorescence screen."""
    self.set(self._DOWN)
get()

Get the position of the fluorescence screen.

Source code in src/instamatic/microscope/components/states.py
152
153
154
def get(self) -> str:
    """Get the position of the fluorescence screen."""
    return self._getter()
set(state)

Set the position of the fluorescence screen (up/down).

Source code in src/instamatic/microscope/components/states.py
156
157
158
def set(self, state: str) -> None:
    """Set the position of the fluorescence screen (up/down)."""
    self._setter(state)
up()

Raise the fluorescence screen.

Source code in src/instamatic/microscope/components/states.py
144
145
146
def up(self) -> None:
    """Raise the fluorescence screen."""
    self.set(self._UP)

State(tem)

Generic class for describing microscope state objects.

Source code in src/instamatic/microscope/components/states.py
13
14
15
16
17
def __init__(self, tem: MicroscopeBase):
    super().__init__()
    self._tem = tem
    self._getter = None
    self._setter = None

Attributes

name property

Return name of the state control.

Methods:

__eq__(other)

Allow str comparison.

Source code in src/instamatic/microscope/components/states.py
22
23
24
25
26
def __eq__(self, other):
    """Allow `str` comparison."""
    if isinstance(other, str):
        return self.state == other
    return False