Skip to content

Commit

Permalink
Merge pull request #78 from kmnhan/manager-thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
kmnhan authored Dec 26, 2024
2 parents aa8d3ed + 0292152 commit 664b2c9
Show file tree
Hide file tree
Showing 32 changed files with 2,201 additions and 639 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ jobs:
export QT_API=${{ matrix.qt-api }}
- name: Test with pytest
if: matrix.python-version != '3.12' || matrix.qt-api != 'pyqt6'
if: matrix.python-version != '3.12' || matrix.qt-api != 'pyside6'
run: |
python -u -m pytest -v
- name: Test with pytest with coverage
if: matrix.python-version == '3.12' && matrix.qt-api == 'pyqt6'
if: matrix.python-version == '3.12' && matrix.qt-api == 'pyside6'
run: |
python -u -m pytest -v --cov erlab --junitxml=junit.xml
- name: Upload coverage to Codecov
if: matrix.python-version == '3.12' && matrix.qt-api == 'pyqt6'
if: matrix.python-version == '3.12' && matrix.qt-api == 'pyside6'
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Upload test results to Codecov
if: ${{ matrix.python-version == '3.12' && matrix.qt-api == 'pyqt6' && !cancelled() }}
if: ${{ matrix.python-version == '3.12' && matrix.qt-api == 'pyside6' && !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
if os.getenv("READTHEDOCS"):
extensions.append("sphinxcontrib.googleanalytics")
googleanalytics_id = "G-DDZYWTBV4S"
html_baseurl = "https://erlabpy.readthedocs.io/en/stable/" # Canonical URL

# templates_path = ["_templates"]
# exclude_patterns = []
Expand Down
4 changes: 2 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ analysis.

.. image:: images/imagetool_light.png
:align: center
:alt: Imagetool
:alt: ImageTool window in light mode
:class: only-light

.. only:: format_html

.. image:: images/imagetool_dark.png
:align: center
:alt: Imagetool
:alt: ImageTool window in dark mode
:class: only-dark

.. toctree::
Expand Down
4 changes: 2 additions & 2 deletions docs/source/user-guide/filtering.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,14 @@
"\n",
".. image:: ../images/dtool_light.png\n",
" :align: center\n",
" :alt: DerivativeTool\n",
" :alt: DerivativeTool window in light mode\n",
" :class: only-light\n",
"\n",
".. only:: format_html\n",
"\n",
" .. image:: ../images/dtool_dark.png\n",
" :align: center\n",
" :alt: DerivativeTool\n",
" :alt: DerivativeTool window in dark mode\n",
" :class: only-dark\n",
"\n",
"- The first section interpolates the data to a grid prior to smoothing.\n",
Expand Down
32 changes: 30 additions & 2 deletions docs/source/user-guide/imagetool.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ The ImageTool window

.. image:: ../images/imagetool_light.png
:align: center
:alt: Imagetool
:alt: ImageTool window in light mode
:class: only-light

.. only:: format_html

.. image:: ../images/imagetool_dark.png
:align: center
:alt: Imagetool
:alt: ImageTool window in dark mode
:class: only-dark

Inspired by *Image Tool* for Igor Pro written by the Advanced Light Source at Lawrence
Expand Down Expand Up @@ -185,4 +185,32 @@ Features
Toggle the console with :kbd:`+`` (Mac) or :kbd:`Ctrl+`` (Windows/Linux) or through
the ``View`` menu.

- Toggle the ``Preview on Hover`` option in the ``View`` menu to show a preview of the
main image when hovering over each tool.

- Explore the menubar for more features!


Tips
~~~~

- Sometimes, you may wish to send data from the manager to a jupyter notebook for
further analysis. You can do this by using the manager console and the `%store
<https://ipython.readthedocs.io/en/stable/config/extensions/storemagic.html>`_ magic
command.

For example, if you want to store the data displayed in a tool with index 0, run the
following in the manager console:

.. code-block:: python
my_data = tools[0].data
%store my_data
In the notebook, you can retrieve the data by running:

.. code-block:: python
%store -r my_data
after which the data will be available as ``my_data`` in the notebook.
2 changes: 2 additions & 0 deletions docs/source/user-guide/io.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@
"\n",
".. image:: ../images/flowchart_single.pdf\n",
" :align: center\n",
" :alt: Flowchart for loading data from a single file\n",
"\n",
"If only all data formats were as simple as this! Unfortunately, there are some setups\n",
"where data that belongs to a single scan is saved over multiple files. In this case, the\n",
Expand All @@ -748,6 +749,7 @@
"\n",
".. image:: ../images/flowchart_multiple.pdf\n",
" :align: center\n",
" :alt: Flowchart for loading data from multiple files\n",
"\n",
"In this case, the method :meth:`identify <erlab.io.dataloader.LoaderBase.identify>`\n",
"should resolve *all* files that belong to the given sequence number, and return a *list*\n",
Expand Down
12 changes: 8 additions & 4 deletions src/erlab/accessors/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
from collections.abc import Collection, Hashable, Iterable, Mapping, Sequence
from typing import TYPE_CHECKING, Any, Literal, cast

import lazy_loader as _lazy
import numpy as np
import tqdm.auto
import xarray as xr
from xarray.core.dataarray import _THIS_ARRAY

Expand All @@ -28,9 +26,15 @@
# Avoid importing until runtime for initial import performance
import joblib
import lmfit
import tqdm.auto as tqdm
else:
import lazy_loader as _lazy

from erlab.utils.misc import LazyImport

lmfit = _lazy.load("lmfit")
joblib = _lazy.load("joblib")
tqdm = LazyImport("tqdm.auto")


def _nested_dict_vals(d):
Expand Down Expand Up @@ -556,7 +560,7 @@ def _output_wrapper(name, da, out=None) -> dict:
parallel_obj = joblib.Parallel(**parallel_kw)

if parallel_obj.return_generator:
out_dicts = tqdm.auto.tqdm( # type: ignore[call-overload]
out_dicts = tqdm.tqdm( # type: ignore[call-overload]
parallel_obj(
itertools.starmap(
joblib.delayed(_output_wrapper), self._obj.data_vars.items()
Expand All @@ -578,7 +582,7 @@ def _output_wrapper(name, da, out=None) -> dict:

else:
result = type(self._obj)()
for name, da in tqdm.auto.tqdm(self._obj.data_vars.items(), **tqdm_kw): # type: ignore[call-overload]
for name, da in tqdm.tqdm(self._obj.data_vars.items(), **tqdm_kw): # type: ignore[call-overload]
_output_wrapper(name, da, result)

result = result.assign_coords(
Expand Down
12 changes: 8 additions & 4 deletions src/erlab/accessors/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
ERLabDatasetAccessor,
either_dict_or_kwargs,
)
from erlab.utils.array import sort_coord_order
from erlab.utils.formatting import format_html_table
from erlab.utils.misc import emit_user_level_warning

Expand Down Expand Up @@ -486,7 +487,6 @@ def __call__(
DataArray
The selected and averaged data.
Note
----
Unlike :meth:`xarray.DataArray.sel`, this method treats all dimensions without
Expand All @@ -506,6 +506,8 @@ def __call__(
"""
indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "qsel")

coord_order = list(self._obj.coords.keys())

# Bin widths for each dimension, zero if width not specified
bin_widths: dict[Hashable, float] = {}

Expand Down Expand Up @@ -554,12 +556,12 @@ def __call__(

unindexed_dims: list[Hashable] = [
k for k in slices | scalars if k not in self._obj.indexes
]
] # Unindexed dimensions, i.e. dimensions without coordinates

if len(unindexed_dims) >= 1:
out = self._obj.assign_coords(
{k: np.arange(self._obj.sizes[k]) for k in unindexed_dims}
)
) # Assign temporary coordinates
else:
out = self._obj

Expand Down Expand Up @@ -594,7 +596,9 @@ def __call__(

print(out_str)

return out.drop_vars(unindexed_dims, errors="ignore")
out = out.drop_vars(unindexed_dims, errors="ignore")

return sort_coord_order(out, keys=coord_order, dims_first=True)

def around(
self, radius: float | dict[Hashable, float], *, average: bool = True, **sel_kw
Expand Down
15 changes: 5 additions & 10 deletions src/erlab/analysis/fit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,11 @@ def fit_edges_linear(x, data, len_fit) -> tuple[float, float, float, float]:
n1, m1
The coefficients of the linear fit for the right edge.
"""
n0, m0 = fit_poly_jit(
np.array(x[:len_fit], dtype=np.float64),
np.array(data[:len_fit], dtype=np.float64),
deg=1,
)
n1, m1 = fit_poly_jit(
np.array(x[-len_fit:], dtype=np.float64),
np.array(data[-len_fit:], dtype=np.float64),
deg=1,
)
na_idx = np.isnan(np.asarray(data))
xv = np.array(x[~na_idx], dtype=np.float64)
yv = np.array(data[~na_idx], dtype=np.float64)
n0, m0 = fit_poly_jit(xv[:len_fit], yv[:len_fit], deg=1)
n1, m1 = fit_poly_jit(xv[-len_fit:], yv[-len_fit:], deg=1)
return n0, m0, n1, m1


Expand Down
Loading

0 comments on commit 664b2c9

Please sign in to comment.