Beispiel #1
0
    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
Beispiel #2
0
 def from_h5_file(cls, source_file, **kwargs):
     result = cls()
     reader = H5Reader(source_file)
     for attr in dir(result):
         try:
             val = reader.read_field(attr)
         except:
             continue
         if isinstance(val, np.ndarray) and val.dtype == "O":
             setattr(result, attr, np.array([np.str(v) for v in val]))
         else:
             setattr(result, attr, val)
     for attr, value in kwargs.items():
         setattr(result, attr, value)
     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