pymcr

pyMCR: Multivariate Curve Resolution for Python

https://github.com/usnistgov/pymcr

Science Score: 33.0%

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

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 6 DOI reference(s) in README
  • Academic publication links
    Links to: sciencedirect.com, nature.com
  • Committers with academic emails
    3 of 8 committers (37.5%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.0%) to scientific vocabulary

Keywords

hyperspectral hyperspectral-data mixture-modeling multivariate multivariate-curve-resolution self-modeling-mixture-analysis spectroscopy unsupervised-learning unsupervised-learning-algorithms unsupervised-machine-learning
Last synced: 6 months ago · JSON representation

Repository

pyMCR: Multivariate Curve Resolution for Python

Basic Info
Statistics
  • Stars: 79
  • Watchers: 5
  • Forks: 27
  • Open Issues: 14
  • Releases: 0
Topics
hyperspectral hyperspectral-data mixture-modeling multivariate multivariate-curve-resolution self-modeling-mixture-analysis spectroscopy unsupervised-learning unsupervised-learning-algorithms unsupervised-machine-learning
Created about 8 years ago · Last pushed over 4 years ago
Metadata Files
Readme Changelog Contributing License

README.rst

.. -*- mode: rst -*-

.. image:: https://github.com/CCampJr/pyMCR/actions/workflows/python-app.yml/badge.svg
    :alt: pytest
    :target: https://github.com/CCampJr/pyMCR/actions/workflows/python-app.yml
    
.. image:: https://codecov.io/gh/CCampJr/pyMCR/branch/master/graph/badge.svg
    :alt: Codecov
    :target: https://codecov.io/gh/CCampJr/pyMCR

.. image:: https://img.shields.io/pypi/pyversions/pyMCR.svg
    :alt: PyPI - Python Version
    :target: https://pypi.org/project/pyMCR/

.. image:: https://img.shields.io/pypi/v/pyMCR.svg
    :alt: PyPI Project Page
    :target: https://pypi.org/project/pyMCR/

.. image:: https://anaconda.org/conda-forge/pymcr/badges/version.svg
    :alt: Anaconda Cloud
    :target: https://anaconda.org/conda-forge/pymcr

.. image:: https://img.shields.io/badge/License-NIST%20Public%20Domain-green.svg
    :alt: NIST Public Domain
    :target: https://github.com/usnistgov/pyMCR/blob/master/LICENSE.md

pyMCR: Multivariate Curve Resolution in Python
===============================================================

Documentation available online at https://pages.nist.gov/pyMCR

Software DOI: https://doi.org/10.18434/M32064

Manuscript DOI: https://doi.org/10.6028/jres.124.018

pyMCR is a small package for performing multivariate curve resolution.
Currently, it implements a simple alternating regression scheme (MCR-AR). The most common
implementation is with ordinary least-squares regression, MCR-ALS.

MCR with non-negativity constraints on both matrices is the same as non-negative matrix factorization (NMF). Historically,
other names were used for MCR as well:

-   Self modeling mixture analysis (SMMA)
-   Self modeling curve resolution (SMCR)

Available methods:

-   Regressors:

    -   `Ordinary least squares `_ (default)
    -   `Non-negatively constrained least squares 
        `_
    -   Native support for `scikit-learn linear model regressors 
        `_
        (e.g., `LinearRegression `_, 
        `RidgeRegression `_, 
        `Lasso `_)

-   Constraints

    -   Non-negativity
    -   Normalization
    -   Zero end-points
    -   Zero (approx) end-points of cumulative summation (can specify nodes as well)
    -   Non-negativity of cumulative summation
    -   Compress or cut values above or below a threshold value
    -   Replace sum-across-features samples (e.g., 0 concentration) with prescribed target
    -   Enforce a plane ("planarize"). E.g., a concentration image is a plane.

-   Error metrics / Loss function

    -   Mean-squared error

-   Other options

    -   Fix known targets (C and/or ST, and let others vary)

What it **does** do:

-   Approximate the concentration and spectral matrices via minimization routines. 
    This is the core the MCR methods.
-   Enable the application of certain constraints in a user-defined order.

What it **does not** do:

-   Estimate the number of components in the sample. This is a bonus feature in 
    some more-advanced MCR-ALS packages.

    - In MATLAB: https://mcrals.wordpress.com/
    - In R: https://cran.r-project.org/web/packages/ALS/index.html

Dependencies
------------

**Note**: These are the developmental system specs. Older versions of certain
packages may work.

-   python >= 3.4
    
    - Tested with 3.4.6, 3.5.4, 3.6.3, 3.6.5, 3.7.1

-   numpy (1.9.3)
    
    - Tested with 1.12.1, 1.13.1, 1.13.3, 1.14.3, 1.14.6

-   scipy (1.0.0)

    - Tested with 1.0.0, 1.0.1, 1.1.0

-   scikit-learn, optional (0.2.0)

Known Issues
------------


Installation
------------

Using pip (hard install)
~~~~~~~~~~~~~~~~~~~~~~~~

.. code::

    # Only Python 3.* installed
    pip install pyMCR

    # If you have both Python 2.* and 3.* you may need
    pip3 install pyMCR

Using pip (soft install [can update with git])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code::
    
    # Make new directory for pyMCR and enter it
    # Clone from github
    git clone https://github.com/usnistgov/pyMCR

    # Only Python 3.* installed
    pip install -e .

    # If you have both Python 2.* and 3.* you may need instead
    pip3 install -e .

    # To update in the future
    git pull

Using setuptools
~~~~~~~~~~~~~~~~

You will need to `download the repository `_
or clone the repository with git:

.. code::
    
    # Make new directory for pyMCR and enter it
    # Clone from github
    git clone https://github.com/usnistgov/pyMCR

Perform the install:

.. code::

    python setup.py install

Logging
--------

**New in pyMCR 0.4.*, the logging module is now automatically loaded and setup during import (via __init__.py) to print messages**. You do not need to do the logger setup below.


**New in pyMCR 0.3.1**, Python's native logging module is now used to capture messages. Though this is not as 
convenient as print() statements, it has many advantages.

- Logging module docs: https://docs.python.org/3.7/library/logging.html
- Logging tutorial: https://docs.python.org/3.7/howto/logging.html#logging-basic-tutorial
- Logging cookbook: https://docs.python.org/3.7/howto/logging-cookbook.html#logging-cookbook

A simple example that prints simplified logging messages to the stdout (command line):

.. code:: python

    import sys
    import logging
    
    # Need to import pymcr or mcr prior to setting up the logger
    from pymcr.mcr import McrAR

    logger = logging.getLogger('pymcr')
    logger.setLevel(logging.DEBUG)

    # StdOut is a "stream"; thus, StreamHandler
    stdout_handler = logging.StreamHandler(stream=sys.stdout)

    # Set the message format. Simple and removing log level or date info
    stdout_format = logging.Formatter('%(message)s')  # Just a basic message akin to print statements
    stdout_handler.setFormatter(stdout_format)

    logger.addHandler(stdout_handler)

    # Begin your code for pyMCR below
    

Usage
-----

.. code:: python

    from pymcr.mcr import McrAR
    mcrar = McrAR()
    
    # MCR assumes a system of the form: D = CS^T
    #
    # Data that you will provide (hyperspectral context):
    # D [n_pixels, n_frequencies]  # Hyperspectral image unraveled in space (2D)
    #
    # initial_spectra [n_components, n_frequencies]  ## S^T in the literature
    # OR
    # initial_conc [n_pixels, n_components]   ## C in the literature

    # If you have an initial estimate of the spectra
    mcrar.fit(D, ST=initial_spectra)

    # Otherwise, if you have an initial estimate of the concentrations
    mcrar.fit(D, C=initial_conc)

Example Results
---------------

Command line and Jupyter notebook examples are provided in the ``Examples/`` folder. Examples of instantiating
the McrAR class with different regressors available in the `documentation `_ .

From ``Examples/Demo.ipynb``:

.. image:: ./Examples/mcr_spectra_retr.png

.. image:: ./Examples/mcr_conc_retr.png


Citing this Software
--------------------

If you use *pyMCR*, citing the following article is much appreciated:

-   `C. H. Camp Jr., "pyMCR: A Python Library for Multivariate Curve Resolution 
    Analysis with Alternating Regression (MCR-AR)", Journal of Research of 
    National Institute of Standards and Technology 124, 1-10 (2019)
    `_.


References
----------

-   `W. H. Lawton and E. A. Sylvestre, "Self Modeling Curve Resolution", 
    Technometrics 13, 617–633 (1971). `_
-   https://mcrals.wordpress.com/theory/
-   `J. Jaumot, R. Gargallo, A. de Juan, and R. Tauler, "A graphical user-friendly 
    interface for MCR-ALS: a new tool for multivariate curve resolution in
    MATLAB", Chemometrics and Intelligent Laboratory Systems 76, 101-110 
    (2005). `_
-   `J. Felten, H. Hall, J. Jaumot, R. Tauler, A. de Juan, and A. Gorzsás, 
    "Vibrational spectroscopic image analysis of biological material using 
    multivariate curve resolution–alternating least squares (MCR-ALS)", Nature Protocols 
    10, 217-240 (2015). `_
    

LICENSE
----------
This software was developed by employees of the National Institute of Standards 
and Technology (NIST), an agency of the Federal Government. Pursuant to 
`title 17 United States Code Section 105 `_, 
works of NIST employees are not subject to copyright protection in the United States and are 
considered to be in the public domain. Permission to freely use, copy, modify, 
and distribute this software and its documentation without fee is hereby granted, 
provided that this notice and disclaimer of warranty appears in all copies.

THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER 
EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY 
THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF 
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM INFRINGEMENT, 
AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE SOFTWARE, OR ANY 
WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT SHALL NIST BE LIABLE 
FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL OR 
CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, OR IN ANY WAY CONNECTED 
WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY, CONTRACT, TORT, OR 
OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR PROPERTY OR 
OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT OF THE 
RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.

Contact
-------
Charles H Camp Jr: `charles.camp@nist.gov `_

Contributors
-------------

-   Charles H Camp Jr
-   Charles Le Losq (charles.lelosq@anu.edu.au)
-   Robert Kern (rkern@enthought.com)
-   Joshua Taillon (joshua.taillon@nist.gov)

Owner

  • Name: National Institute of Standards and Technology
  • Login: usnistgov
  • Kind: organization
  • Location: Gaithersburg, Md.

Department of Commerce

GitHub Events

Total
  • Watch event: 8
  • Fork event: 6
Last Year
  • Watch event: 8
  • Fork event: 6

Committers

Last synced: about 2 years ago

All Time
  • Total Commits: 317
  • Total Committers: 8
  • Avg Commits per committer: 39.625
  • Development Distribution Score (DDS): 0.423
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Charles H. Camp Jr c****r@g****m 183
Charles c****c@N****V 81
Charles H. Camp Jr c****p@n****v 36
sshojiro s****a@g****m 8
Eric Prestat e****t@g****m 3
Charles Le Losq c****q@g****m 2
Joshua Taillon j****n@n****v 2
Robert Kern r****n@g****m 2
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: about 2 years ago

All Time
  • Total issues: 17
  • Total pull requests: 26
  • Average time to close issues: 3 months
  • Average time to close pull requests: 27 days
  • Total issue authors: 11
  • Total pull request authors: 9
  • Average comments per issue: 2.94
  • Average comments per pull request: 1.27
  • Merged pull requests: 19
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • CCampJr (7)
  • pllim (1)
  • GhostDeini (1)
  • sshojiro (1)
  • Bio-data-tricks (1)
  • AndrewHerzing (1)
  • roentgenium (1)
  • ankit7540 (1)
  • aminsagar (1)
  • antonyvam (1)
  • jat255 (1)
Pull Request Authors
  • CCampJr (14)
  • sshojiro (3)
  • ericpre (2)
  • charlesll (2)
  • RyanJMcCarty (1)
  • francisco-dlp (1)
  • ClarkAH (1)
  • jat255 (1)
  • rkern (1)
Top Labels
Issue Labels
help wanted (1) good first issue (1)
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 8,538 last-month
  • Total dependent packages: 1
    (may contain duplicates)
  • Total dependent repositories: 1
    (may contain duplicates)
  • Total versions: 17
  • Total maintainers: 1
pypi.org: pymcr

Multivariate Curve Resolution in Python

  • Versions: 14
  • Dependent Packages: 1
  • Dependent Repositories: 1
  • Downloads: 8,538 Last month
Rankings
Dependent packages count: 4.7%
Forks count: 7.3%
Stargazers count: 7.9%
Average: 11.3%
Downloads: 14.7%
Dependent repos count: 21.7%
Maintainers (1)
Last synced: 6 months ago
conda-forge.org: pymcr
  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Forks count: 33.9%
Dependent repos count: 34.0%
Stargazers count: 35.5%
Average: 38.7%
Dependent packages count: 51.2%
Last synced: 6 months ago

Dependencies

requirements.txt pypi
  • numpy *
  • scipy *