Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous improvements #69

Draft
wants to merge 37 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
307f84a
docs: add docstring
kmnhan Nov 19, 2024
e1e8baa
refactor(plotting): streamline igor CT loading
kmnhan Nov 19, 2024
69ce4aa
docs(accessors.kspace): make decorators private
kmnhan Nov 19, 2024
4285f0b
chore: add emojis to changelog!
kmnhan Nov 19, 2024
3593d41
refactor: move `AxesConfiguration` from `erlab.analysis.kspace` to `e…
kmnhan Nov 19, 2024
d7f3b3c
perf: speed up initial import
kmnhan Nov 19, 2024
752facf
fix(io.dataloader): allow dimensions without coordinates in output data
kmnhan Nov 19, 2024
aa6f5d2
feat(io.plugins): add summary generation to maestro loader
kmnhan Nov 19, 2024
3f219ae
perf(io): implement lazy loading for h5netcdf and nexusformat imports
kmnhan Nov 19, 2024
e939419
chore: cleanup
kmnhan Nov 20, 2024
6ed2a70
fix(io.plugins.maestro): fix wrong temperature attribute
kmnhan Nov 20, 2024
6b4e77c
chore: use pathlib
kmnhan Nov 20, 2024
b724033
chore: move internal function to utils
kmnhan Nov 21, 2024
be66297
refactor(interactive.imagetool): use HDF5 files instead of pickle to …
kmnhan Nov 21, 2024
f1cc59e
chore: cleanup deprecated code
kmnhan Nov 21, 2024
4aa1425
fix(interactive.imagetool): cursor sync for non-uniform coords
kmnhan Nov 21, 2024
e78190f
refactor(interactive): move IconButton to interactive utils and add I…
kmnhan Nov 21, 2024
59326a1
feat(interactive.imagetool.manager): add menubar to manager
kmnhan Nov 21, 2024
1ebfa72
refactor(io.dataloader): improve warning messages and error handling
kmnhan Nov 22, 2024
3e20e63
feat(interactive.imagetool): change manager icon
kmnhan Nov 22, 2024
c9a5496
chore: move some menubar methods to ImageTool
kmnhan Nov 22, 2024
5577249
feat(interactive.imagetool): show dialog when data is being loaded
kmnhan Nov 22, 2024
9e38b2c
refactor(plotting.general): use matplotlib api instead of xarray plot…
kmnhan Nov 22, 2024
5586cce
fix(io.plugins.merlin): fix match signature
kmnhan Nov 22, 2024
a5d38af
feat(interactive.imagetool): add save and load functionality for work…
kmnhan Nov 22, 2024
c1cf7c7
ci(pre-commit): update pre-commit hooks
kmnhan Nov 22, 2024
ac5ac92
style: combine interactive tool classes
kmnhan Nov 22, 2024
cb733d1
test: catch warnings
kmnhan Nov 22, 2024
e14c9fc
fix(interactive.imagetool): retain axis order when opening dtool and …
kmnhan Nov 22, 2024
5699fa3
fix(interactive.imagetool): resolve segfault on save current data
kmnhan Nov 22, 2024
4c74105
fix(io.plugins.lorea): fix file dialog method
kmnhan Nov 22, 2024
6352047
test: refactor imagetool tests
kmnhan Nov 23, 2024
da3425f
feat(interactive.imagetool.manager): improve file opening
kmnhan Nov 24, 2024
c464a3a
style: update type hints to support xarray 2024.11.0
kmnhan Nov 24, 2024
f8b5fb2
test: fix tests
kmnhan Nov 25, 2024
fdb69b4
style: update type hints
kmnhan Nov 25, 2024
0da0554
test: remove flaky tests
kmnhan Nov 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ repos:
# Lint and format with ruff
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.7.2
rev: v0.7.4
hooks:
# Run the linter.
- id: ruff
Expand All @@ -43,7 +43,7 @@ repos:

# Commitizen
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.30.0
rev: v3.31.0
hooks:
- id: commitizen
additional_dependencies: [ cz-changeup ]
Expand Down
259 changes: 130 additions & 129 deletions CHANGELOG.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def setup(app):
"NXgroup": "`NXgroup <nexusformat.nexus.tree.NXgroup>`",
"NXlink": "`NXlink <nexusformat.nexus.tree.NXlink>`",
"NXdata": "`NXdata <nexusformat.nexus.tree.NXdata>`",
"NXentry": "`NXentry <nexusformat.nexus.tree.NXentry>`",
"lmfit.Parameters": "`lmfit.Parameters <lmfit.parameter.Parameters>`",
"lmfit.Model": "`lmfit.Model <lmfit.model.Model>`",
}
Expand Down
36 changes: 31 additions & 5 deletions docs/source/user-guide/imagetool.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,15 @@ execution is a blocking call. This means that you cannot run any other code whil
tool is running. As a workaround, we provide :class:`ImageToolManager
<erlab.interactive.imagetool.ImageToolManager>`.

In the environment where ERLabPy installed, run ``itool-manager`` in a shell to start
the manager application. Subsequent invocations of ImageTool from :func:`itool
<erlab.interactive.imagetool.itool>` and :class:`qshow
<erlab.accessors.general.InteractiveDataArrayAccessor>` will open the tool in the
manager application, leaving the notebook free to run other code.
In the environment where ERLabPy installed, run ``itool-manager`` in a terminal to start
the manager application. Subsequent calls to :func:`itool
<erlab.interactive.imagetool.itool>` and :meth:`DataArray.qshow
<erlab.accessors.general.InteractiveDataArrayAccessor.__call__>` will open the ImageTool
in the manager.

Alternatively, you can run the following code in a python environment where ERLabPy is installed: ::

python -m erlab.interactive.imagetool.manager

.. note::

Expand All @@ -116,3 +120,25 @@ manager application, leaving the notebook free to run other code.
directly while the manager is running by passing `use_manager=False` to :func:`itool
<erlab.interactive.imagetool.itool>` or :class:`qshow
<erlab.accessors.general.InteractiveDataArrayAccessor>`.

The manager application consists of a small window that shows the list of opened
ImageTools, along with some buttons to manage them. Hovering over the buttons will show
tooltips that explain what each button does.

There are three ways to open an ImageTool with the manager:

- Invocations of ImageTool from :func:`itool <erlab.interactive.imagetool.itool>` and :class:`qshow
<erlab.accessors.general.InteractiveDataArrayAccessor>` from any python script or
Jupyter notebook will automatically be added to the manager.

- Open files through the ``File`` menu in the menu bar of the manager application.

- Drag and drop supported files to the manager window.

One of the main features of the manager is that it can save and load the state of
ImageTool windows to a HDF5 file. You can save all ImageTool windows in the manager to a
single file through the ``Save Workspace As...`` menu item in the ``File`` menu. The
saved windows can later be restored through the ``Open Workspace...`` item in the same
menu.

Try exploring the menubar of the manager application to see what you can do!
2 changes: 1 addition & 1 deletion docs/source/user-guide/io.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@
"\n",
"- The experimental geometry should be stored in the ``'configuration'`` attribute as an\n",
" integer. See :ref:`Nomenclature <nomenclature>` and :class:`AxesConfiguration\n",
" <erlab.analysis.kspace.AxesConfiguration>` for more information.\n",
" <erlab.constants.AxesConfiguration>` for more information.\n",
"\n",
"- All standard angle coordinates must follow the naming conventions in\n",
" :ref:`Nomenclature <nomenclature>`.\n",
Expand Down
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Changelog = "https://github.com/kmnhan/erlabpy/blob/main/CHANGELOG.md"
erlab-igor = "erlab.io.igor:IgorBackendEntrypoint"

[tool.commitizen]
change_type_map = { "BREAKING CHANGE" = "Breaking Changes", "feat" = "Features", "fix" = "Bug Fixes", "refactor" = "Code Refactor", "perf" = "Performance" }
change_type_map = { "BREAKING CHANGE" = "🚨 Breaking Changes", "feat" = "Features", "fix" = "🐞 Bug Fixes", "perf" = "⚡️ Performance", "refactor" = "🛠 Code Refactor" }

version_provider = "pep621"
update_changelog_on_bump = true
Expand All @@ -94,11 +94,11 @@ changelog_start_rev = "v1.2.1"
changelog_merge_prerelease = true
name = 'cz_changeup'
change_type_order = [
"Breaking Changes",
"Features",
"Bug Fixes",
"Code Refactor",
"Performance",
"🚨 Breaking Changes",
"Features",
"🐞 Bug Fixes",
"⚡️ Performance",
"🛠 Code Refactor",
]
# cz-changeup configuration
changeup_repo_base_url = "https://github.com/kmnhan/erlabpy"
Expand Down
17 changes: 14 additions & 3 deletions src/erlab/accessors/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
import copy
import itertools
from collections.abc import Collection, Hashable, Iterable, Mapping, Sequence
from typing import Any, Literal, cast
from typing import TYPE_CHECKING, Any, Literal, cast

import joblib
import lmfit
import numpy as np
import tqdm.auto
import xarray as xr
Expand All @@ -25,6 +23,10 @@
from erlab.utils.misc import emit_user_level_warning
from erlab.utils.parallel import joblib_progress

if TYPE_CHECKING:
# Avoid importing until runtime for initial import performance
import lmfit


def _nested_dict_vals(d):
for v in d.values():
Expand Down Expand Up @@ -55,6 +57,8 @@ def _concat_along_keys(d: dict[str, xr.DataArray], dim_name: str) -> xr.DataArra
def _parse_params(
d: dict[str, Any] | lmfit.Parameters, dask: bool
) -> xr.DataArray | _ParametersWrapper:
import lmfit

if isinstance(d, lmfit.Parameters):
# Input to apply_ufunc cannot be a Mapping, so wrap in a class
return _ParametersWrapper(d)
Expand All @@ -70,6 +74,8 @@ def _parse_params(


def _parse_multiple_params(d: dict[str, Any], as_str: bool) -> xr.DataArray:
import lmfit

for k in d:
if isinstance(d[k], int | float | complex | xr.DataArray):
d[k] = {"value": d[k]}
Expand Down Expand Up @@ -252,6 +258,8 @@ def __call__(
scipy.optimize.curve_fit

"""
import lmfit

# Implementation analogous to xarray.Dataset.curve_fit

if params is None:
Expand Down Expand Up @@ -539,6 +547,9 @@ def _output_wrapper(name, da, out=None) -> dict:
}

if parallel:
# Avoid importing until runtime for initial import performance
import joblib

if is_dask:
emit_user_level_warning(
"The input Dataset is chunked. Parallel fitting will not offer any "
Expand Down
5 changes: 3 additions & 2 deletions src/erlab/accessors/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from collections.abc import Hashable, Mapping
from typing import Any

import matplotlib.pyplot as plt
import numpy as np
import xarray as xr

Expand Down Expand Up @@ -54,14 +53,16 @@ def __call__(self, *args, **kwargs):
Keyword arguments to be passed to the plotting function.

"""
import matplotlib.pyplot

from erlab.plotting.erplot import fancy_labels, plot_array

if len(self._obj.dims) == 2:
return plot_array(self._obj, *args, **kwargs)

ax = kwargs.pop("ax", None)
if ax is None:
ax = plt.gca()
ax = matplotlib.pyplot.gca()
kwargs["ax"] = ax

out = self._obj.plot(*args, **kwargs)
Expand Down
Loading