def test_set_tag(self):
     experiment = self._create_experiment()
     experiment.set_tag('Population', False)
     exp2 = Experiment(os.path.join(self.tst_experiment_dir,
                                    'myexperiment',
                                    'experiment.md.json'))
     self.assertTrue('Population' in exp2.metadata.tags)
 def test_create_experiment(self):
     experiment = Experiment()
     metadata = create_experiment()
     experiment.create(metadata.name, metadata.author, metadata.date,
                       self.tst_experiment_dir)
     t1 = os.path.isdir(os.path.join(self.tst_experiment_dir,
                                     'myexperiment'))
     t2 = os.path.isfile(os.path.join(self.tst_experiment_dir,
                                      'myexperiment',
                                      'experiment.md.json'))
     t3 = os.path.isdir(os.path.join(self.tst_experiment_dir,
                                     'myexperiment',
                                     'data'))
     t4 = os.path.isfile(os.path.join(self.tst_experiment_dir,
                                      'myexperiment',
                                      'data',
                                      'rawdataset.md.json'))
     self.assertTrue(t1*t2*t3*t4)  
Beispiel #3
0
    def _import_image(self, experiment: Experiment, image):

        # read metadata from omero
        rawdatasetdir = os.path.dirname(experiment.md_uri)
        filename = os.path.join(rawdatasetdir, 'data', image.getName())
        author = image.getAuthor()
        date = image.getDate().strftime('%Y-%m-%d %I:%M %S %p')
        extension = os.path.splitext(image.getName())[1][1:]

        tags = dict()
        for ann in image.listAnnotations():
            if ann.OMERO_TYPE == omero.model.MapAnnotationI:
                for kv in ann.getValue():
                    tags[kv[0]] = kv[1]

        # print('readed tags:')
        # print('\t author:', author)
        # print('\t date:', date)
        # print('\t extension:', extension)
        # print('\t tags:', tags)

        # write metadata to the experiment
        experiment.import_data(
            filename,
            image.getName(),
            author=author,
            format=extension,
            date=date,
            tags=tags,
            copy=False,
        )

        # register tag to experiment if not exists
        for tag in tags:
            experiment.set_tag(tag, False)

        # copy image
        channel = 0
        imageData = _get_data(image, channel)
        tif = TIFF.open(filename, mode='w')
        for t in range(imageData.shape[0]):
            for z in range(imageData.shape[1]):
                tif.write_image(imageData[t, z, :, :])
        tif.close()
 def test_write_experiment(self):
     experiment = Experiment(self.tst_experiment_file)
     experiment.metadata = create_experiment()
     experiment.write()
     self.assertTrue(filecmp.cmp(self.tst_experiment_file,
                                 self.ref_experiment_file, shallow=False))
 def test_read_experiment(self):
     read_experiment = Experiment(self.ref_experiment_file) 
     ref_experiment_container = create_experiment()
     self.assertEqual(read_experiment.metadata.serialize(),
                      ref_experiment_container.serialize())
 def _create_experiment(self):
     experiment = Experiment()
     metadata = create_experiment()
     experiment.create(metadata.name, metadata.author, metadata.date,
                       self.tst_experiment_dir)
     return experiment  
 def test_get_dataset2(self):
     # processed dataset
     experiment = Experiment(self.ref_experiment_file)
     raw_dataset = experiment.get_dataset('process1')    
     self.assertEqual(raw_dataset.metadata.name, 'process1')        
 def test_get_dataset1(self):
     # raw dataset
     experiment = Experiment(self.ref_experiment_file)
     raw_dataset = experiment.get_dataset('data')    
     self.assertEqual(raw_dataset.metadata.name, 'data')