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