Skip to content

Commit

Permalink
metadata will now be saved as xml file along with the data. argparse …
Browse files Browse the repository at this point in the history
…will parse an extra argument -om or --onlymetadata that will trigger just the saving of metadata
  • Loading branch information
pskeshu committed Nov 15, 2017
1 parent d484c8f commit bcd5e5e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
6 changes: 6 additions & 0 deletions microscoper/args.py
Expand Up @@ -25,5 +25,11 @@ def arguments():
"--big",
help="Save as big TIFF",
action="store_true")
parser.add_argument("-om",
"--onlymetadata",
help="Read and save the metadata without\
saving the images.",
action="store_true")

args = parser.parse_args()
return args
36 changes: 29 additions & 7 deletions microscoper/io.py
@@ -1,8 +1,8 @@
"""Microscoper is a wrapper around bioformats using a forked
python-bioformats to extract the raw images from Olympus IX83
"""Microscoper is a wrapper around bioformats using a forked
python-bioformats to extract the raw images from Olympus IX83
CellSense .vsi format, into a more commonly used TIFF format.
Images are bundled together according to their channels.
Images are bundled together according to their channels.
This code is used internally in SCB Lab, TCIS, TIFR-H.
You're free to modify it and distribute it.
Expand All @@ -16,10 +16,11 @@
import tifffile as tf
import tqdm
from .args import arguments
import xml.dom.minidom


def get_files(directory, keyword):
""" Returns all the files in the given directory
""" Returns all the files in the given directory
and subdirectories, filtering with the keyword.
Usage:
Expand Down Expand Up @@ -103,7 +104,7 @@ def read_images(path, save_directory, big, save_separate):
save_images(np.asarray(images), channel_name, save_directory, big,
save_separate)

return
return metadata


def save_images(images, channel, save_directory, big=False,
Expand All @@ -129,6 +130,14 @@ def save_images(images, channel, save_directory, big=False,
f.save(images)


def save_metadata(metadata, save_directory):
data = xml.dom.minidom.parseString(metadata.to_xml())
pretty_xml_as_string = data.toprettyxml()

with open(save_directory + "metadata.xml", "w") as xmlfile:
xmlfile.write(pretty_xml_as_string)


def _init_logger():
"""This is so that Javabridge doesn't spill out a lot of DEBUG messages
during runtime.
Expand Down Expand Up @@ -187,6 +196,19 @@ def run():

pbar_files.set_description("..." + path[-15:])

read_images(path, save_directory, big=arg.big,
save_separate=arg.separate)
# If the user wants to store meta data for existing data,
# the user may pass -om or --onlymetadata argument which
# will bypass read_images() and get metadata on its own.

if arg.onlymetadata:
metadata = get_metadata(path)

# The default behaviour is to store the files with the
# metadata.
else:
metadata = read_images(path, save_directory, big=arg.big,
save_separate=arg.separate)

save_metadata(metadata, save_directory)

jb.kill_vm()

0 comments on commit bcd5e5e

Please sign in to comment.