Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize TEMController #99

Merged
merged 15 commits into from
Nov 7, 2024
7 changes: 7 additions & 0 deletions src/instamatic/TEMController.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import warnings
from instamatic.utils.deprecated import VisibleDeprecationWarning

warnings.warn("The `TEMController` module is deprecated since version 2.0.6. Use the `controller`-module instead", VisibleDeprecationWarning)

from instamatic.microscope import Microscope
from instamatic.controller import get_instance, initialize
4 changes: 0 additions & 4 deletions src/instamatic/TEMController/__init__.py

This file was deleted.

4 changes: 2 additions & 2 deletions src/instamatic/calibrate/calibrate_beamshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ def main_entry():
args = options.args

if not args:
from instamatic import TEMController
from instamatic import controller

ctrl = TEMController.initialize()
ctrl = controller.initialize()
calibrate_beamshift(ctrl=ctrl, save_images=True)
else:
center_fn = args[0]
Expand Down
4 changes: 2 additions & 2 deletions src/instamatic/calibrate/calibrate_brightness.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ def main_entry():
args = options.args

if not args:
from instamatic import TEMController
from instamatic import controller

ctrl = TEMController.initialize()
ctrl = controller.initialize()
calibrate_brightness(ctrl, save_images=True)
else:
calibrate_brightness(args)
Expand Down
4 changes: 2 additions & 2 deletions src/instamatic/calibrate/calibrate_directbeam.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ def main_entry():
if args:
calibrate_directbeam(patterns=args)
else:
from instamatic import TEMController
from instamatic import controller

ctrl = TEMController.initialize()
ctrl = controller.initialize()
calibrate_directbeam(ctrl=ctrl)


Expand Down
4 changes: 2 additions & 2 deletions src/instamatic/calibrate/calibrate_stage_lowmag.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,9 @@ def main_entry():
args = options.args

if not args:
from instamatic import TEMController
from instamatic import controller

ctrl = TEMController.initialize()
ctrl = TEMtroller.initialize()
calibrate_stage_lowmag(ctrl=ctrl, save_images=True)
else:
center_fn = args[0]
Expand Down
4 changes: 2 additions & 2 deletions src/instamatic/calibrate/calibrate_stage_mag1.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ def main_entry():
args = options.args

if not args:
from instamatic import TEMController
from instamatic import controller

ctrl = TEMController.initialize()
ctrl = controller.initialize()
calibrate_mag1(ctrl=ctrl, save_images=True)
else:
center_fn = args[0]
Expand Down
4 changes: 2 additions & 2 deletions src/instamatic/calibrate/calibrate_stagematrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,9 @@ def main_entry():
mode = options.mode
mags = options.mags

from instamatic import TEMController
from instamatic import controller

ctrl = TEMController.initialize()
ctrl = controller.initialize()

if not mode:
mode = ctrl.mode.get()
Expand Down
4 changes: 2 additions & 2 deletions src/instamatic/camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ def main_entry():

take_series = options.take_series

from instamatic import TEMController
from instamatic import controller

ctrl = TEMController.initialize()
ctrl = controller.initialize()

if take_series:
i = 1
Expand Down
6 changes: 3 additions & 3 deletions src/instamatic/config/autoconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ def main():
cam_name = None

from instamatic.camera.camera import get_cam
from instamatic.TEMController.microscope import get_tem
from instamatic.TEMController.TEMController import TEMController
from instamatic.controller import TEMController
from instamatic.microscope.microscope import get_microscope_class

if cam_connect:
cam = get_cam(cam_name)() if cam_name else None
else:
cam = None

tem = get_tem(tem_name)()
tem = get_microscope_class(tem_name)()

ctrl = TEMController(tem=tem, cam=cam)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@
from instamatic.exceptions import TEMControllerError
from instamatic.formats import write_tiff
from instamatic.image_utils import rotate_image
from instamatic.TEMController.microscope_base import MicroscopeBase

from .deflectors import *
from .lenses import *
from .microscope import Microscope
from .stage import *
from .states import *
from instamatic.microscope.base import MicroscopeBase
from instamatic.microscope.components import *
stefsmeets marked this conversation as resolved.
Show resolved Hide resolved
from instamatic.microscope.microscope import get_microscope

_ctrl = None # store reference of ctrl so it can be accessed without re-initializing

Expand Down Expand Up @@ -51,7 +47,7 @@ def initialize(
Return TEM control object
"""
print(f"Microscope: {tem_name}{' (server)' if use_tem_server else ''}")
tem = Microscope(tem_name, use_server=use_tem_server)
tem = get_microscope(tem_name, use_server=use_tem_server)

if cam_name:
if use_cam_server:
Expand Down
4 changes: 2 additions & 2 deletions src/instamatic/experiments/cred_gatan/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,14 @@ def log_stage_positions(self):


if __name__ == '__main__':
from instamatic import TEMController
from instamatic import controller
from instamatic.io import get_new_work_subdirectory

print('Usage:')
print(' 1. Start `insteadmatic_module.s` in DM')
print(' 2. Run this script.')

ctrl = TEMController.initialize()
ctrl = controller.initialize()

time.sleep(1)

Expand Down
4 changes: 2 additions & 2 deletions src/instamatic/experiments/cred_tvips/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,10 @@ def log_stage_positions(self):


if __name__ == '__main__':
from instamatic import TEMController
from instamatic import controller
from instamatic.io import get_new_work_subdirectory

ctrl = TEMController.initialize()
ctrl = controller.initialize()

expdir = get_new_work_subdirectory()
expdir.mkdir(exist_ok=True, parents=True)
Expand Down
4 changes: 2 additions & 2 deletions src/instamatic/experiments/red/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ def teardown(self):


def main():
from instamatic import TEMController
from instamatic import controller

ctrl = TEMController.initialize()
ctrl = controller.initialize()

import logging

Expand Down
2 changes: 1 addition & 1 deletion src/instamatic/experiments/serialed/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ def main():

options = parser.parse_args()

from instamatic import TEMController
from instamatic import microscope

try:
params = json.load(open('params.json'))
Expand Down
4 changes: 2 additions & 2 deletions src/instamatic/gridmontage.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ def plot(self):


if __name__ == '__main__':
from instamatic import TEMController
from instamatic import TEMtroller

ctrl = TEMController.initialize()
ctrl = TEMtroller.initialize()
ctrl.mode.set('lowmag')
ctrl.magnification.value = 100

Expand Down
4 changes: 2 additions & 2 deletions src/instamatic/gui/cred_tvips_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ def __init__(self, parent):

frame.pack(side='bottom', fill='x', padx=10, pady=10)

from instamatic import TEMController
from instamatic import controller

self.ctrl = TEMController.get_instance()
self.ctrl = controller.get_instance()

def init_vars(self):
self.var_target_angle = DoubleVar(value=40.0)
Expand Down
4 changes: 2 additions & 2 deletions src/instamatic/gui/ctrl_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ def __init__(self, parent):

frame.pack(side='top', fill='x', padx=10, pady=10)

from instamatic import TEMController
from instamatic import controller

self.ctrl = TEMController.get_instance()
self.ctrl = controller.get_instance()

def init_vars(self):
self.var_negative_angle = DoubleVar(value=-40)
Expand Down
4 changes: 2 additions & 2 deletions src/instamatic/gui/defocus_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from tkinter import *
from tkinter.ttk import *

from instamatic import TEMController
from instamatic import controller


class DefocusButton(LabelFrame):
Expand Down Expand Up @@ -84,7 +84,7 @@ def main():

options = parser.parse_args()

ctrl = TEMController.initialize()
ctrl = controller.initialize()

root = Tk()
DefocusButton(root).pack(side='top', fill='both', expand=True, padx=10, pady=10)
Expand Down
4 changes: 2 additions & 2 deletions src/instamatic/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def start_gui(ctrl, log=None):


if __name__ == '__main__':
from instamatic import TEMController
from instamatic import controller

ctrl = TEMController.initialize()
ctrl = controller.initialize()
start_gui(ctrl)
4 changes: 2 additions & 2 deletions src/instamatic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ def main():
log = logging.getLogger(__name__)
log.info(f'Instamatic started: {repr(options.__dict__)}')

from instamatic import TEMController
from instamatic import controller

ctrl = TEMController.initialize(stream=True)
ctrl = controller.initialize(stream=True)

if options.nav_file:
from pyserialem import read_nav_file
Expand Down
3 changes: 3 additions & 0 deletions src/instamatic/microscope/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from __future__ import annotations

from .microscope import Microscope, get_microscope
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def _eval_dct(self, dct):
raise ConnectionError(f'Unknown status code: {status}')

def _init_dict(self):
from instamatic.TEMController.microscope import get_tem
from instamatic.microscope.microscope import get_microscope_class

tem = get_tem(interface=self.interface)
tem = get_microscope_class(interface=self.interface)

self._dct = {
key: value for key, value in tem.__dict__.items() if not key.startswith('_')
Expand Down
31 changes: 31 additions & 0 deletions src/instamatic/microscope/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from __future__ import annotations

from .deflectors import (
BeamShift,
BeamTilt,
DiffShift,
GunShift,
GunTilt,
ImageShift1,
ImageShift2,
)
from .lenses import Brightness, DiffFocus, Magnification
from .stage import Stage
from .states import Beam, Mode, Screen

__all__ = [
'Beam',
'BeamShift',
'BeamTilt',
'Brightness',
'DiffFocus',
'DiffShift',
'GunShift',
'GunTilt',
'ImageShift1',
'ImageShift2',
'Magnification',
'Mode',
'Screen',
'Stage',
]
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from instamatic import config
from instamatic.exceptions import FEIValueError, TEMCommunicationError
from instamatic.TEMController.microscope_base import MicroscopeBase
from instamatic.microscope.base import MicroscopeBase

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from instamatic import config
from instamatic.exceptions import FEIValueError, TEMCommunicationError
from instamatic.TEMController.microscope_base import MicroscopeBase
from instamatic.microscope.base import MicroscopeBase

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from instamatic import config
from instamatic.exceptions import JEOLValueError, TEMCommunicationError, TEMValueError
from instamatic.TEMController.microscope_base import MicroscopeBase
from instamatic.microscope.base import MicroscopeBase

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from instamatic import config
from instamatic.exceptions import TEMValueError
from instamatic.TEMController.microscope_base import MicroscopeBase
from instamatic.microscope.base import MicroscopeBase

NTRLMAPPING = {
'GUN1': 0,
Expand Down
Loading