def test_clone_dataset(self): from mobie.utils import clone_dataset ds2 = 'test-clone' clone_dataset(self.root, self.dataset_name, ds2) validate_project(self.root, assert_true=self.assertTrue, assert_in=self.assertIn, assert_equal=self.assertEqual)
def test_bdv_importer(self): add_bdv_image(self.xml_path, self.root, self.dataset_name, tmp_folder=self.tmp_folder) validate_project(self.root) meta = read_dataset_metadata(f"{self.root}/{self.dataset_name}") self.assertIn(self.image_name, meta["sources"]) im_path = meta["sources"][self.image_name]["image"]["imageData"]["bdv.n5"]["relativePath"] im_path = os.path.join(self.root, self.dataset_name, im_path).replace("xml", "n5") self.assertTrue(os.path.exists(im_path)) with open_file(im_path, "r") as f: data = f["setup0/timepoint0/s0"][:] self.assertTrue(np.allclose(data, self.data))
def check_dataset(self, dataset_folder, exp_shape, raw_name, file_format="bdv.n5"): # validate the full project validate_project( self.root, assert_true=self.assertTrue, assert_in=self.assertIn, assert_equal=self.assertEqual ) # check the raw data folder_name = file_format.replace(".", "-") if file_format.startswith("bdv"): xml_path = os.path.join(dataset_folder, "images", folder_name, f"{raw_name}.xml") raw_path = get_data_path(xml_path, return_absolute_path=True) is_h5 = file_format == "bdv.hdf5" key = get_key(is_h5, 0, 0, 0) else: self.assertEqual(file_format, "ome.zarr") raw_path = os.path.join(dataset_folder, "images", folder_name, f"{raw_name}.ome.zarr") key = "s0" with open_file(raw_path, "r") as f: data = f[key][:] shape = data.shape self.assertEqual(shape, exp_shape) self.assertFalse(np.allclose(data, 0.))
def add_open_organelle_data( address, root, internal_path, source_name=None, dataset_name=None, # region="us-west-2", # we don't seem to need this anon=True, view=None, menu_name=None, is_default_dataset=False, overwrite=False): """ address [str] - root [str] - internal_path [str] - source_name [str] - dataset_name [str] - anon [bool] - view [dict] - default view settings for this source (default: None) menu_name [str] - menu name for this source. If none will be derived from the source name. (default: None) is_default_dataset [bool] - overwrite [bool] """ if not s3_utils.have_boto(): raise RuntimeError( "boto3 is required to access open organelle data. Please install it." ) file_format = 'openOrganelle.s3' if not metadata.project_exists(root): metadata.create_project_metadata(root, [file_format]) endpoint, bucket, container = parse_address(address) dataset_name = bucket if dataset_name is None else dataset_name ds_exists = metadata.dataset_exists(root, dataset_name) ds_folder = os.path.join(root, dataset_name) if ds_exists: ds_metadata = metadata.read_dataset_metadata(ds_folder) sources, views = ds_metadata['sources'], ds_metadata['views'] else: sources, views = {}, {} client = s3_utils.get_client(endpoint, anon=anon) name, source, view = get_source(client, bucket, container, internal_path, endpoint, ds_folder, source_name, view, menu_name) if name in sources: if overwrite: print("The source", name, "exists already and will be over-written") else: print("The source", name, "exists already and will not be over-written") return sources[name] = source views[name] = view if ds_exists: ds_metadata['sources'] = sources ds_metadata['views'] = views metadata.write_dataset_metadata(ds_folder, ds_metadata) else: os.makedirs(ds_folder, exist_ok=True) default_view = views[list(views.keys())[0]] default_view["sourceDisplays"]["uiSelectionGroup"] = "bookmarks" views["default"] = default_view metadata.create_dataset_metadata(ds_folder, sources=sources, views=views) metadata.add_dataset(root, dataset_name, is_default_dataset) validate_project(root)
def test_validate_project(self): from mobie.validation import validate_project validate_project(self.data_folder)