From 1231af19dd14f72a84319073913c17f5ef4e9d3e Mon Sep 17 00:00:00 2001 From: Viljar Femoen Date: Tue, 5 Nov 2024 09:39:25 +0100 Subject: [PATCH 01/15] Reorganize TEMController --- src/instamatic/calibrate/calibrate_beamshift.py | 4 ++-- src/instamatic/calibrate/calibrate_brightness.py | 4 ++-- src/instamatic/calibrate/calibrate_directbeam.py | 4 ++-- src/instamatic/calibrate/calibrate_stage_lowmag.py | 4 ++-- src/instamatic/calibrate/calibrate_stage_mag1.py | 4 ++-- src/instamatic/calibrate/calibrate_stagematrix.py | 4 ++-- src/instamatic/camera/camera.py | 4 ++-- src/instamatic/config/autoconfig.py | 4 ++-- .../TEMController.py => controller.py} | 12 ++++++------ src/instamatic/experiments/cred_gatan/experiment.py | 4 ++-- src/instamatic/experiments/cred_tvips/experiment.py | 4 ++-- src/instamatic/experiments/red/experiment.py | 4 ++-- src/instamatic/experiments/serialed/experiment.py | 2 +- src/instamatic/gridmontage.py | 4 ++-- src/instamatic/gui/cred_tvips_frame.py | 4 ++-- src/instamatic/gui/ctrl_frame.py | 4 ++-- src/instamatic/gui/defocus_button.py | 4 ++-- src/instamatic/gui/gui.py | 4 ++-- src/instamatic/main.py | 4 ++-- .../{TEMController => microscope}/__init__.py | 1 - .../microscope_base.py => microscope/base.py} | 0 .../microscope_client.py => microscope/client.py} | 2 +- src/instamatic/microscope/components/__init__.py | 0 .../components}/deflectors.py | 0 .../components}/lenses.py | 0 .../components}/stage.py | 0 .../components}/states.py | 0 src/instamatic/microscope/interface/__init__.py | 0 .../interface}/fei_microscope.py | 2 +- .../interface}/fei_simu_microscope.py | 2 +- .../interface}/jeol_microscope.py | 2 +- .../interface}/simu_microscope.py | 2 +- .../{TEMController => microscope}/microscope.py | 12 ++++++------ src/instamatic/processing/flatfield.py | 4 ++-- src/instamatic/server/TEMServer_FEI.py | 4 ++-- src/instamatic/server/tem_client.py | 2 +- src/instamatic/server/tem_server.py | 2 +- tests/conftest.py | 4 ++-- tests/test_ctrl.py | 4 ++-- 39 files changed, 62 insertions(+), 63 deletions(-) rename src/instamatic/{TEMController/TEMController.py => controller.py} (98%) rename src/instamatic/{TEMController => microscope}/__init__.py (57%) rename src/instamatic/{TEMController/microscope_base.py => microscope/base.py} (100%) rename src/instamatic/{TEMController/microscope_client.py => microscope/client.py} (98%) create mode 100644 src/instamatic/microscope/components/__init__.py rename src/instamatic/{TEMController => microscope/components}/deflectors.py (100%) rename src/instamatic/{TEMController => microscope/components}/lenses.py (100%) rename src/instamatic/{TEMController => microscope/components}/stage.py (100%) rename src/instamatic/{TEMController => microscope/components}/states.py (100%) create mode 100644 src/instamatic/microscope/interface/__init__.py rename src/instamatic/{TEMController => microscope/interface}/fei_microscope.py (99%) rename src/instamatic/{TEMController => microscope/interface}/fei_simu_microscope.py (99%) rename src/instamatic/{TEMController => microscope/interface}/jeol_microscope.py (99%) rename src/instamatic/{TEMController => microscope/interface}/simu_microscope.py (99%) rename src/instamatic/{TEMController => microscope}/microscope.py (80%) diff --git a/src/instamatic/calibrate/calibrate_beamshift.py b/src/instamatic/calibrate/calibrate_beamshift.py index 3a94c090..1fa69725 100644 --- a/src/instamatic/calibrate/calibrate_beamshift.py +++ b/src/instamatic/calibrate/calibrate_beamshift.py @@ -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] diff --git a/src/instamatic/calibrate/calibrate_brightness.py b/src/instamatic/calibrate/calibrate_brightness.py index c6b659bd..055ea5de 100644 --- a/src/instamatic/calibrate/calibrate_brightness.py +++ b/src/instamatic/calibrate/calibrate_brightness.py @@ -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) diff --git a/src/instamatic/calibrate/calibrate_directbeam.py b/src/instamatic/calibrate/calibrate_directbeam.py index 7a48544f..9ba8b8ff 100644 --- a/src/instamatic/calibrate/calibrate_directbeam.py +++ b/src/instamatic/calibrate/calibrate_directbeam.py @@ -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) diff --git a/src/instamatic/calibrate/calibrate_stage_lowmag.py b/src/instamatic/calibrate/calibrate_stage_lowmag.py index 498172f9..eb4b539b 100644 --- a/src/instamatic/calibrate/calibrate_stage_lowmag.py +++ b/src/instamatic/calibrate/calibrate_stage_lowmag.py @@ -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] diff --git a/src/instamatic/calibrate/calibrate_stage_mag1.py b/src/instamatic/calibrate/calibrate_stage_mag1.py index 31a79aae..056ab710 100644 --- a/src/instamatic/calibrate/calibrate_stage_mag1.py +++ b/src/instamatic/calibrate/calibrate_stage_mag1.py @@ -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] diff --git a/src/instamatic/calibrate/calibrate_stagematrix.py b/src/instamatic/calibrate/calibrate_stagematrix.py index 42724d15..0844519f 100644 --- a/src/instamatic/calibrate/calibrate_stagematrix.py +++ b/src/instamatic/calibrate/calibrate_stagematrix.py @@ -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() diff --git a/src/instamatic/camera/camera.py b/src/instamatic/camera/camera.py index dec3d274..e41057b7 100644 --- a/src/instamatic/camera/camera.py +++ b/src/instamatic/camera/camera.py @@ -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 diff --git a/src/instamatic/config/autoconfig.py b/src/instamatic/config/autoconfig.py index 6047bb88..606a581c 100644 --- a/src/instamatic/config/autoconfig.py +++ b/src/instamatic/config/autoconfig.py @@ -126,8 +126,8 @@ 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.microscope.microscope import get_tem + from instamatic.controller import TEMController if cam_connect: cam = get_cam(cam_name)() if cam_name else None diff --git a/src/instamatic/TEMController/TEMController.py b/src/instamatic/controller.py similarity index 98% rename from src/instamatic/TEMController/TEMController.py rename to src/instamatic/controller.py index 8c7b294c..2773ba7a 100644 --- a/src/instamatic/TEMController/TEMController.py +++ b/src/instamatic/controller.py @@ -13,13 +13,13 @@ 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 instamatic.microscope.base import MicroscopeBase -from .deflectors import * -from .lenses import * -from .microscope import Microscope -from .stage import * -from .states import * +from instamatic.microscope.components.deflectors import * +from instamatic.microscope.components.lenses import * +from instamatic.microscope.microscope import Microscope +from instamatic.microscope.components.stage import * +from instamatic.microscope.components.states import * _ctrl = None # store reference of ctrl so it can be accessed without re-initializing diff --git a/src/instamatic/experiments/cred_gatan/experiment.py b/src/instamatic/experiments/cred_gatan/experiment.py index 53012740..d9219481 100644 --- a/src/instamatic/experiments/cred_gatan/experiment.py +++ b/src/instamatic/experiments/cred_gatan/experiment.py @@ -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) diff --git a/src/instamatic/experiments/cred_tvips/experiment.py b/src/instamatic/experiments/cred_tvips/experiment.py index b6949e9a..de3cfe4b 100644 --- a/src/instamatic/experiments/cred_tvips/experiment.py +++ b/src/instamatic/experiments/cred_tvips/experiment.py @@ -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) diff --git a/src/instamatic/experiments/red/experiment.py b/src/instamatic/experiments/red/experiment.py index 53cdf2b9..f842f768 100644 --- a/src/instamatic/experiments/red/experiment.py +++ b/src/instamatic/experiments/red/experiment.py @@ -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 diff --git a/src/instamatic/experiments/serialed/experiment.py b/src/instamatic/experiments/serialed/experiment.py index 56968f19..47a98a58 100644 --- a/src/instamatic/experiments/serialed/experiment.py +++ b/src/instamatic/experiments/serialed/experiment.py @@ -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')) diff --git a/src/instamatic/gridmontage.py b/src/instamatic/gridmontage.py index 2af58aff..9289ba2b 100644 --- a/src/instamatic/gridmontage.py +++ b/src/instamatic/gridmontage.py @@ -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 diff --git a/src/instamatic/gui/cred_tvips_frame.py b/src/instamatic/gui/cred_tvips_frame.py index de89c0ec..3749cd7b 100644 --- a/src/instamatic/gui/cred_tvips_frame.py +++ b/src/instamatic/gui/cred_tvips_frame.py @@ -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) diff --git a/src/instamatic/gui/ctrl_frame.py b/src/instamatic/gui/ctrl_frame.py index 234af858..1d1c8e4d 100644 --- a/src/instamatic/gui/ctrl_frame.py +++ b/src/instamatic/gui/ctrl_frame.py @@ -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) diff --git a/src/instamatic/gui/defocus_button.py b/src/instamatic/gui/defocus_button.py index 5c8f0002..a0f071a9 100644 --- a/src/instamatic/gui/defocus_button.py +++ b/src/instamatic/gui/defocus_button.py @@ -3,7 +3,7 @@ from tkinter import * from tkinter.ttk import * -from instamatic import TEMController +from instamatic import controller class DefocusButton(LabelFrame): @@ -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) diff --git a/src/instamatic/gui/gui.py b/src/instamatic/gui/gui.py index ef4b1e26..fe686eb6 100644 --- a/src/instamatic/gui/gui.py +++ b/src/instamatic/gui/gui.py @@ -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) diff --git a/src/instamatic/main.py b/src/instamatic/main.py index a1f34078..e120f8ed 100644 --- a/src/instamatic/main.py +++ b/src/instamatic/main.py @@ -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 diff --git a/src/instamatic/TEMController/__init__.py b/src/instamatic/microscope/__init__.py similarity index 57% rename from src/instamatic/TEMController/__init__.py rename to src/instamatic/microscope/__init__.py index 33a98c3e..781bae92 100644 --- a/src/instamatic/TEMController/__init__.py +++ b/src/instamatic/microscope/__init__.py @@ -1,4 +1,3 @@ from __future__ import annotations from .microscope import Microscope -from .TEMController import get_instance, initialize diff --git a/src/instamatic/TEMController/microscope_base.py b/src/instamatic/microscope/base.py similarity index 100% rename from src/instamatic/TEMController/microscope_base.py rename to src/instamatic/microscope/base.py diff --git a/src/instamatic/TEMController/microscope_client.py b/src/instamatic/microscope/client.py similarity index 98% rename from src/instamatic/TEMController/microscope_client.py rename to src/instamatic/microscope/client.py index 54bd5e3b..8980c06c 100644 --- a/src/instamatic/TEMController/microscope_client.py +++ b/src/instamatic/microscope/client.py @@ -114,7 +114,7 @@ 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_tem tem = get_tem(interface=self.interface) diff --git a/src/instamatic/microscope/components/__init__.py b/src/instamatic/microscope/components/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/instamatic/TEMController/deflectors.py b/src/instamatic/microscope/components/deflectors.py similarity index 100% rename from src/instamatic/TEMController/deflectors.py rename to src/instamatic/microscope/components/deflectors.py diff --git a/src/instamatic/TEMController/lenses.py b/src/instamatic/microscope/components/lenses.py similarity index 100% rename from src/instamatic/TEMController/lenses.py rename to src/instamatic/microscope/components/lenses.py diff --git a/src/instamatic/TEMController/stage.py b/src/instamatic/microscope/components/stage.py similarity index 100% rename from src/instamatic/TEMController/stage.py rename to src/instamatic/microscope/components/stage.py diff --git a/src/instamatic/TEMController/states.py b/src/instamatic/microscope/components/states.py similarity index 100% rename from src/instamatic/TEMController/states.py rename to src/instamatic/microscope/components/states.py diff --git a/src/instamatic/microscope/interface/__init__.py b/src/instamatic/microscope/interface/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/instamatic/TEMController/fei_microscope.py b/src/instamatic/microscope/interface/fei_microscope.py similarity index 99% rename from src/instamatic/TEMController/fei_microscope.py rename to src/instamatic/microscope/interface/fei_microscope.py index 4da3cf7a..27e07900 100644 --- a/src/instamatic/TEMController/fei_microscope.py +++ b/src/instamatic/microscope/interface/fei_microscope.py @@ -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__) diff --git a/src/instamatic/TEMController/fei_simu_microscope.py b/src/instamatic/microscope/interface/fei_simu_microscope.py similarity index 99% rename from src/instamatic/TEMController/fei_simu_microscope.py rename to src/instamatic/microscope/interface/fei_simu_microscope.py index 14605be1..7613f913 100644 --- a/src/instamatic/TEMController/fei_simu_microscope.py +++ b/src/instamatic/microscope/interface/fei_simu_microscope.py @@ -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__) diff --git a/src/instamatic/TEMController/jeol_microscope.py b/src/instamatic/microscope/interface/jeol_microscope.py similarity index 99% rename from src/instamatic/TEMController/jeol_microscope.py rename to src/instamatic/microscope/interface/jeol_microscope.py index f9d6ada5..5a55eaa7 100644 --- a/src/instamatic/TEMController/jeol_microscope.py +++ b/src/instamatic/microscope/interface/jeol_microscope.py @@ -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__) diff --git a/src/instamatic/TEMController/simu_microscope.py b/src/instamatic/microscope/interface/simu_microscope.py similarity index 99% rename from src/instamatic/TEMController/simu_microscope.py rename to src/instamatic/microscope/interface/simu_microscope.py index 8f224d2b..be37c70e 100644 --- a/src/instamatic/TEMController/simu_microscope.py +++ b/src/instamatic/microscope/interface/simu_microscope.py @@ -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, diff --git a/src/instamatic/TEMController/microscope.py b/src/instamatic/microscope/microscope.py similarity index 80% rename from src/instamatic/TEMController/microscope.py rename to src/instamatic/microscope/microscope.py index 5470d3a0..5f3214f2 100644 --- a/src/instamatic/TEMController/microscope.py +++ b/src/instamatic/microscope/microscope.py @@ -1,7 +1,7 @@ from __future__ import annotations from instamatic import config -from instamatic.TEMController.microscope_base import MicroscopeBase +from instamatic.microscope.base import MicroscopeBase default_tem_interface = config.microscope.interface @@ -19,13 +19,13 @@ def get_tem(interface: str) -> 'type[MicroscopeBase]': raise PermissionError('Access to the TEM interface requires admin rights.') if simulate or interface == 'simulate': - from .simu_microscope import SimuMicroscope as cls + from .interface.simu_microscope import SimuMicroscope as cls elif interface == 'jeol': - from .jeol_microscope import JeolMicroscope as cls + from .interface.jeol_microscope import JeolMicroscope as cls elif interface == 'fei': - from .fei_microscope import FEIMicroscope as cls + from .interface.fei_microscope import FEIMicroscope as cls elif interface == 'fei_simu': - from .fei_simu_microscope import FEISimuMicroscope as cls + from .interface.fei_simu_microscope import FEISimuMicroscope as cls else: raise ValueError(f'No such microscope interface: `{interface}`') @@ -52,7 +52,7 @@ def Microscope(name: str = None, use_server: bool = False) -> MicroscopeBase: interface = config.microscope.interface if use_server: - from .microscope_client import MicroscopeClient + from .client import MicroscopeClient tem = MicroscopeClient(interface=interface) else: diff --git a/src/instamatic/processing/flatfield.py b/src/instamatic/processing/flatfield.py index 37a01671..ffdd52a8 100644 --- a/src/instamatic/processing/flatfield.py +++ b/src/instamatic/processing/flatfield.py @@ -9,7 +9,7 @@ import numpy as np from tqdm.auto import tqdm -from instamatic import TEMController, config +from instamatic import config, controller from instamatic.formats import * @@ -234,7 +234,7 @@ def main_entry(): args = options.args if options.collect: - ctrl = TEMController.initialize() + ctrl = controller.initialize() collect_flatfield(ctrl=ctrl, save_images=False) ctrl.close() exit() diff --git a/src/instamatic/server/TEMServer_FEI.py b/src/instamatic/server/TEMServer_FEI.py index b6f01855..0ac435bf 100644 --- a/src/instamatic/server/TEMServer_FEI.py +++ b/src/instamatic/server/TEMServer_FEI.py @@ -10,7 +10,7 @@ import threading from socket import * -from instamatic import TEMController, config +from instamatic import TEMtroller, config HOST = config.settings.fei_server_host PORT = config.settings.fei_server_port @@ -68,7 +68,7 @@ def main(): logging.captureWarnings(True) log = logging.getLogger(__name__) - ctrl = TEMController.initialize() + ctrl = TEMtroller.initialize() s = socket(AF_INET, SOCK_STREAM) s.bind((HOST, PORT)) diff --git a/src/instamatic/server/tem_client.py b/src/instamatic/server/tem_client.py index ce184193..bf591161 100644 --- a/src/instamatic/server/tem_client.py +++ b/src/instamatic/server/tem_client.py @@ -1,7 +1,7 @@ from __future__ import annotations from instamatic import config -from instamatic.TEMController.microscope_client import MicroscopeClient +from instamatic.microscope.client import MicroscopeClient microscope_id = config.microscope.name diff --git a/src/instamatic/server/tem_server.py b/src/instamatic/server/tem_server.py index 209ac557..0ee63069 100644 --- a/src/instamatic/server/tem_server.py +++ b/src/instamatic/server/tem_server.py @@ -10,7 +10,7 @@ import traceback from instamatic import config -from instamatic.TEMController import Microscope +from instamatic.microscope import Microscope from .serializer import dumper, loader diff --git a/tests/conftest.py b/tests/conftest.py index 73a1a864..4b2e4e4d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,7 +8,7 @@ # Actually importing the controller class breaks the tests if TYPE_CHECKING: - from instamatic.TEMController.TEMController import TEMController + from instamatic.controller import TEMController base_drc = Path(__file__).parent @@ -21,7 +21,7 @@ def pytest_configure(): @pytest.fixture(scope='module') def ctrl() -> 'TEMController': - from instamatic.TEMController import initialize + from instamatic.controller import initialize ctrl = initialize() diff --git a/tests/test_ctrl.py b/tests/test_ctrl.py index 8c262772..123b34a9 100644 --- a/tests/test_ctrl.py +++ b/tests/test_ctrl.py @@ -5,9 +5,9 @@ def test_setup(ctrl): - from instamatic import TEMController + from instamatic import controller - ctrl2 = TEMController.get_instance() + ctrl2 = controller.get_instance() assert ctrl2 is ctrl From 74e772d407272b3647ca42a875ee907955078c20 Mon Sep 17 00:00:00 2001 From: Viljar Femoen Date: Tue, 5 Nov 2024 10:32:12 +0100 Subject: [PATCH 02/15] Import from module instead of files --- src/instamatic/controller.py | 6 +--- .../microscope/components/__init__.py | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/instamatic/controller.py b/src/instamatic/controller.py index 2773ba7a..b9c44f61 100644 --- a/src/instamatic/controller.py +++ b/src/instamatic/controller.py @@ -14,12 +14,8 @@ from instamatic.formats import write_tiff from instamatic.image_utils import rotate_image from instamatic.microscope.base import MicroscopeBase - -from instamatic.microscope.components.deflectors import * -from instamatic.microscope.components.lenses import * +from instamatic.microscope.components import * from instamatic.microscope.microscope import Microscope -from instamatic.microscope.components.stage import * -from instamatic.microscope.components.states import * _ctrl = None # store reference of ctrl so it can be accessed without re-initializing diff --git a/src/instamatic/microscope/components/__init__.py b/src/instamatic/microscope/components/__init__.py index e69de29b..9c1f61c0 100644 --- a/src/instamatic/microscope/components/__init__.py +++ b/src/instamatic/microscope/components/__init__.py @@ -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', +] From e7f628c1b489d932667a83ba391086425a78b764 Mon Sep 17 00:00:00 2001 From: Viljar Femoen Date: Tue, 5 Nov 2024 11:11:26 +0100 Subject: [PATCH 03/15] Add deprecation decorator --- src/instamatic/utils/deprecated.py | 37 +++++++++++++++ tests/test_deprecated.py | 72 ++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 src/instamatic/utils/deprecated.py create mode 100644 tests/test_deprecated.py diff --git a/src/instamatic/utils/deprecated.py b/src/instamatic/utils/deprecated.py new file mode 100644 index 00000000..20e78eee --- /dev/null +++ b/src/instamatic/utils/deprecated.py @@ -0,0 +1,37 @@ +"""Deprecation decorator.""" + +from __future__ import annotations + + +def deprecated(since: str, alternative: str, removed: str = None): + """Mark a function as deprecated, printing a warning whenever it is used. + + Parameters + ---------- + since : str + Version that the deprecation was introduced + alternative : str + Name of alternative function + removed : str, optional + Planned version to remove the function + + Notes + ----- + Does not work on entire classes, but works on member methods, classmethods and staticmethods. + If used in a chain with classmethod/staticmethod, place the deprecation decorator underneath those + """ + import warnings + from functools import wraps + + def decorator(func): + @wraps(func) + def wrapped(*args, **kwargs): + msg = f'Function {func.__name__} is deprecated since {since}, use {alternative} instead.' + if removed is not None: + msg += f' Will be removed in version {removed}.' + warnings.warn(msg, DeprecationWarning) + return func(*args, **kwargs) + + return wrapped + + return decorator diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py new file mode 100644 index 00000000..fba3c27d --- /dev/null +++ b/tests/test_deprecated.py @@ -0,0 +1,72 @@ +from __future__ import annotations + +import pytest + +from instamatic.utils.deprecated import deprecated + + +def test_basic(): + @deprecated(since='2.0', alternative='bar') + def foo() -> int: + return 1 + + with pytest.warns( + DeprecationWarning, match='Function foo is deprecated since 2.0, use bar instead.' + ): + assert foo() == 1 + + +def test_with_removed(): + @deprecated(since='2.0', alternative='bar', removed='3.0') + def foo() -> int: + return 1 + + with pytest.warns( + DeprecationWarning, + match='Function foo is deprecated since 2.0, use bar instead. Will be removed in version 3.0.', + ): + assert foo() == 1 + + +def test_on_member_method(): + class Foo: + @deprecated(since='2.0', alternative='baz') + def bar(self) -> int: + return 1 + + with pytest.warns( + DeprecationWarning, match='Function bar is deprecated since 2.0, use baz instead.' + ): + foo = Foo() + assert foo.bar() == 1 + + +def test_on_class_method(): + class Foo: + @classmethod + @deprecated(since='2.0', alternative='baz') + def bar(cls) -> int: + return 1 + + with pytest.warns( + DeprecationWarning, match='Function bar is deprecated since 2.0, use baz instead.' + ): + foo = Foo() + assert foo.bar() == 1 + assert Foo.bar() == 1 + + +def test_on_static_method(): + class Foo: + @staticmethod + @deprecated(since='2.0', alternative='baz') + def bar() -> int: + return 1 + + foo = Foo() + + with pytest.warns( + DeprecationWarning, match='Function bar is deprecated since 2.0, use baz instead.' + ): + assert foo.bar() == 1 + assert Foo.bar() == 1 From 8d51615e2a875156f9cebdaa7c9792d4920d96a2 Mon Sep 17 00:00:00 2001 From: Viljar Femoen Date: Tue, 5 Nov 2024 11:19:44 +0100 Subject: [PATCH 04/15] Rename Microscope -> get_microscope, get_tem -> get_microscope_class --- src/instamatic/config/autoconfig.py | 4 ++-- src/instamatic/controller.py | 4 ++-- src/instamatic/microscope/__init__.py | 2 +- src/instamatic/microscope/client.py | 4 ++-- src/instamatic/microscope/microscope.py | 25 +++++++++++++++++++++---- src/instamatic/server/tem_server.py | 4 ++-- 6 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/instamatic/config/autoconfig.py b/src/instamatic/config/autoconfig.py index 606a581c..6936f466 100644 --- a/src/instamatic/config/autoconfig.py +++ b/src/instamatic/config/autoconfig.py @@ -126,15 +126,15 @@ def main(): cam_name = None from instamatic.camera.camera import get_cam - from instamatic.microscope.microscope import get_tem 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) diff --git a/src/instamatic/controller.py b/src/instamatic/controller.py index b9c44f61..88e07978 100644 --- a/src/instamatic/controller.py +++ b/src/instamatic/controller.py @@ -15,7 +15,7 @@ from instamatic.image_utils import rotate_image from instamatic.microscope.base import MicroscopeBase from instamatic.microscope.components import * -from instamatic.microscope.microscope import Microscope +from instamatic.microscope.microscope import get_microscope _ctrl = None # store reference of ctrl so it can be accessed without re-initializing @@ -47,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: diff --git a/src/instamatic/microscope/__init__.py b/src/instamatic/microscope/__init__.py index 781bae92..5b708582 100644 --- a/src/instamatic/microscope/__init__.py +++ b/src/instamatic/microscope/__init__.py @@ -1,3 +1,3 @@ from __future__ import annotations -from .microscope import Microscope +from .microscope import Microscope, get_microscope diff --git a/src/instamatic/microscope/client.py b/src/instamatic/microscope/client.py index 8980c06c..d13d7041 100644 --- a/src/instamatic/microscope/client.py +++ b/src/instamatic/microscope/client.py @@ -114,9 +114,9 @@ def _eval_dct(self, dct): raise ConnectionError(f'Unknown status code: {status}') def _init_dict(self): - from instamatic.microscope.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('_') diff --git a/src/instamatic/microscope/microscope.py b/src/instamatic/microscope/microscope.py index 5f3214f2..2ee551cb 100644 --- a/src/instamatic/microscope/microscope.py +++ b/src/instamatic/microscope/microscope.py @@ -2,13 +2,14 @@ from instamatic import config from instamatic.microscope.base import MicroscopeBase +from instamatic.utils.deprecated import deprecated default_tem_interface = config.microscope.interface -__all__ = ['Microscope', 'get_tem'] +__all__ = ['get_microscope', 'get_microscope_class'] -def get_tem(interface: str) -> 'type[MicroscopeBase]': +def get_microscope_class(interface: str) -> 'type[MicroscopeBase]': """Grab tem class with the specific 'interface'.""" simulate = config.settings.simulate @@ -32,7 +33,7 @@ def get_tem(interface: str) -> 'type[MicroscopeBase]': return cls -def Microscope(name: str = None, use_server: bool = False) -> MicroscopeBase: +def get_microscope(name: str = None, use_server: bool = False) -> MicroscopeBase: """Generic class to load microscope interface class. name: str @@ -56,7 +57,23 @@ def Microscope(name: str = None, use_server: bool = False) -> MicroscopeBase: tem = MicroscopeClient(interface=interface) else: - cls = get_tem(interface=interface) + cls = get_microscope_class(interface=interface) tem = cls(name=name) return tem + + +@deprecated(since='2.0.6', alternative='get_microscope') +def Microscope(name: str = None, use_server: bool = False) -> MicroscopeBase: + return get_microscope(name=name, use_server=use_server) + + +Microscope.__doc__ = get_microscope.__doc__ + + +@deprecated(since='2.0.6', alternative='get_microscope_class') +def get_tem(interface: str) -> 'type[MicroscopeBase]': + return get_microscope_class(interface=interface) + + +get_tem.__doc__ == get_microscope_class.__doc__ diff --git a/src/instamatic/server/tem_server.py b/src/instamatic/server/tem_server.py index 0ee63069..eb630a9e 100644 --- a/src/instamatic/server/tem_server.py +++ b/src/instamatic/server/tem_server.py @@ -10,7 +10,7 @@ import traceback from instamatic import config -from instamatic.microscope import Microscope +from instamatic.microscope import get_microscope from .serializer import dumper, loader @@ -45,7 +45,7 @@ def __init__(self, log=None, q=None, name=None): def run(self): """Start the server thread.""" - self.tem = Microscope(name=self._name, use_server=False) + self.tem = get_microscope(name=self._name, use_server=False) print(f'Initialized connection to microscope: {self.tem.name}') while True: From c0ae5397e2f677d6efe16399559546aca0402eb9 Mon Sep 17 00:00:00 2001 From: Viljar Femoen Date: Tue, 5 Nov 2024 16:57:47 +0100 Subject: [PATCH 05/15] Make deprecations visible --- src/instamatic/utils/deprecated.py | 7 ++++++- tests/test_deprecated.py | 12 ++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/instamatic/utils/deprecated.py b/src/instamatic/utils/deprecated.py index 20e78eee..4d75f9a9 100644 --- a/src/instamatic/utils/deprecated.py +++ b/src/instamatic/utils/deprecated.py @@ -2,6 +2,11 @@ from __future__ import annotations +class VisibleDeprecationWarning(UserWarning): + """ + Numpy-inspired deprecation warning which will be shown by default. + The default `DeprecationWarning` does not show by default. + """ def deprecated(since: str, alternative: str, removed: str = None): """Mark a function as deprecated, printing a warning whenever it is used. @@ -29,7 +34,7 @@ def wrapped(*args, **kwargs): msg = f'Function {func.__name__} is deprecated since {since}, use {alternative} instead.' if removed is not None: msg += f' Will be removed in version {removed}.' - warnings.warn(msg, DeprecationWarning) + warnings.warn(msg, VisibleDeprecationWarning) return func(*args, **kwargs) return wrapped diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index fba3c27d..e4c7259f 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -2,7 +2,7 @@ import pytest -from instamatic.utils.deprecated import deprecated +from instamatic.utils.deprecated import deprecated, VisibleDeprecationWarning def test_basic(): @@ -11,7 +11,7 @@ def foo() -> int: return 1 with pytest.warns( - DeprecationWarning, match='Function foo is deprecated since 2.0, use bar instead.' + VisibleDeprecationWarning, match='Function foo is deprecated since 2.0, use bar instead.' ): assert foo() == 1 @@ -22,7 +22,7 @@ def foo() -> int: return 1 with pytest.warns( - DeprecationWarning, + VisibleDeprecationWarning, match='Function foo is deprecated since 2.0, use bar instead. Will be removed in version 3.0.', ): assert foo() == 1 @@ -35,7 +35,7 @@ def bar(self) -> int: return 1 with pytest.warns( - DeprecationWarning, match='Function bar is deprecated since 2.0, use baz instead.' + VisibleDeprecationWarning, match='Function bar is deprecated since 2.0, use baz instead.' ): foo = Foo() assert foo.bar() == 1 @@ -49,7 +49,7 @@ def bar(cls) -> int: return 1 with pytest.warns( - DeprecationWarning, match='Function bar is deprecated since 2.0, use baz instead.' + VisibleDeprecationWarning, match='Function bar is deprecated since 2.0, use baz instead.' ): foo = Foo() assert foo.bar() == 1 @@ -66,7 +66,7 @@ def bar() -> int: foo = Foo() with pytest.warns( - DeprecationWarning, match='Function bar is deprecated since 2.0, use baz instead.' + VisibleDeprecationWarning, match='Function bar is deprecated since 2.0, use baz instead.' ): assert foo.bar() == 1 assert Foo.bar() == 1 From efa311ecc536d2724c71207f2fd2cb3c1462ddad Mon Sep 17 00:00:00 2001 From: Viljar Femoen Date: Tue, 5 Nov 2024 16:58:37 +0100 Subject: [PATCH 06/15] Add TEMControl (deprecated) for compatibility --- src/instamatic/TEMController.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/instamatic/TEMController.py diff --git a/src/instamatic/TEMController.py b/src/instamatic/TEMController.py new file mode 100644 index 00000000..08786f43 --- /dev/null +++ b/src/instamatic/TEMController.py @@ -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 From 583ec478b4e192619bf36ca8cf3aa490a04ed58a Mon Sep 17 00:00:00 2001 From: Viljar Femoen Date: Thu, 7 Nov 2024 12:41:44 +0100 Subject: [PATCH 07/15] Explicitly import components --- src/instamatic/controller.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/instamatic/controller.py b/src/instamatic/controller.py index 88e07978..66a022d3 100644 --- a/src/instamatic/controller.py +++ b/src/instamatic/controller.py @@ -13,8 +13,8 @@ from instamatic.exceptions import TEMControllerError from instamatic.formats import write_tiff from instamatic.image_utils import rotate_image +from instamatic.microscope import components from instamatic.microscope.base import MicroscopeBase -from instamatic.microscope.components import * from instamatic.microscope.microscope import get_microscope _ctrl = None # store reference of ctrl so it can be accessed without re-initializing @@ -99,21 +99,21 @@ def __init__(self, tem: MicroscopeBase, cam: Optional[CameraBase] = None): self.tem = tem self.cam = cam - self.gunshift = GunShift(tem) - self.guntilt = GunTilt(tem) - self.beamshift = BeamShift(tem) - self.beamtilt = BeamTilt(tem) - self.imageshift1 = ImageShift1(tem) - self.imageshift2 = ImageShift2(tem) - self.diffshift = DiffShift(tem) - self.stage = Stage(tem) + self.gunshift = components.GunShift(tem) + self.guntilt = components.GunTilt(tem) + self.beamshift = components.BeamShift(tem) + self.beamtilt = components.BeamTilt(tem) + self.imageshift1 = components.ImageShift1(tem) + self.imageshift2 = components.ImageShift2(tem) + self.diffshift = components.DiffShift(tem) + self.stage = components.Stage(tem) self.stageposition = self.stage # for backwards compatibility - self.magnification = Magnification(tem) - self.brightness = Brightness(tem) - self.difffocus = DiffFocus(tem) - self.beam = Beam(tem) - self.screen = Screen(tem) - self.mode = Mode(tem) + self.magnification = components.Magnification(tem) + self.brightness = components.Brightness(tem) + self.difffocus = components.DiffFocus(tem) + self.beam = components.Beam(tem) + self.screen = components.Screen(tem) + self.mode = components.Mode(tem) self.autoblank = False self._saved_alignments = config.get_alignments() From 2437876ebc9790fc276874d2deaa357c68009bf2 Mon Sep 17 00:00:00 2001 From: Viljar Femoen Date: Thu, 7 Nov 2024 12:42:06 +0100 Subject: [PATCH 08/15] Add type hints --- src/instamatic/microscope/components/deflectors.py | 4 +++- src/instamatic/microscope/components/lenses.py | 4 +++- src/instamatic/microscope/components/stage.py | 4 +++- src/instamatic/microscope/components/states.py | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/instamatic/microscope/components/deflectors.py b/src/instamatic/microscope/components/deflectors.py index 57085b97..b194ac1b 100644 --- a/src/instamatic/microscope/components/deflectors.py +++ b/src/instamatic/microscope/components/deflectors.py @@ -3,6 +3,8 @@ from collections import namedtuple from typing import Tuple +from instamatic.microscope.base import MicroscopeBase + DeflectorTuple = namedtuple('DeflectorTuple', ['x', 'y']) @@ -13,7 +15,7 @@ class Deflector: functions. """ - def __init__(self, tem): + def __init__(self, tem: MicroscopeBase): super().__init__() self._tem = tem self._getter = None diff --git a/src/instamatic/microscope/components/lenses.py b/src/instamatic/microscope/components/lenses.py index 35023725..3680147d 100644 --- a/src/instamatic/microscope/components/lenses.py +++ b/src/instamatic/microscope/components/lenses.py @@ -1,11 +1,13 @@ from __future__ import annotations +from instamatic.microscope.base import MicroscopeBase + class Lens: """Generic microscope lens object defined by one value Must be subclassed to set the self._getter, self._setter functions.""" - def __init__(self, tem): + def __init__(self, tem: MicroscopeBase): super().__init__() self._tem = tem self._getter = None diff --git a/src/instamatic/microscope/components/stage.py b/src/instamatic/microscope/components/stage.py index 4eed5039..5d5ae0f5 100644 --- a/src/instamatic/microscope/components/stage.py +++ b/src/instamatic/microscope/components/stage.py @@ -7,6 +7,8 @@ import numpy as np +from instamatic.microscope.base import MicroscopeBase + # namedtuples to store results from .get() StagePositionTuple = namedtuple('StagePositionTuple', ['x', 'y', 'z', 'a', 'b']) @@ -14,7 +16,7 @@ class Stage: """Stage control.""" - def __init__(self, tem): + def __init__(self, tem: MicroscopeBase): super().__init__() self._tem = tem self._setter = self._tem.setStagePosition diff --git a/src/instamatic/microscope/components/states.py b/src/instamatic/microscope/components/states.py index 3cb8b95e..7170747a 100644 --- a/src/instamatic/microscope/components/states.py +++ b/src/instamatic/microscope/components/states.py @@ -2,11 +2,13 @@ import time +from instamatic.microscope.base import MicroscopeBase + class State: """Generic class for describing microscope state objects.""" - def __init__(self, tem): + def __init__(self, tem: MicroscopeBase): super().__init__() self._tem = tem self._getter = None From fa52acc6d6713f7acc8096685dff9324da0c8325 Mon Sep 17 00:00:00 2001 From: Viljar Femoen Date: Thu, 7 Nov 2024 12:48:50 +0100 Subject: [PATCH 09/15] Move definitions of deprecated functions --- src/instamatic/TEMController.py | 27 ++++++++++++++++++++++--- src/instamatic/microscope/__init__.py | 2 +- src/instamatic/microscope/microscope.py | 17 ---------------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/instamatic/TEMController.py b/src/instamatic/TEMController.py index 08786f43..02b4f779 100644 --- a/src/instamatic/TEMController.py +++ b/src/instamatic/TEMController.py @@ -1,7 +1,28 @@ +from __future__ import annotations + +# ruff: noqa: E402 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.utils.deprecated import VisibleDeprecationWarning, deprecated + +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 +from instamatic.microscope.base import MicroscopeBase + + +@deprecated(since='2.0.6', alternative='instamatic.microscope.get_microscope') +def Microscope(name: str = None, use_server: bool = False) -> MicroscopeBase: + from instamatic.microscope import get_microscope + + return get_microscope(name=name, use_server=use_server) + + +@deprecated(since='2.0.6', alternative='instamatic.microscope.get_microscope_class') +def get_tem(interface: str) -> 'type[MicroscopeBase]': + from instamatic.microscope import get_microscope_class + + return get_microscope_class(interface=interface) diff --git a/src/instamatic/microscope/__init__.py b/src/instamatic/microscope/__init__.py index 5b708582..c805dbba 100644 --- a/src/instamatic/microscope/__init__.py +++ b/src/instamatic/microscope/__init__.py @@ -1,3 +1,3 @@ from __future__ import annotations -from .microscope import Microscope, get_microscope +from .microscope import get_microscope, get_microscope_class diff --git a/src/instamatic/microscope/microscope.py b/src/instamatic/microscope/microscope.py index 2ee551cb..c7a0d8ab 100644 --- a/src/instamatic/microscope/microscope.py +++ b/src/instamatic/microscope/microscope.py @@ -2,7 +2,6 @@ from instamatic import config from instamatic.microscope.base import MicroscopeBase -from instamatic.utils.deprecated import deprecated default_tem_interface = config.microscope.interface @@ -61,19 +60,3 @@ def get_microscope(name: str = None, use_server: bool = False) -> MicroscopeBase tem = cls(name=name) return tem - - -@deprecated(since='2.0.6', alternative='get_microscope') -def Microscope(name: str = None, use_server: bool = False) -> MicroscopeBase: - return get_microscope(name=name, use_server=use_server) - - -Microscope.__doc__ = get_microscope.__doc__ - - -@deprecated(since='2.0.6', alternative='get_microscope_class') -def get_tem(interface: str) -> 'type[MicroscopeBase]': - return get_microscope_class(interface=interface) - - -get_tem.__doc__ == get_microscope_class.__doc__ From 3f68f1eb7b9240d21dd22dd8a790e3f060233829 Mon Sep 17 00:00:00 2001 From: Viljar Femoen Date: Thu, 7 Nov 2024 13:02:50 +0100 Subject: [PATCH 10/15] Revert update to new import. Will show warnings --- src/instamatic/calibrate/calibrate_beamshift.py | 4 ++-- src/instamatic/calibrate/calibrate_brightness.py | 4 ++-- src/instamatic/calibrate/calibrate_directbeam.py | 4 ++-- src/instamatic/calibrate/calibrate_stage_lowmag.py | 4 ++-- src/instamatic/calibrate/calibrate_stage_mag1.py | 4 ++-- src/instamatic/calibrate/calibrate_stagematrix.py | 4 ++-- src/instamatic/camera/camera.py | 4 ++-- src/instamatic/experiments/cred_gatan/experiment.py | 4 ++-- src/instamatic/experiments/cred_tvips/experiment.py | 4 ++-- src/instamatic/experiments/red/experiment.py | 4 ++-- src/instamatic/experiments/serialed/experiment.py | 2 +- src/instamatic/gridmontage.py | 4 ++-- src/instamatic/gui/cred_tvips_frame.py | 4 ++-- src/instamatic/gui/ctrl_frame.py | 4 ++-- src/instamatic/gui/defocus_button.py | 4 ++-- src/instamatic/gui/gui.py | 4 ++-- src/instamatic/main.py | 4 ++-- src/instamatic/microscope/client.py | 2 +- src/instamatic/processing/flatfield.py | 4 ++-- src/instamatic/server/TEMServer_FEI.py | 4 ++-- src/instamatic/server/tem_server.py | 4 ++-- tests/conftest.py | 4 ++-- 22 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/instamatic/calibrate/calibrate_beamshift.py b/src/instamatic/calibrate/calibrate_beamshift.py index 1fa69725..3a94c090 100644 --- a/src/instamatic/calibrate/calibrate_beamshift.py +++ b/src/instamatic/calibrate/calibrate_beamshift.py @@ -342,9 +342,9 @@ def main_entry(): args = options.args if not args: - from instamatic import controller + from instamatic import TEMController - ctrl = controller.initialize() + ctrl = TEMController.initialize() calibrate_beamshift(ctrl=ctrl, save_images=True) else: center_fn = args[0] diff --git a/src/instamatic/calibrate/calibrate_brightness.py b/src/instamatic/calibrate/calibrate_brightness.py index 055ea5de..c6b659bd 100644 --- a/src/instamatic/calibrate/calibrate_brightness.py +++ b/src/instamatic/calibrate/calibrate_brightness.py @@ -206,9 +206,9 @@ def main_entry(): args = options.args if not args: - from instamatic import controller + from instamatic import TEMController - ctrl = controller.initialize() + ctrl = TEMController.initialize() calibrate_brightness(ctrl, save_images=True) else: calibrate_brightness(args) diff --git a/src/instamatic/calibrate/calibrate_directbeam.py b/src/instamatic/calibrate/calibrate_directbeam.py index 9ba8b8ff..7a48544f 100644 --- a/src/instamatic/calibrate/calibrate_directbeam.py +++ b/src/instamatic/calibrate/calibrate_directbeam.py @@ -393,9 +393,9 @@ def main_entry(): if args: calibrate_directbeam(patterns=args) else: - from instamatic import controller + from instamatic import TEMController - ctrl = controller.initialize() + ctrl = TEMController.initialize() calibrate_directbeam(ctrl=ctrl) diff --git a/src/instamatic/calibrate/calibrate_stage_lowmag.py b/src/instamatic/calibrate/calibrate_stage_lowmag.py index eb4b539b..498172f9 100644 --- a/src/instamatic/calibrate/calibrate_stage_lowmag.py +++ b/src/instamatic/calibrate/calibrate_stage_lowmag.py @@ -430,9 +430,9 @@ def main_entry(): args = options.args if not args: - from instamatic import controller + from instamatic import TEMController - ctrl = TEMtroller.initialize() + ctrl = TEMController.initialize() calibrate_stage_lowmag(ctrl=ctrl, save_images=True) else: center_fn = args[0] diff --git a/src/instamatic/calibrate/calibrate_stage_mag1.py b/src/instamatic/calibrate/calibrate_stage_mag1.py index 056ab710..31a79aae 100644 --- a/src/instamatic/calibrate/calibrate_stage_mag1.py +++ b/src/instamatic/calibrate/calibrate_stage_mag1.py @@ -289,9 +289,9 @@ def main_entry(): args = options.args if not args: - from instamatic import controller + from instamatic import TEMController - ctrl = controller.initialize() + ctrl = TEMController.initialize() calibrate_mag1(ctrl=ctrl, save_images=True) else: center_fn = args[0] diff --git a/src/instamatic/calibrate/calibrate_stagematrix.py b/src/instamatic/calibrate/calibrate_stagematrix.py index 0844519f..42724d15 100644 --- a/src/instamatic/calibrate/calibrate_stagematrix.py +++ b/src/instamatic/calibrate/calibrate_stagematrix.py @@ -528,9 +528,9 @@ def main_entry(): mode = options.mode mags = options.mags - from instamatic import controller + from instamatic import TEMController - ctrl = controller.initialize() + ctrl = TEMController.initialize() if not mode: mode = ctrl.mode.get() diff --git a/src/instamatic/camera/camera.py b/src/instamatic/camera/camera.py index e41057b7..dec3d274 100644 --- a/src/instamatic/camera/camera.py +++ b/src/instamatic/camera/camera.py @@ -157,9 +157,9 @@ def main_entry(): take_series = options.take_series - from instamatic import controller + from instamatic import TEMController - ctrl = controller.initialize() + ctrl = TEMController.initialize() if take_series: i = 1 diff --git a/src/instamatic/experiments/cred_gatan/experiment.py b/src/instamatic/experiments/cred_gatan/experiment.py index d9219481..53012740 100644 --- a/src/instamatic/experiments/cred_gatan/experiment.py +++ b/src/instamatic/experiments/cred_gatan/experiment.py @@ -462,14 +462,14 @@ def log_stage_positions(self): if __name__ == '__main__': - from instamatic import controller + from instamatic import TEMController from instamatic.io import get_new_work_subdirectory print('Usage:') print(' 1. Start `insteadmatic_module.s` in DM') print(' 2. Run this script.') - ctrl = controller.initialize() + ctrl = TEMController.initialize() time.sleep(1) diff --git a/src/instamatic/experiments/cred_tvips/experiment.py b/src/instamatic/experiments/cred_tvips/experiment.py index de3cfe4b..b6949e9a 100644 --- a/src/instamatic/experiments/cred_tvips/experiment.py +++ b/src/instamatic/experiments/cred_tvips/experiment.py @@ -620,10 +620,10 @@ def log_stage_positions(self): if __name__ == '__main__': - from instamatic import controller + from instamatic import TEMController from instamatic.io import get_new_work_subdirectory - ctrl = controller.initialize() + ctrl = TEMController.initialize() expdir = get_new_work_subdirectory() expdir.mkdir(exist_ok=True, parents=True) diff --git a/src/instamatic/experiments/red/experiment.py b/src/instamatic/experiments/red/experiment.py index f842f768..53cdf2b9 100644 --- a/src/instamatic/experiments/red/experiment.py +++ b/src/instamatic/experiments/red/experiment.py @@ -202,9 +202,9 @@ def teardown(self): def main(): - from instamatic import controller + from instamatic import TEMController - ctrl = controller.initialize() + ctrl = TEMController.initialize() import logging diff --git a/src/instamatic/experiments/serialed/experiment.py b/src/instamatic/experiments/serialed/experiment.py index 47a98a58..56968f19 100644 --- a/src/instamatic/experiments/serialed/experiment.py +++ b/src/instamatic/experiments/serialed/experiment.py @@ -613,7 +613,7 @@ def main(): options = parser.parse_args() - from instamatic import microscope + from instamatic import TEMController try: params = json.load(open('params.json')) diff --git a/src/instamatic/gridmontage.py b/src/instamatic/gridmontage.py index 9289ba2b..2af58aff 100644 --- a/src/instamatic/gridmontage.py +++ b/src/instamatic/gridmontage.py @@ -207,9 +207,9 @@ def plot(self): if __name__ == '__main__': - from instamatic import TEMtroller + from instamatic import TEMController - ctrl = TEMtroller.initialize() + ctrl = TEMController.initialize() ctrl.mode.set('lowmag') ctrl.magnification.value = 100 diff --git a/src/instamatic/gui/cred_tvips_frame.py b/src/instamatic/gui/cred_tvips_frame.py index 3749cd7b..de89c0ec 100644 --- a/src/instamatic/gui/cred_tvips_frame.py +++ b/src/instamatic/gui/cred_tvips_frame.py @@ -193,9 +193,9 @@ def __init__(self, parent): frame.pack(side='bottom', fill='x', padx=10, pady=10) - from instamatic import controller + from instamatic import TEMController - self.ctrl = controller.get_instance() + self.ctrl = TEMController.get_instance() def init_vars(self): self.var_target_angle = DoubleVar(value=40.0) diff --git a/src/instamatic/gui/ctrl_frame.py b/src/instamatic/gui/ctrl_frame.py index 1d1c8e4d..234af858 100644 --- a/src/instamatic/gui/ctrl_frame.py +++ b/src/instamatic/gui/ctrl_frame.py @@ -187,9 +187,9 @@ def __init__(self, parent): frame.pack(side='top', fill='x', padx=10, pady=10) - from instamatic import controller + from instamatic import TEMController - self.ctrl = controller.get_instance() + self.ctrl = TEMController.get_instance() def init_vars(self): self.var_negative_angle = DoubleVar(value=-40) diff --git a/src/instamatic/gui/defocus_button.py b/src/instamatic/gui/defocus_button.py index a0f071a9..5c8f0002 100644 --- a/src/instamatic/gui/defocus_button.py +++ b/src/instamatic/gui/defocus_button.py @@ -3,7 +3,7 @@ from tkinter import * from tkinter.ttk import * -from instamatic import controller +from instamatic import TEMController class DefocusButton(LabelFrame): @@ -84,7 +84,7 @@ def main(): options = parser.parse_args() - ctrl = controller.initialize() + ctrl = TEMController.initialize() root = Tk() DefocusButton(root).pack(side='top', fill='both', expand=True, padx=10, pady=10) diff --git a/src/instamatic/gui/gui.py b/src/instamatic/gui/gui.py index fe686eb6..ef4b1e26 100644 --- a/src/instamatic/gui/gui.py +++ b/src/instamatic/gui/gui.py @@ -180,7 +180,7 @@ def start_gui(ctrl, log=None): if __name__ == '__main__': - from instamatic import controller + from instamatic import TEMController - ctrl = controller.initialize() + ctrl = TEMController.initialize() start_gui(ctrl) diff --git a/src/instamatic/main.py b/src/instamatic/main.py index e120f8ed..a1f34078 100644 --- a/src/instamatic/main.py +++ b/src/instamatic/main.py @@ -165,9 +165,9 @@ def main(): log = logging.getLogger(__name__) log.info(f'Instamatic started: {repr(options.__dict__)}') - from instamatic import controller + from instamatic import TEMController - ctrl = controller.initialize(stream=True) + ctrl = TEMController.initialize(stream=True) if options.nav_file: from pyserialem import read_nav_file diff --git a/src/instamatic/microscope/client.py b/src/instamatic/microscope/client.py index d13d7041..f6cc63c3 100644 --- a/src/instamatic/microscope/client.py +++ b/src/instamatic/microscope/client.py @@ -114,7 +114,7 @@ def _eval_dct(self, dct): raise ConnectionError(f'Unknown status code: {status}') def _init_dict(self): - from instamatic.microscope.microscope import get_microscope_class + from instamatic.microscope import get_microscope_class tem = get_microscope_class(interface=self.interface) diff --git a/src/instamatic/processing/flatfield.py b/src/instamatic/processing/flatfield.py index ffdd52a8..37a01671 100644 --- a/src/instamatic/processing/flatfield.py +++ b/src/instamatic/processing/flatfield.py @@ -9,7 +9,7 @@ import numpy as np from tqdm.auto import tqdm -from instamatic import config, controller +from instamatic import TEMController, config from instamatic.formats import * @@ -234,7 +234,7 @@ def main_entry(): args = options.args if options.collect: - ctrl = controller.initialize() + ctrl = TEMController.initialize() collect_flatfield(ctrl=ctrl, save_images=False) ctrl.close() exit() diff --git a/src/instamatic/server/TEMServer_FEI.py b/src/instamatic/server/TEMServer_FEI.py index 0ac435bf..b6f01855 100644 --- a/src/instamatic/server/TEMServer_FEI.py +++ b/src/instamatic/server/TEMServer_FEI.py @@ -10,7 +10,7 @@ import threading from socket import * -from instamatic import TEMtroller, config +from instamatic import TEMController, config HOST = config.settings.fei_server_host PORT = config.settings.fei_server_port @@ -68,7 +68,7 @@ def main(): logging.captureWarnings(True) log = logging.getLogger(__name__) - ctrl = TEMtroller.initialize() + ctrl = TEMController.initialize() s = socket(AF_INET, SOCK_STREAM) s.bind((HOST, PORT)) diff --git a/src/instamatic/server/tem_server.py b/src/instamatic/server/tem_server.py index eb630a9e..209ac557 100644 --- a/src/instamatic/server/tem_server.py +++ b/src/instamatic/server/tem_server.py @@ -10,7 +10,7 @@ import traceback from instamatic import config -from instamatic.microscope import get_microscope +from instamatic.TEMController import Microscope from .serializer import dumper, loader @@ -45,7 +45,7 @@ def __init__(self, log=None, q=None, name=None): def run(self): """Start the server thread.""" - self.tem = get_microscope(name=self._name, use_server=False) + self.tem = Microscope(name=self._name, use_server=False) print(f'Initialized connection to microscope: {self.tem.name}') while True: diff --git a/tests/conftest.py b/tests/conftest.py index 4b2e4e4d..efe3eb56 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -21,9 +21,9 @@ def pytest_configure(): @pytest.fixture(scope='module') def ctrl() -> 'TEMController': - from instamatic.controller import initialize + from instamatic import controller - ctrl = initialize() + ctrl = controller.initialize() # set instant stage movement for testing ctrl.tem._set_instant_stage_movement() From bcd687f73f4d273ee37b8bf6fda798af2911d177 Mon Sep 17 00:00:00 2001 From: Viljar Femoen Date: Thu, 7 Nov 2024 13:48:25 +0100 Subject: [PATCH 11/15] Expand backwards compatibility --- src/instamatic/TEMController/TEMController.py | 3 +++ .../{TEMController.py => TEMController/__init__.py} | 10 ++-------- src/instamatic/TEMController/microscope.py | 10 ++++++++++ src/instamatic/TEMController/microscope_client.py | 3 +++ src/instamatic/config/autoconfig.py | 6 +++--- src/instamatic/server/tem_client.py | 2 +- tests/conftest.py | 6 +++--- tests/test_ctrl.py | 4 ++-- 8 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 src/instamatic/TEMController/TEMController.py rename src/instamatic/{TEMController.py => TEMController/__init__.py} (73%) create mode 100644 src/instamatic/TEMController/microscope.py create mode 100644 src/instamatic/TEMController/microscope_client.py diff --git a/src/instamatic/TEMController/TEMController.py b/src/instamatic/TEMController/TEMController.py new file mode 100644 index 00000000..fc633455 --- /dev/null +++ b/src/instamatic/TEMController/TEMController.py @@ -0,0 +1,3 @@ +from __future__ import annotations + +from instamatic.controller import TEMController diff --git a/src/instamatic/TEMController.py b/src/instamatic/TEMController/__init__.py similarity index 73% rename from src/instamatic/TEMController.py rename to src/instamatic/TEMController/__init__.py index 02b4f779..4add11de 100644 --- a/src/instamatic/TEMController.py +++ b/src/instamatic/TEMController/__init__.py @@ -1,6 +1,6 @@ +# ruff: noqa: E402 from __future__ import annotations -# ruff: noqa: E402 import warnings from instamatic.utils.deprecated import VisibleDeprecationWarning, deprecated @@ -10,6 +10,7 @@ VisibleDeprecationWarning, ) + from instamatic.controller import get_instance, initialize from instamatic.microscope.base import MicroscopeBase @@ -19,10 +20,3 @@ def Microscope(name: str = None, use_server: bool = False) -> MicroscopeBase: from instamatic.microscope import get_microscope return get_microscope(name=name, use_server=use_server) - - -@deprecated(since='2.0.6', alternative='instamatic.microscope.get_microscope_class') -def get_tem(interface: str) -> 'type[MicroscopeBase]': - from instamatic.microscope import get_microscope_class - - return get_microscope_class(interface=interface) diff --git a/src/instamatic/TEMController/microscope.py b/src/instamatic/TEMController/microscope.py new file mode 100644 index 00000000..5562732b --- /dev/null +++ b/src/instamatic/TEMController/microscope.py @@ -0,0 +1,10 @@ +from __future__ import annotations + +from instamatic.utils.deprecated import deprecated + + +@deprecated(since='2.0.6', alternative='instamatic.microscope.get_microscope_class') +def get_tem(interface: str) -> 'type[MicroscopeBase]': + from instamatic.microscope import get_microscope_class + + return get_microscope_class(interface=interface) diff --git a/src/instamatic/TEMController/microscope_client.py b/src/instamatic/TEMController/microscope_client.py new file mode 100644 index 00000000..ca7755d9 --- /dev/null +++ b/src/instamatic/TEMController/microscope_client.py @@ -0,0 +1,3 @@ +from __future__ import annotations + +from instamatic.microscope.client import MicroscopeClient diff --git a/src/instamatic/config/autoconfig.py b/src/instamatic/config/autoconfig.py index 6936f466..6047bb88 100644 --- a/src/instamatic/config/autoconfig.py +++ b/src/instamatic/config/autoconfig.py @@ -126,15 +126,15 @@ def main(): cam_name = None from instamatic.camera.camera import get_cam - from instamatic.controller import TEMController - from instamatic.microscope.microscope import get_microscope_class + from instamatic.TEMController.microscope import get_tem + from instamatic.TEMController.TEMController import TEMController if cam_connect: cam = get_cam(cam_name)() if cam_name else None else: cam = None - tem = get_microscope_class(tem_name)() + tem = get_tem(tem_name)() ctrl = TEMController(tem=tem, cam=cam) diff --git a/src/instamatic/server/tem_client.py b/src/instamatic/server/tem_client.py index bf591161..ce184193 100644 --- a/src/instamatic/server/tem_client.py +++ b/src/instamatic/server/tem_client.py @@ -1,7 +1,7 @@ from __future__ import annotations from instamatic import config -from instamatic.microscope.client import MicroscopeClient +from instamatic.TEMController.microscope_client import MicroscopeClient microscope_id = config.microscope.name diff --git a/tests/conftest.py b/tests/conftest.py index efe3eb56..9a71e297 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,7 +8,7 @@ # Actually importing the controller class breaks the tests if TYPE_CHECKING: - from instamatic.controller import TEMController + from instamatic.TEMController.TEMController import TEMController base_drc = Path(__file__).parent @@ -21,9 +21,9 @@ def pytest_configure(): @pytest.fixture(scope='module') def ctrl() -> 'TEMController': - from instamatic import controller + from instamatic import TEMController - ctrl = controller.initialize() + ctrl = TEMController.initialize() # set instant stage movement for testing ctrl.tem._set_instant_stage_movement() diff --git a/tests/test_ctrl.py b/tests/test_ctrl.py index 123b34a9..8c262772 100644 --- a/tests/test_ctrl.py +++ b/tests/test_ctrl.py @@ -5,9 +5,9 @@ def test_setup(ctrl): - from instamatic import controller + from instamatic import TEMController - ctrl2 = controller.get_instance() + ctrl2 = TEMController.get_instance() assert ctrl2 is ctrl From 6edc0b3cfe6cd743305ca7181cb053a7727014ff Mon Sep 17 00:00:00 2001 From: Viljar Femoen Date: Thu, 7 Nov 2024 13:59:48 +0100 Subject: [PATCH 12/15] Improve traceback message --- src/instamatic/TEMController/__init__.py | 1 + src/instamatic/utils/deprecated.py | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/instamatic/TEMController/__init__.py b/src/instamatic/TEMController/__init__.py index 4add11de..2bc4ea6f 100644 --- a/src/instamatic/TEMController/__init__.py +++ b/src/instamatic/TEMController/__init__.py @@ -8,6 +8,7 @@ warnings.warn( 'The `TEMController` module is deprecated since version 2.0.6. Use the `controller`-module instead', VisibleDeprecationWarning, + stacklevel=2, ) diff --git a/src/instamatic/utils/deprecated.py b/src/instamatic/utils/deprecated.py index 4d75f9a9..046c9e4a 100644 --- a/src/instamatic/utils/deprecated.py +++ b/src/instamatic/utils/deprecated.py @@ -2,12 +2,14 @@ from __future__ import annotations + class VisibleDeprecationWarning(UserWarning): - """ - Numpy-inspired deprecation warning which will be shown by default. + """Numpy-inspired deprecation warning which will be shown by default. + The default `DeprecationWarning` does not show by default. """ + def deprecated(since: str, alternative: str, removed: str = None): """Mark a function as deprecated, printing a warning whenever it is used. @@ -34,7 +36,7 @@ def wrapped(*args, **kwargs): msg = f'Function {func.__name__} is deprecated since {since}, use {alternative} instead.' if removed is not None: msg += f' Will be removed in version {removed}.' - warnings.warn(msg, VisibleDeprecationWarning) + warnings.warn(msg, VisibleDeprecationWarning, stacklevel=2) return func(*args, **kwargs) return wrapped From 0598875cb30cd36b632ff1fe2d4ea08d7382936f Mon Sep 17 00:00:00 2001 From: Viljar Femoen Date: Thu, 7 Nov 2024 14:07:22 +0100 Subject: [PATCH 13/15] Increase similarity to old version --- src/instamatic/TEMController/TEMController.py | 2 +- src/instamatic/TEMController/__init__.py | 14 +++----------- src/instamatic/TEMController/microscope.py | 10 ++++++++++ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/instamatic/TEMController/TEMController.py b/src/instamatic/TEMController/TEMController.py index fc633455..316588a4 100644 --- a/src/instamatic/TEMController/TEMController.py +++ b/src/instamatic/TEMController/TEMController.py @@ -1,3 +1,3 @@ from __future__ import annotations -from instamatic.controller import TEMController +from instamatic.controller import TEMController, get_instance, initialize diff --git a/src/instamatic/TEMController/__init__.py b/src/instamatic/TEMController/__init__.py index 2bc4ea6f..b5d9cf4b 100644 --- a/src/instamatic/TEMController/__init__.py +++ b/src/instamatic/TEMController/__init__.py @@ -3,7 +3,7 @@ import warnings -from instamatic.utils.deprecated import VisibleDeprecationWarning, deprecated +from instamatic.utils.deprecated import VisibleDeprecationWarning warnings.warn( 'The `TEMController` module is deprecated since version 2.0.6. Use the `controller`-module instead', @@ -11,13 +11,5 @@ stacklevel=2, ) - -from instamatic.controller import get_instance, initialize -from instamatic.microscope.base import MicroscopeBase - - -@deprecated(since='2.0.6', alternative='instamatic.microscope.get_microscope') -def Microscope(name: str = None, use_server: bool = False) -> MicroscopeBase: - from instamatic.microscope import get_microscope - - return get_microscope(name=name, use_server=use_server) +from .microscope import Microscope +from .TEMController import get_instance, initialize diff --git a/src/instamatic/TEMController/microscope.py b/src/instamatic/TEMController/microscope.py index 5562732b..230dd7ce 100644 --- a/src/instamatic/TEMController/microscope.py +++ b/src/instamatic/TEMController/microscope.py @@ -1,10 +1,20 @@ from __future__ import annotations +from instamatic.microscope.base import MicroscopeBase from instamatic.utils.deprecated import deprecated +__all__ = ['Microscope', 'get_tem'] + @deprecated(since='2.0.6', alternative='instamatic.microscope.get_microscope_class') def get_tem(interface: str) -> 'type[MicroscopeBase]': from instamatic.microscope import get_microscope_class return get_microscope_class(interface=interface) + + +@deprecated(since='2.0.6', alternative='instamatic.microscope.get_microscope') +def Microscope(name: str = None, use_server: bool = False) -> MicroscopeBase: + from instamatic.microscope import get_microscope + + return get_microscope(name=name, use_server=use_server) From d399cafda41822f1115fc138c32a79d9611433a7 Mon Sep 17 00:00:00 2001 From: Viljar Femoen Date: Thu, 7 Nov 2024 14:10:13 +0100 Subject: [PATCH 14/15] Revert --- tests/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 9a71e297..73a1a864 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -21,9 +21,9 @@ def pytest_configure(): @pytest.fixture(scope='module') def ctrl() -> 'TEMController': - from instamatic import TEMController + from instamatic.TEMController import initialize - ctrl = TEMController.initialize() + ctrl = initialize() # set instant stage movement for testing ctrl.tem._set_instant_stage_movement() From e809c110596df442d433a59a389838b8eda3d5ac Mon Sep 17 00:00:00 2001 From: Viljar Femoen Date: Thu, 7 Nov 2024 14:14:27 +0100 Subject: [PATCH 15/15] Fix formatting --- tests/test_deprecated.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index e4c7259f..c4076a49 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -2,7 +2,7 @@ import pytest -from instamatic.utils.deprecated import deprecated, VisibleDeprecationWarning +from instamatic.utils.deprecated import VisibleDeprecationWarning, deprecated def test_basic(): @@ -11,7 +11,8 @@ def foo() -> int: return 1 with pytest.warns( - VisibleDeprecationWarning, match='Function foo is deprecated since 2.0, use bar instead.' + VisibleDeprecationWarning, + match='Function foo is deprecated since 2.0, use bar instead.', ): assert foo() == 1 @@ -35,7 +36,8 @@ def bar(self) -> int: return 1 with pytest.warns( - VisibleDeprecationWarning, match='Function bar is deprecated since 2.0, use baz instead.' + VisibleDeprecationWarning, + match='Function bar is deprecated since 2.0, use baz instead.', ): foo = Foo() assert foo.bar() == 1 @@ -49,7 +51,8 @@ def bar(cls) -> int: return 1 with pytest.warns( - VisibleDeprecationWarning, match='Function bar is deprecated since 2.0, use baz instead.' + VisibleDeprecationWarning, + match='Function bar is deprecated since 2.0, use baz instead.', ): foo = Foo() assert foo.bar() == 1 @@ -66,7 +69,8 @@ def bar() -> int: foo = Foo() with pytest.warns( - VisibleDeprecationWarning, match='Function bar is deprecated since 2.0, use baz instead.' + VisibleDeprecationWarning, + match='Function bar is deprecated since 2.0, use baz instead.', ): assert foo.bar() == 1 assert Foo.bar() == 1