FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects

Support extracting and storing snapshots from non-data mcd files

Merged Mo Al Sa'd requested to merge dev into main
4 files
+ 78
47
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 18
27
@@ -12,16 +12,23 @@ from .metadefs import MetaDefinitions as defs
class ImcRaw:
def __init__(self, input_dir, code=None):
self.input_dir = input_dir
def __init__(self, mcd_fn, code=None, txt_fns=None):
self.mcd_fn = mcd_fn
self.code = code
self.mcd_fn = None
self.txt_fns = [] # text filenames
# parse files
self._find_files()
self._parse_files()
self._build_object_lists()
self._assign_imc_meta_summary()
self.txt_fns = txt_fns # text filenames
self.panoramas = []
self.acquisitions = []
try:
self._parse_files()
self._build_object_lists()
self._assign_imc_meta_summary()
self.has_acquisitions = True
except Exception as e:
if self.panoramas and not self.acquisitions:
# seems to be an mcd file with snapshot content only, swallow the exception
self.has_acquisitions = False
else:
raise e
def _assign_imc_meta_summary(self):
# assign run timestamp from the first acquisition
@@ -29,7 +36,6 @@ class ImcRaw:
# assign code
if not self.code:
self.code = self.timestamp.strftime('%Y%m%d-%H%M%S-%f')
self.rawmeta = self._parser.xml_str.replace("\n", "")
self.mcd_sw_version = self.slides[0].get_property(defs.SWVERSION)
# set meta summary
self.meta_summary = OrderedDict()
@@ -74,28 +80,12 @@ class ImcRaw:
_panoramas.append(panorama)
self.meta_summary['panoramas'] = _panoramas
def _find_files(self):
# check whether the input_dir points to an mcd file
if self.input_dir.is_file():
if self.input_dir.suffix != '.mcd':
raise Exception('Input file does not seem to be a valid mcd file')
self.mcd_fn = self.input_dir
else:
# check if mcd file exists
files = list(self.input_dir.glob('*.mcd'))
if not files:
raise Exception('No mcd file was found in the input folder')
elif len(files) > 1:
raise Exception('More than one mcd files were found in the input folder')
self.mcd_fn = files[0]
# text files
self.txt_fns = list(self.input_dir.glob('*.txt'))
def _parse_files(self):
try:
self._parser = ImcDataParser(self.mcd_fn, textfilenames=self.txt_fns)
self._parser.read_mcd_xml()
self._parser.parse_mcd_xml()
self.rawmeta = self._parser.xml_str.replace("\n", "")
except Exception as e:
raise Exception('Error parsing raw files: {}'.format(str(e)))
@@ -162,6 +152,7 @@ class ImcRaw:
self._parser.save_snapshot_image(q, out_folder)
def save_meta_xml(self, out_folder):
out_folder.mkdir(parents=True, exist_ok=True)
fn = "mcd_schema.xml"
fn = out_folder.joinpath(fn)
with open(fn, "w") as f:
Loading