Esempio n. 1
0
def get_data_by_id(run_id: int) -> List:
    """
    Load data from database and reshapes into 1D arrays with minimal
    name, unit and label metadata.
    """

    data = load_by_id(run_id)
    conn = data.conn
    deps = get_dependents(conn, run_id)
    output = []
    for dep in deps:

        dependencies = get_dependencies(conn, dep)
        data_axis = get_layout(conn, dep)
        rawdata = data.get_values(data_axis['name'])
        data_axis['data'] = flatten_1D_data_for_plot(rawdata)
        raw_setpoint_data = data.get_setpoints(data_axis['name'])
        my_output = []

        for i, dependency in enumerate(dependencies):
            axis = get_layout(conn, dependency[0])
            axis['data'] = flatten_1D_data_for_plot(raw_setpoint_data[i])
            my_output.append(axis)

        my_output.append(data_axis)
        output.append(my_output)
    return output
Esempio n. 2
0
def get_ds_structure(ds):
    """
    Return the structure of the dataset, i.e., a dictionary in the form
        {'parameter' : {
            'unit' : unit,
            'axes' : list of dependencies,
            'values' : [],
            },
        ...
        }
    """

    structure = {}

    # for each data param (non-independent param)
    for dependent_id in get_dependents(ds.conn, ds.run_id):

        # get name etc.
        layout = get_layout(ds.conn, dependent_id)
        name = layout['name']
        structure[name] = {'values': [], 'unit': layout['unit'], 'axes': []}

        # find dependencies (i.e., axes) and add their names/units in the right order
        dependencies = get_dependencies(ds.conn, dependent_id)
        for dep_id, iax in dependencies:
            dep_layout = get_layout(ds.conn, dep_id)
            dep_name = dep_layout['name']
            structure[name]['axes'].insert(iax, dep_name)
            structure[dep_name] = {'values': [], 'unit': dep_layout['unit']}

    return structure
Esempio n. 3
0
def test_get_dependents(experiment):

    x = ParamSpec('x', 'numeric')
    t = ParamSpec('t', 'numeric')
    y = ParamSpec('y', 'numeric', depends_on=['x', 't'])

    # Make a dataset
    (_, run_id, _) = mut.create_run(experiment.conn,
                                    experiment.exp_id,
                                    name='testrun',
                                    guid=generate_guid(),
                                    parameters=[x, t, y])

    deps = mut.get_dependents(experiment.conn, run_id)

    layout_id = mut.get_layout_id(experiment.conn, 'y', run_id)

    assert deps == [layout_id]

    # more parameters, more complicated dependencies

    x_raw = ParamSpec('x_raw', 'numeric')
    x_cooked = ParamSpec('x_cooked', 'numeric', inferred_from=['x_raw'])
    z = ParamSpec('z', 'numeric', depends_on=['x_cooked'])

    (_, run_id, _) = mut.create_run(experiment.conn,
                                    experiment.exp_id,
                                    name='testrun',
                                    guid=generate_guid(),
                                    parameters=[x, t, x_raw, x_cooked, y, z])

    deps = mut.get_dependents(experiment.conn, run_id)

    expected_deps = [
        mut.get_layout_id(experiment.conn, 'y', run_id),
        mut.get_layout_id(experiment.conn, 'z', run_id)
    ]

    assert deps == expected_deps
Esempio n. 4
0
def getDatasetStructure(ds):
    structure = {}

    # for each data param (non-independent param)
    for dependent_id in get_dependents(ds.conn, ds.run_id):

        # get name etc.
        layout = get_layout(ds.conn, dependent_id)
        name = layout['name']
        structure[name] = {'values': [], 'unit': layout['unit'], 'axes': []}

        # find dependencies (i.e., axes) and add their names/units in the right order
        dependencies = get_dependencies(ds.conn, dependent_id)
        for dep_id, iax in dependencies:
            dep_layout = get_layout(ds.conn, dep_id)
            dep_name = dep_layout['name']
            structure[name]['axes'].insert(iax, dep_name)
            structure[dep_name] = {'values': [], 'unit': dep_layout['unit']}

    return structure
Esempio n. 5
0
def get_structure(ds):
    structure = OrderedDict({})

    # for each data param (non-independent param)
    for dependent_id in get_dependents(ds.conn, ds.run_id):

        # get name etc.
        layout = get_layout(ds.conn, dependent_id)
        name = layout['name']
        structure[name] = {'unit': layout['unit']}
        structure[name]['dependencies'] = []

        # find dependencies (i.e., axes) and
        # add their names/units in the right order
        dependencies = get_dependencies(ds.conn, dependent_id)
        for dep_id, iax in dependencies:
            dep_layout = get_layout(ds.conn, dep_id)
            dep_struct = {
                'name': dep_layout['name'],
                'unit': dep_layout['unit']
            }
            structure[name]['dependencies'].insert(iax, dep_struct)

    return structure
Esempio n. 6
0
def get_data_by_id(run_id: int) -> List:
    """
    Load data from database and reshapes into 1D arrays with minimal
    name, unit and label metadata (see `get_layout` function).

    Args:
        run_id: run ID from the database

    Returns:
        a list of lists of dictionaries like this:

        [
          # each element in this list refers
          # to one dependent (aka measured) parameter
            [
              # each element in this list refers
              # to one independent (aka setpoint) parameter
              # that the dependent parameter depends on;
              # a dictionary with the data and metadata of the dependent
              # parameter is in the *last* element in this list
                ...
                {
                    'data': <1D numpy array of points>,
                    'name': <name of the parameter>,
                    'label': <label of the parameter or ''>,
                    'unit': <unit of the parameter or ''>
                },
                ...
            ],
            ...
        ]
    """

    data = load_by_id(run_id)

    conn = data.conn
    deps = get_dependents(conn, run_id)

    output = []
    for dep in deps:

        dependencies = get_dependencies(conn, dep)

        data_axis: Dict[str, Union[str, np.ndarray]] = get_layout(conn, dep)

        rawdata = data.get_values(data_axis['name'])
        data_axis['data'] = flatten_1D_data_for_plot(rawdata)

        raw_setpoint_data = data.get_setpoints(data_axis['name'])

        output_axes = []

        max_size = 0
        for dependency in dependencies:
            axis: Dict[str,
                       Union[str,
                             np.ndarray]] = get_layout(conn, dependency[0])

            mydata = flatten_1D_data_for_plot(raw_setpoint_data[axis['name']])
            axis['data'] = mydata

            size = mydata.size
            if size > max_size:
                max_size = size

            output_axes.append(axis)

        for axis in output_axes:
            size = axis['data'].size  # type: ignore
            if size < max_size:
                if max_size % size != 0:
                    raise RuntimeError("Inconsistent shapes of data. Got "
                                       f"{size} which is not a whole fraction"
                                       f"of {max_size}")
                axis['data'] = np.repeat(axis['data'], max_size // size)

        output_axes.append(data_axis)

        output.append(output_axes)
    return output