How to use the larray.Axis function in larray

To help you get started, we’ve selected a few larray examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github liam2 / liam2 / liam2 / groupby.py View on Github external
#
#            data = [100.0 * value / divisor
#                    for value, divisor in zip(data, divisors)]

        # convert to a 1d array. We don't simply use data = np.array(data),
        # because if data is a list of ndarray (for example if we use
        # groupby(a, expr=id), *and* all the ndarrays have the same length,
        # the result is a 2d array instead of an array of ndarrays like we
        # need (at this point).
        arr = np.empty(len(data), dtype=type(data[0]))
        arr[:] = data
        data = arr

        # and reshape it
        data = data.reshape(len_pvalues)
        axes = [la.Axis(axis_labels, axis_name)
                for axis_name, axis_labels in zip(labels, possible_values)]
        # FIXME: also handle totals
        return la.LArray(data, axes)
        # return la.LArray(data, labels, possible_values,
github liam2 / liam2 / liam2 / charts.py View on Github external
def prepare(self, args, kwargs):
        axes = [la.Axis(np.unique(arg)) for arg in args]
        c = kwargs.get('c', 'b')
        unq_colors = np.unique(c)
        if len(unq_colors) >= self.colorbar_threshold:
            # we will add a colorbar in this case, so we do not need a legend
            self.show_legend = False
        else:
            # prepend a fake axis that will be used to make a legend
            axes = [la.Axis(unq_colors)] + axes
        return args, axes
github liam2 / liam2 / liam2 / utils.py View on Github external
def aslabeledarray(data):
    sequence = (tuple, list)
    if isinstance(data, la.LArray):
        return data
    elif (isinstance(data, sequence) and len(data) and
          isinstance(data[0], la.LArray)):
        # XXX: use la.stack?
        # TODO: check that all arrays have the same axes
        axes = [la.Axis(len(data))] + list(data[0].axes)
        return la.LArray(data, axes)
    else:
        return la.LArray(data)
github liam2 / liam2 / liam2 / data.py View on Github external
if isinstance(global_type, list):
                # make sure we do not keep in memory columns which are
                # present in the input file but where not asked for by the
                # modeller. They are not accessible anyway.
                array = add_and_drop_fields(array, global_type)
            attrs = global_data.attrs
            dim_names = getattr(attrs, 'dimensions', None)
            if dim_names is not None:
                # we serialise dim_names as a numpy array so that it is
                # stored as a native hdf type and not a pickle but we
                # prefer to work with simple lists
                # also files serialized using Python2 are "bytes" not "str"
                dim_names = [str(dim_name) for dim_name in dim_names]
                pvalues = [getattr(attrs, 'dim%d_pvalues' % i)
                           for i in range(len(dim_names))]
                axes = [la.Axis(labels, axis_name)
                        for axis_name, labels in zip(dim_names, pvalues)]
                array = la.LArray(array, axes)
            globals_data[name] = array

        input_entities = input_root.entities

        entities_tables = {}
        print(" * indexing tables")
        for ent_name, entity in entities.items():
            print("    -", ent_name, "...", end=' ')

            table = getattr(input_entities, ent_name)
            assert_valid_type(table, list(entity.fields.in_input.name_types))

            rows_per_period, id_to_rownum_per_period = \
                timed(index_table, table)
github liam2 / liam2 / liam2 / charts.py View on Github external
length = len(args[0])
                if any(len(a) != length for a in args):
                    raise ValueError("when plotting multiple arrays, they must "
                                     "have compatible axes")
        if len(args) == 1:
            data = args[0]
            if not isinstance(data, (np.ndarray, la.LArray)):
                data = np.asarray(data)
            if ndim(data) == ndim_req:
                # move the last axis first so that the last dimension is stacked
                axes = list(range(data.ndim))
                data = data.transpose(axes[-1], *axes[:-1])
            elif ndim(data) == ndim_req - 1:
                if isinstance(data, la.LArray):
                    # add dummy axis and move it as the first axis
                    data = data.expand(la.Axis(1, '__dummy__')).transpose('__dummy__')
                else:
                    data = data[np.newaxis]
            else:
                raise dimerror
        elif all(ndim(a) == ndim_req - 1 for a in args):
            data = args
        else:
            raise dimerror
        return np.asarray(data), aslabeledarray(data).axes