From 7ef2cd7eabca4b9352e61f4dd131edb2ec8439c8 Mon Sep 17 00:00:00 2001 From: Romain Bazile Date: Wed, 1 Dec 2021 13:33:40 +0100 Subject: [PATCH] Various comment updates and small sourcery suggestions --- scripts/planktoscope/light.py | 6 +----- scripts/planktoscope/module.py | 5 +++-- scripts/planktoscope/mqtt.py | 2 +- scripts/planktoscope/segmenter/__init__.py | 7 ++++--- scripts/planktoscope/segmenter/ecotaxa.py | 4 ++-- scripts/planktoscope/segmenter/streamer.py | 1 + scripts/planktoscope/stepper.py | 1 + 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/scripts/planktoscope/light.py b/scripts/planktoscope/light.py index 3e156b2..5975e53 100644 --- a/scripts/planktoscope/light.py +++ b/scripts/planktoscope/light.py @@ -11,11 +11,7 @@ from loguru import logger import subprocess # nosec # Library to send command over I2C for the light module on the fan -try: - import smbus2 as smbus -except ModuleNotFoundError: # We need this to install the library on machine that do not have the module yet - subprocess.run("pip3 install smbus2".split()) # nosec - import smbus2 as smbus +import smbus2 as smbus import enum diff --git a/scripts/planktoscope/module.py b/scripts/planktoscope/module.py index 0912777..8cf3bbf 100644 --- a/scripts/planktoscope/module.py +++ b/scripts/planktoscope/module.py @@ -52,7 +52,7 @@ class ModuleProcess(multiprocessing.Process): action = last_message["action"] if action == "on": # Treat the received messages here - + pass elif action != "": logger.warning( f"We did not understand the received request {action} - {last_message}" @@ -92,4 +92,5 @@ class ModuleProcess(multiprocessing.Process): # This is called if this script is launched directly if __name__ == "__main__": - # This should be tests of your module \ No newline at end of file + # This should be tests of your module + pass \ No newline at end of file diff --git a/scripts/planktoscope/mqtt.py b/scripts/planktoscope/mqtt.py index 1632fbc..baaad2c 100644 --- a/scripts/planktoscope/mqtt.py +++ b/scripts/planktoscope/mqtt.py @@ -86,7 +86,7 @@ class MQTT_Client: @logger.catch def connect(self): logger.info(f"trying to connect to {self.server}:{self.port}") - # TODO add try: except ConnectionRefusedError: block here + # TODO #104 add try: except ConnectionRefusedError: block here # This is a symptom that Mosquitto may have failed to start self.client.connect(self.server, self.port, 60) self.client.on_connect = self.on_connect diff --git a/scripts/planktoscope/segmenter/__init__.py b/scripts/planktoscope/segmenter/__init__.py index 814e2ea..b3662d8 100644 --- a/scripts/planktoscope/segmenter/__init__.py +++ b/scripts/planktoscope/segmenter/__init__.py @@ -274,7 +274,7 @@ class SegmenterProcess(multiprocessing.Process): h_stddev = np.std(h_channel, where=mask) s_stddev = np.std(s_channel, where=mask) v_stddev = np.std(v_channel, where=mask) - # TODO Add skewness and kurtosis calculation (with scipy) here + # TODO #103 Add skewness and kurtosis calculation (with scipy) here # using https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.skew.html#scipy.stats.skew # and https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.kurtosis.html#scipy.stats.kurtosis # h_quartiles = np.quantile(h_channel, quartiles) @@ -789,7 +789,7 @@ class SegmenterProcess(multiprocessing.Process): else: self.segmenter_client.client.publish( "status/segmenter", - f'{{"status":"An exception was raised during the segmentation: {e}."}}', + f'{{"status":"An exception was raised during the segmentation: {exception}."}}', ) # Reset process_id self.__process_id = "" @@ -856,6 +856,7 @@ class SegmenterProcess(multiprocessing.Process): self.__ecotaxa_path, # filename includes project name, timestamp and sample id f"ecotaxa_{project}_{date}_{sample}.zip", + # TODO #102 sanitize the filename to remove potential problems with spaces and special characters ) self.__working_path = path @@ -978,7 +979,7 @@ class SegmenterProcess(multiprocessing.Process): elif last_message["action"] != "": logger.warning( - f"We did not understand the received request {action} - {last_message}" + f"We did not understand the received request {last_message}" ) ################################################################################ diff --git a/scripts/planktoscope/segmenter/ecotaxa.py b/scripts/planktoscope/segmenter/ecotaxa.py index c8b6ab4..a87a616 100644 --- a/scripts/planktoscope/segmenter/ecotaxa.py +++ b/scripts/planktoscope/segmenter/ecotaxa.py @@ -205,7 +205,7 @@ def ecotaxa_export(archive_filepath, metadata, image_base_path, keep_files=False logger.error("No objects metadata recorded, cannot continue the export") return 0 - # fix crappy old camera resolution that was not exported as string + # sometimes the camera resolution is not exported as string if type(metadata["acq_camera_resolution"]) != str: metadata[ "acq_camera_resolution" @@ -216,7 +216,7 @@ def ecotaxa_export(archive_filepath, metadata, image_base_path, keep_files=False tsv_line = {} tsv_line.update(metadata) tsv_line.update(("object_" + k, v) for k, v in roi["metadata"].items()) - tsv_line.update({"object_id": roi["name"]}) + tsv_line["object_id"] = roi["name"] filename = roi["name"] + ".jpg" diff --git a/scripts/planktoscope/segmenter/streamer.py b/scripts/planktoscope/segmenter/streamer.py index c0cbae5..d7d592f 100644 --- a/scripts/planktoscope/segmenter/streamer.py +++ b/scripts/planktoscope/segmenter/streamer.py @@ -50,6 +50,7 @@ class StreamingHandler(http.server.BaseHTTPRequestHandler): ) break frame = file.getvalue() + # TODO #101 insert try block here to catch ConnectionResetError: [Errno 104] Connection reset by peer self.wfile.write(b"--FRAME\r\n") self.send_header("Content-Type", "image/jpeg") self.send_header("Content-Length", len(frame)) diff --git a/scripts/planktoscope/stepper.py b/scripts/planktoscope/stepper.py index 18836ac..f4815fb 100644 --- a/scripts/planktoscope/stepper.py +++ b/scripts/planktoscope/stepper.py @@ -185,6 +185,7 @@ class StepperProcess(multiprocessing.Process): if os.path.exists("/home/pi/PlanktoScope/hardware.json"): # load hardware.json with open("/home/pi/PlanktoScope/hardware.json", "r") as config_file: + # TODO #100 insert guard for config_file empty configuration = json.load(config_file) logger.debug(f"Hardware configuration loaded is {configuration}") else: