Skip to content

Commit

Permalink
Bring implementation in line with comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-allan committed Jun 29, 2021
1 parent 3c33007 commit b3f5dfc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
22 changes: 10 additions & 12 deletions isyntax2raw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()):
Expand All @@ -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 = {
Expand Down Expand Up @@ -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'''
Expand Down
4 changes: 2 additions & 2 deletions isyntax2raw/cli/isyntax2raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit b3f5dfc

Please sign in to comment.