From e483c3ddfb852bcd97fd929388fd4e81d08fb2ba Mon Sep 17 00:00:00 2001 From: Joe Knapper Date: Mon, 15 Jan 2024 17:40:17 +0000 Subject: [PATCH 1/3] custom scan name from gui --- .../things/smart_scan.py | 7 ++++--- .../tabContentComponents/slideScanContent.vue | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/openflexure_microscope_server/things/smart_scan.py b/src/openflexure_microscope_server/things/smart_scan.py index 13b42bc0..183c6a90 100644 --- a/src/openflexure_microscope_server/things/smart_scan.py +++ b/src/openflexure_microscope_server/things/smart_scan.py @@ -341,12 +341,12 @@ class SmartScanThing(Thing): scan_name = self.latest_scan_name return os.path.join(self.scans_folder_path, scan_name) - def new_scan_folder(self) -> str: + def new_scan_folder(self, scan_name: Optional[str]="") -> str: """Create a new empty folder, into which we can save scan images""" if not os.path.exists(self.scans_folder_path): os.makedirs(self.scans_folder_path) for j in range(999999): - folder_path = os.path.join(self.scans_folder_path, f"scan_{j:06}") + folder_path = os.path.join(self.scans_folder_path, f"scan_{scan_name}{j:06}") if not os.path.exists(folder_path): os.makedirs(folder_path) self._latest_scan_name = os.path.basename(folder_path) @@ -364,6 +364,7 @@ class SmartScanThing(Thing): csm: CSMDep, background_detect: BackgroundDep, recentre: RecentreStage, + scan_name: Optional[str] ): """Move the stage to cover an area, taking images that can be tiled together. @@ -441,7 +442,7 @@ class SmartScanThing(Thing): ids = [] start_time = time.strftime("%H_%M_%S-%d_%m_%Y") - scan_folder = self.new_scan_folder() + scan_folder = self.new_scan_folder(scan_name) images_folder = os.path.join(scan_folder, "images") os.mkdir(images_folder) raw_images_folder = os.path.join(images_folder, "raw") diff --git a/webapp/src/components/tabContentComponents/slideScanContent.vue b/webapp/src/components/tabContentComponents/slideScanContent.vue index 8e09623d..91ee6b80 100644 --- a/webapp/src/components/tabContentComponents/slideScanContent.vue +++ b/webapp/src/components/tabContentComponents/slideScanContent.vue @@ -46,10 +46,20 @@ + +
+ +
Date: Mon, 15 Jan 2024 20:27:35 +0000 Subject: [PATCH 2/3] Improve scan naming logic and type hints Removed an unnecessary `Optional` and removed the `scan_` prefix from scans that have a non-empty name. I also added a closing ` to a logging statement. --- .../things/smart_scan.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/openflexure_microscope_server/things/smart_scan.py b/src/openflexure_microscope_server/things/smart_scan.py index 183c6a90..85240219 100644 --- a/src/openflexure_microscope_server/things/smart_scan.py +++ b/src/openflexure_microscope_server/things/smart_scan.py @@ -341,12 +341,24 @@ class SmartScanThing(Thing): scan_name = self.latest_scan_name return os.path.join(self.scans_folder_path, scan_name) - def new_scan_folder(self, scan_name: Optional[str]="") -> str: - """Create a new empty folder, into which we can save scan images""" + def new_scan_folder(self, scan_name: str="scan") -> str: + """Create a new empty folder, into which we can save scan images + + The folder will be named `{scan_name}_000001/` where the number is + zero-padded to be 6 digits long (to allow correct sorting if the + scans are ordered alphanumerically). + + Note that if you have discontinuous numbering (e.g. you've got scans + numbered 1 through 10, but you deleted scan 5), then the gaps will + get filled in - so there's no guarantee, for now, that the numbers + will correspond to order of creation. This may change in the future. + """ if not os.path.exists(self.scans_folder_path): os.makedirs(self.scans_folder_path) + if not scan_name: + scan_name = "scan" for j in range(999999): - folder_path = os.path.join(self.scans_folder_path, f"scan_{scan_name}{j:06}") + folder_path = os.path.join(self.scans_folder_path, f"{scan_name}_{j:06}") if not os.path.exists(folder_path): os.makedirs(folder_path) self._latest_scan_name = os.path.basename(folder_path) @@ -364,7 +376,7 @@ class SmartScanThing(Thing): csm: CSMDep, background_detect: BackgroundDep, recentre: RecentreStage, - scan_name: Optional[str] + scan_name: str="", ): """Move the stage to cover an area, taking images that can be tiled together. From e7a3003c4712de5421a58a54e9d324735a540f12 Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Mon, 15 Jan 2024 20:42:54 +0000 Subject: [PATCH 3/3] Add a closing ` to the logging statement This was mistakenly not added to the previous commit. --- src/openflexure_microscope_server/things/smart_scan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openflexure_microscope_server/things/smart_scan.py b/src/openflexure_microscope_server/things/smart_scan.py index 85240219..d86088e7 100644 --- a/src/openflexure_microscope_server/things/smart_scan.py +++ b/src/openflexure_microscope_server/things/smart_scan.py @@ -845,7 +845,7 @@ class SmartScanThing(Thing): self, logger: InvocationLogger, cmd: list[str], ) -> CompletedProcess: """Run a subprocess and log any output""" - logger.info(f"Running command in subprocess: `{' '.join(cmd)}") + logger.info(f"Running command in subprocess: `{' '.join(cmd)}`") output = run(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True) for pipe in [output.stdout, output.stderr]: if pipe: