Skip to content

Commit

Permalink
Fix warnings (#102)
Browse files Browse the repository at this point in the history
* Fix warnings for 3.12

* Fix deprecation warnings introduced in #99
  • Loading branch information
viljarjf authored Nov 11, 2024
1 parent ed2cddd commit 7a9e38b
Show file tree
Hide file tree
Showing 28 changed files with 57 additions and 58 deletions.
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 = controller.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 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
2 changes: 1 addition & 1 deletion src/instamatic/experiments/cred/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Experiment(ExperimentBase):
"""Initialize continuous rotation electron diffraction experiment.
ctrl:
Instance of instamatic.TEMController.TEMController
Instance of instamatic.controller.TEMController
path:
`str` or `pathlib.Path` object giving the path to save data at
log:
Expand Down
6 changes: 3 additions & 3 deletions src/instamatic/experiments/cred_gatan/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Experiment(ExperimentBase):
rotation electron diffraction data.
ctrl: `TEMController`
Instance of instamatic.TEMController.TEMController
Instance of instamatic.controller.TEMController
path: str
`str` or `pathlib.Path` object giving the path to save data at
log: `logging.Logger`
Expand Down 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
6 changes: 3 additions & 3 deletions src/instamatic/experiments/cred_tvips/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class Experiment(ExperimentBase):
rotation electron diffraction data.
ctrl: `TEMController`
Instance of instamatic.TEMController.TEMController
Instance of instamatic.controller.TEMController
path: str
`str` or `pathlib.Path` object giving the path to save data at
log: `logging.Logger`
Expand Down 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
6 changes: 3 additions & 3 deletions src/instamatic/experiments/red/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Experiment(ExperimentBase):
"""Initialize stepwise rotation electron diffraction experiment.
ctrl:
Instance of instamatic.TEMController.TEMController
Instance of instamatic.controller.TEMController
path:
`str` or `pathlib.Path` object giving the path to save data at
log:
Expand Down 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
4 changes: 2 additions & 2 deletions 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 controller

try:
params = json.load(open('params.json'))
Expand All @@ -628,7 +628,7 @@ def main():
logging.captureWarnings(True)
log = logging.getLogger(__name__)

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

exp = Experiment(ctrl, params, log=log)
exp.report_status()
Expand Down
2 changes: 1 addition & 1 deletion src/instamatic/formats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def write_tiff(fname: str, data, header: dict = None):
fname = Path(fname).with_suffix('.tiff')

with tifffile.TiffWriter(fname) as f:
f.save(data=data, software='instamatic', description=header)
f.write(data=data, software='instamatic', description=header)


def read_tiff(fname: str) -> (np.array, dict):
Expand Down
7 changes: 3 additions & 4 deletions src/instamatic/formats/mrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,11 +599,11 @@ def read_image(filename, index=None, cache=None, no_strict_mrc=False, force_volu
else:
d_len = h['nx'][0] * h['ny'][0]
dtype = numpy.dtype(mrc2numpy[h['mode'][0]])
offset = 1024 + int(h['nsymbt']) + idx * d_len * dtype.itemsize
offset = 1024 + int(h['nsymbt'][0]) + idx * d_len * dtype.itemsize
total = file_size(f)
if total != (
1024
+ int(h['nsymbt'])
+ int(h['nsymbt'][0])
+ int(h['nx'][0]) * int(h['ny'][0]) * int(h['nz'][0]) * dtype.itemsize
):
raise util.InvalidHeaderException(
Expand Down Expand Up @@ -650,15 +650,14 @@ def reshape_data(out, h, index, count, force_volume=False):
out : array
Array with image information from the file
"""

if index is None and int(h['nz'][0]) > 1 and (count == h['nx'][0] or force_volume):
if h['mapc'][0] == 2 and h['mapr'][0] == 1:
out = out.reshape((int(h['nx'][0]), int(h['ny'][0]), int(h['nz'][0])))
for i in range(out.shape[2]):
out[:, :, i] = out[:, :, i].squeeze().T
else:
out = out.reshape((int(h['nx'][0]), int(h['ny'][0]), int(h['nz'][0])))
elif int(h['ny']) > 1:
elif int(h['ny'][0]) > 1:
if h['mapc'][0] == 2 and h['mapr'][0] == 1:
out = out.reshape((int(h['ny'][0]), int(h['nx'][0]))) # .transpose() # Test this!
else:
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 controller

ctrl = TEMController.initialize()
ctrl = controller.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
4 changes: 2 additions & 2 deletions src/instamatic/processing/flatfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *


Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/instamatic/server/TEMServer_FEI.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import threading
from socket import *

from instamatic import TEMController, config
from instamatic import config, controller

HOST = config.settings.fei_server_host
PORT = config.settings.fei_server_port
Expand Down Expand Up @@ -68,7 +68,7 @@ def main():
logging.captureWarnings(True)
log = logging.getLogger(__name__)

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

s = socket(AF_INET, SOCK_STREAM)
s.bind((HOST, PORT))
Expand Down
2 changes: 1 addition & 1 deletion src/instamatic/server/tem_client.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/instamatic/server/tem_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import traceback

from instamatic import config
from instamatic.TEMController import Microscope
from instamatic.microscope import get_microscope

from .serializer import dumper, loader

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/instamatic/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def find_peak_max(
interpolate the pattern to get the peak maximum position with
subpixel precision.
"""
y1 = ndimage.filters.gaussian_filter1d(arr, sigma)
y1 = ndimage.gaussian_filter1d(arr, sigma)
c1 = np.argmax(y1) # initial guess for beam center

win_len = 2 * w + 1
Expand Down
Loading

0 comments on commit 7a9e38b

Please sign in to comment.