class EHooke: """Encapsulates all the code for processing a fluorescence frame""" def __init__(self,params_obj=None,param_file=None): """Creates FluorFrame object, sets up parameters and loads images It makes no sense to create a EHooke object without data or parameters. So one must either supply params, a Parameters object, or param_file, in which case EHooke loads the parameters file. """ self.params = None """Parameters: this can be a reference to an external object to be changed for recomputing any step. """ if params_obj is None: self.params = Parameters() self.params.load_parameters(param_file) else: self.params = params_obj self.fluor_frame = FluorFrame() """FluorFrame: manager for the fluor and phase images, plus masks""" def load_images(self): """checks which images to load and loads them into the fluor_frame """ ffparams = self.params.fluor_frame_params self.fluor_frame.load_fluor(ffparams) if ffparams.phase_file is not None: self.fluor_frame.load_phase(ffparams) def create_masks(self): """creates masks using the current parameters""" mparams = self.params.mask_params self.fluor_frame.create_masks(mparams) def align_fluor_to_phase(self): """aligns the fluorescence image to the phase mask, if a phase file exists""" if ffparams.phase_file is not None: self.fluor_frame.align_fluor(self.params.fluor_frame_params) def save_mask_overlay(self, fname, back=(0,0,1), fore=(1,1,0), mask='phase',image='phase'): """saves the mask overlay image to a file""" img = self.fluor_frame.mask_overlay(back, fore, mask,image) imsave(fname,img) def save_mask_contour(self, fname, mask='phase',image='phase', color=(1,1,0)): """saves the mask contour image to a file""" img = self.fluor_frame.contour_overlay(mask,image,color) imsave(fname,img)
class Session: """eHooke session This class manages the folder with data and report files (in the server path) and a EHooke instance for running the computations """ def __init__(self): self.id=str(uuid.uuid4()) """str: Unique identifier for this session""" self.folder = SESSION_FOLDER+'/'+self.id """str: main session folder with all generated files""" self.data_folder = self.folder+'/Data' """str: subfolder for session data (phase, fluor and params file)""" self.params = Parameters() """Parameters: parameters object to share with ehooke instance""" self.params_file = None """str: parameters file name""" self.fluor_file = None """str: fluor file name, to override parameters so that params can be imported from other sessions""" self.phase_file = None """str: phase file name, to override parameters so that params can be imported from other sessions""" self.name = 'Session' """str: session name, user defined""" self.description = '' """str: session description, user defined""" self.mask_image = None """str: filename for the current mask image, none if no mask is computed""" self.ehooke = None """EHooke: to be initialized upon starting the session (only with images and parameters""" #TODO change this to work with multiprocessing #<LK 2015-06-30> def setup(self): """creates session folder (add other setup stuff here)""" if not os.path.exists(self.folder): os.mkdir(self.folder) if not os.path.exists(self.data_folder): os.mkdir(self.data_folder) def set_phase(self,file_name): """sets the phase file without computing anything Overrides the file name in the parameters file. This is necessary in order to allow importing parameter files to the session """ self.phase_file = file_name self.params.fluor_frame_params.phase_file = file_name def set_fluor(self,file_name): """sets the fluorescence file without computing anything Overrides the file name in the parameters file. This is necessary in order to allow importing parameter files to the session """ self.fluor_file = file_name self.params.fluor_frame_params.fluor_file = file_name def set_parameters_file(self, file_name): """sets and reloads parameters (but overrides fluor_file and phase_file in order to allow parameter updates after uploading the image files """ self.params_file = file_name self.params.load_parameters(file_name) if self.fluor_file != self.params.fluor_frame_params.fluor_file or \ self.phase_file != self.params.fluor_frame_params.phase_file: self.params.fluor_frame_params.fluor_file = self.fluor_file self.params.fluor_frame_params.phase_file = self.phase_file self.params.save_parameters(file_name) def start_ehooke(self): """Initiates the ehooke process and loads images if there is no fluorescence image specified, returns false and error message otherwise returns true,'' if ehooke is not none does nothing and returns ok """ if self.ehooke is not None: return (True,'') if self.fluor_file is None: return (False,'Cannot start eHooke without a fluorescence image') self.ehooke = EHooke(self.params) self.ehooke.load_images() return (True,'') def save_overlay(self, back=(1,1,1), fore=(0,1,1), mask='phase',image='phase'): """saves the overlay image to overlay.png""" self.ehooke.save_mask_overlay(self.folder+'/overlay.png',back, fore, mask,image) self.mask_image = self.folder+'/overlay.png' def recompute_mask(self): res,msg = self.start_ehooke() if res: self.ehooke.create_masks() self.save_overlay() return (res,msg)
class Session: """eHooke session This class manages the folder with data and report files (in the server path) and a EHooke instance for running the computations """ def __init__(self): self.id = str(uuid.uuid4()) """str: Unique identifier for this session""" self.folder = SESSION_FOLDER + '/' + self.id """str: main session folder with all generated files""" self.data_folder = self.folder + '/Data' """str: subfolder for session data (phase, fluor and params file)""" self.params = Parameters() """Parameters: parameters object to share with ehooke instance""" self.params_file = None """str: parameters file name""" self.fluor_file = None """str: fluor file name, to override parameters so that params can be imported from other sessions""" self.phase_file = None """str: phase file name, to override parameters so that params can be imported from other sessions""" self.name = 'Session' """str: session name, user defined""" self.description = '' """str: session description, user defined""" self.mask_image = None """str: filename for the current mask image, none if no mask is computed""" self.ehooke = None """EHooke: to be initialized upon starting the session (only with images and parameters""" #TODO change this to work with multiprocessing #<LK 2015-06-30> def setup(self): """creates session folder (add other setup stuff here)""" if not os.path.exists(self.folder): os.mkdir(self.folder) if not os.path.exists(self.data_folder): os.mkdir(self.data_folder) def set_phase(self, file_name): """sets the phase file without computing anything Overrides the file name in the parameters file. This is necessary in order to allow importing parameter files to the session """ self.phase_file = file_name self.params.fluor_frame_params.phase_file = file_name def set_fluor(self, file_name): """sets the fluorescence file without computing anything Overrides the file name in the parameters file. This is necessary in order to allow importing parameter files to the session """ self.fluor_file = file_name self.params.fluor_frame_params.fluor_file = file_name def set_parameters_file(self, file_name): """sets and reloads parameters (but overrides fluor_file and phase_file in order to allow parameter updates after uploading the image files """ self.params_file = file_name self.params.load_parameters(file_name) if self.fluor_file != self.params.fluor_frame_params.fluor_file or \ self.phase_file != self.params.fluor_frame_params.phase_file: self.params.fluor_frame_params.fluor_file = self.fluor_file self.params.fluor_frame_params.phase_file = self.phase_file self.params.save_parameters(file_name) def start_ehooke(self): """Initiates the ehooke process and loads images if there is no fluorescence image specified, returns false and error message otherwise returns true,'' if ehooke is not none does nothing and returns ok """ if self.ehooke is not None: return (True, '') if self.fluor_file is None: return (False, 'Cannot start eHooke without a fluorescence image') self.ehooke = EHooke(self.params) self.ehooke.load_images() return (True, '') def save_overlay(self, back=(1, 1, 1), fore=(0, 1, 1), mask='phase', image='phase'): """saves the overlay image to overlay.png""" self.ehooke.save_mask_overlay(self.folder + '/overlay.png', back, fore, mask, image) self.mask_image = self.folder + '/overlay.png' def recompute_mask(self): res, msg = self.start_ehooke() if res: self.ehooke.create_masks() self.save_overlay() return (res, msg)
class EHooke: """Encapsulates all the code for processing a fluorescence frame""" def __init__(self, params_obj=None, param_file=None): """Creates FluorFrame object, sets up parameters and loads images It makes no sense to create a EHooke object without data or parameters. So one must either supply params, a Parameters object, or param_file, in which case EHooke loads the parameters file. """ self.params = None """Parameters: this can be a reference to an external object to be changed for recomputing any step. """ if params_obj is None: self.params = Parameters() self.params.load_parameters(param_file) else: self.params = params_obj self.fluor_frame = FluorFrame() """FluorFrame: manager for the fluor and phase images, plus masks""" def load_images(self): """checks which images to load and loads them into the fluor_frame """ ffparams = self.params.fluor_frame_params self.fluor_frame.load_fluor(ffparams) if ffparams.phase_file is not None: self.fluor_frame.load_phase(ffparams) def create_masks(self): """creates masks using the current parameters""" mparams = self.params.mask_params self.fluor_frame.create_masks(mparams) def align_fluor_to_phase(self): """aligns the fluorescence image to the phase mask, if a phase file exists""" if ffparams.phase_file is not None: self.fluor_frame.align_fluor(self.params.fluor_frame_params) def save_mask_overlay(self, fname, back=(0, 0, 1), fore=(1, 1, 0), mask='phase', image='phase'): """saves the mask overlay image to a file""" img = self.fluor_frame.mask_overlay(back, fore, mask, image) imsave(fname, img) def save_mask_contour(self, fname, mask='phase', image='phase', color=(1, 1, 0)): """saves the mask contour image to a file""" img = self.fluor_frame.contour_overlay(mask, image, color) imsave(fname, img)