parent
7103ea2a97
commit
693b8de376
|
@ -25,19 +25,26 @@ class DacMetadata(object):
|
|||
|
||||
class Sequence(object):
|
||||
def __init__(self, catalog, sequence_id, micro_manager_metadata_file_path):
|
||||
"""
|
||||
:param Catalog catalog:
|
||||
:param str sequence_id: eg 'res_soleil2018/GGH/GGH_2018_cin2_phiG_I_327_vis_-40_1/Pos0'
|
||||
:param str micro_manager_metadata_file_path: eg '/Users/graffy/ownCloud/ipr/lipase/raw-images/res_soleil2018/GGH/GGH_2018_cin2_phiG_I_327_vis_-40_1/Pos0/metadata.txt'
|
||||
"""
|
||||
self.catalog = catalog
|
||||
self.sequence_id = sequence_id
|
||||
self.micro_manager_metadata_file_path = micro_manager_metadata_file_path
|
||||
print(micro_manager_metadata_file_path)
|
||||
print('reading micro manager metatdata from %s' % micro_manager_metadata_file_path)
|
||||
# note : the micromanager metadata files are encoded in latin-1, not utf8 (see accents in comments)
|
||||
with open(micro_manager_metadata_file_path, "r") as mmm_file:
|
||||
with open(os.path.realpath(micro_manager_metadata_file_path), "r") as mmm_file:
|
||||
self.mmm = json.load(mmm_file, encoding='latin-1') # note : the micromanager metadata files are encoded in latin-1, not utf8 (see accents in comments)
|
||||
|
||||
micro_manager_metadata_file_parent_path = '/'.join(micro_manager_metadata_file_path.split('/')[0:-2])
|
||||
(pos_dir_path, file_name) = os.path.split(micro_manager_metadata_file_path) # pylint: disable=unused-variable
|
||||
(micro_manager_metadata_file_parent_path, pos_dir_name) = os.path.split(pos_dir_path) # pylint: disable=unused-variable
|
||||
assert pos_dir_name[0:3] == 'Pos', 'unexpected value : %s is expected to be of the form "Pos<n>"' % pos_dir_name
|
||||
print('micro_manager_metadata_file_parent_path = %s' % micro_manager_metadata_file_parent_path)
|
||||
dac_file_path = micro_manager_metadata_file_parent_path + '/display_and_comments.txt'
|
||||
dac_id = '/'.join(self.sequence_id.split('/')[0:-1])
|
||||
dac_file_path = os.path.join(micro_manager_metadata_file_parent_path, 'display_and_comments.txt')
|
||||
(dac_id, file_name) = os.path.split(self.sequence_id)
|
||||
self.dac = DacMetadata(dac_id, dac_file_path)
|
||||
|
||||
for channel_index in range(self.num_channels):
|
||||
|
@ -74,7 +81,8 @@ class Sequence(object):
|
|||
return int(summary['BitDepth'])
|
||||
|
||||
def get_root_path(self):
|
||||
return '/'.join(self.micro_manager_metadata_file_path.split('/')[:-1])
|
||||
(dir_name, file_name) = os.path.split(self.micro_manager_metadata_file_path) # pylint: disable=unused-variable
|
||||
return dir_name
|
||||
|
||||
def get_image_file_path(self, channel_index, frame_index, slice_index=0):
|
||||
'''
|
||||
|
@ -86,7 +94,7 @@ class Sequence(object):
|
|||
assert channel_index < self.num_channels
|
||||
frame_info = self.mmm['FrameKey-%d-%d-%d' % (frame_index, channel_index, slice_index)]
|
||||
rel_file_path = frame_info['FileName']
|
||||
return self.get_root_path() + '/' + rel_file_path
|
||||
return os.path.join(self.get_root_path(), rel_file_path)
|
||||
|
||||
def get_channel_index(self, channel_id):
|
||||
'''
|
||||
|
@ -175,11 +183,11 @@ class ImageCatalog(object):
|
|||
self.sequences = {}
|
||||
|
||||
sequence_paths = find_dirs_containing_file('metadata.txt', self.raw_images_root)
|
||||
sequence_ids = [ sequence_path.replace(raw_images_root+'/', '') for sequence_path in sequence_paths ]
|
||||
sequence_ids = [ os.path.relpath(sequence_path, raw_images_root) for sequence_path in sequence_paths ]
|
||||
# nb : we use the path as sequence id because the "Comment" field in the summary section of the metadata file is not guaranteed to be unique (eg they are the same in res_soleil2018/white/white_24112018_1/Pos0 and in res_soleil2018/white/white_24112018_2/Pos0)
|
||||
|
||||
for sequence_id in sequence_ids:
|
||||
micro_manager_metadata_file_path = raw_images_root + '/' + sequence_id + '/metadata.txt'
|
||||
micro_manager_metadata_file_path = os.path.join(raw_images_root, sequence_id, 'metadata.txt')
|
||||
# micro_manager_metadata_file_path = '/tmp/toto.json'
|
||||
self.sequences[sequence_id] = Sequence(self, sequence_id, micro_manager_metadata_file_path)
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""Lipase user settings."""
|
||||
import json
|
||||
from os.path import expanduser
|
||||
#from os.path import expanduser
|
||||
#import os.path
|
||||
import os
|
||||
|
||||
|
||||
class UserSettings(object):
|
||||
|
@ -39,8 +41,8 @@ class UserSettings(object):
|
|||
|
||||
def get_settings_file_path(self):
|
||||
"""Return the location of lipase user settings file."""
|
||||
home = expanduser("~")
|
||||
return '%s/.fr.univ-rennes1.ipr.lipase.json' % home
|
||||
home = os.path.expanduser("~")
|
||||
return os.path.join(home, '.fr.univ-rennes1.ipr.lipase.json')
|
||||
|
||||
def save(self):
|
||||
"""Save user settings."""
|
||||
|
@ -52,7 +54,7 @@ def test():
|
|||
"""Unit test."""
|
||||
settings = UserSettings()
|
||||
print(settings.raw_images_root_path)
|
||||
settings.raw_images_root_path = '/Users/graffy/ownCloud/ipr/lipase/raw-images'
|
||||
settings.raw_images_root_path = os.path.join(os.sep, 'Users', 'graffy', 'ownCloud', 'ipr', 'lipase', 'raw-images')
|
||||
# settings.toto = 'hello'
|
||||
settings.save()
|
||||
|
||||
|
|
Loading…
Reference in New Issue