Skip to content

Commit

Permalink
Merge branch 'RELEASE_next_minor' into RELEASE_next_major
Browse files Browse the repository at this point in the history
  • Loading branch information
francisco-dlp committed Feb 9, 2017
2 parents 723e17d + 2dcf28d commit 8e7af33
Show file tree
Hide file tree
Showing 124 changed files with 4,219 additions and 4,157 deletions.
16 changes: 9 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,32 @@ before_install:
install:

- if [[ $MINIMAL_ENV == 'False' ]] ; then
DEPS="nose numpy scipy matplotlib ipython h5py sympy scikit-learn dill natsort setuptools scikit-image cython lxml ipyparallel";
DEPS="numpy scipy matplotlib ipython h5py sympy scikit-learn dill natsort setuptools scikit-image cython lxml ipyparallel";
conda create -n testenv --yes $DEPS;
source activate testenv;
conda install pip;
python setup.py install;
else pip3 install .;
pip install pytest pytest-xdist;
else pip install pytest;
pip3 install .;
fi

script:
- if [[ $MINIMAL_ENV == 'False' ]]; then
python setup.py build_ext --inplace;
pip install coverage coveralls;
python continuous_integration/nosetest.py --with-coverage hyperspy.tests;
pip install coverage coveralls pytest-cov;
py.test --cov=hyperspy --pyargs hyperspy;
else python3 setup.py build_ext --inplace;
echo "available installed python libraries (pip3 list):"
pip3 list;
pip3 install coverage coveralls;
python3 continuous_integration/nosetest.py --with-coverage hyperspy.tests;
pip3 install coverage coveralls pytest-cov;
py.test --cov=hyperspy --pyargs hyperspy.tests;
fi

after_success:
- coveralls
- if [[ $MINIMAL_ENV == 'False' ]]; then
if [[ $TRAVIS_OS_NAME == 'osx' ]]; then
if [[ $TRAVIS_OS_NAME == 'osx' ]]; then
python setup.py bdist_wheel;
else python setup.py sdist;
fi;
Expand Down
2 changes: 1 addition & 1 deletion anaconda_hyperspy_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
- ipyparallel
- jupyter
- matplotlib
- nose
- pytest
- numpy
- qt
- scikit-image
Expand Down
8 changes: 5 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ shallow_clone: true
environment:

global:
TEST_DEPS: "nose wheel pip"
TEST_DEPS: "pytest pytest-cov wheel pip"
NSIS_DIR: "%PROGRAMFILES(x86)%/NSIS"


Expand Down Expand Up @@ -67,7 +67,7 @@ test_script:
# Run the project tests
- ps: Add-AppveyorMessage "Running tests..."
- "python setup.py build_ext --inplace"
- "python continuous_integration/nosetest.py hyperspy.tests"
- "py.test"
- "python setup.py clean"
- ps: Add-AppveyorMessage "Testing completed."

Expand Down Expand Up @@ -101,7 +101,7 @@ before_deploy:
- ps: Add-AppveyorMessage "Setting up WinPython environment..."
- ps: Start-FileDownload ('http://freefr.dl.sourceforge.net/project/nsis/NSIS%202/2.46/nsis-2.46-strlen_8192.zip') ../nsis_patch.zip
- ps: if ((Get-FileHash '../nsis_patch.zip').Hash -ne '3BA22DDC0F14DBD75A9487EB6C9BD85F535E7038927D251103B97E0AAD94EEAD') { exit(1) }
- "7z x ../nsis_patch.zip -o%NSIS_DIR -aoa"
- "7z x ../nsis_patch.zip -o%NSIS_DIR% -aoa"
- ps: Start-FileDownload ('http://nsis.sourceforge.net/mediawiki/images/e/eb/Textreplace.zip') ../Textreplace.zip
- ps: if ((Get-FileHash '../Textreplace.zip').Hash -ne '6462C0C22E87E7C81DD9076D40ACC74C515243A56F10F4F8FE720F7099DB3BA2') { exit(1) }
- "7z x ../Textreplace.zip -o%NSIS_DIR% -aoa"
Expand All @@ -116,6 +116,8 @@ before_deploy:
- "%CMD_IN_ENV% python.exe -c \"import sys; print(sys.version)\""
- "%CMD_IN_ENV% python.exe setup.py recythonize"
- "%CMD_IN_ENV% python.exe setup.py install"
# Try to run twice as workaround for permission error
- "%CMD_IN_ENV% pip install hyperspyui || pip install hyperspyui"
# setting back the config:
- "ren %WP_INSTDIR%\\settings\\pydistutils_bak.cfg pydistutils.cfg"
# Custom installer step
Expand Down
40 changes: 0 additions & 40 deletions continuous_integration/nosetest.py

This file was deleted.

31 changes: 0 additions & 31 deletions doc/user_guide/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -243,37 +243,6 @@ In addition, since version 0.7.2 the lowess filter requires statsmodels.
In Windows HyperSpy uses the Ipython's QtConsole and therefore Qt and PyQt or
PySide are also required.


In Debian/Ubuntu you can install the libraries as follows:

.. code-block:: bash
$ sudo apt-get install python-numpy python-matplotlib ipython
ipython-notebook python-traits python-traitsui python-h5py
python-scikit-learn python-scikit-image python-nose
python-statsmodels python3-tqdm
..
In Arch Linux, the following command should install the required packages to
get a fully functional installation:
.. code-block:: bash
$ sudo pacman -Sy python2 python2-numpy python2-matplotlib python2-pip
python2-traits python2-traitsui python2-h5py python2-scikit-learn python2-nose
python2-statsmodels python2-pillow python2-pyqt4 python2-pyqt5 python2-scipy
python2-pandas python2-setuptools ipython2 python2-jinja python2-pyzmq
python2-pyqt4 python2-tornado python2-sip python2-pygments python2-scikit-image
# Or, just run this command from the root hyperspy directory to import the
# list of packages and install automatically:
$ xargs sudo pacman -Sy --noconfirm < doc/package_lists/arch_linux_package_list.txt
# Once these are installed, go to the HyperSpy directory and run:
$ sudo pip2 install -e ./
# If desired, the python2-seaborn library can also be installed from AUR for prettier plotting
.. _known-issues:

Known issues
Expand Down
31 changes: 27 additions & 4 deletions doc/user_guide/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ parameters for spectroscopy than the one that ships with HyperSpy:
... centre=0,
... module="numpy")
If the expression is inconvenient to write out in full (e.g. it's long and/or
complicated), multiple substitutions can be given, separated by semicolumns.
Both symbolic and numerical substitutions are allowed:

.. code-block:: python
>>> expression = "h / sqrt(p2) ; p2 = 2 * m0 * e1 * x * brackets;"
>>> expression += "brackets = 1 + (e1 * x) / (2 * m0 * c * c) ;"
>>> expression += "m0 = 9.1e-31 ; c = 3e8; e1 = 1.6e-19 ; h = 6.6e-34"
>>> wavelength = hs.model.components1D.Expression(
... expression=expression,
... name="Electron wavelength with voltage")
:py:class:`~._components.expression.Expression` uses `Sympy
<http://www.sympy.org>`_ internally to turn the string into
a funtion. By default it "translates" the expression using
Expand Down Expand Up @@ -523,15 +536,25 @@ For example:
A 5.000000
centre 0.000000
.. deprecated:: 1.1.3
Setting the :py:attr:`~.component.Parameter.twin_function` and
:py:attr:`~.component.Parameter.twin_inverse_function` attributes. Set the
:py:attr:`~.component.Parameter.twin_function_expr` and
:py:attr:`~.component.Parameter.twin_inverse_function_expr` attributes
instead.

.. versionadded:: 1.1.3
:py:attr:`~.component.Parameter.twin_function_expr` and
:py:attr:`~.component.Parameter.twin_inverse_function_expr`.

By default the coupling function is the identity function. However it is
possible to set a different coupling function by setting the
:py:attr:`~.component.Parameter.twin_function` and
:py:attr:`~.component.Parameter.twin_inverse_function` attributes. For
:py:attr:`~.component.Parameter.twin_function_expr` and
:py:attr:`~.component.Parameter.twin_inverse_function_expr` attributes. For
example:

>>> gaussian2.A.twin_function = lambda x: x**2
>>> gaussian2.A.twin_inverse_function = lambda x: np.sqrt(np.abs(x))
>>> gaussian2.A.twin_function_expr = "x**2"
>>> gaussian2.A.twin_inverse_function_expr = "sqrt(abs(x))"
>>> gaussian2.A.value = 4
>>> m.print_current_values()
Components Parameter Value
Expand Down
28 changes: 25 additions & 3 deletions hyperspy/_components/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ def fn_wrapped(self, x):
return fn_wrapped


def _parse_substitutions(string, simultaneous=True):
import sympy
splits = map(str.strip, string.split(';'))
expr = sympy.sympify(next(splits))
# We substitute one by one manually, as passing all at the same time does
# not work as we want (subsitutions inside other substitutions do not work)
for sub in splits:
expr = expr.subs(*tuple(map(str.strip, sub.split('='))))
return expr

class Expression(Component):

"""Create a component from a string expression.
Expand All @@ -34,7 +44,8 @@ class docstring.
Parameters
----------
expression: str
Component function in SymPy text expression format. See the SymPy
Component function in SymPy text expression format with
substitutions separated by `;`. See examples and the SymPy
documentation for details. The only additional constraint is that
the variable must be `x`. Also, in `module` is "numexpr" the
functions are limited to those that numexpr support. See its
Expand Down Expand Up @@ -72,6 +83,17 @@ class docstring.
... x0=0,
... position="x0",)
Substitutions for long or complicated expressions are separated by
semicolumns:
>>> expr = 'A*B/(A+B) ; A = sin(x)+one; B = cos(y) - two; y = tan(x)'
>>> comp = hs.model.components1D.Expression(
... expression=expr,
... name='my function')
>>> comp.parameters
(<Parameter one of my function component>,
<Parameter two of my function component>)
"""

import sympy
Expand All @@ -94,15 +116,15 @@ class docstring.

if autodoc:
self.__doc__ = _CLASS_DOC % (
name, sympy.latex(sympy.sympify(expression)))
name, sympy.latex(_parse_substitutions(expression)))

def function(self, x):
return self._f(x, *[p.value for p in self.parameters])

def compile_function(self, module="numpy"):
import sympy
from sympy.utilities.lambdify import lambdify
expr = sympy.sympify(self._str_expression)
expr = _parse_substitutions(self._str_expression)

rvars = sympy.symbols([s.name for s in expr.free_symbols], real=True)
real_expr = expr.subs(
Expand Down
11 changes: 6 additions & 5 deletions hyperspy/_signals/eels.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ def add_elements(self, elements, include_pre_edges=False):
>>> s = hs.signals.EELSSpectrum(np.arange(1024))
>>> s.add_elements(('C', 'O'))
Adding C_K subshell
Adding O_K subshell
Raises
------
Expand Down Expand Up @@ -226,13 +224,16 @@ def align_zero_loss_peak(
Examples
--------
>>>> s_ll.align_zero_loss_peak()
>>> s_ll = hs.signals.EELSSpectrum(np.zeros(1000))
>>> s_ll.data[100] = 100
>>> s_ll.align_zero_loss_peak()
Aligning both the lowloss signal and another signal
>>>> s_ll.align_zero_loss_peak(also_align=[s])
>>> s = hs.signals.EELSSpectrum(np.range(1000))
>>> s_ll.align_zero_loss_peak(also_align=[s])
Aligning within a narrow range of the lowloss signal
>>>> s_ll.align_zero_loss_peak(signal_range=(-10.,10.))
>>> s_ll.align_zero_loss_peak(signal_range=(-10.,10.))
See Also
Expand Down

0 comments on commit 8e7af33

Please sign in to comment.