Skip to content

Commit

Permalink
Merge pull request #26 from kmnhan/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
kmnhan authored Apr 25, 2024
2 parents 942a810 + c98c38e commit 85a60b3
Show file tree
Hide file tree
Showing 73 changed files with 1,388 additions and 4,801 deletions.
7 changes: 4 additions & 3 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ body:
- type: textarea
id: what-happened
attributes:
label: What happened?
label: Description
description: |
Thanks for reporting a bug! Please describe what you were trying to get done.
Tell us what happened, what went wrong.
Expand All @@ -16,7 +16,7 @@ body:
- type: textarea
id: what-did-you-expect-to-happen
attributes:
label: What did you expect to happen?
label: Expected behavior
description: |
A clear and concise description of what you expected to happen.
validations:
Expand All @@ -27,7 +27,8 @@ body:
attributes:
label: Minimal Complete Verifiable Example
description: |
Minimal, self-contained copy-pastable example that demonstrates the issue. This will be automatically formatted into code, so no need for markdown backticks.
Minimal, self-contained copy-pastable example that demonstrates the issue.
This will be automatically formatted into code, so no need for markdown backticks.
render: Python

- type: checkboxes
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ blank_issues_enabled: false
contact_links:
- name: Ask a question or start a discussion
url: https://github.com/kmnhan/erlabpy/discussions
about: Please ask and answer questions here.
about: Ask and answer questions on the discussions page!
9 changes: 5 additions & 4 deletions .github/ISSUE_TEMPLATE/feature-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ body:
- type: textarea
id: description
attributes:
label: Is your feature request related to a problem? Please describe.
label: Description
description: |
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Is your feature request related to a problem?
Please provide a clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
validations:
required: true
- type: textarea
id: solution
attributes:
label: Describe the solution you'd like
label: Possible solution
description: |
A clear and concise description of what you want to happen.
- type: textarea
id: alternatives
attributes:
label: Describe alternatives you've considered
label: Alternatives
description: |
A clear and concise description of any alternative solutions or features you've considered.
validations:
Expand Down
3 changes: 1 addition & 2 deletions docs/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ dependencies:
- qtawesome>=1.3.1
- qtpy>=2.4.1
- scipy>=1.12.0
- superqt>=0.6.2
- tqdm>=4.66.2
- uncertainties>=3.0.1
- uncertainties>=3.1.4
- varname>=0.13.0
- xarray>=2024.02.0
- hvplot
Expand Down
3 changes: 1 addition & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ pyqtgraph>=0.13.1
qtawesome>=1.3.1
qtpy>=2.4.1
scipy>=1.12.0
superqt>=0.6.2
tqdm>=4.66.2
uncertainties>=3.0.1
uncertainties>=3.1.4
varname>=0.13.0
xarray>=2024.02.0
sphinx
Expand Down
2 changes: 2 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
# nitpicky = False
# nitpick_ignore = [("py:class", "numpy.float64")]

highlight_language = "python3"

# -- Linkcode settings -------------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/extensions/linkcode.html

Expand Down
9 changes: 3 additions & 6 deletions docs/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,9 @@ Code standards
- Please try to add type annotations to your code. This will help with code completion
and static analysis.

- Although it would be great to enforce static type checking, our code base currently
does not pass the tests. It would require a large amount of work to get it to pass, so
we are not enforcing it at the moment, and it is unclear whether the extra effort is
worth it. See `this article
<https://typing.readthedocs.io/en/latest/source/typing_anti_pitch.html>`_ for some
reasons to avoid static type checking.
- We are in the process of adding type annotations to the codebase, and most of it
should pass `mypy <https://mypy.readthedocs.io/en/stable/>`_ except for the io and
interactive modules.

Documentation
=============
Expand Down
14 changes: 2 additions & 12 deletions docs/source/erlab.accessors.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
Extensions to xarray (:mod:`erlab.accessors`)
=============================================
Accessors (:mod:`erlab.accessors`)
==================================

.. automodule:: erlab.accessors


.. rubric:: Classes

.. autosummary::

PlotAccessor
ImageToolAccessor
SelectionAccessor
MomentumAccessor
4 changes: 0 additions & 4 deletions docs/source/erlab.characterization.rst

This file was deleted.

4 changes: 2 additions & 2 deletions docs/source/pyplots/norms.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ def sample_plot(norms, labels, kw0, kw1, cmap):
figsize=eplt.figwh(),
)

for norm, label, k0, k1 in zip(norms, labels, kw0, kw1):
for norm, label, k0, k1 in zip(norms, labels, kw0, kw1, strict=True):
axs[0].plot(x, norm(**k0, **k1)(x), label=label)

bar_data = modulatedBarData(384, 256)
for i, (ax, norm, k1) in enumerate(zip(axs[1:], norms, kw1)):
for i, (ax, norm, k1) in enumerate(zip(axs[1:], norms, kw1, strict=True)):
ax.plot(
0.5,
1,
Expand Down
20 changes: 9 additions & 11 deletions docs/source/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
API Reference
*************

ERLabPy is organized into multiple subpackages and submodules.
ERLabPy is organized into multiple subpackages and submodules classified by their functionality. The following table lists the subpackages and submodules of ERLabPy.

Subpackages
===========

======================== ========================
Subpackage Description
======================== ========================
`erlab.analysis` Data analysis
`erlab.io` Read & write ARPES data
`erlab.plotting` Plot
`erlab.interactive` Interactive plotting based on Qt and pyqtgraph
`erlab.characterization` Analyze sample characterization results such as XRD and transport measurements
`erlab.analysis` Routines for analyzing ARPES data.
`erlab.io` Reading and writing data.
`erlab.plotting` Functions related to static plotting with matplotlib.
`erlab.interactive` Interactive tools and widgets based on Qt and pyqtgraph
`erlab.accessors` `xarray accessors <https://docs.xarray.dev/en/stable/internals/extending-xarray.html>`_. You will not need to import this module directly.
======================== ========================

.. currentmodule:: erlab
Expand All @@ -26,7 +26,7 @@ Subpackage Description
erlab.io
erlab.plotting
erlab.interactive
erlab.characterization
erlab.accessors

Submodules
==========
Expand All @@ -35,15 +35,13 @@ Submodules
Submodule Description
================== ==================
`erlab.lattice` Tools for working with real and reciprocal lattices.
`erlab.constants` Physical constants and unit conversion
`erlab.accessors` `xarray accessors <https://docs.xarray.dev/en/stable/internals/extending-xarray.html>`_
`erlab.parallel` Helpers for parallel processing
`erlab.constants` Physical constants and functions for unit conversion.
`erlab.parallel` Helpers for parallel processing.
================== ==================

.. toctree::
:hidden:

erlab.lattice
erlab.constants
erlab.accessors
erlab.parallel
100 changes: 62 additions & 38 deletions docs/source/user-guide/curve-fitting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,22 @@
"Curve fitting\n",
"=============\n",
"\n",
"ERLabPy provides two choices for curve fitting: `lmfit\n",
"<https://lmfit.github.io/lmfit-py/>`_ and `iminuit\n",
"<https://github.com/scikit-hep/iminuit>`_. \n",
"Curve fitting in ERLabPy largely relies on `lmfit <https://lmfit.github.io/lmfit-py/>`_.\n",
"Along with some convenient models for common fitting tasks, ERLabPy provides a powerful\n",
"accessor that streamlines curve fitting on multidimensional xarray objects.\n",
"\n",
"- `lmfit <https://lmfit.github.io/lmfit-py/>`_ provides a high-level interface to\n",
" optimization and curve fitting problems for Python. It builds on and extends many of\n",
" the optimization methods of :mod:`scipy.optimize`, and provides a common interface for\n",
" all of its supported optimization methods.\n",
"ERLabPy also provides optional integration of lmfit models with `iminuit\n",
"<https://github.com/scikit-hep/iminuit>`_, which is a Python interface to the `Minuit\n",
"C++ library <https://root.cern.ch/doc/master/Minuit2Page.html>`_ developed at CERN.\n",
"\n",
"- `iminuit <https://github.com/scikit-hep/iminuit>`_ is a Python interface to the Minuit\n",
" C++ library, highly compatible with Jupyter notebooks and the SciPy ecosystem.\n",
" Although developed for high-energy physics, it is a simple and easy-to-use tool for\n",
" solving optimization problems.\n",
"In this tutorial, we will start with the basics of curve fitting using lmfit, introduce\n",
"some models that are available in ERLabPy, and demonstrate curve fitting with the\n",
":meth:`modelfit <erlab.accessors.fit.ModelFitDataArrayAccessor.__call__>` accessor to\n",
"fit multidimensional xarray objects. Finally, we will show how to use `iminuit\n",
"<https://github.com/scikit-hep/iminuit>`_ with lmfit models.\n",
"\n",
"In this tutorial, we will show how to use both libraries to fit a simple function to a\n",
"set of data points.\n",
"\n",
"Basic fitting with lmfit\n",
"------------------------"
"Basic fitting with ``lmfit``\n",
"----------------------------"
]
},
{
Expand Down Expand Up @@ -320,11 +317,16 @@
"<https://lmfit.github.io/lmfit-py/fitting.html>`_.\n",
"\n",
"Fitting with pre-defined models\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n",
"-------------------------------\n",
"\n",
"Creating composite models with different prefixes every time can be cumbersome, so\n",
"ERLabPy provides some pre-defined models in :mod:`erlab.analysis.fit.models`. One\n",
"example is :class:`MultiPeakModel <erlab.analysis.fit.models.MultiPeakModel>`, which is\n",
"ERLabPy provides some pre-defined models in :mod:`erlab.analysis.fit.models`.\n",
"\n",
"\n",
"Fitting multiple peaks\n",
"~~~~~~~~~~~~~~~~~~~~~~\n",
"\n",
"One example is :class:`MultiPeakModel <erlab.analysis.fit.models.MultiPeakModel>`, which is\n",
"a composite model of multiple Gaussian or Lorentzian peaks on a linear background. By\n",
"supplying keyword arguments, you can specify the number of peaks, their shapes, whether\n",
"to multiply with a Fermi-Dirac distribution, and whether to convolve the result with\n",
Expand Down Expand Up @@ -388,7 +390,7 @@
"metadata": {},
"outputs": [],
"source": [
"data = generate_data(bandshift=-0.2, count=5e+8).T\n",
"data = generate_data(bandshift=-0.2, count=5e8, seed=1).T\n",
"cut = data.qsel(ky=0.3)\n",
"cut.qplot(colorbar=True)"
]
Expand Down Expand Up @@ -468,8 +470,8 @@
}
},
"source": [
"Fitting xarray objects\n",
"----------------------\n",
"Fitting ``xarray`` objects\n",
"--------------------------\n",
"\n",
"ERLabPy provides accessors for xarray objects that allows you to fit data with lmfit\n",
"models: :meth:`xarray.DataArray.modelfit\n",
Expand Down Expand Up @@ -738,11 +740,25 @@
" \"slope\": -0.1,\n",
" },\n",
")\n",
"\n",
"result_ds"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's overlay the fitted peak positions on the data."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"result_ds.modelfit_data.qplot()\n",
"\n",
"center_fitted = result_ds.modelfit_coefficients.sel(param=\"center\")\n",
"plt.plot(center_fitted, center_fitted.beta, \".\")"
"result_center = result_ds.sel(param=\"center\")\n",
"plt.plot(result_center.modelfit_coefficients, result_center.beta, '.-')"
]
},
{
Expand Down Expand Up @@ -834,15 +850,15 @@
" guess=True,\n",
" )\n",
"\n",
".. note ::\n",
"\n",
" - Note that the initial run will take a long time due to the overhead of creating\n",
" parallel workers. Subsequent calls will run faster, since joblib's default backend\n",
" will try to reuse the workers.\n",
" \n",
" - The accessor has some intrinsic overhead due to post-processing. If you need the\n",
" best performance, handle the parallelization yourself with joblib and\n",
" :meth:`lmfit.Model.fit <lmfit.model.Model.fit>`.\n",
" .. note ::\n",
" \n",
" - Note that the initial run will take a long time due to the overhead of creating\n",
" parallel workers. Subsequent calls will run faster, since joblib's default backend\n",
" will try to reuse the workers.\n",
" \n",
" - The accessor has some intrinsic overhead due to post-processing. If you need the\n",
" best performance, handle the parallelization yourself with joblib and\n",
" :meth:`lmfit.Model.fit <lmfit.model.Model.fit>`.\n",
"\n",
"Saving and loading fits\n",
"~~~~~~~~~~~~~~~~~~~~~~~\n",
Expand Down Expand Up @@ -948,8 +964,16 @@
"Also check out the interactive Fermi edge fitting tool,\n",
":func:`erlab.interactive.goldtool`.\n",
"\n",
"Using iminuit\n",
"-------------\n",
"Using ``iminuit``\n",
"-----------------\n",
"\n",
".. note::\n",
"\n",
" This part requires `iminuit <https://github.com/scikit-hep/iminuit>`_.\n",
"\n",
"`iminuit <https://github.com/scikit-hep/iminuit>`_ is a powerful Python interface to the\n",
"`Minuit C++ library <https://root.cern.ch/doc/master/Minuit2Page.html>`_ developed at\n",
"CERN. To learn more, see the `iminuit documentation <http://scikit-hep.org/iminuit/>`_.\n",
"\n",
"ERLabPy provides a thin wrapper around :class:`iminuit.Minuit` that allows you to use\n",
"lmfit models with iminuit. The example below conducts the same fit as the previous one,\n",
Expand Down Expand Up @@ -1049,7 +1073,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/source/user-guide/indexing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"source": [
"from erlab.io.exampledata import generate_data\n",
"\n",
"dat = generate_data()"
"dat = generate_data(seed=1)"
]
},
{
Expand Down
Loading

0 comments on commit 85a60b3

Please sign in to comment.