Skip to content

Commit

Permalink
Merge f3b2e0f into fd41ec6
Browse files Browse the repository at this point in the history
  • Loading branch information
joernweissenborn committed Sep 17, 2018
2 parents fd41ec6 + f3b2e0f commit f2f95ce
Show file tree
Hide file tree
Showing 87 changed files with 3,795 additions and 4,773 deletions.
28 changes: 15 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ matrix:
# this prevents the tests to upload stuff to coveralls.io
- echo "done"

- python: 3.6
# taken from https://quick-sphinx-tutorial.readthedocs.io/en/latest/advanced.html
env: TOXENV=docs
before_install:
- echo "before_install"
- python -m pip install -U pip>=9.0.1
- pip install tox
script:
- tox
after_success:
# this prevents the tests to upload stuff to coveralls.io
- echo "done"

# LINUX
- python: "3.6"
env: linux-py36
Expand Down Expand Up @@ -74,6 +61,21 @@ matrix:
- source activate py37
- python -m pip install -U pip>=9.0.1

allow_failures:

- python: 3.6
# taken from https://quick-sphinx-tutorial.readthedocs.io/en/latest/advanced.html
env: TOXENV=docs
before_install:
- echo "before_install"
- python -m pip install -U pip>=9.0.1
- pip install tox
script:
- tox
after_success:
# this prevents the tests to upload stuff to coveralls.io
- echo "done"

# - python: 3.6
# env: win_coverage
# install:
Expand Down
4 changes: 2 additions & 2 deletions docs/_templates/known_packages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
For changes to take effect you might also have to run `make clean_all`
afterwards.
{% set known_packages=['glotaran.dataio', 'glotaran.fitmodel', 'glotaran.model', 'glotaran.models', 'glotaran.models.damped_oscillation', 'glotaran.models.spectral_temporal', 'glotaran.models.spectral_temporal.c_matrix_cython', 'glotaran.plotting', 'glotaran.specification_parser'] %}
{% set child_modules=['glotaran.dataio', 'glotaran.dataio.chlorospec_format', 'glotaran.dataio.mlsd_file_format', 'glotaran.dataio.spectral_timetrace', 'glotaran.dataio.wavelength_time_explicit_file', 'glotaran.fitmodel', 'glotaran.fitmodel.fitmodel', 'glotaran.fitmodel.matrix', 'glotaran.fitmodel.matrix_group', 'glotaran.fitmodel.matrix_group_generator', 'glotaran.fitmodel.result', 'glotaran.model', 'glotaran.model.compartment_constraints', 'glotaran.model.dataset', 'glotaran.model.dataset_descriptor', 'glotaran.model.initial_concentration', 'glotaran.model.megacomplex', 'glotaran.model.model', 'glotaran.model.parameter', 'glotaran.model.parameter_group', 'glotaran.models', 'glotaran.models.damped_oscillation', 'glotaran.models.damped_oscillation.doas_matrix', 'glotaran.models.damped_oscillation.doas_megacomplex', 'glotaran.models.damped_oscillation.doas_model', 'glotaran.models.damped_oscillation.doas_spectral_matrix', 'glotaran.models.damped_oscillation.oscillation', 'glotaran.models.spectral_temporal', 'glotaran.models.spectral_temporal.c_matrix_cython', 'glotaran.models.spectral_temporal.c_matrix_cython.c_matrix_cython', 'glotaran.models.spectral_temporal.irf', 'glotaran.models.spectral_temporal.irf_gaussian', 'glotaran.models.spectral_temporal.irf_measured', 'glotaran.models.spectral_temporal.k_matrix', 'glotaran.models.spectral_temporal.kinetic_fitmodel', 'glotaran.models.spectral_temporal.kinetic_matrix', 'glotaran.models.spectral_temporal.kinetic_megacomplex', 'glotaran.models.spectral_temporal.kinetic_model', 'glotaran.models.spectral_temporal.kinetic_result', 'glotaran.models.spectral_temporal.spectral_matrix', 'glotaran.models.spectral_temporal.spectral_shape', 'glotaran.models.spectral_temporal.spectral_shape_gaussian', 'glotaran.models.spectral_temporal.spectral_temporal_dataset', 'glotaran.models.spectral_temporal.spectral_temporal_dataset_descriptor', 'glotaran.plotting', 'glotaran.plotting.basic_plots', 'glotaran.plotting.glotaran_color_codes', 'glotaran.specification_parser', 'glotaran.specification_parser.model_spec_yaml', 'glotaran.specification_parser.model_spec_yaml_doas', 'glotaran.specification_parser.model_spec_yaml_kinetic', 'glotaran.specification_parser.parser', 'glotaran.specification_parser.utils'] %}
{% set known_packages=['glotaran.analysis', 'glotaran.analysis.test', 'glotaran.dataio', 'glotaran.model', 'glotaran.models', 'glotaran.models.damped_oscillation', 'glotaran.models.spectral_temporal', 'glotaran.parse', 'glotaran.plotting'] %}
{% set child_modules=['glotaran.analysis', 'glotaran.analysis.dataset', 'glotaran.analysis.fitresult', 'glotaran.analysis.fitting', 'glotaran.analysis.grouping', 'glotaran.analysis.simulation', 'glotaran.analysis.test', 'glotaran.analysis.test.mock', 'glotaran.analysis.test.test_fitting', 'glotaran.analysis.test.test_grouping', 'glotaran.analysis.test.test_simulation', 'glotaran.analysis.variable_projection', 'glotaran.dataio', 'glotaran.dataio.chlorospec_format', 'glotaran.dataio.mlsd_file_format', 'glotaran.dataio.spectral_timetrace', 'glotaran.dataio.wavelength_time_explicit_file', 'glotaran.model', 'glotaran.model.base_model', 'glotaran.model.compartment_constraints', 'glotaran.model.dataset', 'glotaran.model.dataset_descriptor', 'glotaran.model.model', 'glotaran.model.model_item', 'glotaran.model.model_item_validator', 'glotaran.model.parameter', 'glotaran.model.parameter_group', 'glotaran.models', 'glotaran.models.damped_oscillation', 'glotaran.models.damped_oscillation.doas_matrix', 'glotaran.models.damped_oscillation.doas_megacomplex', 'glotaran.models.damped_oscillation.doas_model', 'glotaran.models.damped_oscillation.doas_spectral_matrix', 'glotaran.models.damped_oscillation.oscillation', 'glotaran.models.spectral_temporal', 'glotaran.models.spectral_temporal.initial_concentration', 'glotaran.models.spectral_temporal.irf', 'glotaran.models.spectral_temporal.k_matrix', 'glotaran.models.spectral_temporal.kinetic_matrix', 'glotaran.models.spectral_temporal.kinetic_megacomplex', 'glotaran.models.spectral_temporal.kinetic_model', 'glotaran.models.spectral_temporal.kinetic_result', 'glotaran.models.spectral_temporal.spectral_matrix', 'glotaran.models.spectral_temporal.spectral_shape', 'glotaran.models.spectral_temporal.spectral_temporal_dataset', 'glotaran.models.spectral_temporal.spectral_temporal_dataset_descriptor', 'glotaran.parse', 'glotaran.parse.parser', 'glotaran.parse.register', 'glotaran.plotting', 'glotaran.plotting.basic_plots', 'glotaran.plotting.glotaran_color_codes'] %}
{% block module %}

{% endblock %}
41 changes: 20 additions & 21 deletions docs/api_documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,31 @@ The API Documentation for glotaran is automatically created from its docstrings.
.. autosummary::
:toctree: api

glotaran.analysis
glotaran.analysis.dataset
glotaran.analysis.fitresult
glotaran.analysis.fitting
glotaran.analysis.grouping
glotaran.analysis.simulation
glotaran.analysis.test
glotaran.analysis.test.mock
glotaran.analysis.test.test_fitting
glotaran.analysis.test.test_grouping
glotaran.analysis.test.test_simulation
glotaran.analysis.variable_projection
glotaran.dataio
glotaran.dataio.chlorospec_format
glotaran.dataio.mlsd_file_format
glotaran.dataio.spectral_timetrace
glotaran.dataio.wavelength_time_explicit_file
glotaran.fitmodel
glotaran.fitmodel.fitmodel
glotaran.fitmodel.matrix
glotaran.fitmodel.matrix_group
glotaran.fitmodel.matrix_group_generator
glotaran.fitmodel.result
glotaran.model
glotaran.model.base_model
glotaran.model.compartment_constraints
glotaran.model.dataset
glotaran.model.dataset_descriptor
glotaran.model.initial_concentration
glotaran.model.megacomplex
glotaran.model.model
glotaran.model.model_item
glotaran.model.model_item_validator
glotaran.model.parameter
glotaran.model.parameter_group
glotaran.models
Expand All @@ -43,28 +50,20 @@ The API Documentation for glotaran is automatically created from its docstrings.
glotaran.models.damped_oscillation.doas_spectral_matrix
glotaran.models.damped_oscillation.oscillation
glotaran.models.spectral_temporal
glotaran.models.spectral_temporal.c_matrix_cython
glotaran.models.spectral_temporal.c_matrix_cython.c_matrix_cython
glotaran.models.spectral_temporal.initial_concentration
glotaran.models.spectral_temporal.irf
glotaran.models.spectral_temporal.irf_gaussian
glotaran.models.spectral_temporal.irf_measured
glotaran.models.spectral_temporal.k_matrix
glotaran.models.spectral_temporal.kinetic_fitmodel
glotaran.models.spectral_temporal.kinetic_matrix
glotaran.models.spectral_temporal.kinetic_megacomplex
glotaran.models.spectral_temporal.kinetic_model
glotaran.models.spectral_temporal.kinetic_result
glotaran.models.spectral_temporal.spectral_matrix
glotaran.models.spectral_temporal.spectral_shape
glotaran.models.spectral_temporal.spectral_shape_gaussian
glotaran.models.spectral_temporal.spectral_temporal_dataset
glotaran.models.spectral_temporal.spectral_temporal_dataset_descriptor
glotaran.parse
glotaran.parse.parser
glotaran.parse.register
glotaran.plotting
glotaran.plotting.basic_plots
glotaran.plotting.glotaran_color_codes
glotaran.specification_parser
glotaran.specification_parser.model_spec_yaml
glotaran.specification_parser.model_spec_yaml_doas
glotaran.specification_parser.model_spec_yaml_kinetic
glotaran.specification_parser.parser
glotaran.specification_parser.utils
glotaran.plotting.glotaran_color_codes
14 changes: 7 additions & 7 deletions glotaran/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
# workaround to import Model and Dataset with
# `from glotaran import Model`/`from glotaran import Dataset`

from glotaran.specification_parser import parse_yml # noqa: E402
from glotaran.specification_parser import parse_file # noqa: E402
from glotaran import dataio, model # noqa: E402
# from glotaran.specification_parser import parse_yml # noqa: E402
# from glotaran.specification_parser import parse_file # noqa: E402
# from glotaran import dataio, model # noqa: E402
from glotaran import model # noqa: E402

__version__ = '0.0.8'

Dataset = model.Dataset
DatasetDescriptor = model.DatasetDescriptor
Model = model.Model
ParameterGroup = model.ParameterGroup

# Top level API
Expand All @@ -21,10 +21,10 @@
# loadSomethingFromFile
# Load Glotaran analysis protocol (*.gat or *.yml) from file

load = parse_file # short for loadProtocol
parse = parse_yml # short for loadProtocol
# load = parse_file # short for loadProtocol
# parse = parse_yml # short for loadProtocol

io = dataio
# io = dataio

# # user calls this object whatever
# glotaran._loadProtocol()
Expand Down
4 changes: 4 additions & 0 deletions glotaran/analysis/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Glotaran Analysis Package
This package contains functions for model simulation and fitting.
"""
30 changes: 30 additions & 0 deletions glotaran/analysis/dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""This package contains functions for dataset analysis."""

from typing import Tuple
import numpy as np

from glotaran.model.dataset import Dataset


def dataset_svd(dataset: Dataset) -> Tuple[np.array, np.array, np.array]:
"""Returns the singular value decomposition of a dataset.
Parameters
----------
dataset : glotaran.model.dataset.Dataset
Returns
-------
tuple :
(lsv, svals, rsv)
lsv : np.array
left singular values
svals : np.array
singular values
rsv : np.array
right singular values
"""
lsv, svals, rsv = np.linalg.svd(dataset.data().T)
return lsv, svals, rsv.T
103 changes: 103 additions & 0 deletions glotaran/analysis/fitresult.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
"""This package contains the FitResult object"""

import numpy as np
from dataclasses import dataclass
from typing import Dict, List
from lmfit.minimizer import MinimizerResult


from glotaran.model.dataset import Dataset
from glotaran.model.parameter_group import ParameterGroup


@dataclass
class DatasetResult:
"""DatasetResult holds the fitresults for the data."""
label: str
compartments: List[str]
non_linear_matrix: np.ndarray
conditionally_non_linear_parameter: np.ndarray
data: Dataset


class FitResult:
"""The result of a fit."""

def __init__(self,
lm_result: MinimizerResult,
dataset_results: Dict[str, DatasetResult],
):
"""
Parameters
----------
lm_result: MinimizerResult
dataset_results: dict(str, DatasetResult)
Returns
-------
"""
self._lm_result = lm_result
self._dataset_results = dataset_results

@property
def best_fit_parameter(self) -> ParameterGroup:
"""The best fit parameters."""
return ParameterGroup.from_parameter_dict(self._lm_result.params)

def get_dataset(self, label: str):
"""get_dataset returns the DatasetResult for the given dataset.
Parameters
----------
label : str
The label of the dataset.
Returns
-------
dataset_result: DatasetResult
The result for the dataset.
"""
return self._dataset_results[label]

def __str__(self):
string = "# Fitresult\n\n"

# pylint: disable=invalid-name

ll = 32
lr = 13

string += "Optimization Result".ljust(ll-1)
string += "|"
string += "|".rjust(lr)
string += "\n"
string += "|".rjust(ll, "-")
string += "|".rjust(lr, "-")
string += "\n"

string += "Number of residual evaluation |".rjust(ll)
string += f"{self._lm_result.nfev} |".rjust(lr)
string += "\n"
string += "Number of variables |".rjust(ll)
string += f"{self._lm_result.nvarys} |".rjust(lr)
string += "\n"
string += "Number of datapoints |".rjust(ll)
string += f"{self._lm_result.ndata} |".rjust(lr)
string += "\n"
string += "Negrees of freedom |".rjust(ll)
string += f"{self._lm_result.nfree} |".rjust(lr)
string += "\n"
string += "Chi Square |".rjust(ll)
string += f"{self._lm_result.chisqr:.6f} |".rjust(lr)
string += "\n"
string += "Reduced Chi Square |".rjust(ll)
string += f"{self._lm_result.redchi:.6f} |".rjust(lr)
string += "\n"

string += "\n"
string += "## Best Fit Parameter\n\n"
string += f"{self.best_fit_parameter}"
string += "\n"

return string

0 comments on commit f2f95ce

Please sign in to comment.