https://github.com/brightway-lca/matrix_utils

Utilities to build and iterate on matrices using datapackages

https://github.com/brightway-lca/matrix_utils

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.3%) to scientific vocabulary

Keywords

matrix numpy
Last synced: 11 months ago · JSON representation

Repository

Utilities to build and iterate on matrices using datapackages

Basic Info
  • Host: GitHub
  • Owner: brightway-lca
  • License: bsd-3-clause
  • Language: Jupyter Notebook
  • Default Branch: main
  • Homepage:
  • Size: 1.2 MB
Statistics
  • Stars: 5
  • Watchers: 4
  • Forks: 1
  • Open Issues: 7
  • Releases: 2
Topics
matrix numpy
Created over 5 years ago · Last pushed 12 months ago
Metadata Files
Readme Changelog License Code of conduct

README.md

matrix_utils

Library for building matrices from data packages from bw_processing. Designed for use with the Brightway life cycle assessment framework.

Table of Contents

Background

The calculation library of the Brightway LCA framework has traditionally include matrix-building functionality. As the new capabilities in bw_processing have increased matrix-building complexity, this library is a refactoring to split matrix utilities from the LCA classes, which will remain in the calculation library.

matrix_utils supports all the features made available in bw_processing: static and dynamic resources, data package policies, vector and array resources. It also improves on the previous matrix building code by speeding up the mapping from data source ids to row and column ids.

Backwards compatibility

This library presents a completely different API than the functions previously present in bw2calc. Most ideas become easier, or even possible; however, some things are more complicated. In particular, the notion that we have a single array that defines a matrix is no longer true - a matrix can be defined by many input arrays, and they can interact with each other (either adding to existing matrix values or replacing them altogether).

Install

Install using pip or conda (channel cmutel).

Depends on numpy, scipy, pandas, bwprocessing, statsarrays.

Usage

MappedMatrix class

The primary use case for matrix_utils is the MappedMatrix class:

```python

In [1]: from matrix_utils import MappedMatrix

In [2]: mm = MappedMatrix(packages=[some_datapackage], matrix="foo")

In [3]: mm.matrix Out[3]: <8x8 sparse matrix of type '' with 11 stored elements in Compressed Sparse Row format> ```

MappedMatrix takes the following arguments. Note that all arguments must be keyword arguments:

  • packages: list, required. List of bw_processing data packages. The packages must be instantiated, you can't give file locations of PyFilesystem2 file systems.
  • matrix: str, required. Label of matrix to build. Used to filter data in packages, so must be identical to the matrix value in the package(s).
  • use_vectors: bool, default True. Include vector data resources when building matrices.
  • use_arrays: bool, default True. Include array data resources when building matrices. Note that each data package resource group can only provide either vector or array data.
  • use_distributions: bool, default False. Include probability distribution data resources when building matrices.
  • row_mapper: matrix_utils.ArrayMapper, default None. Optional mapping class used to translate data source ids to matrix row indices. In LCA, one would reuse this mapping class to make sure the dimensions of multiple matrices align.
  • col_mapper: matrix_utils.ArrayMapper, default None. Optional mapping class used to translate data source ids to matrix column indices. In LCA, one would reuse this mapping class to make sure the dimensions of multiple matrices align.
  • seed_override: int, default None. Override the random seed given in the data package. Note that this is ignored if the data package is combinatorial.

MappedMatrix is iterable; calling next() will draw new samples from all included stochastic resources, and rebuild the matrix.

You may also find it useful to iterate through MappedMatrix.groups, which are instances of ResourceGroup, documented below.

ResourceGroup class

A bw_processing data package is essentially a metadata file and a bag of data resources. These resources are grouped, for multiple resources are needed to build one matrix, or one component of one matrix. For example, one needs not only the data vector, but also the row and column indices to build a simple matrix. One could also have a flip vector, in another file, used to flip the signs of data elements before matrix insertion.

The ResourceGroup class provides a single interface to these data files and their metadata. ResourceGroup instances are created automatically by MappedMatrix, and available via MappedMatrix.groups. The source code is pretty readable, and in general you probably don't need to worry about this low-level class, but the following could be useful:

  • ResourceGroup.data_original: The data as it is present in the datapackage, before masking (i.e. the Numpy data vector or array, or the data interface). This is the raw input data, duplicate elements are not aggregated (if applicable).
  • ResourceGroup.data_current: The data sample used (before aggregation) to build the matrix. It is both masked and flipped.
  • ResourceGroup.row|col_mapped: Mapped row and column indices. Has the same length as the datapackage resource, but uses -1 for values which weren't mapped.
  • ResourceGroup.row|col_masked: The data after the custom filter and mapping mask have been applied.
  • rResourceGroup.row|col_matrix: Row and column indices (but not data) for insertion into the matrix. These indices are after aggregation within the resource group (if any).
  • ResourceGroup.calculate(vector=None): Function to recalculate matrix row, column, and data vectors. Uses the current state of the indexers, but re-draws values from data iterators. If vector is given, use this instead of the given data source.
  • ResourceGroup.indexer: The instance of the Indexer class applicable for this ResourceGroup. Only used for data arrays.
  • ResourceGroup.ncols: The integer number of columns in a data array. Returns None if a data vector is present.

Contributing

Your contribution is welcome! Please follow the pull request workflow, even for minor changes.

When contributing to this repository with a major change, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository.

Please note we have a code of conduct, please follow it in all your interactions with the project.

Documentation and coding standards

Maintainers

License

BSD-3-Clause. Copyright 2020 Chris Mutel.

Owner

  • Name: Brightway LCA software framework
  • Login: brightway-lca
  • Kind: organization

Open source framework for Brightway framework

GitHub Events

Total
  • Issues event: 3
  • Watch event: 2
  • Delete event: 3
  • Push event: 4
  • Pull request event: 5
  • Create event: 6
Last Year
  • Issues event: 3
  • Watch event: 2
  • Delete event: 3
  • Push event: 4
  • Pull request event: 5
  • Create event: 6

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 126
  • Total Committers: 4
  • Avg Commits per committer: 31.5
  • Development Distribution Score (DDS): 0.048
Past Year
  • Commits: 22
  • Committers: 2
  • Avg Commits per committer: 11.0
  • Development Distribution Score (DDS): 0.182
Top Committers
Name Email Commits
Chris Mutel c****l@g****m 120
renovate[bot] 2****] 4
Aleksandra Kim 3****m 1
mixib 5****b 1

Issues and Pull Requests

Last synced: 12 months ago

All Time
  • Total issues: 14
  • Total pull requests: 10
  • Average time to close issues: 2 months
  • Average time to close pull requests: 21 days
  • Total issue authors: 4
  • Total pull request authors: 3
  • Average comments per issue: 0.29
  • Average comments per pull request: 0.1
  • Merged pull requests: 8
  • Bot issues: 1
  • Bot pull requests: 7
Past Year
  • Issues: 2
  • Pull requests: 3
  • Average time to close issues: about 23 hours
  • Average time to close pull requests: 4 minutes
  • Issue authors: 1
  • Pull request authors: 2
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 2
Top Authors
Issue Authors
  • cmutel (13)
  • mixib (1)
  • renovate[bot] (1)
Pull Request Authors
  • renovate[bot] (9)
  • cmutel (2)
  • mixib (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 5,979 last-month
  • Total dependent packages: 7
    (may contain duplicates)
  • Total dependent repositories: 1
    (may contain duplicates)
  • Total versions: 21
  • Total maintainers: 1
pypi.org: matrix-utils

Tools to create matrices from data packages

  • Versions: 20
  • Dependent Packages: 7
  • Dependent Repositories: 1
  • Downloads: 5,979 Last month
Rankings
Dependent packages count: 1.4%
Downloads: 7.2%
Average: 10.1%
Dependent repos count: 21.6%
Maintainers (1)
Last synced: 12 months ago
conda-forge.org: matrix_utils
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Forks count: 53.7%
Average: 56.5%
Stargazers count: 59.3%
Last synced: 11 months ago

Dependencies

.github/workflows/python-package-deploy.yml actions
  • actions/checkout master composite
  • actions/setup-python v5 composite
  • pypa/gh-action-pypi-publish release/v1 composite
.github/workflows/python-test.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
  • codecov/codecov-action v3 composite
pyproject.toml pypi
  • bw_processing *
  • numpy *
  • pandas *
  • scipy *
  • stats_arrays *
binder/environment.yml conda
  • appdirs
  • astunparse >=1.6.1
  • bw2parameters
  • docopt
  • eight
  • fasteners
  • fs
  • future
  • lxml
  • numpy
  • pandas
  • peewee >=3.9.4
  • pypardiso
  • pyprind
  • requests
  • scipy
  • stats_arrays
  • voluptuous
  • whoosh
  • wrapt