From b3f5dfcc8be3afdc17aca7d43c93474e585ecaa3 Mon Sep 17 00:00:00 2001 From: Chris Allan Date: Tue, 29 Jun 2021 12:13:57 +0100 Subject: [PATCH] Bring implementation in line with comments --- isyntax2raw/__init__.py | 22 ++++++++++------------ isyntax2raw/cli/isyntax2raw.py | 4 ++-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/isyntax2raw/__init__.py b/isyntax2raw/__init__.py index f78f15e..353a1d8 100644 --- a/isyntax2raw/__init__.py +++ b/isyntax2raw/__init__.py @@ -375,13 +375,10 @@ def wait_any(self, regions): else: return self.pixel_engine.wait_any(regions) - def write_metadata_json_cli(self): - self.write_metadata_json(self.slide_directory) - - def write_metadata_json(self, output_file_path): + def write_metadata_json(self, metadata_file): '''write metadata to a JSON file''' - with open(output_file_path, "w", encoding="utf-8") as f: + with open(metadata_file, "w", encoding="utf-8") as f: metadata = self.get_metadata() for image in range(self.num_images()): @@ -390,7 +387,7 @@ def write_metadata_json(self, output_file_path): json.dump(metadata, f) - def write_metadata_xml(self): + def write_metadata_xml(self, metadata_file): ome_timestamp = self.acquisition_datetime() xml_values = { @@ -421,20 +418,21 @@ def write_metadata_xml(self): loader = PackageLoader() template = loader.import_("isyntax2raw.resources.ome_template") xml = template(xml_values).render() - ome_xml_file = os.path.join( - self.slide_directory, "OME", "METADATA.ome.xml" - ) - with open(ome_xml_file, "w", encoding="utf-8") as omexml: + with open(metadata_file, "w", encoding="utf-8") as omexml: omexml.write(xml) def write_metadata(self): os.makedirs(os.path.join(self.slide_directory, "OME"), exist_ok=True) + metadata_file = os.path.join( self.slide_directory, "OME", "METADATA.json" ) - self.write_metadata_json(metadata_file) - self.write_metadata_xml() + + metadata_file = os.path.join( + self.slide_directory, "OME", "METADATA.ome.xml" + ) + self.write_metadata_xml(metadata_file) def get_size(self, dim_range): '''calculate the length in pixels of a dimension''' diff --git a/isyntax2raw/cli/isyntax2raw.py b/isyntax2raw/cli/isyntax2raw.py index 8bec27b..e131efd 100644 --- a/isyntax2raw/cli/isyntax2raw.py +++ b/isyntax2raw/cli/isyntax2raw.py @@ -87,9 +87,9 @@ def write_tiles( def write_metadata(debug, input_path, output_file): with WriteTiles( None, None, None, None, - None, None, None, input_path, output_file + None, None, None, input_path, None ) as wt: - wt.write_metadata_json_cli() + wt.write_metadata_json(output_file) def main():