Skip to content

Commit

Permalink
Black, isort, and flake8.
Browse files Browse the repository at this point in the history
  • Loading branch information
canismarko committed Jul 15, 2024
1 parent 9b3d9a7 commit bb64593
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 65 deletions.
4 changes: 3 additions & 1 deletion src/haven/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ def write_safe(self):
delete = with_thread_lock(Cache.delete)


def tiled_client(entry_node=None, uri=None, cache_filepath=None, structure_clients="dask"):
def tiled_client(
entry_node=None, uri=None, cache_filepath=None, structure_clients="dask"
):
config = load_config()
# Create a cache for saving local copies
if cache_filepath is None:
Expand Down
10 changes: 6 additions & 4 deletions src/haven/instrument/aerotech.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@
import pint
from apstools.synApps.asyn import AsynRecord
from ophyd import Component as Cpt
from ophyd import EpicsMotor, EpicsSignal
from ophyd import FormattedComponent as FCpt
from ophyd import Kind, Signal, flyers
from ophyd import Kind, Signal
from ophyd.status import SubscriptionStatus

from .._iconfig import load_config
from ..exceptions import InvalidScanParameters
from .delay import DG645Delay
from .device import make_device
from .stage import XYStage
from .motor import HavenMotor
from .stage import XYStage

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -487,7 +486,10 @@ def check_flyscan_bounds(self):
This checks to make sure no spurious pulses are expected from taxiing.
"""
end_points = [(self.flyer_taxi_start, self.pso_start), (self.flyer_taxi_end, self.pso_end)]
end_points = [
(self.flyer_taxi_start, self.pso_start),
(self.flyer_taxi_end, self.pso_end),
]
step_size = self.flyer_step_size()
for taxi, pso in end_points:
# Make sure we're not going to have extra pulses
Expand Down
3 changes: 2 additions & 1 deletion src/haven/instrument/aps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging

from apstools.devices.aps_machine import ApsMachineParametersDevice
from ophyd import Component as Cpt, EpicsSignalRO
from ophyd import Component as Cpt
from ophyd import EpicsSignalRO

from .._iconfig import load_config
from .device import make_device
Expand Down
32 changes: 19 additions & 13 deletions src/haven/instrument/area_detector.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
import logging
import time
from enum import IntEnum
from collections import OrderedDict, namedtuple
from enum import IntEnum
from typing import Dict
import warnings

import pandas as pd
import numpy as np
import pandas as pd
from apstools.devices import CamMixin_V34, SingleTrigger_V34
from ophyd import ADComponent as ADCpt
from ophyd import Component as Cpt
from ophyd import DetectorBase as OphydDetectorBase
from ophyd import (
Device,
EigerDetectorCam,
Kind,
Lambda750kCam,
OphydObject,
Signal,
SimDetectorCam,
SingleTrigger,
Signal,
Device,
)
from ophyd.status import StatusBase, SubscriptionStatus
from ophyd.areadetector.base import EpicsSignalWithRBV as SignalWithRBV
from ophyd.areadetector.filestore_mixins import FileStoreHDF5IterativeWrite, FileStoreTIFFIterativeWrite
from ophyd.areadetector.filestore_mixins import (
FileStoreHDF5IterativeWrite,
FileStoreTIFFIterativeWrite,
)
from ophyd.areadetector.plugins import (
HDF5Plugin_V31,
HDF5Plugin_V34,
Expand All @@ -33,12 +36,12 @@
PvaPlugin_V34,
ROIPlugin_V31,
ROIPlugin_V34,
TIFFPlugin_V31,
TIFFPlugin_V34,
)
from ophyd.areadetector.plugins import StatsPlugin_V31 as OphydStatsPlugin_V31
from ophyd.areadetector.plugins import StatsPlugin_V34 as OphydStatsPlugin_V34
from ophyd.areadetector.plugins import TIFFPlugin_V31, TIFFPlugin_V34
from ophyd.flyers import FlyerInterface
from ophyd.status import StatusBase, SubscriptionStatus

from .. import exceptions
from .._iconfig import load_config
Expand Down Expand Up @@ -71,6 +74,7 @@ class EraseState(IntEnum):
DONE = 0
ERASE = 1


class AcquireState(IntEnum):
DONE = 0
ACQUIRE = 1
Expand Down Expand Up @@ -100,7 +104,7 @@ class DetectorState(IntEnum):
ABORTED = 10


fly_event = namedtuple("fly_event", ('timestamp', 'value'))
fly_event = namedtuple("fly_event", ("timestamp", "value"))


class FlyerMixin(FlyerInterface, Device):
Expand Down Expand Up @@ -304,7 +308,10 @@ class DynamicFileStore(Device):
iconfig values.
"""
def __init__(self, *args, write_path_template="/{root_path}/%Y/%m/{name}/", **kwargs):

def __init__(
self, *args, write_path_template="/{root_path}/%Y/%m/{name}/", **kwargs
):
super().__init__(*args, write_path_template=write_path_template, **kwargs)
# Format the file_write_template with per-device values
config = load_config()
Expand All @@ -330,8 +337,7 @@ def stage(self):
super().stage()


class TIFFFilePlugin(DynamicFileStore, FileStoreTIFFIterativeWrite, TIFFPlugin_V34):
...
class TIFFFilePlugin(DynamicFileStore, FileStoreTIFFIterativeWrite, TIFFPlugin_V34): ...


class DetectorBase(FlyerMixin, OphydDetectorBase):
Expand All @@ -343,7 +349,7 @@ def __init__(self, *args, description=None, **kwargs):

@property
def default_time_signal(self):
return self.cam.acquire_time
return self.cam.acquire_time


class StatsMixin:
Expand Down
13 changes: 9 additions & 4 deletions src/haven/instrument/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@
from ophyd import ADComponent as ADCpt
from ophyd import CamBase, EpicsSignal, Kind
from ophyd.areadetector.plugins import (
HDF5Plugin_V34,
ImagePlugin_V34,
OverlayPlugin_V34,
PvaPlugin_V34,
ROIPlugin_V34,
TIFFPlugin_V34,
)

from .. import exceptions
from .._iconfig import load_config
from .area_detector import ( # noqa: F401
AsyncCamMixin,
DetectorBase,
HDF5FilePlugin,
SimDetector,
SingleImageModeTrigger,
StatsPlugin_V34,
HDF5FilePlugin,
TIFFFilePlugin,
)
from .device import make_device
Expand All @@ -41,7 +39,14 @@ class AravisDetector(SingleImageModeTrigger, DetectorBase):
A gige-vision camera described by EPICS.
"""

_default_configuration_attrs = ("cam", "hdf", "stats1", "stats2", "stats3", "stats4")
_default_configuration_attrs = (
"cam",
"hdf",
"stats1",
"stats2",
"stats3",
"stats4",
)
_default_read_attrs = ("cam", "hdf", "stats1", "stats2", "stats3", "stats4")

cam = ADCpt(AravisCam, "cam1:")
Expand Down
10 changes: 3 additions & 7 deletions src/haven/instrument/motor.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import asyncio
import logging
import warnings
from collections import OrderedDict
from typing import Mapping, Sequence, Generator, Dict
from typing import Mapping, Sequence

from scipy.interpolate import CubicSpline
import numpy as np
from apstools.utils.misc import safe_ophyd_name
from ophyd import Component as Cpt
from ophyd import EpicsMotor, EpicsSignal, EpicsSignalRO, Signal, Kind, get_cl
from ophyd.flyers import FlyerInterface
from ophyd.status import Status
from ophyd import EpicsMotor, EpicsSignal, EpicsSignalRO, Kind

from .._iconfig import load_config
from .device import make_device, resolve_device_names
Expand All @@ -30,6 +25,7 @@ class HavenMotor(MotorFlyer, EpicsMotor):
Returns to the previous value when being unstaged.
"""

# Extra motor record components
encoder_resolution = Cpt(EpicsSignal, ".ERES", kind=Kind.config)
description = Cpt(EpicsSignal, ".DESC", kind="omitted")
Expand Down
13 changes: 6 additions & 7 deletions src/haven/instrument/motor_flyer.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from collections import OrderedDict
import logging
from typing import Generator, Dict
from collections import OrderedDict
from typing import Dict, Generator

from scipy.interpolate import CubicSpline
import numpy as np

from ophyd import Component as Cpt, Kind, Signal, get_cl, Device
from ophyd import Component as Cpt
from ophyd import Device, Kind, Signal, get_cl
from ophyd.flyers import FlyerInterface
from ophyd.status import Status

from scipy.interpolate import CubicSpline

log = logging.getLogger()

Expand Down Expand Up @@ -206,7 +205,7 @@ def _update_fly_params(self, *args, **kwargs):
direction = 1 if start_position < end_position else -1
# Determine taxi distance to accelerate to req speed, v^2/(2*a) = d
# x1.5 for safety margin
step_size = abs((start_position - end_position) / (num_points-1))
step_size = abs((start_position - end_position) / (num_points - 1))
if step_size <= 0:
log.warning(
f"{self} step_size is non-positive. Could not update fly scan"
Expand Down
4 changes: 3 additions & 1 deletion src/haven/plans/fly.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
__all__ = ["fly_scan", "grid_fly_scan"]


def fly_line_scan(detectors: list, flyer, start, stop, num, extra_signals=(), combine_streams=True):
def fly_line_scan(
detectors: list, flyer, start, stop, num, extra_signals=(), combine_streams=True
):
"""A plan stub for fly-scanning a single trajectory.
Parameters
Expand Down
1 change: 0 additions & 1 deletion src/haven/run_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import databroker
from bluesky import RunEngine as BlueskyRunEngine
from bluesky import suspenders
from bluesky.callbacks.best_effort import BestEffortCallback

from .exceptions import ComponentNotFound
Expand Down
4 changes: 1 addition & 3 deletions src/haven/tests/test_aerotech.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,7 @@ def test_pso_bad_window_forward(aerotech_flyer):
flyer = aerotech_flyer
# Set up scan parameters
flyer.encoder_resolution.put(1)
flyer.encoder_step_size.put(
5 / flyer.encoder_resolution.get()
) # In encoder counts
flyer.encoder_step_size.put(5 / flyer.encoder_resolution.get()) # In encoder counts
flyer.encoder_window_start.put(-5) # In encoder counts
flyer.encoder_window_end.put(None) # High end is outside the window range
flyer.pso_end.put(100)
Expand Down
10 changes: 7 additions & 3 deletions src/haven/tests/test_area_detector.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import time

import pytest
import numpy as np
from ophyd.sim import instantiate_fake_device
import pytest
from ophyd import ADComponent as ADCpt
from ophyd.areadetector.cam import AreaDetectorCam
from ophyd.sim import instantiate_fake_device

from haven.instrument.area_detector import load_area_detectors, DetectorBase, DetectorState
from haven.instrument.area_detector import (
DetectorBase,
DetectorState,
load_area_detectors,
)


class Detector(DetectorBase):
Expand Down
4 changes: 3 additions & 1 deletion src/haven/tests/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def test_load_cameras(sim_registry):

@pytest.fixture()
def camera(sim_registry):
camera = instantiate_fake_device(AravisDetector, prefix="255idgigeA:", name="camera")
camera = instantiate_fake_device(
AravisDetector, prefix="255idgigeA:", name="camera"
)
return camera


Expand Down
11 changes: 7 additions & 4 deletions src/haven/tests/test_fly_plans.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import pytest
from collections import OrderedDict
from unittest.mock import MagicMock

import numpy as np
from ophyd import sim, EpicsMotor
import pytest
from ophyd import EpicsMotor, sim

from haven.plans.fly import FlyerCollector, fly_scan, grid_fly_scan
from haven.instrument.motor_flyer import MotorFlyer
from haven.plans.fly import FlyerCollector, fly_scan, grid_fly_scan


@pytest.fixture()
Expand Down Expand Up @@ -275,7 +275,10 @@ def test_fly_grid_scan(aerotech_flyer):
flyer_start_positions = [
msg.args[0]
for msg in messages
if (msg.command == "set" and msg.obj.name == f"{flyer.name}_flyer_start_position")
if (
msg.command == "set"
and msg.obj.name == f"{flyer.name}_flyer_start_position"
)
]
flyer_end_positions = [
msg.args[0]
Expand Down
9 changes: 1 addition & 8 deletions src/haven/tests/test_motor.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
from collections import OrderedDict

import pytest
from ophyd.sim import instantiate_fake_device
from ophyd.flyers import FlyerInterface
from ophyd import StatusBase
import numpy as np

from haven.instrument.motor import HavenMotor, load_motors
from haven.instrument.motor_flyer import MotorFlyer
Expand Down Expand Up @@ -51,9 +46,7 @@ def test_skip_existing_motors(sim_registry, mocked_device_names):
"""
# Create an existing fake motor
m1 = HavenMotor(
"255idVME:m1", name="kb_mirrors_horiz_upstream", labels={"motors"}
)
m1 = HavenMotor("255idVME:m1", name="kb_mirrors_horiz_upstream", labels={"motors"})
# Load the Ophyd motor definitions
load_motors()
# Were the motors imported correctly
Expand Down
Loading

0 comments on commit bb64593

Please sign in to comment.