def from_file_projection_array(source_file="projection_eeg_62_surface_16k.mat", matlab_data_name="ProjectionMatrix"): source_full_path = try_get_absolute_path("tvb_data.projectionMatrix", source_file) reader = FileReader(source_full_path) return reader.read_array(matlab_data_name=matlab_data_name)
def from_file(source_file="connectivity_76.zip", instance=None): if instance is None: result = Connectivity() else: result = instance source_full_path = try_get_absolute_path("tvb_data.connectivity", source_file) if source_file.endswith(".h5"): reader = H5Reader(source_full_path) result.weights = reader.read_field("weights") result.centres = reader.read_field("centres") result.region_labels = reader.read_field("region_labels") result.orientations = reader.read_optional_field("orientations") result.cortical = reader.read_optional_field("cortical") result.hemispheres = reader.read_field("hemispheres") result.areas = reader.read_optional_field("areas") result.tract_lengths = reader.read_field("tract_lengths") else: reader = ZipReader(source_full_path) result.weights = reader.read_array_from_file("weights") result.centres = reader.read_array_from_file("centres", use_cols=(1, 2, 3)) result.region_labels = reader.read_array_from_file("centres", dtype=numpy.str, use_cols=(0,)) result.orientations = reader.read_optional_array_from_file("average_orientations") result.cortical = reader.read_optional_array_from_file("cortical", dtype=numpy.bool) result.hemispheres = reader.read_optional_array_from_file("hemispheres", dtype=numpy.bool) result.areas = reader.read_optional_array_from_file("areas") result.tract_lengths = reader.read_array_from_file("tract_lengths") return result
def from_file(source_file="nonexistent.zip", instance=None): ''' Borrowed from connectivity.Connectivity - copied here and modified to match filesnames of Berlin connectivity .txts in connectivity.zip (ie orientation.txt rather than average_orientations.txt) :param source_file: :param instance: :return: Connectivity object from source_file. ''' if instance is None: result = connectivity.Connectivity() else: result = instance source_full_path = try_get_absolute_path("tvb_data.connectivity", source_file) reader = ZipReader(source_full_path) result.areas = reader.read_array_from_file("area") result.region_labels = reader.read_array_from_file("centres", dtype=numpy.str, use_cols=(0,)) result.centres = reader.read_array_from_file("centres", use_cols=(1, 2, 3)) result.cortical = reader.read_array_from_file("cortical", dtype=numpy.bool) result.hemispheres = reader.read_array_from_file("hemisphere", dtype=numpy.bool) result.orientations = reader.read_array_from_file("orientation") result.tract_lengths = reader.read_array_from_file("tract") result.weights = reader.read_array_from_file("weights") return result
def from_file(source_file="regionMapping_16k_76.txt"): source_full_path = try_get_absolute_path("tvb_data.regionMapping", source_file) reader = FileReader(source_full_path) result = RegionMapping() result.array_data = reader.read_array(dtype=numpy.int32) return result
def from_file(source_file="local_connectivity_16384.mat", instance=None): source_full_path = try_get_absolute_path("tvb_data.local_connectivity", source_file) reader = FileReader(source_full_path) matrix = reader.read_array(matlab_data_name="LocalCoupling") return matrix
def from_file(source_file="regionMapping_16k_76.txt", instance=None): source_full_path = try_get_absolute_path("tvb_data.regionMapping", source_file) reader = FileReader(source_full_path) mapping = reader.read_array(dtype=numpy.int32) return mapping
def from_file_region_mapping_array(source_file=os.path.join( "cortex_reg13", "all_regions_cortex_reg13.txt")): source_full_path = try_get_absolute_path("tvb_data.surfaceData", source_file) reader = FileReader(source_full_path) return reader.read_array(dtype=numpy.int32)
def from_file(cls, source_file="meg_151.txt.bz2"): result = super(SensorsMEG, cls).from_file(source_file) source_full_path = try_get_absolute_path("tvb_data.sensors", source_file) reader = FileReader(source_full_path) result.orientations = reader.read_array(use_cols=(4, 5, 6)) return result
def populate_table(result, source_file): source_full_path = try_get_absolute_path("tvb_data.tables", source_file) zip_data = numpy.load(source_full_path) result.df = zip_data['df'] result.xmin, result.xmax = zip_data['min_max'] result.data = zip_data['f'] return result
def from_file(cls, source_file="meg_151.txt.bz2", instance=None): #labels, locations = super(SensorsMEG, cls).from_file(source_file=source_file) source_full_path = try_get_absolute_path("tvb_data.sensors", source_file) reader = FileReader(source_full_path) orientations = reader.read_array(use_cols=(4, 5, 6)) return orientations
def from_file(source_file="local_connectivity_16384.mat"): result = LocalConnectivity() source_full_path = try_get_absolute_path("tvb_data.local_connectivity", source_file) reader = FileReader(source_full_path) result.matrix = reader.read_array(matlab_data_name="LocalCoupling") return result
def from_file(cls, source_file=None, matlab_data_name=None, is_brainstorm=False, instance=None): source_full_path = try_get_absolute_path("tvb_data.projectionMatrix", source_file) reader = FileReader(source_full_path) if is_brainstorm: projection_data = reader.read_gain_from_brainstorm() else: projection_data = reader.read_array(matlab_data_name=matlab_data_name) return projection_data
def from_file(cls, source_file="eeg_brainstorm_65.txt"): result = cls() source_full_path = try_get_absolute_path("tvb_data.sensors", source_file) reader = FileReader(source_full_path) result.labels = reader.read_array(dtype=numpy.str, use_cols=(0,)) result.locations = reader.read_array(use_cols=(1, 2, 3)) return result
def import_surface_rm(project_id, conn_gid): # Import surface and region mapping from tvb_data berlin subjects (68 regions) rm_file = try_get_absolute_path("tvb_data", "berlinSubjects/DH_20120806/DH_20120806_RegionMapping.txt") surface_zip_file = try_get_absolute_path("tvb_data", "berlinSubjects/DH_20120806/DH_20120806_Surface_Cortex.zip") surface_importer = ABCAdapter.build_adapter_from_class(ZIPSurfaceImporter) surface_imp_model = ZIPSurfaceImporterModel() surface_imp_model.uploaded = surface_zip_file surface_imp_operation = fire_operation(project_id, surface_importer, surface_imp_model) surface_imp_operation = wait_to_finish(surface_imp_operation) surface_gid = dao.get_results_for_operation(surface_imp_operation.id)[0].gid rm_importer = ABCAdapter.build_adapter_from_class(RegionMappingImporter) rm_imp_model = RegionMappingImporterModel() rm_imp_model.mapping_file = rm_file rm_imp_model.surface = surface_gid rm_imp_model.connectivity = conn_gid rm_import_operation = fire_operation(project_id, rm_importer, rm_imp_model) wait_to_finish(rm_import_operation)
def from_file(cls, source_file="eeg_brainstorm_65.txt", instance=None): source_full_path = try_get_absolute_path("tvb_data.sensors", source_file) reader = FileReader(source_full_path) labels = reader.read_array(dtype="string", use_cols=(0, )) locations = reader.read_array(use_cols=(1, 2, 3)) return labels, locations
def from_file(cls, source_file="cortex_16384.zip"): """Construct a Surface from source_file.""" result = cls() source_full_path = try_get_absolute_path("tvb_data.surfaceData", source_file) reader = ZipReader(source_full_path) result.vertices = reader.read_array_from_file("vertices.txt") result.vertex_normals = reader.read_array_from_file("normals.txt") result.triangles = reader.read_array_from_file("triangles.txt", dtype=numpy.int32) return result
def from_file(source_file=os.path.join("cortex_reg13", "region_mapping", "o52r00_irp2008_hemisphere_both_subcortical_false_regions_74.txt.bz2"), instance=None): if instance is None: result = RegionMapping() else: result = instance source_full_path = try_get_absolute_path("tvb_data.surfaceData", source_file) reader = FileReader(source_full_path) result.array_data = reader.read_array(dtype=numpy.int32) return result
def from_file(source_file="regionMapping_16k_76.txt", instance=None): if instance is None: result = RegionMapping() else: result = instance source_full_path = try_get_absolute_path("tvb_data.regionMapping", source_file) reader = FileReader(source_full_path) result.array_data = reader.read_array(dtype=numpy.int32) return result
def from_file(source_file=os.path.join("cortex_reg13", "local_connectivity_surface_cortex_reg13.mat"), instance=None): if instance is None: result = LocalConnectivity() else: result = instance source_full_path = try_get_absolute_path("tvb_data.surfaceData", source_file) reader = FileReader(source_full_path) result.matrix = reader.read_array(matlab_data_name="LocalCoupling") return result
def from_file(source_file=os.path.join("cortex_reg13", "all_regions_cortex_reg13.txt"), instance=None): if instance is None: result = RegionMapping() else: result = instance source_full_path = try_get_absolute_path("tvb_data.surfaceData", source_file) reader = FileReader(source_full_path) result.array_data = reader.read_array(dtype=numpy.int32) return result
def from_file(cls, source_file="eeg_unitvector_62.txt.bz2", instance=None): if instance is None: result = cls() else: result = instance source_full_path = try_get_absolute_path("tvb_data.sensors", source_file) reader = FileReader(source_full_path) result.labels = reader.read_array(dtype="string", use_cols=(0, )) result.locations = reader.read_array(use_cols=(1, 2, 3)) return result
def load_surface_projection_matrix(result, source_file): source_full_path = try_get_absolute_path("tvb_data.projectionMatrix", source_file) if source_file.endswith(".mat"): # consider we have a brainstorm format mat = scipy.io.loadmat(source_full_path) gain, loc, ori = (mat[field] for field in 'Gain GridLoc GridOrient'.split()) result.projection_data = (gain.reshape( (gain.shape[0], -1, 3)) * ori).sum(axis=-1) elif source_file.endswith(".npy"): # numpy array with the projection matrix already computed result.projection_data = numpy.load(source_full_path) else: raise Exception( "The projection matrix must be either a numpy array or a brainstorm mat file" ) return result
def from_file(cls, source_file=os.path.join("cortex_reg13", "surface_cortex_reg13.zip"), instance=None): """ Construct a Surface from source_file. """ if instance is None: result = cls() else: result = instance source_full_path = try_get_absolute_path("tvb_data.surfaceData", source_file) reader = ZipReader(source_full_path) result.vertices = reader.read_array_from_file("vertices.txt") result.vertex_normals = reader.read_array_from_file("normals.txt") result.triangles = reader.read_array_from_file("triangles.txt", dtype=numpy.int32) return result
def from_file(source_file="connectivity_76.zip", instance=None): source_full_path = try_get_absolute_path("tvb_data.connectivity", source_file) if source_file.endswith(".h5"): reader = H5Reader(source_full_path) weights = reader.read_field("weights") centres = reader.read_field("centres") region_labels = reader.read_field("region_labels") orientations = reader.read_optional_field("orientations") cortical = reader.read_optional_field("cortical") hemispheres = reader.read_field("hemispheres") areas = reader.read_optional_field("areas") tract_lengths = reader.read_field("tract_lengths") else: reader = ZipReader(source_full_path) weights = reader.read_array_from_file("weights") if reader.has_file_like("centres"): centres = reader.read_array_from_file("centres", use_cols=(1, 2, 3)) region_labels = reader.read_array_from_file("centres", dtype=numpy.str, use_cols=(0, )) else: centres = reader.read_array_from_file("centers", use_cols=(1, 2, 3)) region_labels = reader.read_array_from_file("centers", dtype=numpy.str, use_cols=(0, )) orientations = reader.read_optional_array_from_file( "average_orientations") cortical = reader.read_optional_array_from_file("cortical", dtype=numpy.bool) hemispheres = reader.read_optional_array_from_file( "hemispheres", dtype=numpy.bool) areas = reader.read_optional_array_from_file("areas") tract_lengths = reader.read_array_from_file("tract_lengths") return weights, centres, region_labels, orientations, cortical, hemispheres, areas, tract_lengths