Skip to content
Snippets Groups Projects
Commit 64322c8c authored by Jan Kotanski's avatar Jan Kotanski
Browse files

New upstream version 0.10.10+54.g37dda7b

parent 5737f41d
No related branches found
No related tags found
No related merge requests found
Showing
with 791 additions and 0 deletions
include src/nexpy/definitions/base_classes/*.xml
recursive-include src/nexpy/gui/resources *
recursive-include src/nexpy/examples *
include versioneer.py
include src/nexpy/_version.py
PKG-INFO 0 → 100644
Metadata-Version: 1.1
Name: NeXpy
Version: 0.10.10+54.g37dda7b
Summary: NeXpy: A Python GUI to analyze NeXus data
Home-page: http://nexpy.github.io/nexpy/
Author: NeXpy Development Team
Author-email: nexpydev@gmail.com
License: BSD
Download-URL: https://github.com/nexpy/nexpy/
Description:
NeXpy provides a high-level python interface to `NeXus data
<http://www.nexusformat.org/>`_ contained within a simple GUI. It is designed to
provide an intuitive interactive toolbox allowing users both to access existing
NeXus files and to create new NeXus-conforming data structures without expert
knowledge of the file format.
The latest development version is always available from `NeXpy's GitHub
site <https://github.com/nexpy/nexpy>`_.
Platform: any
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Visualization
README 0 → 100644
Introduction
============
NeXpy provides a high-level python interface to NeXus data contained within a
simple GUI. It is designed to provide an intuitive interactive toolbox allowing
users both to access existing NeXus files and to create new NeXus-conforming
data structures without expert knowledge of the file format.
Installing and Running
======================
Released versions of NeXpy are available on PyPI. If you have the Python Setup
Tools <https://pypi.python.org/pypi/setuptools> installed, then you can install
using either::
$ pip install nexpy
or::
$ easy_install nexpy
The latest development versions of NeXpy can be downloaded from the NeXpy Git
repository <https://github.com/nexpy/nexpy>.
$ git clone https://github.com/nexpy/nexpy.git
To install in the standard Python location:
$ cd nexpy
$ python setup.py install
To install in an alternate location:
$ python setup.py install --prefix=/path/to/installation/dir
Prerequisites
=============
Python Command-Line API
-----------------------
The current version of NeXpy uses h5py to read and write NeXus files because
of its ability to handle large data files. There is therefore no dependency
on the NeXus C API (http://download.nexusformat.org/doc/html/napi.html).
This also means that the current version cannot read and write HDF4 or XML
NeXus files.
If you only intend to utilize the Python API from the command-line, the only
other required library is Numpy.
* nexusformat (https://github.com/nexpy/nexusformat)
* h5py (http://www.h5py.org)
* numpy (http://numpy.scipy.org/)
NeXpy GUI
---------
The GUI is built using the PyQt. The latest version supports PyQt4, PySide,
and, with v0.10.0, PyQt5, and should load whichever library it finds. None are
listed as a dependency but one or other must be installed. PyQt5 is included
in the Anaconda default distribution (https://store.continuum.io/cshop/anaconda/)
while PySide is included in the Enthought Python Distribution
(http://www.enthought.com) or within Enthought's Canopy Application
(https://www.enthought.com/products/canopy/).
The GUI includes an IPython shell (http://ipython.org/) and a
Matplotlib plotting pane (http://matplotlib.sourceforge.net). The IPython shell
is embedded in the Qt GUI using an implementation based on the newly-released
Jupyter QtConsole, which has replaced the old IPython QtConsole.
* jupyter (http://jupyter.org/)
* IPython v4.0.0 (http://ipython.org/)
* matplotlib v1.4.0 (http://matplotlib.sourceforge.net/)
Some people have reported that NeXpy crashes on launch on some Linux systems.
We believe that this may be due to both PyQt4 and PyQt5 being installed,
although that doesn't cause a problem on all systems. If NeXpy crashes on
launch, please try setting the environment variable QT_API to either 'pyqt',
for the PyQt4 library, 'pyqt5' for the PyQt5 library, or 'pyside', for the
PySide library, depending on what you have installed, e.g., in BASH, type::
$ export QT_API=pyqt
Additional Packages
-------------------
Additional functionality is provided by other external Python packages.
Least-squares fitting requires Matt Newville's least-squares fitting package,
lmfit-py. Importers may also require libraries to read the imported files in
their native format, e.g., spec2nexus for reading SPEC files.
From v0.4.3, the log window is colorized if ansi2html is installed.
From v0.9.1, a new 2D smoothing option is available in the list of
interpolations in the signal tab if astropy is installed. It is labelled
'convolve' and provides, by default, a 2-pixel Gaussian smoothing of the
data. The number of pixels can be changed in the shell by setting
'plotview.smooth'.
The following packages are recommended.
* Least-squares fitting: lmfit (http://newville.github.io/lmfit-py/)
* TIFF file imports: tifffile (https://pypi.python.org/pypi/tifffile)
* CBF file imports: pycbf (http://sourceforge.net/projects/cbflib/files/cbflib/pycbf/)
* SPEC file imports: spec2nexus (http://spec2nexus.readthedocs.org/)
* Log file colorization: ansi2html (https://pypi.python.org/pypi/ansi2html/)
* Gaussian smoothing: astropy (http://www.astropy.org)
The following libraries are used by the full installation of NeXpy. There is
more details of the nature of these dependencies in the NeXpy documentation
(http://nexpy.github.io/nexpy).
PySide v1.1.0 http://www.pyside.org/
jupyter http://jupyter.org
IPython v1.1.0 http://ipython.org/
h5py http://www.h5py.org/
numpy,scipy http://numpy.scipy.org
matplotlib v1.2.0 http://matplotlib.sourceforge.net
lmfit http://newville.github.io/lmfit-py (Fitting only)
spec2nexus http://spec2nexus.readthedocs.org (SPEC reader only)
astrop
To run with the GUI
===================
To run from the install location, add the $prefix/bin directory to your path
(only if you installed outside the python installation), and then run:
nexpy
User Support
============
Consult the NeXpy documentation at http://nexpy.github.io/nexpy for details
of both the Python command-line API and how to use the NeXpy GUI.
If you discover any bugs, please submit a Github issue to
https://github.com/nexpy/nexpy/issues, preferably with relevant tracebacks.
[bdist_rpm]
requires = h5py,numpy >= 1.6.0,scipy,jupyter,python-ipython >= 4.0.0,python-matplotlib >= 1.4.0,python-pyside >= 1.1.0
[versioneer]
vcs = git
style = pep440
versionfile_source = src/nexpy/_version.py
versionfile_build = nexpy/_version.py
tag_prefix = v
[egg_info]
tag_build =
tag_date = 0
setup.py 0 → 100755
#!/usr/bin/env python
#-----------------------------------------------------------------------------
# Copyright (c) 2013-2014, NeXpy Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING, distributed with this software.
#-----------------------------------------------------------------------------
from setuptools import setup, find_packages, Extension
import os, sys
import pkg_resources
pkg_resources.require('numpy')
import numpy
import versioneer
# pull in some definitions from the package's __init__.py file
sys.path.insert(0, os.path.join('src', ))
import nexpy
import nexpy.requires
verbose=1
setup (name = nexpy.__package_name__, # NeXpy
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
license = nexpy.__license__,
description = nexpy.__description__,
long_description = nexpy.__long_description__,
author=nexpy.__author_name__,
author_email=nexpy.__author_email__,
url=nexpy.__url__,
download_url=nexpy.__download_url__,
platforms='any',
install_requires = nexpy.requires.pkg_requirements,
extras_require = nexpy.requires.extra_requirements,
package_dir = {'': 'src'},
packages = find_packages('src'),
include_package_data = True,
package_data = {
'nexpy.gui': ['resources/icon/*.svg',
'resources/icon/*.png',
'resources/*.png',
],
'nexpy.definitions': ['base_classes/*.xml'],
'nexpy': [
'examples/*.*',
'examples/*/*.*',
'examples/*/*/*.*',
],
},
entry_points={
# create & install scripts in <python>/bin
'gui_scripts': ['nexpy = nexpy.nexpygui:main',],
},
classifiers= ['Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: BSD License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Visualization'],
)
Metadata-Version: 1.1
Name: NeXpy
Version: 0.10.10+54.g37dda7b
Summary: NeXpy: A Python GUI to analyze NeXus data
Home-page: http://nexpy.github.io/nexpy/
Author: NeXpy Development Team
Author-email: nexpydev@gmail.com
License: BSD
Download-URL: https://github.com/nexpy/nexpy/
Description:
NeXpy provides a high-level python interface to `NeXus data
<http://www.nexusformat.org/>`_ contained within a simple GUI. It is designed to
provide an intuitive interactive toolbox allowing users both to access existing
NeXus files and to create new NeXus-conforming data structures without expert
knowledge of the file format.
The latest development version is always available from `NeXpy's GitHub
site <https://github.com/nexpy/nexpy>`_.
Platform: any
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Visualization
MANIFEST.in
README
setup.cfg
setup.py
versioneer.py
src/NeXpy.egg-info/PKG-INFO
src/NeXpy.egg-info/SOURCES.txt
src/NeXpy.egg-info/dependency_links.txt
src/NeXpy.egg-info/entry_points.txt
src/NeXpy.egg-info/requires.txt
src/NeXpy.egg-info/top_level.txt
src/nexpy/__init__.py
src/nexpy/_version.py
src/nexpy/nexpygui.py
src/nexpy/requires.py
src/nexpy/api/__init__.py
src/nexpy/api/frills/__init__.py
src/nexpy/api/frills/fit.py
src/nexpy/api/frills/functions/__init__.py
src/nexpy/api/frills/functions/gaussian.py
src/nexpy/api/frills/functions/linear.py
src/nexpy/api/frills/functions/lorentzian.py
src/nexpy/api/frills/functions/polynomial.py
src/nexpy/api/frills/functions/pseudovoigt.py
src/nexpy/definitions/__init__.py
src/nexpy/definitions/base_classes/NXaperture.nxdl.xml
src/nexpy/definitions/base_classes/NXattenuator.nxdl.xml
src/nexpy/definitions/base_classes/NXbeam.nxdl.xml
src/nexpy/definitions/base_classes/NXbeam_stop.nxdl.xml
src/nexpy/definitions/base_classes/NXbending_magnet.nxdl.xml
src/nexpy/definitions/base_classes/NXcapillary.nxdl.xml
src/nexpy/definitions/base_classes/NXcharacterization.nxdl.xml
src/nexpy/definitions/base_classes/NXcollection.nxdl.xml
src/nexpy/definitions/base_classes/NXcollimator.nxdl.xml
src/nexpy/definitions/base_classes/NXcrystal.nxdl.xml
src/nexpy/definitions/base_classes/NXdata.nxdl.xml
src/nexpy/definitions/base_classes/NXdetector.nxdl.xml
src/nexpy/definitions/base_classes/NXdetector_group.nxdl.xml
src/nexpy/definitions/base_classes/NXdetector_module.nxdl.xml
src/nexpy/definitions/base_classes/NXdisk_chopper.nxdl.xml
src/nexpy/definitions/base_classes/NXentry.nxdl.xml
src/nexpy/definitions/base_classes/NXenvironment.nxdl.xml
src/nexpy/definitions/base_classes/NXevent_data.nxdl.xml
src/nexpy/definitions/base_classes/NXfermi_chopper.nxdl.xml
src/nexpy/definitions/base_classes/NXfilter.nxdl.xml
src/nexpy/definitions/base_classes/NXflipper.nxdl.xml
src/nexpy/definitions/base_classes/NXgeometry.nxdl.xml
src/nexpy/definitions/base_classes/NXguide.nxdl.xml
src/nexpy/definitions/base_classes/NXinsertion_device.nxdl.xml
src/nexpy/definitions/base_classes/NXinstrument.nxdl.xml
src/nexpy/definitions/base_classes/NXlog.nxdl.xml
src/nexpy/definitions/base_classes/NXmirror.nxdl.xml
src/nexpy/definitions/base_classes/NXmoderator.nxdl.xml
src/nexpy/definitions/base_classes/NXmonitor.nxdl.xml
src/nexpy/definitions/base_classes/NXmonochromator.nxdl.xml
src/nexpy/definitions/base_classes/NXnote.nxdl.xml
src/nexpy/definitions/base_classes/NXobject.nxdl.xml
src/nexpy/definitions/base_classes/NXorientation.nxdl.xml
src/nexpy/definitions/base_classes/NXparameters.nxdl.xml
src/nexpy/definitions/base_classes/NXpinhole.nxdl.xml
src/nexpy/definitions/base_classes/NXpolarizer.nxdl.xml
src/nexpy/definitions/base_classes/NXpositioner.nxdl.xml
src/nexpy/definitions/base_classes/NXprocess.nxdl.xml
src/nexpy/definitions/base_classes/NXroot.nxdl.xml
src/nexpy/definitions/base_classes/NXsample.nxdl.xml
src/nexpy/definitions/base_classes/NXsensor.nxdl.xml
src/nexpy/definitions/base_classes/NXshape.nxdl.xml
src/nexpy/definitions/base_classes/NXslit.nxdl.xml
src/nexpy/definitions/base_classes/NXsource.nxdl.xml
src/nexpy/definitions/base_classes/NXsubentry.nxdl.xml
src/nexpy/definitions/base_classes/NXtranslation.nxdl.xml
src/nexpy/definitions/base_classes/NXuser.nxdl.xml
src/nexpy/definitions/base_classes/NXvelocity_selector.nxdl.xml
src/nexpy/definitions/base_classes/NXxraylens.nxdl.xml
src/nexpy/examples/README.rst
src/nexpy/examples/chopper.nxs
src/nexpy/examples/example.nxs
src/nexpy/examples/plugins/README.rst
src/nexpy/examples/plugins/chopper/__init__.py
src/nexpy/examples/plugins/chopper/convert_qe.py
src/nexpy/examples/plugins/chopper/get_ei.py
src/nexpy/examples/scripts/README.rst
src/nexpy/examples/scripts/chopper_plot.py
src/nexpy/examples/scripts/example.py
src/nexpy/examples/scripts/spefix.py
src/nexpy/gui/__init__.py
src/nexpy/gui/consoleapp.py
src/nexpy/gui/datadialogs.py
src/nexpy/gui/fitdialogs.py
src/nexpy/gui/importdialog.py
src/nexpy/gui/mainwindow.py
src/nexpy/gui/plotview.py
src/nexpy/gui/pyqt.py
src/nexpy/gui/scripteditor.py
src/nexpy/gui/treeview.py
src/nexpy/gui/utils.py
src/nexpy/gui/resources/back.png
src/nexpy/gui/resources/backward-icon.png
src/nexpy/gui/resources/equal.png
src/nexpy/gui/resources/filesave.png
src/nexpy/gui/resources/forward-icon.png
src/nexpy/gui/resources/forward.png
src/nexpy/gui/resources/hand.png
src/nexpy/gui/resources/home.png
src/nexpy/gui/resources/link-icon.png
src/nexpy/gui/resources/lock-icon.png
src/nexpy/gui/resources/move.png
src/nexpy/gui/resources/pause-icon.png
src/nexpy/gui/resources/qt4_editor_options.png
src/nexpy/gui/resources/refresh-icon.png
src/nexpy/gui/resources/subplots.png
src/nexpy/gui/resources/unlock-icon.png
src/nexpy/gui/resources/zoom_to_rect.png
src/nexpy/gui/resources/icon/NeXpy.png
src/nexpy/gui/resources/icon/NeXpy.svg
src/nexpy/plugins/__init__.py
src/nexpy/readers/__init__.py
src/nexpy/readers/readcatalog.py
src/nexpy/readers/readspe.py
src/nexpy/readers/readspec.py
src/nexpy/readers/readstack.py
src/nexpy/readers/readtiff.py
src/nexpy/readers/readtxt.py
\ No newline at end of file
[gui_scripts]
nexpy = nexpy.nexpygui:main
ansi2html
h5py
ipython>=4.0.0
jupyter
matplotlib>=1.5.0
nexusformat>=0.4.17
numpy>=1.6.0
scipy
[spec]
spec2nexus>=2017.901.4
nexpy
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#-----------------------------------------------------------------------------
# Copyright (c) 2013-2014, NeXpy Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING, distributed with this software.
#-----------------------------------------------------------------------------
__package_name__ = u'NeXpy'
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
__documentation_author__ = u'Ray Osborn'
__documentation_copyright__ = u'2013-2015, Ray Osborn'
__license__ = u'BSD'
__author_name__ = u'NeXpy Development Team'
__author_email__ = u'nexpydev@gmail.com'
__author__ = __author_name__ + u' <' + __author_email__ + u'>'
__url__ = u'http://nexpy.github.io/nexpy/'
__download_url__ = u'https://github.com/nexpy/nexpy/'
__description__ = u'NeXpy: A Python GUI to analyze NeXus data'
__long_description__ = \
u"""
NeXpy provides a high-level python interface to `NeXus data
<http://www.nexusformat.org/>`_ contained within a simple GUI. It is designed to
provide an intuitive interactive toolbox allowing users both to access existing
NeXus files and to create new NeXus-conforming data structures without expert
knowledge of the file format.
The latest development version is always available from `NeXpy's GitHub
site <https://github.com/nexpy/nexpy>`_.
"""
# This file was generated by 'versioneer.py' (0.15) from
# revision-control system data, or from the parent directory name of an
# unpacked source archive. Distribution tarballs contain a pre-generated copy
# of this file.
import json
import sys
version_json = '''
{
"dirty": false,
"error": null,
"full-revisionid": "37dda7bc8cb62e8325dc13d069160b0b250a9b77",
"version": "0.10.10+54.g37dda7b"
}
''' # END VERSION_JSON
def get_versions():
return json.loads(version_json)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#-----------------------------------------------------------------------------
# Copyright (c) 2013-2017, NeXpy Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING, distributed with this software.
#-----------------------------------------------------------------------------
import numpy as np
from lmfit import minimize, Parameters, Parameter, fit_report, __version__
from nexusformat.nexus import *
class Fit(object):
"""Class defining the data, parameters, and results of a least-squares fit.
Attributes
----------
x : ndarray
x-values of data.
y : ndarray
y-values of data.
e : ndarray, optional
standard deviations of the y-values.
use_errors : bool
set to True if the errors are to be used in the fit.
data : NXdata
NXdata group containing the signal and axis.
functions : list of Function objects
Functions to be used in constructing the fit model.
fit
Results of the fit.
"""
def __init__(self, data=None, functions=None, use_errors=True):
self.x = None
self.y = None
self.e = None
self.use_errors = use_errors
self.set_data(data)
self.functions = functions
self.fit = None
self.result = None
def set_data(self, data):
"""
Initialize the data used in the fit
Parameters
----------
data : NXdata
NXdata group containing the signal and axis.
"""
if isinstance(data, NXdata):
self.data = data
signal = data.nxsignal
axes = data.nxaxes[0]
errors = data.nxerrors
if len(signal.shape) != 1:
raise ValueError("Fit only possible on one-dimensional data")
self.x = axes.nxdata.astype(np.float64)
self.y = signal.nxdata.astype(np.float64)
if errors and self.use_errors:
self.e = errors.nxdata.astype(np.float64)
else:
raise TypeError("Must be an NXdata group")
def get_model(self, x=None, f=None):
"""Returns the value of the model.
Parameters
----------
x : ndarray, optional
x-values where the model is calculated. Defaults to `self.x`
f : Function, optional
Function to be included in the model. Defaults to all the functions.
Returns
-------
model : ndarray
values of the model at the requested x-varlues.
"""
if x is None:
x = self.x
model = np.zeros(x.shape,np.float64)
if f:
model = f.module.values(x, [p.value for p in f.parameters])
else:
for f in self.functions:
model += f.module.values(x, [p.value for p in f.parameters])
return model
def residuals(self, parameters):
"""Returns the residuals for the specified parameters
Parameters
----------
parameters : List of Parameters
Parameter objects containing the values to be used in the model.
Returns
-------
residuals : ndarray
Differences between the y-values and the model.
"""
if __version__ > '0.8.3':
for parameter in parameters:
self.parameters[parameter].value = parameters[parameter].value
if self.e is not None:
return (self.y - self.get_model()) / self.e
else:
return self.y - self.get_model()
def fit_data(self):
"""Run a scipy leastsq regression."""
self.parameters = Parameters()
for f in self.functions:
for p in f.parameters:
p.original_name = p.name
self.parameters[f.name+p.name] = p
if p.value is None:
p.value = 1.0
p.init_value = p.value
self.result = minimize(self.residuals, self.parameters,
method='least-squares')
if __version__ > '0.8.3':
for parameter in self.parameters:
self.parameters[parameter].value = \
self.result.params[parameter].value
self.parameters[parameter].stderr = \
self.result.params[parameter].stderr
self.parameters[parameter].correl = \
self.result.params[parameter].correl
for f in self.functions:
for p in f.parameters:
p.name = p.original_name
def fit_report(self):
"""Return the report created by lmfit."""
return str(fit_report(self.parameters))
def save(self, x=None):
"""Save the fit results in a NXprocess group.
Parameters
----------
x : ndarray, optional
x-values at which to calculate the model. Defaults to `self.x`
Returns
-------
group : NXprocess
NXprocess group that contains the data, models and parameters.
"""
group = NXprocess(program='lmfit', version=__version__)
group['data'] = self.data
for f in self.functions:
group[f.name] = NXdata(NXfield(self.get_model(x, f), name='model'),
NXfield(x, name=self.data.nxaxes[0].nxname),
title='Fit Results')
parameters = NXparameters()
for p in f.parameters:
parameters[p.name] = NXfield(p.value, error=p.stderr,
initial_value=p.init_value,
min=str(p.min), max=str(p.max))
group[f.name]['parameters'] = parameters
group['title'] = 'Fit Results'
group['fit'] = NXdata(NXfield(self.get_model(x), name='model'),
NXfield(x, name=self.data.nxaxes[0].nxname),
title='Fit Results')
if self.result is not None:
fit = NXparameters()
fit.nfev = self.result.nfev
fit.chisq = self.result.chisqr
fit.redchi = self.result.redchi
fit.message = self.result.message
group['statistics'] = fit
group.note = NXnote(self.result.message,
('Chi^2 = %s\n' % self.result.chisqr +
'Reduced Chi^2 = %s\n' % self.result.redchi +
'No. of Function Evaluations = %s\n' % self.result.nfev +
'No. of Variables = %s\n' % self.result.nvarys +
'No. of Data Points = %s\n' % self.result.ndata +
'No. of Degrees of Freedom = %s\n' % self.result.nfree +
'%s' % self.fit_report()))
return group
class Function(object):
"""Class defining a function to be used in the fit.
Attributes
----------
name : str
name of the function
module : Python module
module containing the function code.
function_index : int
index of the function
"""
def __init__(self, name=None, module=None, parameters=None, function_index=0):
self.name = name
self.module = module
self._parameters = parameters
self.function_index = function_index
def __lt__(self, other):
return self.function_index < other.function_index
@property
def parameters(self):
"""List of parameters defining the function."""
if self._parameters is None:
self._parameters = [Parameter(name)
for name in self.module.parameters]
return self._parameters
def guess_parameters(self, x, y):
"""Return a list of parameters determined by the function's `guess` method."""
[setattr(p, 'value', g) for p,g in zip(self.parameters,
self.module.guess(x, y))]
@property
def parameter_values(self):
"""Return a list of parameter values."""
return [p.value for p in self.parameters]
def function_values(self, x):
"""Return the calculated values with the current parameters."""
return self.module.values(x, self.parameter_values)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#-----------------------------------------------------------------------------
# Copyright (c) 2013, NeXpy Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING, distributed with this software.
#-----------------------------------------------------------------------------
import numpy as np
function_name = 'Gaussian'
parameters = ['Integral', 'Sigma', 'Center']
factor = np.sqrt(2*np.pi)
def values(x, p):
integral, sigma, center = p
return integral * np.exp(-(x-center)**2/(2*sigma**2)) / (sigma * factor)
def guess(x, y):
center = (x*y).sum()/y.sum()
sigma = np.sqrt(np.fabs(((x-center)**2*y).sum()/y.sum()))
integral = y.max() * sigma * factor
return integral, sigma, center
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#-----------------------------------------------------------------------------
# Copyright (c) 2013, NeXpy Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING, distributed with this software.
#-----------------------------------------------------------------------------
function_name = 'Linear'
parameters = ['Constant', 'Slope']
def values(x, p):
constant, slope = p
return constant + slope*x
def guess(x, y):
slope = (y[-1]-y[0]) / (x[-1]-x[0])
constant = y[0] - slope*x[0]
return constant, slope
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#-----------------------------------------------------------------------------
# Copyright (c) 2013, NeXpy Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING, distributed with this software.
#-----------------------------------------------------------------------------
import numpy as np
function_name = 'Lorentzian'
parameters = ['Integral', 'Gamma', 'Center']
def values(x, p):
integral, gamma, center = p
return integral * (gamma/np.pi) / ((x-center)**2 + gamma**2)
def guess(x, y):
center = (x*y).sum()/y.sum()
gamma = np.sqrt(np.fabs(((x-center)**2*y).sum()/y.sum()))
integral = y.max() * np.pi * gamma
return integral, gamma, center
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment