def test_store_load_structuralMRI(tmph5factory): volume = Volume( origin=numpy.zeros((3, 3)), voxel_size=numpy.zeros((3, 3)) ) structural_mri = StructuralMRI( array_data=numpy.zeros((3, 3)), weighting="T1", volume=volume ) tmp_file = tmph5factory("StructuralMRI_{}.h5".format(volume.gid)) with StructuralMRIH5(tmp_file) as f: f.store(structural_mri) structural_mri_stored = StructuralMRI() with pytest.raises(TraitAttributeError): structural_mri_stored.array_data with pytest.raises(TraitAttributeError): structural_mri_stored.volume with StructuralMRIH5(tmp_file) as f: f.load_into(structural_mri_stored) assert structural_mri_stored.array_data.shape == (3, 3) # referenced datatype is not loaded with pytest.raises(TraitAttributeError): structural_mri_stored.volume
def _create_mri(self, volume): mri = StructuralMRI(storage_path=self.storage_path) mri.volume = volume mri.title = "NIFTI Import - " + os.path.split(self.data_file)[1] mri.dimensions_labels = ["X", "Y", "Z"] mri.weighting = "T1" self.parser.parse(mri, False) return mri
def _create_mri(self, volume, title): mri = StructuralMRI() mri.title = title mri.dimensions_labels = ["X", "Y", "Z"] mri.weighting = "T1" mri.array_data = self.parser.parse() mri.volume = volume return h5.store_complete(mri, self.storage_path)
def launch(self, view_model): resolution = view_model.resolution weighting = view_model.weighting inj_f_thresh = view_model.inj_f_thresh / 100. vol_thresh = view_model.vol_thresh project = dao.get_project_by_id(self.current_project_id) manifest_file = self.file_handler.get_allen_mouse_cache_folder( project.name) manifest_file = os.path.join(manifest_file, 'mouse_connectivity_manifest.json') cache = MouseConnectivityCache(resolution=resolution, manifest_file=manifest_file) # the method creates a dictionary with information about which experiments need to be downloaded ist2e = dictionary_builder(cache, False) # the method downloads experiments necessary to build the connectivity projmaps = download_an_construct_matrix(cache, weighting, ist2e, False) # the method cleans the file projmaps in 4 steps projmaps = pms_cleaner(projmaps) # download from the AllenSDK the annotation volume, the template volume vol, annot_info = cache.get_annotation_volume() template, template_info = cache.get_template_volume() # rotate template in the TVB 3D reference: template = rotate_reference(template) # grab the StructureTree instance structure_tree = cache.get_structure_tree() # the method includes in the parcellation only brain regions whose volume is greater than vol_thresh projmaps = areas_volume_threshold(cache, projmaps, vol_thresh, resolution) # the method exclude from the experimental dataset # those exps where the injected fraction of pixel in the injection site is lower than than the inj_f_thr projmaps = infected_threshold(cache, projmaps, inj_f_thresh) # the method creates file order and keyword that will be the link between the SC order and the # id key in the Allen database [order, key_ord] = create_file_order(projmaps, structure_tree) # the method builds the Structural Connectivity (SC) matrix structural_conn = construct_structural_conn(projmaps, order, key_ord) # the method returns the coordinate of the centres and the name of the brain areas in the selected parcellation [centres, names] = construct_centres(cache, order, key_ord) # the method returns the tract lengths between the brain areas in the selected parcellation tract_lengths = construct_tract_lengths(centres) # the method associated the parent and the grandparents to the child in the selected parcellation with # the biggest volume [unique_parents, unique_grandparents ] = parents_and_grandparents_finder(cache, order, key_ord, structure_tree) # the method returns a volume indexed between 0 and N-1, with N=tot brain areas in the parcellation. # -1=background and areas that are not in the parcellation vol_parcel = mouse_brain_visualizer(vol, order, key_ord, unique_parents, unique_grandparents, structure_tree, projmaps) # results: Connectivity, Volume & RegionVolumeMapping # Connectivity result_connectivity = Connectivity() result_connectivity.centres = centres result_connectivity.region_labels = numpy.array(names) result_connectivity.weights = structural_conn result_connectivity.tract_lengths = tract_lengths result_connectivity.configure() # Volume result_volume = Volume() result_volume.origin = numpy.array([[0.0, 0.0, 0.0]]) result_volume.voxel_size = numpy.array( [resolution, resolution, resolution]) # result_volume.voxel_unit= micron # Region Volume Mapping result_rvm = RegionVolumeMapping() result_rvm.volume = result_volume result_rvm.array_data = vol_parcel result_rvm.connectivity = result_connectivity result_rvm.title = "Volume mouse brain " result_rvm.dimensions_labels = ["X", "Y", "Z"] # Volume template result_template = StructuralMRI() result_template.array_data = template result_template.weighting = 'T1' result_template.volume = result_volume connectivity_index = h5.store_complete(result_connectivity, self.storage_path) volume_index = h5.store_complete(result_volume, self.storage_path) rvm_index = h5.store_complete(result_rvm, self.storage_path) template_index = h5.store_complete(result_template, self.storage_path) return [connectivity_index, volume_index, rvm_index, template_index]
def launch(self, resolution, weighting, inf_vox_thresh, vol_thresh): resolution = int(resolution) weighting = int(weighting) inf_vox_thresh = float(inf_vox_thresh) vol_thresh = float(vol_thresh) project = dao.get_project_by_id(self.current_project_id) manifest_file = self.file_handler.get_allen_mouse_cache_folder( project.name) manifest_file = os.path.join(manifest_file, 'mouse_connectivity_manifest.json') cache = MouseConnectivityCache(resolution=resolution, manifest_file=manifest_file) # the method creates a dictionary with information about which experiments need to be downloaded ist2e = DictionaireBuilder(cache, False) # the method downloads experiments necessary to build the connectivity projmaps = DownloadAndConstructMatrix(cache, weighting, ist2e, False) # the method cleans the file projmaps in 4 steps projmaps = pmsCleaner(projmaps) #download from the AllenSDK the annotation volume, the ontology, the template volume Vol, annot_info = cache.get_annotation_volume() ontology = cache.get_ontology() template, template_info = cache.get_template_volume() #rotate template in the TVB 3D reference: template = RotateReference(template) # the method includes in the parcellation only brain regions whose volume is greater than vol_thresh projmaps = AreasVolumeTreshold(cache, projmaps, vol_thresh, resolution, Vol, ontology) # the method includes in the parcellation only brain regions where at least one injection experiment had infected more than N voxel (where N is inf_vox_thresh) projmaps = AreasVoxelTreshold(cache, projmaps, inf_vox_thresh, Vol, ontology) # the method creates file order and keyord that will be the link between the SC order and the id key in the Allen database [order, key_ord] = CreateFileOrder(projmaps, ontology) # the method builds the Structural Connectivity (SC) matrix SC = ConstructingSC(projmaps, order, key_ord) # the method returns the coordinate of the centres and the name of the brain areas in the selected parcellation [centres, names] = Construct_centres(cache, ontology, order, key_ord) # the method returns the tract lengths between the brain areas in the selected parcellation tract_lengths = ConstructTractLengths(centres) # the method associated the parent and the grandparents to the child in the selected parcellation with the biggest volume [unique_parents, unique_grandparents ] = ParentsAndGrandParentsFinder(cache, order, key_ord, ontology) # the method returns a volume indexed between 0 and N-1, with N=tot brain areas in the parcellation. -1=background and areas that are not in the parcellation Vol_parcel = MouseBrainVisualizer(Vol, order, key_ord, unique_parents, unique_grandparents, ontology, projmaps) # results: Connectivity, Volume & RegionVolumeMapping # Connectivity result_connectivity = Connectivity(storage_path=self.storage_path) result_connectivity.centres = centres result_connectivity.region_labels = names result_connectivity.weights = SC result_connectivity.tract_lengths = tract_lengths # Volume result_volume = Volume(storage_path=self.storage_path) result_volume.origin = [[0.0, 0.0, 0.0]] result_volume.voxel_size = [resolution, resolution, resolution] # result_volume.voxel_unit= micron # Region Volume Mapping result_rvm = RegionVolumeMapping(storage_path=self.storage_path) result_rvm.volume = result_volume result_rvm.array_data = Vol_parcel result_rvm.connectivity = result_connectivity result_rvm.title = "Volume mouse brain " result_rvm.dimensions_labels = ["X", "Y", "Z"] # Volume template result_template = StructuralMRI(storage_path=self.storage_path) result_template.array_data = template result_template.weighting = 'T1' result_template.volume = result_volume return [ result_connectivity, result_volume, result_rvm, result_template ]
def launch(self, resolution, weighting, inj_f_thresh, vol_thresh): resolution = int(resolution) weighting = int(weighting) inj_f_thresh = float(inj_f_thresh)/100. vol_thresh = float(vol_thresh) project = dao.get_project_by_id(self.current_project_id) manifest_file = self.file_handler.get_allen_mouse_cache_folder(project.name) manifest_file = os.path.join(manifest_file, 'mouse_connectivity_manifest.json') cache = MouseConnectivityCache(resolution=resolution, manifest_file=manifest_file) # the method creates a dictionary with information about which experiments need to be downloaded ist2e = dictionary_builder(cache, False) # the method downloads experiments necessary to build the connectivity projmaps = download_an_construct_matrix(cache, weighting, ist2e, False) # the method cleans the file projmaps in 4 steps projmaps = pms_cleaner(projmaps) # download from the AllenSDK the annotation volume, the template volume vol, annot_info = cache.get_annotation_volume() template, template_info = cache.get_template_volume() # rotate template in the TVB 3D reference: template = rotate_reference(template) # grab the StructureTree instance structure_tree = cache.get_structure_tree() # the method includes in the parcellation only brain regions whose volume is greater than vol_thresh projmaps = areas_volume_threshold(cache, projmaps, vol_thresh, resolution) # the method exclude from the experimental dataset # those exps where the injected fraction of pixel in the injection site is lower than than the inj_f_thr projmaps = infected_threshold(cache, projmaps, inj_f_thresh) # the method creates file order and keyword that will be the link between the SC order and the # id key in the Allen database [order, key_ord] = create_file_order(projmaps, structure_tree) # the method builds the Structural Connectivity (SC) matrix structural_conn = construct_structural_conn(projmaps, order, key_ord) # the method returns the coordinate of the centres and the name of the brain areas in the selected parcellation [centres, names] = construct_centres(cache, order, key_ord) # the method returns the tract lengths between the brain areas in the selected parcellation tract_lengths = construct_tract_lengths(centres) # the method associated the parent and the grandparents to the child in the selected parcellation with # the biggest volume [unique_parents, unique_grandparents] = parents_and_grandparents_finder(cache, order, key_ord, structure_tree) # the method returns a volume indexed between 0 and N-1, with N=tot brain areas in the parcellation. # -1=background and areas that are not in the parcellation vol_parcel = mouse_brain_visualizer(vol, order, key_ord, unique_parents, unique_grandparents, structure_tree, projmaps) # results: Connectivity, Volume & RegionVolumeMapping # Connectivity result_connectivity = Connectivity(storage_path=self.storage_path) result_connectivity.centres = centres result_connectivity.region_labels = names result_connectivity.weights = structural_conn result_connectivity.tract_lengths = tract_lengths # Volume result_volume = Volume(storage_path=self.storage_path) result_volume.origin = [[0.0, 0.0, 0.0]] result_volume.voxel_size = [resolution, resolution, resolution] # result_volume.voxel_unit= micron # Region Volume Mapping result_rvm = RegionVolumeMapping(storage_path=self.storage_path) result_rvm.volume = result_volume result_rvm.array_data = vol_parcel result_rvm.connectivity = result_connectivity result_rvm.title = "Volume mouse brain " result_rvm.dimensions_labels = ["X", "Y", "Z"] # Volume template result_template = StructuralMRI(storage_path=self.storage_path) result_template.array_data = template result_template.weighting = 'T1' result_template.volume = result_volume return [result_connectivity, result_volume, result_rvm, result_template]