コード例 #1
0
def read_ts(path=os.path.join(PATIENT_VIRTUAL_HEAD, "ep", "ts.h5"), data=None):
    """
    :param path: Path towards a valid TimeSeries H5 file
    :return: Timeseries in a numpy array
    """
    print "Reading TimeSeries from:", path
    h5_file = h5py.File(path, 'r', libver='latest')
    print_metadata(h5_file)
    print "Structures:", h5_file["/"].keys()

    if isinstance(data, dict):

        for key in data:
            print "Data expected shape:", h5_file['/' + key].shape
            data[key] = h5_file['/' + key][()]
            print "Actual Data shape", data[key].shape
            print "First Channel sv sum", numpy.sum(data[key][:, 0])

    else:

        print "Data expected shape:", h5_file['/data'].shape

        data = h5_file['/data'][()]
        print "Actual Data shape", data.shape
        print "First Channel sv sum", numpy.sum(data[:, 0])

    total_time = int(h5_file["/"].attrs["Simulated_period"][0])
    nr_of_steps = int(h5_file["/data"].attrs["Number_of_steps"][0])
    start_time = float(h5_file["/data"].attrs["Start_time"][0])

    time = numpy.linspace(start_time, total_time, nr_of_steps)

    h5_file.close()
    return time, data
コード例 #2
0
ファイル: read_write.py プロジェクト: alzami1986/tvb-epilepsy
def read_hypothesis(path=os.path.join(PATIENT_VIRTUAL_HEAD, "ep", "hypo_ep.h5"), output="object", hypo_name=None,
                    update_hypothesis=True):
    """
    :param path: Path towards an hypothesis H5 file
    :return: hypothesis object
    """

    print "Reading Hypothesis from:", path
    h5_file = h5py.File(path, 'r', libver='latest')

    print_metadata(h5_file)

    overwrite_fields_dict = {"seizure_indices":
                                 numpy.array(numpy.where(h5_file["/EZ hypothesis"][()] > 0)).astype("i").squeeze()}

    if isinstance(hypo_name, basestring):
        overwrite_fields_dict.update({"name": hypo_name})

    if output == "dict":
        hyp = dict()
    else:
        hyp = Hypothesis(h5_file['/Connectivity'][()].shape[0], h5_file['/Connectivity'][()])

    read_object_from_h5_file(hyp, h5_file, hyp_attributes_dict, add_overwrite_fields_dict=overwrite_fields_dict)

    if output != "dict" and update_hypothesis:
        hyp._update_parameters(hyp.seizure_indices)

    h5_file.close()

    return hyp
コード例 #3
0
ファイル: read_write.py プロジェクト: alzami1986/tvb-epilepsy
def read_simulation_settings(path=os.path.join(PATIENT_VIRTUAL_HEAD, "ep", "sim_ep.h5"), output="object",
                             hypothesis=None):
    """
    :param path: Path towards an hypothesis H5 file
    :return: hypothesis object
    """

    print "Reading simulation settings from:", path
    h5_file = h5py.File(path, 'r', libver='latest')

    print_metadata(h5_file)

    if output == "dict" or not (isinstance(hypothesis, Hypothesis)):
        model = dict()
        if hypothesis is not None:
            warnings.warn("hypothesis is not a Hypothesis object. Returning a dictionary for model.")
    else:
        if h5_file['/' + "model.name"][()] == "Epileptor":
            model = model_build_dict[h5_file['/' + "model.name"][()]](hypothesis)
        else:
            model = model_build_dict[h5_file['/' + "model.name"][()]](hypothesis,
                                                                      zmode=h5_file['/' + "model.zmode"][()])

    if h5_file['/' + "model.name"][()] != "Epileptor":
        overwrite_fields_dict = {"zmode": numpy.array(h5_file['/' + "model.zmode"][()])}
        if h5_file['/' + "model.name"][()] == "EpileptorDPrealistic":
            overwrite_fields_dict.update({"pmode": numpy.array(h5_file['/' + "model.pmode"][()])})

    read_object_from_h5_file(model, h5_file, epileptor_model_attributes_dict[h5_file['/' + "model.name"][()]],
                             add_overwrite_fields_dict=overwrite_fields_dict)

    if output == "dict":
        sim_settings = dict()
    else:
        sim_settings = SimulationSettings()

    # overwrite_fields_dict = {"monitor_expressions": h5_file['/' + "Monitor expressions"][()].tostring().split(","),
    #                          "variables_names": h5_file['/' + "Variables names"][()].tostring().split(",")}
    overwrite_fields_dict = {"monitor_expressions": h5_file['/' + "Monitor expressions"][()].tolist(),
                             "variables_names": h5_file['/' + "Variables names"][()].tolist()}

    read_object_from_h5_file(sim_settings, h5_file, simulation_settings_attributes_dict,
                             add_overwrite_fields_dict=overwrite_fields_dict)

    h5_file.close()

    return model, sim_settings
コード例 #4
0
ファイル: read_write.py プロジェクト: alzami1986/tvb-epilepsy
def read_epileptogenicity(path=os.path.join(PATIENT_VIRTUAL_HEAD, "ep", "ep.h5")):
    """
    :param path: Path towards an epileptogenicity H5 file
    :return: epileptogenicity in a numpy array
    """
    print "Reading Epileptogenicity from:", path
    h5_file = h5py.File(path, 'r', libver='latest')

    print_metadata(h5_file)
    print "Structures:", h5_file["/"].keys()
    print "Values expected shape:", h5_file['/values'].shape

    values = h5_file['/values'][()]
    print "Actual values shape", values.shape

    h5_file.close()
    return values
コード例 #5
0
def read_ts_epi(path=os.path.join(PATIENT_VIRTUAL_HEAD, "ep", "ts.h5")):
    """
    :param path: Path towards a valid TimeSeries H5 file
    :return: Timeseries in a numpy array
    """
    print "Reading TimeSeries from:", path
    h5_file = h5py.File(path, 'r', libver='latest')

    print_metadata(h5_file)
    print "Structures:", h5_file["/"].keys()
    print "Data expected shape:", h5_file['/data'].shape

    data = h5_file['/data'][()]
    print "Actual Data shape", data.shape
    print "First Channel sv sum", numpy.sum(data[:, 0, :], axis=1)

    h5_file.close()
    return data
コード例 #6
0
def read_epileptogenicity(
        path=os.path.join(PATIENT_VIRTUAL_HEAD, "ep", "ep.h5"), logger=logger):
    """
    :param path: Path towards an epileptogenicity H5 file
    :return: epileptogenicity in a numpy array
    """
    logger.info("Reading Epileptogenicity from:\n" + path)
    h5_file = h5py.File(path, 'r', libver='latest')

    print_metadata(h5_file, logger)
    logger.info("Structures:\n" + str(h5_file["/"].keys()))
    logger.info("Values expected shape: " + str(h5_file['/values'].shape))

    values = h5_file['/values'][()]
    logger.info("Actual values shape: " + str(values.shape))

    h5_file.close()
    return values
コード例 #7
0
def read_ts_epi(
        path=os.path.join(PATIENT_VIRTUAL_HEAD, "ep", "ts.h5"), logger=logger):
    """
    :param path: Path towards a valid TimeSeries H5 file
    :return: Timeseries in a numpy array
    """
    logger.info("Reading TimeSeries from:\n" + path)
    h5_file = h5py.File(path, 'r', libver='latest')

    print_metadata(h5_file, logger)
    logger.info("Structures:\n" + str(h5_file["/"].keys()))
    logger.info("Values expected shape: " + str(h5_file['/data'].shape))
    h5_file['/data']

    data = h5_file['/data'][()]
    logger.info("Actual Data shape: " + str(data.shape))
    logger.info("First Channel sv sum: " +
                str(numpy.sum(data[:, 0, :], axis=1)))

    h5_file.close()
    return data