Example #1
0
    def load(self, filename, load_pipeline):
        '''Load a workspace from a .cpi file
        
        filename - path to file to load
        
        load_pipeline - true to load the pipeline from the file, false to
                        use the current pipeline.
        '''
        import shutil
        from .pipeline import M_PIPELINE, M_DEFAULT_INPUT_FOLDER, \
             M_DEFAULT_OUTPUT_FOLDER
        import cellprofiler.measurements as cpmeas
        from cellprofiler.preferences import set_default_image_directory, \
             set_default_output_directory
        
        if self.__measurements is not None:
            self.close()
        self.__loading = True
        try:
            #
            # Copy the file to a temporary location before opening
            #
            fd, self.__filename = cpmeas.make_temporary_file()
            os.close(fd)
            
            shutil.copyfile(filename, self.__filename)
                
            self.__measurements = cpmeas.Measurements(
                filename = self.__filename, mode = "r+")
            if self.__file_list is not None:
                self.__file_list.remove_notification_callback(
                    self.__on_file_list_changed)
            self.__file_list = HDF5FileList(self.measurements.hdf5_dict.hdf5_file)
            self.__file_list.add_notification_callback(self.__on_file_list_changed)
            if load_pipeline and self.__measurements.has_feature(
                cpmeas.EXPERIMENT, M_PIPELINE):
                pipeline_txt = self.__measurements.get_experiment_measurement(
                    M_PIPELINE).encode("utf-8")
                self.pipeline.load(StringIO(pipeline_txt))
            elif load_pipeline:
                self.pipeline.clear()
            else:
                fd = StringIO()
                self.pipeline.savetxt(fd, save_image_plane_details = False)
                self.__measurements.add_experiment_measurement(
                    M_PIPELINE, fd.getvalue())

            for feature, function in (
                (M_DEFAULT_INPUT_FOLDER, set_default_image_directory),
                (M_DEFAULT_OUTPUT_FOLDER, set_default_output_directory)):
                if self.measurements.has_feature(cpmeas.EXPERIMENT, feature):
                    path = self.measurements[cpmeas.EXPERIMENT, feature]
                    if os.path.isdir(path):
                        function(path)
                
        finally:
            self.__loading = False
        self.notify(self.WorkspaceLoadedEvent(self))
Example #2
0
    def load(self, filename, load_pipeline):
        '''Load a workspace from a .cpi file
        
        filename - path to file to load
        
        load_pipeline - true to load the pipeline from the file, false to
                        use the current pipeline.
        '''
        import shutil
        from .pipeline import M_PIPELINE
        import cellprofiler.measurements as cpmeas

        if self.__measurements is not None:
            self.close()
        #
        # Copy the file to a temporary location before opening
        #
        fd, self.__filename = cpmeas.make_temporary_file()
        os.close(fd)

        shutil.copyfile(filename, self.__filename)

        self.__measurements = cpmeas.Measurements(filename=self.__filename,
                                                  mode="r+")
        if self.__file_list is not None:
            self.__file_list.remove_notification_callback(
                self.__on_file_list_changed)
        self.__file_list = HDF5FileList(self.measurements.hdf5_dict.hdf5_file)
        self.__file_list.add_notification_callback(self.__on_file_list_changed)
        if load_pipeline and self.__measurements.has_feature(
                cpmeas.EXPERIMENT, M_PIPELINE):
            pipeline_txt = self.__measurements.get_experiment_measurement(
                M_PIPELINE).encode("utf-8")
            self.pipeline.load(StringIO(pipeline_txt))
        elif load_pipeline:
            self.pipeline.clear()
        else:
            fd = StringIO()
            self.pipeline.savetxt(fd, save_image_plane_details=False)
            self.__measurements.add_experiment_measurement(
                M_PIPELINE, fd.getvalue())
        self.notify(self.WorkspaceLoadedEvent(self))
Example #3
0
 def load(self, filename, load_pipeline):
     '''Load a workspace from a .cpi file
     
     filename - path to file to load
     
     load_pipeline - true to load the pipeline from the file, false to
                     use the current pipeline.
     '''
     import shutil
     from .pipeline import M_PIPELINE
     import cellprofiler.measurements as cpmeas
     
     if self.__measurements is not None:
         self.close()
     #
     # Copy the file to a temporary location before opening
     #
     fd, self.__filename = cpmeas.make_temporary_file()
     os.close(fd)
     
     shutil.copyfile(filename, self.__filename)
         
     self.__measurements = cpmeas.Measurements(
         filename = self.__filename, mode = "r+")
     if self.__file_list is not None:
         self.__file_list.remove_notification_callback(
             self.__on_file_list_changed)
     self.__file_list = HDF5FileList(self.measurements.hdf5_dict.hdf5_file)
     self.__file_list.add_notification_callback(self.__on_file_list_changed)
     if load_pipeline and self.__measurements.has_feature(
         cpmeas.EXPERIMENT, M_PIPELINE):
         pipeline_txt = self.__measurements.get_experiment_measurement(
             M_PIPELINE).encode("utf-8")
         self.pipeline.load(StringIO(pipeline_txt))
     elif load_pipeline:
         self.pipeline.clear()
     else:
         fd = StringIO()
         self.pipeline.savetxt(fd, save_image_plane_details = False)
         self.__measurements.add_experiment_measurement(
             M_PIPELINE, fd.getvalue())
     self.notify(self.WorkspaceLoadedEvent(self))
Example #4
0
    def load(self, filename, load_pipeline):
        '''Load a workspace from a .cpi file
        
        filename - path to file to load
        
        load_pipeline - true to load the pipeline from the file, false to
                        use the current pipeline.
        '''
        import shutil
        from .pipeline import M_PIPELINE, M_DEFAULT_INPUT_FOLDER, \
             M_DEFAULT_OUTPUT_FOLDER
        import cellprofiler.measurements as cpmeas
        from cellprofiler.preferences import set_default_image_directory, \
             set_default_output_directory

        image_set_and_measurements_are_same = False
        if self.__measurements is not None:
            image_set_and_measurements_are_same = (id(
                self.__measurements) == id(self.__image_set))
            self.close()
        self.__loading = True
        try:
            #
            # Copy the file to a temporary location before opening
            #
            fd, self.__filename = cpmeas.make_temporary_file()
            os.close(fd)

            shutil.copyfile(filename, self.__filename)

            self.__measurements = cpmeas.Measurements(filename=self.__filename,
                                                      mode="r+")
            if self.__file_list is not None:
                self.__file_list.remove_notification_callback(
                    self.__on_file_list_changed)
            self.__file_list = HDF5FileList(
                self.measurements.hdf5_dict.hdf5_file)
            self.__file_list.add_notification_callback(
                self.__on_file_list_changed)
            if load_pipeline and self.__measurements.has_feature(
                    cpmeas.EXPERIMENT, M_PIPELINE):
                pipeline_txt = self.__measurements.get_experiment_measurement(
                    M_PIPELINE).encode("utf-8")
                self.pipeline.load(StringIO(pipeline_txt))
            elif load_pipeline:
                self.pipeline.clear()
            else:
                fd = StringIO()
                self.pipeline.savetxt(fd, save_image_plane_details=False)
                self.__measurements.add_experiment_measurement(
                    M_PIPELINE, fd.getvalue())

            for feature, function in ((M_DEFAULT_INPUT_FOLDER,
                                       set_default_image_directory),
                                      (M_DEFAULT_OUTPUT_FOLDER,
                                       set_default_output_directory)):
                if self.measurements.has_feature(cpmeas.EXPERIMENT, feature):
                    path = self.measurements[cpmeas.EXPERIMENT, feature]
                    if os.path.isdir(path):
                        function(path)
            if image_set_and_measurements_are_same:
                self.__image_set = self.__measurements

        finally:
            self.__loading = False
        self.notify(self.WorkspaceLoadedEvent(self))