Reverted logging style
This commit is contained in:
parent
e25c23cf1c
commit
6fb61e1e3f
24 changed files with 100 additions and 106 deletions
|
|
@ -1,8 +1,4 @@
|
||||||
[MESSAGES CONTROL]
|
[MESSAGES CONTROL]
|
||||||
|
|
||||||
disable=fixme,C,R
|
disable=fixme,C,R
|
||||||
max-line-length = 88
|
max-line-length = 88
|
||||||
|
|
||||||
[LOGGING]
|
|
||||||
|
|
||||||
logging-format-style=new
|
|
||||||
|
|
@ -72,7 +72,7 @@ root_log.addHandler(fh)
|
||||||
access_log.addHandler(afh)
|
access_log.addHandler(afh)
|
||||||
|
|
||||||
# Log server paths being used
|
# Log server paths being used
|
||||||
logging.info("Running with data path {}", OPENFLEXURE_VAR_PATH)
|
logging.info("Running with data path %s", OPENFLEXURE_VAR_PATH)
|
||||||
|
|
||||||
logging.info("Creating app")
|
logging.info("Creating app")
|
||||||
# Create flask app
|
# Create flask app
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ def handle_extension_error(extension_name):
|
||||||
yield
|
yield
|
||||||
except Exception: # pylint: disable=W0703
|
except Exception: # pylint: disable=W0703
|
||||||
logging.error(
|
logging.error(
|
||||||
"Exception loading builtin extension {}: \n{}",
|
"Exception loading builtin extension %s: \n%s",
|
||||||
extension_name,
|
extension_name,
|
||||||
traceback.format_exc(),
|
traceback.format_exc(),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ class JPEGSharpnessMonitor:
|
||||||
raise e
|
raise e
|
||||||
if stop < 1:
|
if stop < 1:
|
||||||
stop = len(jpeg_times)
|
stop = len(jpeg_times)
|
||||||
logging.debug("changing stop to {}", (stop))
|
logging.debug("changing stop to %s", (stop))
|
||||||
jpeg_times = jpeg_times[start:stop]
|
jpeg_times = jpeg_times[start:stop]
|
||||||
jpeg_zs = np.interp(jpeg_times, stage_times, stage_zs)
|
jpeg_zs = np.interp(jpeg_times, stage_times, stage_zs)
|
||||||
return jpeg_times, jpeg_zs, jpeg_sizes[start:stop]
|
return jpeg_times, jpeg_zs, jpeg_sizes[start:stop]
|
||||||
|
|
@ -258,13 +258,12 @@ def fast_up_down_up_autofocus(
|
||||||
# Ensure the MJPEG stream has started
|
# Ensure the MJPEG stream has started
|
||||||
microscope.camera.start_stream_recording()
|
microscope.camera.start_stream_recording()
|
||||||
|
|
||||||
df = dz # TODO: refactor so I actually use dz in the code below!
|
|
||||||
logging.debug("Initial move")
|
logging.debug("Initial move")
|
||||||
if initial_move_up:
|
if initial_move_up:
|
||||||
m.focus_rel(df / 2)
|
m.focus_rel(dz / 2)
|
||||||
# move down
|
# move down
|
||||||
logging.debug("Move down")
|
logging.debug("Move down")
|
||||||
i, z = m.focus_rel(-df)
|
i, z = m.focus_rel(-dz)
|
||||||
# now inspect where the sharpest point is, and estimate the sharpness
|
# now inspect where the sharpest point is, and estimate the sharpness
|
||||||
# (JPEG size) that we should find at the start of the Z stack
|
# (JPEG size) that we should find at the start of the Z stack
|
||||||
_, jz, js = m.move_data(i)
|
_, jz, js = m.move_data(i)
|
||||||
|
|
@ -285,14 +284,13 @@ def fast_up_down_up_autofocus(
|
||||||
inow = np.argmax(
|
inow = np.argmax(
|
||||||
js < current_js
|
js < current_js
|
||||||
) # use the curve we recorded to estimate our position
|
) # use the curve we recorded to estimate our position
|
||||||
# TODO: fancy interpolation stuff
|
|
||||||
|
|
||||||
# So, the Z position corresponding to our current sharpness value is zs[inow]
|
# So, the Z position corresponding to our current sharpness value is zs[inow]
|
||||||
# That means we should move forwards, by best_z - zs[inow]
|
# That means we should move forwards, by best_z - zs[inow]
|
||||||
logging.debug("Correction move")
|
logging.debug("Correction move")
|
||||||
correction_move = best_z + target_z - jz[inow]
|
correction_move = best_z + target_z - jz[inow]
|
||||||
logging.debug(
|
logging.debug(
|
||||||
"Fast autofocus scan: correcting backlash by moving {} steps",
|
"Fast autofocus scan: correcting backlash by moving %s steps",
|
||||||
(correction_move),
|
(correction_move),
|
||||||
)
|
)
|
||||||
m.focus_rel(correction_move)
|
m.focus_rel(correction_move)
|
||||||
|
|
|
||||||
|
|
@ -95,10 +95,10 @@ class AutostorageExtension(BaseExtension):
|
||||||
|
|
||||||
def on_microscope(self, microscope_obj):
|
def on_microscope(self, microscope_obj):
|
||||||
"""Function to automatically call when the parent LabThing has a microscope attached."""
|
"""Function to automatically call when the parent LabThing has a microscope attached."""
|
||||||
logging.debug("Autostorage extension found microscope {}", microscope_obj)
|
logging.debug("Autostorage extension found microscope %s", microscope_obj)
|
||||||
if hasattr(microscope_obj, "captures"):
|
if hasattr(microscope_obj, "captures"):
|
||||||
logging.debug(
|
logging.debug(
|
||||||
"Autostorage extension bound to CaptureManager {}", self.capture_manager
|
"Autostorage extension bound to CaptureManager %s", self.capture_manager
|
||||||
)
|
)
|
||||||
|
|
||||||
# Store a reference to the CaptureManager
|
# Store a reference to the CaptureManager
|
||||||
|
|
@ -117,7 +117,7 @@ class AutostorageExtension(BaseExtension):
|
||||||
# If preferred path does not exist, or cannot be written to
|
# If preferred path does not exist, or cannot be written to
|
||||||
if not (os.path.isdir(location) and check_rw(location)):
|
if not (os.path.isdir(location) and check_rw(location)):
|
||||||
logging.error(
|
logging.error(
|
||||||
"Preferred capture path {} is missing or cannot be written to. Restoring defaults.",
|
"Preferred capture path %s is missing or cannot be written to. Restoring defaults.",
|
||||||
location,
|
location,
|
||||||
)
|
)
|
||||||
# Reset the storage location to default
|
# Reset the storage location to default
|
||||||
|
|
|
||||||
|
|
@ -63,15 +63,15 @@ def auto_expose_and_freeze_settings(camera):
|
||||||
|
|
||||||
logging.info("Freezing the camera settings...")
|
logging.info("Freezing the camera settings...")
|
||||||
camera.shutter_speed = camera.exposure_speed
|
camera.shutter_speed = camera.exposure_speed
|
||||||
logging.info("Shutter speed = {}", (camera.shutter_speed))
|
logging.info("Shutter speed = %s", (camera.shutter_speed))
|
||||||
camera.exposure_mode = "off"
|
camera.exposure_mode = "off"
|
||||||
logging.info("Auto exposure disabled")
|
logging.info("Auto exposure disabled")
|
||||||
g = camera.awb_gains
|
g = camera.awb_gains
|
||||||
camera.awb_mode = "off"
|
camera.awb_mode = "off"
|
||||||
camera.awb_gains = g
|
camera.awb_gains = g
|
||||||
logging.info("Auto white balance disabled, gains are {}", (g))
|
logging.info("Auto white balance disabled, gains are %s", (g))
|
||||||
logging.info(
|
logging.info(
|
||||||
"Analogue gain: {}, Digital gain: {}", camera.analog_gain, camera.digital_gain
|
"Analogue gain: %s, Digital gain: %s", camera.analog_gain, camera.digital_gain
|
||||||
)
|
)
|
||||||
adjust_exposure_to_setpoint(camera, 215)
|
adjust_exposure_to_setpoint(camera, 215)
|
||||||
|
|
||||||
|
|
@ -98,7 +98,7 @@ def lst_from_channels(channels):
|
||||||
# lst_resolution = list(np.ceil(full_resolution / 64.0).astype(int))
|
# lst_resolution = list(np.ceil(full_resolution / 64.0).astype(int))
|
||||||
lst_resolution = [(r // 64) + 1 for r in full_resolution]
|
lst_resolution = [(r // 64) + 1 for r in full_resolution]
|
||||||
# NB the size of the LST is 1/64th of the image, but rounded UP.
|
# NB the size of the LST is 1/64th of the image, but rounded UP.
|
||||||
logging.info("Generating a lens shading table at {}x{}", *lst_resolution)
|
logging.info("Generating a lens shading table at %sx%s", *lst_resolution)
|
||||||
lens_shading = np.zeros([channels.shape[0]] + lst_resolution, dtype=np.float)
|
lens_shading = np.zeros([channels.shape[0]] + lst_resolution, dtype=np.float)
|
||||||
for i in range(lens_shading.shape[0]):
|
for i in range(lens_shading.shape[0]):
|
||||||
image_channel = channels[i, :, :]
|
image_channel = channels[i, :, :]
|
||||||
|
|
@ -116,7 +116,7 @@ def lst_from_channels(channels):
|
||||||
image_channel, [(0, lw * 32 - iw), (0, lh * 32 - ih)], mode="edge"
|
image_channel, [(0, lw * 32 - iw), (0, lh * 32 - ih)], mode="edge"
|
||||||
) # Pad image to the right and bottom
|
) # Pad image to the right and bottom
|
||||||
logging.info(
|
logging.info(
|
||||||
"Channel shape: {}x{}, shading table shape: {}x{}, after padding {}",
|
"Channel shape: %sx%s, shading table shape: %sx%s, after padding %s",
|
||||||
iw,
|
iw,
|
||||||
ih,
|
ih,
|
||||||
lw * 32,
|
lw * 32,
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,7 @@ class ScanExtension(BaseExtension):
|
||||||
|
|
||||||
for x_y in line:
|
for x_y in line:
|
||||||
# Move to new grid position without changing z
|
# Move to new grid position without changing z
|
||||||
logging.debug("Moving to step {}", ([x_y[0], x_y[1], next_z]))
|
logging.debug("Moving to step %s", ([x_y[0], x_y[1], next_z]))
|
||||||
microscope.stage.move_abs([x_y[0], x_y[1], next_z])
|
microscope.stage.move_abs([x_y[0], x_y[1], next_z])
|
||||||
# Refocus
|
# Refocus
|
||||||
if autofocus_enabled:
|
if autofocus_enabled:
|
||||||
|
|
@ -270,11 +270,11 @@ class ScanExtension(BaseExtension):
|
||||||
# Make sure we use our current best estimate of focus (i.e. the current position) next point
|
# Make sure we use our current best estimate of focus (i.e. the current position) next point
|
||||||
next_z = microscope.stage.position[2]
|
next_z = microscope.stage.position[2]
|
||||||
|
|
||||||
logging.debug("Returning to {}", (initial_position))
|
logging.debug("Returning to %s", (initial_position))
|
||||||
microscope.stage.move_abs(initial_position)
|
microscope.stage.move_abs(initial_position)
|
||||||
|
|
||||||
end = time.time()
|
end = time.time()
|
||||||
logging.info("Scan took {} seconds", end - start)
|
logging.info("Scan took %s seconds", end - start)
|
||||||
|
|
||||||
def stack(
|
def stack(
|
||||||
self,
|
self,
|
||||||
|
|
@ -298,17 +298,17 @@ class ScanExtension(BaseExtension):
|
||||||
|
|
||||||
# Store initial position
|
# Store initial position
|
||||||
initial_position = microscope.stage.position
|
initial_position = microscope.stage.position
|
||||||
logging.debug("Starting z-stack from position {}", microscope.stage.position)
|
logging.debug("Starting z-stack from position %s", microscope.stage.position)
|
||||||
|
|
||||||
with microscope.lock:
|
with microscope.lock:
|
||||||
# Move to center scan
|
# Move to center scan
|
||||||
logging.debug("Moving to z-stack starting position")
|
logging.debug("Moving to z-stack starting position")
|
||||||
microscope.stage.move_rel([0, 0, int((-step_size * steps) / 2)])
|
microscope.stage.move_rel([0, 0, int((-step_size * steps) / 2)])
|
||||||
logging.debug("Starting scan from position {}", microscope.stage.position)
|
logging.debug("Starting scan from position %s", microscope.stage.position)
|
||||||
|
|
||||||
for i in range(steps):
|
for i in range(steps):
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
logging.debug("Capturing from position {}", microscope.stage.position)
|
logging.debug("Capturing from position %s", microscope.stage.position)
|
||||||
self.capture(
|
self.capture(
|
||||||
microscope,
|
microscope,
|
||||||
basename,
|
basename,
|
||||||
|
|
@ -328,10 +328,10 @@ class ScanExtension(BaseExtension):
|
||||||
return
|
return
|
||||||
|
|
||||||
if i != steps - 1:
|
if i != steps - 1:
|
||||||
logging.debug("Moving z by {}", (step_size))
|
logging.debug("Moving z by %s", (step_size))
|
||||||
microscope.stage.move_rel([0, 0, step_size])
|
microscope.stage.move_rel([0, 0, step_size])
|
||||||
if return_to_start:
|
if return_to_start:
|
||||||
logging.debug("Returning to {}", (initial_position))
|
logging.debug("Returning to %s", (initial_position))
|
||||||
microscope.stage.move_abs(initial_position)
|
microscope.stage.move_abs(initial_position)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ class ZipGetterAPIView(View):
|
||||||
if not session_id in default_zip_manager.session_zips:
|
if not session_id in default_zip_manager.session_zips:
|
||||||
return abort(404) # 404 Not Found
|
return abort(404) # 404 Not Found
|
||||||
|
|
||||||
logging.info("Session ID: {}", session_id)
|
logging.info("Session ID: %s", session_id)
|
||||||
|
|
||||||
return send_file(
|
return send_file(
|
||||||
default_zip_manager.zip_fp_from_id(session_id).name,
|
default_zip_manager.zip_fp_from_id(session_id).name,
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class SleepFor(ActionView):
|
||||||
|
|
||||||
def post(self, args):
|
def post(self, args):
|
||||||
sleep_time = args.get("time")
|
sleep_time = args.get("time")
|
||||||
logging.info("Going to sleep for {}...", sleep_time)
|
logging.info("Going to sleep for %s...", sleep_time)
|
||||||
start = time.time()
|
start = time.time()
|
||||||
time.sleep(sleep_time)
|
time.sleep(sleep_time)
|
||||||
end = time.time()
|
end = time.time()
|
||||||
|
|
|
||||||
|
|
@ -73,10 +73,10 @@ def init_default_extensions(extension_dir):
|
||||||
default_ext_path = os.path.join(extension_dir, "defaults.py")
|
default_ext_path = os.path.join(extension_dir, "defaults.py")
|
||||||
|
|
||||||
if not os.path.isfile(default_ext_path): # If user extensions file doesn't exist
|
if not os.path.isfile(default_ext_path): # If user extensions file doesn't exist
|
||||||
logging.warning("No extension file found at {}. Creating...", (extension_dir))
|
logging.warning("No extension file found at %s. Creating...", (extension_dir))
|
||||||
create_file(default_ext_path)
|
create_file(default_ext_path)
|
||||||
|
|
||||||
logging.info("Populating {}...", (default_ext_path))
|
logging.info("Populating %s...", (default_ext_path))
|
||||||
with open(default_ext_path, "w") as outfile:
|
with open(default_ext_path, "w") as outfile:
|
||||||
outfile.write(_DEFAULT_EXTENSION_INIT)
|
outfile.write(_DEFAULT_EXTENSION_INIT)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ def build_gui_from_dict(gui_description, extension_object):
|
||||||
if "route" in form and form["route"] in ext_rules.keys():
|
if "route" in form and form["route"] in ext_rules.keys():
|
||||||
form["route"] = ext_rules[form["route"]]["urls"][0]
|
form["route"] = ext_rules[form["route"]]["urls"][0]
|
||||||
else:
|
else:
|
||||||
logging.warning("No valid expandable route found for {}", form["route"])
|
logging.warning("No valid expandable route found for %s", form["route"])
|
||||||
|
|
||||||
# Inject extension information
|
# Inject extension information
|
||||||
api_gui["id"] = extension_object.name
|
api_gui["id"] = extension_object.name
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,11 @@ class MoveStageAPI(ActionView):
|
||||||
# Handle absolute positioning (calculate a relative move from current position and target)
|
# Handle absolute positioning (calculate a relative move from current position and target)
|
||||||
if (args.get("absolute")) and (microscope.stage): # Only if stage exists
|
if (args.get("absolute")) and (microscope.stage): # Only if stage exists
|
||||||
target_position = axes_to_array(args, ["x", "y", "z"])
|
target_position = axes_to_array(args, ["x", "y", "z"])
|
||||||
logging.debug("TARGET: {}", (target_position))
|
logging.debug("TARGET: %s", (target_position))
|
||||||
position = [
|
position = [
|
||||||
target_position[i] - microscope.stage.position[i] for i in range(3)
|
target_position[i] - microscope.stage.position[i] for i in range(3)
|
||||||
]
|
]
|
||||||
logging.debug("DELTA: {}", (position))
|
logging.debug("DELTA: %s", (position))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Get coordinates from payload
|
# Get coordinates from payload
|
||||||
|
|
|
||||||
|
|
@ -113,10 +113,10 @@ class BaseCamera(metaclass=ABCMeta):
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""Close the BaseCamera and all attached StreamObjects."""
|
"""Close the BaseCamera and all attached StreamObjects."""
|
||||||
logging.info("Closing {}", (self))
|
logging.info("Closing %s", (self))
|
||||||
# Stop worker thread
|
# Stop worker thread
|
||||||
self.stop_worker()
|
self.stop_worker()
|
||||||
logging.info("Closed {}", (self))
|
logging.info("Closed %s", (self))
|
||||||
|
|
||||||
# START AND STOP WORKER THREAD
|
# START AND STOP WORKER THREAD
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -156,10 +156,10 @@ class PiCameraStreamer(BaseCamera):
|
||||||
for key in PiCameraStreamer.picamera_settings_keys:
|
for key in PiCameraStreamer.picamera_settings_keys:
|
||||||
try:
|
try:
|
||||||
value = getattr(self.camera, key)
|
value = getattr(self.camera, key)
|
||||||
logging.debug("Reading PiCamera().{}: {}", key, value)
|
logging.debug("Reading PiCamera().%s: %s", key, value)
|
||||||
conf_dict["picamera"][key] = value
|
conf_dict["picamera"][key] = value
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
logging.debug("Unable to read PiCamera attribute {}", (key))
|
logging.debug("Unable to read PiCamera attribute %s", (key))
|
||||||
|
|
||||||
# Include a serialised lens shading table
|
# Include a serialised lens shading table
|
||||||
if (
|
if (
|
||||||
|
|
@ -243,22 +243,22 @@ class PiCameraStreamer(BaseCamera):
|
||||||
# Set exposure mode
|
# Set exposure mode
|
||||||
if "exposure_mode" in settings_dict:
|
if "exposure_mode" in settings_dict:
|
||||||
logging.debug(
|
logging.debug(
|
||||||
"Applying exposure_mode: {}", (settings_dict["exposure_mode"])
|
"Applying exposure_mode: %s", (settings_dict["exposure_mode"])
|
||||||
)
|
)
|
||||||
self.camera.exposure_mode = settings_dict["exposure_mode"]
|
self.camera.exposure_mode = settings_dict["exposure_mode"]
|
||||||
|
|
||||||
# Apply gains and let them settle
|
# Apply gains and let them settle
|
||||||
if "analog_gain" in settings_dict:
|
if "analog_gain" in settings_dict:
|
||||||
logging.debug("Applying analog_gain: {}", (settings_dict["analog_gain"]))
|
logging.debug("Applying analog_gain: %s", (settings_dict["analog_gain"]))
|
||||||
set_analog_gain(self.camera, float(settings_dict["analog_gain"]))
|
set_analog_gain(self.camera, float(settings_dict["analog_gain"]))
|
||||||
if "digital_gain" in settings_dict:
|
if "digital_gain" in settings_dict:
|
||||||
logging.debug("Applying digital_gain: {}", (settings_dict["digital_gain"]))
|
logging.debug("Applying digital_gain: %s", (settings_dict["digital_gain"]))
|
||||||
set_digital_gain(self.camera, float(settings_dict["digital_gain"]))
|
set_digital_gain(self.camera, float(settings_dict["digital_gain"]))
|
||||||
|
|
||||||
# Apply shutter speed
|
# Apply shutter speed
|
||||||
if "shutter_speed" in settings_dict:
|
if "shutter_speed" in settings_dict:
|
||||||
logging.debug(
|
logging.debug(
|
||||||
"Applying shutter_speed: {}", (settings_dict["shutter_speed"])
|
"Applying shutter_speed: %s", (settings_dict["shutter_speed"])
|
||||||
)
|
)
|
||||||
self.camera.shutter_speed = int(settings_dict["shutter_speed"])
|
self.camera.shutter_speed = int(settings_dict["shutter_speed"])
|
||||||
|
|
||||||
|
|
@ -268,17 +268,17 @@ class PiCameraStreamer(BaseCamera):
|
||||||
if "awb_gains" in settings_dict:
|
if "awb_gains" in settings_dict:
|
||||||
logging.debug("Applying awb_mode: off")
|
logging.debug("Applying awb_mode: off")
|
||||||
self.camera.awb_mode = "off"
|
self.camera.awb_mode = "off"
|
||||||
logging.debug("Applying awb_gains: {}", (settings_dict["awb_gains"]))
|
logging.debug("Applying awb_gains: %s", (settings_dict["awb_gains"]))
|
||||||
self.camera.awb_gains = settings_dict["awb_gains"]
|
self.camera.awb_gains = settings_dict["awb_gains"]
|
||||||
elif "awb_mode" in settings_dict:
|
elif "awb_mode" in settings_dict:
|
||||||
logging.debug("Applying awb_mode: {}", (settings_dict["awb_mode"]))
|
logging.debug("Applying awb_mode: %s", (settings_dict["awb_mode"]))
|
||||||
self.camera.awb_mode = settings_dict["awb_mode"]
|
self.camera.awb_mode = settings_dict["awb_mode"]
|
||||||
|
|
||||||
# Handle some properties that can be quickly applied
|
# Handle some properties that can be quickly applied
|
||||||
batched_keys = ["framerate", "saturation"]
|
batched_keys = ["framerate", "saturation"]
|
||||||
for key in batched_keys:
|
for key in batched_keys:
|
||||||
if (key in settings_dict) and hasattr(self.camera, key):
|
if (key in settings_dict) and hasattr(self.camera, key):
|
||||||
logging.debug("Applying {}: {}", key, settings_dict[key])
|
logging.debug("Applying %s: %s", key, settings_dict[key])
|
||||||
setattr(self.camera, key, settings_dict[key])
|
setattr(self.camera, key, settings_dict[key])
|
||||||
|
|
||||||
# Final optional pause to settle
|
# Final optional pause to settle
|
||||||
|
|
@ -303,7 +303,7 @@ class PiCameraStreamer(BaseCamera):
|
||||||
for i in range(2):
|
for i in range(2):
|
||||||
if np.abs(centre[i] - 0.5) + size / 2 > 0.5:
|
if np.abs(centre[i] - 0.5) + size / 2 > 0.5:
|
||||||
centre[i] = 0.5 + (1.0 - size) / 2 * np.sign(centre[i] - 0.5)
|
centre[i] = 0.5 + (1.0 - size) / 2 * np.sign(centre[i] - 0.5)
|
||||||
logging.info("setting zoom, centre {}, size {}", centre, size)
|
logging.info("setting zoom, centre %s, size %s", centre, size)
|
||||||
new_fov = (centre[0] - size / 2, centre[1] - size / 2, size, size)
|
new_fov = (centre[0] - size / 2, centre[1] - size / 2, size, size)
|
||||||
self.camera.zoom = new_fov
|
self.camera.zoom = new_fov
|
||||||
|
|
||||||
|
|
@ -325,11 +325,11 @@ class PiCameraStreamer(BaseCamera):
|
||||||
self.preview_active = True
|
self.preview_active = True
|
||||||
except picamerax.exc.PiCameraMMALError as e:
|
except picamerax.exc.PiCameraMMALError as e:
|
||||||
logging.error(
|
logging.error(
|
||||||
"Suppressed a MMALError in start_preview. Exception: {}", (e)
|
"Suppressed a MMALError in start_preview. Exception: %s", (e)
|
||||||
)
|
)
|
||||||
except picamerax.exc.PiCameraValueError as e:
|
except picamerax.exc.PiCameraValueError as e:
|
||||||
logging.error(
|
logging.error(
|
||||||
"Suppressed a ValueError exception in start_preview. Exception: {}",
|
"Suppressed a ValueError exception in start_preview. Exception: %s",
|
||||||
(e),
|
(e),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -359,7 +359,7 @@ class PiCameraStreamer(BaseCamera):
|
||||||
if not self.record_active:
|
if not self.record_active:
|
||||||
|
|
||||||
# Start the camera video recording on port 2
|
# Start the camera video recording on port 2
|
||||||
logging.info("Recording to {}", (output))
|
logging.info("Recording to %s", (output))
|
||||||
|
|
||||||
self.camera.start_recording(
|
self.camera.start_recording(
|
||||||
output,
|
output,
|
||||||
|
|
@ -401,17 +401,17 @@ class PiCameraStreamer(BaseCamera):
|
||||||
"""
|
"""
|
||||||
for k in kwargs.keys():
|
for k in kwargs.keys():
|
||||||
logging.warning(
|
logging.warning(
|
||||||
"Warning, kwarg {} is invalid for stop_stream_recording.", k
|
"Warning, kwarg %s is invalid for stop_stream_recording.", k
|
||||||
)
|
)
|
||||||
with self.lock:
|
with self.lock:
|
||||||
# Stop the camera video recording on port 1
|
# Stop the camera video recording on port 1
|
||||||
try:
|
try:
|
||||||
self.camera.stop_recording(splitter_port=splitter_port)
|
self.camera.stop_recording(splitter_port=splitter_port)
|
||||||
except picamerax.exc.PiCameraNotRecording:
|
except picamerax.exc.PiCameraNotRecording:
|
||||||
logging.info("Not recording on splitter_port {}", (splitter_port))
|
logging.info("Not recording on splitter_port %s", (splitter_port))
|
||||||
else:
|
else:
|
||||||
logging.info(
|
logging.info(
|
||||||
"Stopped MJPEG stream on port {}. Switching to {}.",
|
"Stopped MJPEG stream on port %s. Switching to %s.",
|
||||||
splitter_port,
|
splitter_port,
|
||||||
self.image_resolution,
|
self.image_resolution,
|
||||||
)
|
)
|
||||||
|
|
@ -431,7 +431,7 @@ class PiCameraStreamer(BaseCamera):
|
||||||
"""
|
"""
|
||||||
for k in kwargs.keys():
|
for k in kwargs.keys():
|
||||||
logging.warning(
|
logging.warning(
|
||||||
"Warning, kwarg {} is invalid for stop_stream_recording.", k
|
"Warning, kwarg %s is invalid for stop_stream_recording.", k
|
||||||
)
|
)
|
||||||
with self.lock(timeout=None):
|
with self.lock(timeout=None):
|
||||||
# Reduce the resolution for video streaming
|
# Reduce the resolution for video streaming
|
||||||
|
|
@ -465,7 +465,7 @@ class PiCameraStreamer(BaseCamera):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logging.debug(
|
logging.debug(
|
||||||
"Started MJPEG stream at {} on port {}",
|
"Started MJPEG stream at %s on port %s",
|
||||||
self.stream_resolution,
|
self.stream_resolution,
|
||||||
splitter_port,
|
splitter_port,
|
||||||
)
|
)
|
||||||
|
|
@ -496,7 +496,7 @@ class PiCameraStreamer(BaseCamera):
|
||||||
output_object (str/BytesIO): Target object.
|
output_object (str/BytesIO): Target object.
|
||||||
"""
|
"""
|
||||||
with self.lock:
|
with self.lock:
|
||||||
logging.info("Capturing to {}", (output))
|
logging.info("Capturing to %s", (output))
|
||||||
|
|
||||||
# Set resolution and stop stream recording if necessary
|
# Set resolution and stop stream recording if necessary
|
||||||
if not use_video_port:
|
if not use_video_port:
|
||||||
|
|
@ -532,7 +532,7 @@ class PiCameraStreamer(BaseCamera):
|
||||||
logging.debug("Creating PiRGBArray")
|
logging.debug("Creating PiRGBArray")
|
||||||
with picamerax.array.PiRGBArray(self.camera) as output:
|
with picamerax.array.PiRGBArray(self.camera) as output:
|
||||||
|
|
||||||
logging.info("Capturing to {}", (output))
|
logging.info("Capturing to %s", (output))
|
||||||
|
|
||||||
self.camera.capture(output, format="rgb", use_video_port=True)
|
self.camera.capture(output, format="rgb", use_video_port=True)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ if __name__ == "__main__":
|
||||||
# fix the shutter speed
|
# fix the shutter speed
|
||||||
cam.shutter_speed = cam.exposure_speed
|
cam.shutter_speed = cam.exposure_speed
|
||||||
|
|
||||||
logging.info("Current a/d gains: {}, {}", cam.analog_gain, cam.digital_gain)
|
logging.info("Current a/d gains: %s, %s", cam.analog_gain, cam.digital_gain)
|
||||||
|
|
||||||
logging.info("Attempting to set analogue gain to 1")
|
logging.info("Attempting to set analogue gain to 1")
|
||||||
set_analog_gain(cam, 1)
|
set_analog_gain(cam, 1)
|
||||||
|
|
@ -65,7 +65,7 @@ if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
logging.info(
|
logging.info(
|
||||||
"Current a/d gains: {}, {}", cam.analog_gain, cam.digital_gain
|
"Current a/d gains: %s, %s", cam.analog_gain, cam.digital_gain
|
||||||
)
|
)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|
|
||||||
|
|
@ -25,23 +25,23 @@ def make_file_list(directory, formats):
|
||||||
glob.glob("{}/**/*.{}".format(directory, fmt.lower()), recursive=True)
|
glob.glob("{}/**/*.{}".format(directory, fmt.lower()), recursive=True)
|
||||||
)
|
)
|
||||||
|
|
||||||
logging.info("{} capture files found on disk", (len(files)))
|
logging.info("%s capture files found on disk", (len(files)))
|
||||||
|
|
||||||
return files
|
return files
|
||||||
|
|
||||||
|
|
||||||
def build_captures_from_exif(capture_path):
|
def build_captures_from_exif(capture_path):
|
||||||
logging.debug("Reloading captures from {}...", (capture_path))
|
logging.debug("Reloading captures from %s...", (capture_path))
|
||||||
files = make_file_list(capture_path, EXIF_FORMATS)
|
files = make_file_list(capture_path, EXIF_FORMATS)
|
||||||
captures = OrderedDict()
|
captures = OrderedDict()
|
||||||
|
|
||||||
for f in files:
|
for f in files:
|
||||||
logging.debug("Reloading capture {}...", (f))
|
logging.debug("Reloading capture %s...", (f))
|
||||||
capture = capture_from_path(f)
|
capture = capture_from_path(f)
|
||||||
if capture:
|
if capture:
|
||||||
captures[capture.id] = capture
|
captures[capture.id] = capture
|
||||||
|
|
||||||
logging.info("{} capture files successfully reloaded", (len(captures)))
|
logging.info("%s capture files successfully reloaded", (len(captures)))
|
||||||
|
|
||||||
return captures
|
return captures
|
||||||
|
|
||||||
|
|
@ -58,7 +58,7 @@ def capture_from_path(path):
|
||||||
capture.sync_basic_metadata()
|
capture.sync_basic_metadata()
|
||||||
return capture
|
return capture
|
||||||
except (InvalidImageDataError, json.decoder.JSONDecodeError):
|
except (InvalidImageDataError, json.decoder.JSONDecodeError):
|
||||||
logging.error("Invalid metadata at {}.", (path))
|
logging.error("Invalid metadata at %s.", (path))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -75,7 +75,7 @@ class CaptureObject(object):
|
||||||
|
|
||||||
# Store a nice ID
|
# Store a nice ID
|
||||||
self.id = uuid.uuid4() #: str: Unique capture ID
|
self.id = uuid.uuid4() #: str: Unique capture ID
|
||||||
logging.debug("Created CaptureObject {}", (self.id))
|
logging.debug("Created CaptureObject %s", (self.id))
|
||||||
|
|
||||||
self.time = datetime.datetime.now()
|
self.time = datetime.datetime.now()
|
||||||
|
|
||||||
|
|
@ -97,17 +97,17 @@ class CaptureObject(object):
|
||||||
self.tags = []
|
self.tags = []
|
||||||
|
|
||||||
def write(self, s):
|
def write(self, s):
|
||||||
logging.debug("Writing to {}", self)
|
logging.debug("Writing to %s", self)
|
||||||
self.stream.write(s)
|
self.stream.write(s)
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
logging.info("Writing image data to disk {}", self.file)
|
logging.info("Writing image data to disk %s", self.file)
|
||||||
with open(self.file, "wb") as outfile:
|
with open(self.file, "wb") as outfile:
|
||||||
outfile.write(self.stream.getbuffer())
|
outfile.write(self.stream.getbuffer())
|
||||||
self.stream.close()
|
self.stream.close()
|
||||||
logging.info("Writing metadata to disk {}", self.file)
|
logging.info("Writing metadata to disk %s", self.file)
|
||||||
self._init_metadata()
|
self._init_metadata()
|
||||||
logging.info("Finished writing to disk {}", self.file)
|
logging.info("Finished writing to disk %s", self.file)
|
||||||
|
|
||||||
def open(self, mode):
|
def open(self, mode):
|
||||||
return open(self.file, mode)
|
return open(self.file, mode)
|
||||||
|
|
@ -175,7 +175,7 @@ class CaptureObject(object):
|
||||||
}
|
}
|
||||||
|
|
||||||
def read_full_metadata(self):
|
def read_full_metadata(self):
|
||||||
logging.info("Reading full capture metadata from {}...", self.file)
|
logging.info("Reading full capture metadata from %s...", self.file)
|
||||||
exif_dict = self._read_exif()
|
exif_dict = self._read_exif()
|
||||||
return self._decode_usercomment(exif_dict)
|
return self._decode_usercomment(exif_dict)
|
||||||
|
|
||||||
|
|
@ -271,7 +271,7 @@ class CaptureObject(object):
|
||||||
|
|
||||||
# Write new data to file EXIF, if supported
|
# Write new data to file EXIF, if supported
|
||||||
if self.format.upper() in EXIF_FORMATS and self.exists:
|
if self.format.upper() in EXIF_FORMATS and self.exists:
|
||||||
logging.info("Writing Exif data to {}", self.file)
|
logging.info("Writing Exif data to %s", self.file)
|
||||||
|
|
||||||
# Extract current Exif data
|
# Extract current Exif data
|
||||||
exif_dict = self._read_exif()
|
exif_dict = self._read_exif()
|
||||||
|
|
@ -286,7 +286,7 @@ class CaptureObject(object):
|
||||||
|
|
||||||
# Serialize metadata
|
# Serialize metadata
|
||||||
metadata_string = json.dumps(metadata_dict, cls=JSONEncoder)
|
metadata_string = json.dumps(metadata_dict, cls=JSONEncoder)
|
||||||
logging.debug("Saving metadata string to file: {}", metadata_string)
|
logging.debug("Saving metadata string to file: %s", metadata_string)
|
||||||
|
|
||||||
# Insert metadata into exif_dict
|
# Insert metadata into exif_dict
|
||||||
exif_dict["Exif"][piexif.ExifIFD.UserComment] = metadata_string.encode()
|
exif_dict["Exif"][piexif.ExifIFD.UserComment] = metadata_string.encode()
|
||||||
|
|
@ -296,7 +296,7 @@ class CaptureObject(object):
|
||||||
|
|
||||||
# Insert exif into file
|
# Insert exif into file
|
||||||
piexif.insert(exif_bytes, self.file)
|
piexif.insert(exif_bytes, self.file)
|
||||||
logging.info("Finished writing Exif data to {}", self.file)
|
logging.info("Finished writing Exif data to %s", self.file)
|
||||||
|
|
||||||
# PROPERTIES
|
# PROPERTIES
|
||||||
|
|
||||||
|
|
@ -316,7 +316,7 @@ class CaptureObject(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.exists: # If data file exists
|
if self.exists: # If data file exists
|
||||||
logging.info("Opening from file {}", (self.file))
|
logging.info("Opening from file %s", (self.file))
|
||||||
with open(self.file, "rb") as f:
|
with open(self.file, "rb") as f:
|
||||||
d = io.BytesIO(f.read()) # Load bytes from file
|
d = io.BytesIO(f.read()) # Load bytes from file
|
||||||
d.seek(0) # Rewind loaded bytestream
|
d.seek(0) # Rewind loaded bytestream
|
||||||
|
|
@ -364,7 +364,7 @@ class CaptureObject(object):
|
||||||
"""If the StreamObject has been saved, delete the file."""
|
"""If the StreamObject has been saved, delete the file."""
|
||||||
|
|
||||||
if os.path.isfile(self.file):
|
if os.path.isfile(self.file):
|
||||||
logging.info("Deleting file {}", (self.file))
|
logging.info("Deleting file %s", (self.file))
|
||||||
os.remove(self.file)
|
os.remove(self.file)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ class CaptureManager:
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
logging.info("Closing {}", (self))
|
logging.info("Closing %s", (self))
|
||||||
# Close all StreamObjects
|
# Close all StreamObjects
|
||||||
for capture_list in [self.images.values(), self.videos.values()]:
|
for capture_list in [self.images.values(), self.videos.values()]:
|
||||||
for stream_object in capture_list:
|
for stream_object in capture_list:
|
||||||
|
|
@ -75,9 +75,9 @@ class CaptureManager:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if os.path.isdir(self.paths["temp"]):
|
if os.path.isdir(self.paths["temp"]):
|
||||||
logging.info("Clearing {}...", (self.paths["temp"]))
|
logging.info("Clearing %s...", (self.paths["temp"]))
|
||||||
shutil.rmtree(self.paths["temp"])
|
shutil.rmtree(self.paths["temp"])
|
||||||
logging.debug("Cleared {}.", (self.paths["temp"]))
|
logging.debug("Cleared %s.", (self.paths["temp"]))
|
||||||
|
|
||||||
def rebuild_captures(self):
|
def rebuild_captures(self):
|
||||||
self.images = build_captures_from_exif(self.paths["default"])
|
self.images = build_captures_from_exif(self.paths["default"])
|
||||||
|
|
@ -158,7 +158,7 @@ class CaptureManager:
|
||||||
|
|
||||||
# Update capture list
|
# Update capture list
|
||||||
capture_key = str(output.id)
|
capture_key = str(output.id)
|
||||||
logging.debug("Adding image {} with key {}", output, capture_key)
|
logging.debug("Adding image %s with key %s", output, capture_key)
|
||||||
|
|
||||||
self.images[capture_key] = output
|
self.images[capture_key] = output
|
||||||
|
|
||||||
|
|
@ -205,7 +205,7 @@ class CaptureManager:
|
||||||
|
|
||||||
# Update capture list
|
# Update capture list
|
||||||
capture_key = str(output.id)
|
capture_key = str(output.id)
|
||||||
logging.debug("Adding video {} with key {}", output, capture_key)
|
logging.debug("Adding video %s with key %s", output, capture_key)
|
||||||
self.videos[capture_key] = output
|
self.videos[capture_key] = output
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ def load_json_file(config_path) -> dict:
|
||||||
"""
|
"""
|
||||||
config_path = os.path.expanduser(config_path)
|
config_path = os.path.expanduser(config_path)
|
||||||
|
|
||||||
logging.info("Loading {}...", config_path)
|
logging.info("Loading %s...", config_path)
|
||||||
|
|
||||||
with open(config_path) as config_file:
|
with open(config_path) as config_file:
|
||||||
try:
|
try:
|
||||||
|
|
@ -109,7 +109,7 @@ def save_json_file(config_path: str, config_dict: dict):
|
||||||
"""
|
"""
|
||||||
config_path = os.path.expanduser(config_path)
|
config_path = os.path.expanduser(config_path)
|
||||||
|
|
||||||
logging.info("Saving {}...", config_path)
|
logging.info("Saving %s...", config_path)
|
||||||
logging.debug(config_dict)
|
logging.debug(config_dict)
|
||||||
|
|
||||||
with open(config_path, "w") as outfile:
|
with open(config_path, "w") as outfile:
|
||||||
|
|
@ -142,14 +142,14 @@ def initialise_file(config_path, populate: str = "{}\n"):
|
||||||
"""
|
"""
|
||||||
config_path = os.path.expanduser(config_path)
|
config_path = os.path.expanduser(config_path)
|
||||||
|
|
||||||
logging.debug("Initialising {}", (config_path))
|
logging.debug("Initialising %s", (config_path))
|
||||||
logging.debug("Exists: {}", (os.path.exists(config_path)))
|
logging.debug("Exists: %s", (os.path.exists(config_path)))
|
||||||
|
|
||||||
if not os.path.exists(config_path): # If user config file doesn't exist
|
if not os.path.exists(config_path): # If user config file doesn't exist
|
||||||
logging.warning("No config file found at {}. Creating...", (config_path))
|
logging.warning("No config file found at %s. Creating...", (config_path))
|
||||||
create_file(config_path)
|
create_file(config_path)
|
||||||
|
|
||||||
logging.info("Populating {}...", (config_path))
|
logging.info("Populating %s...", (config_path))
|
||||||
with open(config_path, "w") as outfile:
|
with open(config_path, "w") as outfile:
|
||||||
outfile.write(populate)
|
outfile.write(populate)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ class Microscope:
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""Shut down the microscope hardware."""
|
"""Shut down the microscope hardware."""
|
||||||
logging.info("Closing {}", (self))
|
logging.info("Closing %s", (self))
|
||||||
if self.camera:
|
if self.camera:
|
||||||
try:
|
try:
|
||||||
self.camera.close()
|
self.camera.close()
|
||||||
|
|
@ -83,7 +83,7 @@ class Microscope:
|
||||||
except TimeoutError as e:
|
except TimeoutError as e:
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
self.captures.close()
|
self.captures.close()
|
||||||
logging.info("Closed {}", (self))
|
logging.info("Closed %s", (self))
|
||||||
|
|
||||||
def setup(self, configuration):
|
def setup(self, configuration):
|
||||||
"""
|
"""
|
||||||
|
|
@ -196,7 +196,7 @@ class Microscope:
|
||||||
Applies a settings dictionary to the microscope. Missing parameters will be left untouched.
|
Applies a settings dictionary to the microscope. Missing parameters will be left untouched.
|
||||||
"""
|
"""
|
||||||
with self.lock:
|
with self.lock:
|
||||||
logging.debug("Microscope: Applying settings: {}", (settings))
|
logging.debug("Microscope: Applying settings: %s", (settings))
|
||||||
|
|
||||||
# If attached to a camera
|
# If attached to a camera
|
||||||
if ("camera" in settings) and self.camera:
|
if ("camera" in settings) and self.camera:
|
||||||
|
|
@ -329,14 +329,14 @@ class Microscope:
|
||||||
|
|
||||||
# Load cached bits of metadata
|
# Load cached bits of metadata
|
||||||
if cache_key:
|
if cache_key:
|
||||||
logging.debug("Reading cached microscope metadata: {}", cache_key)
|
logging.debug("Reading cached microscope metadata: %s", cache_key)
|
||||||
metadata = self.metadata_cache.get(cache_key, None)
|
metadata = self.metadata_cache.get(cache_key, None)
|
||||||
if not metadata:
|
if not metadata:
|
||||||
logging.debug("Building and caching microscope metadata: {}", cache_key)
|
logging.debug("Building and caching microscope metadata: %s", cache_key)
|
||||||
metadata = self.force_get_metadata()
|
metadata = self.force_get_metadata()
|
||||||
self.metadata_cache[cache_key] = metadata
|
self.metadata_cache[cache_key] = metadata
|
||||||
else:
|
else:
|
||||||
logging.debug("Building microscope metadata: {}", cache_key)
|
logging.debug("Building microscope metadata: %s", cache_key)
|
||||||
metadata = self.force_get_metadata()
|
metadata = self.force_get_metadata()
|
||||||
|
|
||||||
# Keys that should never be cached
|
# Keys that should never be cached
|
||||||
|
|
@ -362,7 +362,7 @@ class Microscope:
|
||||||
metadata: dict = None,
|
metadata: dict = None,
|
||||||
cache_key: str = None,
|
cache_key: str = None,
|
||||||
):
|
):
|
||||||
logging.debug("Microscope capturing to {}", filename)
|
logging.debug("Microscope capturing to %s", filename)
|
||||||
if not annotations:
|
if not annotations:
|
||||||
annotations = {}
|
annotations = {}
|
||||||
if not metadata:
|
if not metadata:
|
||||||
|
|
@ -384,7 +384,7 @@ class Microscope:
|
||||||
extras = {}
|
extras = {}
|
||||||
if fmt == "jpeg":
|
if fmt == "jpeg":
|
||||||
extras["thumbnail"] = (*THUMBNAIL_SIZE, 85)
|
extras["thumbnail"] = (*THUMBNAIL_SIZE, 85)
|
||||||
logging.info("Starting microscope capture {}", output.file)
|
logging.info("Starting microscope capture %s", output.file)
|
||||||
self.camera.capture(
|
self.camera.capture(
|
||||||
output,
|
output,
|
||||||
use_video_port=use_video_port,
|
use_video_port=use_video_port,
|
||||||
|
|
@ -395,6 +395,6 @@ class Microscope:
|
||||||
)
|
)
|
||||||
|
|
||||||
output.put_and_save(tags, annotations, full_metadata)
|
output.put_and_save(tags, annotations, full_metadata)
|
||||||
logging.debug("Finished capture to {}", output.file)
|
logging.debug("Finished capture to %s", output.file)
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ def main():
|
||||||
logging.info("Loading user settings...")
|
logging.info("Loading user settings...")
|
||||||
settings = user_settings.load()
|
settings = user_settings.load()
|
||||||
cap_path = str(settings.get("captures", {}).get("paths", {}).get("default"))
|
cap_path = str(settings.get("captures", {}).get("paths", {}).get("default"))
|
||||||
logging.info("Capture path found: {}", cap_path)
|
logging.info("Capture path found: %s", cap_path)
|
||||||
|
|
||||||
if not cap_path:
|
if not cap_path:
|
||||||
logging.error(
|
logging.error(
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ def launch_timeout_test_process(target, args=(), kwargs=None, timeout=10):
|
||||||
# If thread is still active
|
# If thread is still active
|
||||||
if p.is_alive():
|
if p.is_alive():
|
||||||
logging.error(
|
logging.error(
|
||||||
"Function {} reached timeout after {} seconds. Terminating.",
|
"Function %s reached timeout after %s seconds. Terminating.",
|
||||||
target,
|
target,
|
||||||
timeout,
|
timeout,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -80,13 +80,13 @@ class MissingStage(BaseStage):
|
||||||
|
|
||||||
self._position = list(np.array(self._position) + np.array(initial_move))
|
self._position = list(np.array(self._position) + np.array(initial_move))
|
||||||
logging.debug(np.array(self._position) + np.array(initial_move))
|
logging.debug(np.array(self._position) + np.array(initial_move))
|
||||||
logging.debug("New position: {}", self._position)
|
logging.debug("New position: %s", self._position)
|
||||||
|
|
||||||
def move_abs(self, final, **kwargs):
|
def move_abs(self, final, **kwargs):
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
self._position = list(final)
|
self._position = list(final)
|
||||||
logging.debug("New position: {}", self._position)
|
logging.debug("New position: %s", self._position)
|
||||||
|
|
||||||
def zero_position(self):
|
def zero_position(self):
|
||||||
"""Set the current position to zero"""
|
"""Set the current position to zero"""
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ class SangaStage(BaseStage):
|
||||||
|
|
||||||
@backlash.setter
|
@backlash.setter
|
||||||
def backlash(self, blsh):
|
def backlash(self, blsh):
|
||||||
logging.debug("Setting backlash to {}", (blsh))
|
logging.debug("Setting backlash to %s", (blsh))
|
||||||
if blsh is None:
|
if blsh is None:
|
||||||
self._backlash = None
|
self._backlash = None
|
||||||
elif isinstance(blsh, Iterable):
|
elif isinstance(blsh, Iterable):
|
||||||
|
|
@ -118,7 +118,7 @@ class SangaStage(BaseStage):
|
||||||
backlash: (default: True) whether to correct for backlash.
|
backlash: (default: True) whether to correct for backlash.
|
||||||
"""
|
"""
|
||||||
with self.lock:
|
with self.lock:
|
||||||
logging.debug("Moving sangaboard by {}", displacement)
|
logging.debug("Moving sangaboard by %s", displacement)
|
||||||
if not backlash or self.backlash is None:
|
if not backlash or self.backlash is None:
|
||||||
return self.board.move_rel(displacement, axis=axis)
|
return self.board.move_rel(displacement, axis=axis)
|
||||||
if axis is not None:
|
if axis is not None:
|
||||||
|
|
@ -158,7 +158,7 @@ class SangaStage(BaseStage):
|
||||||
"""Make an absolute move to a position
|
"""Make an absolute move to a position
|
||||||
"""
|
"""
|
||||||
with self.lock:
|
with self.lock:
|
||||||
logging.debug("Moving sangaboard to {}", final)
|
logging.debug("Moving sangaboard to %s", final)
|
||||||
self.board.move_abs(final, **kwargs)
|
self.board.move_abs(final, **kwargs)
|
||||||
# Settle outside of the stage lock so that another move request
|
# Settle outside of the stage lock so that another move request
|
||||||
# can just take over before settling
|
# can just take over before settling
|
||||||
|
|
@ -262,7 +262,7 @@ class SangaDeltaStage(SangaStage):
|
||||||
# Transform into delta coordinates
|
# Transform into delta coordinates
|
||||||
displacement = np.dot(self.Tdv, displacement)
|
displacement = np.dot(self.Tdv, displacement)
|
||||||
|
|
||||||
logging.debug("Delta displacement: {}", (displacement))
|
logging.debug("Delta displacement: %s", (displacement))
|
||||||
|
|
||||||
# Do the move
|
# Do the move
|
||||||
SangaStage.move_rel(self, displacement, axis=None, backlash=backlash)
|
SangaStage.move_rel(self, displacement, axis=None, backlash=backlash)
|
||||||
|
|
@ -274,7 +274,7 @@ class SangaDeltaStage(SangaStage):
|
||||||
# Transform into delta coordinates
|
# Transform into delta coordinates
|
||||||
final = np.dot(self.Tdv, final)
|
final = np.dot(self.Tdv, final)
|
||||||
|
|
||||||
logging.debug("Delta final: {}", (final))
|
logging.debug("Delta final: %s", (final))
|
||||||
|
|
||||||
# Do the move
|
# Do the move
|
||||||
SangaStage.move_abs(self, final, **kwargs)
|
SangaStage.move_abs(self, final, **kwargs)
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ class Timer(object):
|
||||||
|
|
||||||
def __exit__(self, type_, value, traceback):
|
def __exit__(self, type_, value, traceback):
|
||||||
self.end = time.time()
|
self.end = time.time()
|
||||||
logging.debug("{} time: {}", self.name, self.end - self.start)
|
logging.debug("%s time: %s", self.name, self.end - self.start)
|
||||||
|
|
||||||
|
|
||||||
def deserialise_array_b64(b64_string, dtype, shape):
|
def deserialise_array_b64(b64_string, dtype, shape):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue