Beispiel #1
0
def import_dynamics(filename: Text) -> Dynamics:
    """
    Load dynamics from a file (format TempoDynamicsFormat version 1.0).

    Parameters
    ----------
    filename: str
        Path and filename to file that should read in.

    Returns
    -------
    dynamics: Dynamics
        The time evolution stored in the file `filename`.
    """
    dyn = load_object(filename)
    assert "version" in dyn, \
        "Can't import dynamics from file {} ".format(filename) \
        + "because it doesn't have a 'version' field."
    assert dyn["version"] == "1.0", \
        "Can't import dynamics from file {} ".format(filename) \
        + "as it appears to be an incompatible version."
    assert_tempo_dynamics_dict(dyn)
    return Dynamics(times=list(dyn["times"]),
                    states=list(dyn["states"]),
                    name=dyn["name"],
                    description=dyn["description"],
                    description_dict=dyn["description_dict"])
def import_process_tensor(filename: Text) -> ProcessTensor:
    """
    Load process tensor from a file (format ProcessTensorFormat version 1.0).

    Parameters
    ----------
    filename: str
        Path and filename to file that should read in.

    Returns
    -------
    process_tensor: ProcessTensor
        The process tensor stored in the file `filename`.
    """
    p_t = load_object(filename)
    assert "version" in p_t, \
        "Can't import process tensor from file {} ".format(filename) \
        + "because it doesn't have a 'version' field."
    assert p_t["version"] == "1.0", \
        "Can't import process tensor from file {} ".format(filename) \
        + "as it appears to be an incompatible version."
    assert_process_tensor_dict(p_t)

    return ProcessTensor(times=p_t["times"],
                         tensors=list(p_t["tensors"]),
                         initial_tensor=p_t["initial_tensor"],
                         name=p_t["name"],
                         description=p_t["description"],
                         description_dict=p_t["description_dict"])
def assert_tempo_dynamics_file(filename: Text) -> None:
    """
    Assert that the file is of correct .tempoDynamics form
    [see tempo.assert_tempo_dynamics_file() for more details].

    Parameters
    ----------
    filename: str
        Path to the file.

    Raises
    ------
    `AssertionError`:
        If the data found in the file is not of the correct .tempoDynamics
        form.
    """
    t_dyn_dict = load_object(filename)
    assert_tempo_dynamics_dict(t_dyn_dict)
def print_process_tensor_file(filename: Text) -> None:
    """Print header of .processTensor file. """
    p_t_dict = load_object(filename)
    print_process_tensor_dict(p_t_dict)
def print_tempo_dynamics_file(filename: Text) -> None:
    """Print header of .processTensor file. """
    t_dyn_dict = load_object(filename)
    print_tempo_dynamics_dict(t_dyn_dict)