Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ lockfiles/
# other names
.jython_cache/
tst/

# test stuff
ignore/
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.11
3.12
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
},
"python-envs.pythonProjects": [
{
"path": "ignore/xas_toolbox_old",
"envManager": "ms-python.python:venv",
"packageManager": "ms-python.python:pip"
}
],
"python.analysis.typeCheckingMode": "off",
}
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ name = "xas-toolbox"
classifiers = [
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
Expand All @@ -26,7 +25,7 @@ dependencies = [
dynamic = ["version"]
license.file = "LICENSE"
readme = "README.md"
requires-python = ">=3.11"
requires-python = ">=3.12"

[dependency-groups]
dev = [
Expand Down Expand Up @@ -59,6 +58,8 @@ version_file = "src/xas_toolbox/_version.py"
[tool.mypy]
ignore_missing_imports = true # Ignore missing stubs in imported modules
implicit_optional = true
local_partial_types = true
allow_redefinition_new = true # allow reassigning variables to different types.

[tool.pytest.ini_options]
# Run pytest with all our checkers, and don't spam us with massive tracebacks on error
Expand Down
4 changes: 2 additions & 2 deletions src/xas_toolbox/io/filetypes/nexus/nxs_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ def _get_element_meta(self, val: str):
return

parser = etree.XMLParser(recover=True)
_path: str = self.elementMeta[val][0]
xml_name: str = self.elementMeta[val][-1]
_path: str = self.elementMeta[val][0] # type: ignore
xml_name: str = self.elementMeta[val][-1] # type: ignore

with h5py.File(self.path, "r") as f:
if _path not in f.keys():
Expand Down
42 changes: 21 additions & 21 deletions src/xas_toolbox/io/measurement_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, get_value: Callable[[ScanData | str], Any]):
self._time = None

@property
def i0(self) -> None:
def i0(self) -> Any:
"""
Set `_i0` internally if no initial value. <br>
Will return `_i0` if it's already been set.
Expand All @@ -51,7 +51,7 @@ def i0(self, i0):
self._i0 = i0

@property
def energy(self) -> None:
def energy(self) -> Any:
"""
Set `_energy` internally if no initial value. <br>
Will return `_energy` if it's already been set.
Expand All @@ -67,7 +67,7 @@ def energy(self, energy):
self._energy = energy

@property
def angle(self) -> None:
def angle(self) -> Any:
"""
Set `_angle` internally if no initial value. <br>
Will return `_angle` if it's already been set.
Expand All @@ -83,7 +83,7 @@ def angle(self, angle):
self._angle = angle

@property
def time(self) -> None:
def time(self) -> Any:
"""
Set `_time` internally if no initial value. <br>
Will return `_time` it it's already been set.
Expand Down Expand Up @@ -116,7 +116,7 @@ def __init__(self, get_value: Callable[[ScanData | str], Any]):
self._mufluor = None

@property
def ifluor(self) -> None:
def ifluor(self) -> Any:
"""
Set `_ifluor` internally if no initial value. <br>
Will return `_ifluor` if it's already been set.
Expand All @@ -132,7 +132,7 @@ def ifluor(self, ifluor):
self._ifluor = ifluor

@property
def mufluor(self) -> None:
def mufluor(self) -> Any:
"""
Set `_mufluor` internally if no initial value. <br>
Will return `_mufluor` if it's already been set.
Expand Down Expand Up @@ -165,7 +165,7 @@ def __init__(self, get_value: Callable[[ScanData | str], Any]):
self._mutrans = None

@property
def itrans(self) -> None:
def itrans(self) -> Any:
"""
Set `_itrans` internally if no initial value. <br>
Will return `_itrans` if it's already been set.
Expand All @@ -181,7 +181,7 @@ def itrans(self, itrans):
self._itrans = itrans

@property
def mutrans(self) -> None:
def mutrans(self) -> Any:
"""
Set `_mutrans` internally if no initial value. <br>
Will return `_mutrans` if it's already been set.
Expand Down Expand Up @@ -214,7 +214,7 @@ def __init__(self, get_value: Callable[[ScanData | str], Any]):
self._murefer = None

@property
def irefer(self) -> None:
def irefer(self) -> Any:
"""
Set `_irefer` internally if no initial value. <br>
Will return `_irefer` if it's already been set.
Expand All @@ -230,7 +230,7 @@ def irefer(self, irefer):
self._irefer = irefer

@property
def murefer(self) -> None:
def murefer(self) -> Any:
"""
Set `_murefer` internally if no initial value. <br>
Will return `_murefer` if it's already been set.
Expand Down Expand Up @@ -265,7 +265,7 @@ def __init__(self, get_value: Callable[[ScanData | str], Any]):
self._raw_scaler_in_window = None

@property
def dtc_factors(self) -> None:
def dtc_factors(self) -> Any:
"""
Set `_dtc_factors` internally if no initial value. <br>
Will return `_dtc_factors` if it's already been set.
Expand All @@ -281,7 +281,7 @@ def dtc_factors(self, dtc_factors):
self._dtc_factors = dtc_factors

@property
def raw_scaler_in_window(self) -> None:
def raw_scaler_in_window(self) -> Any:
"""
Set `_raw_scaler_in_window` internally if no initial value. <br>
Will return `_raw_scaler_in_window` if it's already been set.
Expand All @@ -297,7 +297,7 @@ def raw_scaler_in_window(self, raw_scaler_in_window):
self._raw_scaler_in_window = raw_scaler_in_window

@property
def mcas(self) -> None:
def mcas(self) -> Any:
"""
Set `_mcas` internally if no initial value. <br>
Will return `_mcas` if it's already been set.
Expand Down Expand Up @@ -342,7 +342,7 @@ def __init__(self, get_value: Callable[[ScanMeta | ElementMeta | str], Any]):
self._ref_edge = None

@property
def path(self) -> None:
def path(self) -> Any:
"""
Set `_path` internally if no initial value. <br>
Will return `_path` if it's already been set.
Expand All @@ -358,7 +358,7 @@ def path(self, path):
self._path = path

@property
def repetition_files(self) -> None:
def repetition_files(self) -> Any:
"""
Set `_repetition_files` internally if no initial value. <br>
Will return `_repetition_files` if it's already been set.
Expand All @@ -374,7 +374,7 @@ def repetition_files(self, repetition_files):
self._repetition_files = repetition_files

@property
def start_time(self) -> None:
def start_time(self) -> Any:
"""
Set `_start_time` internally if no initial value. <br>
Will return `_start_time` if it's already been set.
Expand All @@ -390,7 +390,7 @@ def start_time(self, start_time):
self._start_time = start_time

@property
def end_time(self) -> None:
def end_time(self) -> Any:
"""
Set `_end_time` internally if no initial value. <br>
Will return `_end_time` if it's already been set.
Expand All @@ -406,7 +406,7 @@ def end_time(self, end_time):
self._end_time = end_time

@property
def symbol(self) -> None:
def symbol(self) -> Any:
"""
Set `_symbol` internally if no initial value. <br>
Will return `_symbol` if it's already been set.
Expand All @@ -423,7 +423,7 @@ def symbol(self, symbol):
raise ValueError("symbol must be str.")

@property
def ref_symbol(self) -> None:
def ref_symbol(self) -> Any:
"""
Set `_ref_symbol` internally if no initial value. <br>
Will return `_ref_symbol` if it's already been set.
Expand All @@ -440,7 +440,7 @@ def ref_symbol(self, ref_symbol):
raise ValueError("ref_symbol must be str.")

@property
def edge(self) -> None:
def edge(self) -> Any:
"""
Set `_edge` internally if no initial value. <br>
Will return `_edge` if it's already been set.
Expand All @@ -457,7 +457,7 @@ def edge(self, edge):
raise ValueError("edge must be str.")

@property
def ref_edge(self) -> None:
def ref_edge(self) -> Any:
"""
Set `_ref_edge` internally if no initial value. <br>
Will return `_ref_edge` if it's already been set.
Expand Down
14 changes: 8 additions & 6 deletions src/xas_toolbox/utils/maths/filter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Literal
from typing import Any, Literal

import numpy as np # type ignore

Expand All @@ -21,7 +21,9 @@ def _remove_negative_gradient(


def resize_with_replacement(
data: list[np.ndarray], placeholder: float | int = np.nan
data: list[np.ndarray[tuple[Any, ...], np.dtype[Any]]]
| np.ndarray[tuple[Any, ...], np.dtype[Any]],
placeholder: float | int = np.nan,
) -> np.ndarray:
"""
For a list of variable-length arrays resize to
Expand Down Expand Up @@ -84,18 +86,18 @@ def normalise_matrix(
return out


def remove_nans(*arrays: np.ndarray) -> list[np.ndarray]:
def remove_nans(*arrays):
"""
If a NaN or inf. value exists in one of the arrays
in the set, remove the point from all of them.

Arguments:
*arrays (tuple[np.ndarray]): List of arrays.
*arrays: List of arrays.

Returns:
arrays (list[np.ndarray]): List of arrays with NaN/inf removed.
arrays: List of arrays with NaN/inf removed.
"""
arrays = list(arrays)

bad_idxs = [np.where(~np.isfinite(a)) for a in arrays]
for val in bad_idxs:
if len(val) == 1:
Expand Down
2 changes: 1 addition & 1 deletion src/xas_toolbox/xas/alignment/align_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,5 @@ def align_scan(scan: XasMeasurement) -> XasMeasurement:
scan_out.energy = x_out
if scan_out.auxData:
scan_out.auxData.energy = x_out
scan_out.meta.energy_shift = delta_x
scan_out.meta.energy_shift = delta_x # type: ignore
return scan_out
6 changes: 3 additions & 3 deletions src/xas_toolbox/xas/corrections/pre_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def pre_edge_bkg(
for i in range(y.shape[0]):
# make sure only first edge looked at for stacks.
if isinstance(e0_idx[i], np.ndarray):
e0_idx_tmp = e0_idx[i][0]
e0_idx_tmp = e0_idx[i][0] # type: ignore
else:
e0_idx_tmp = e0_idx[i]

Expand Down Expand Up @@ -177,7 +177,7 @@ def norm_and_flatten(
pre_bkg: np.ndarray,
post_bkg: np.ndarray,
edge_step: float | np.ndarray,
ie0: int | np.ndarray[int],
ie0: int | np.ndarray[tuple[int, ...]],
flatten: bool = True,
):
"""
Expand Down Expand Up @@ -331,7 +331,7 @@ def pre_edge(
x, y, e0, e0_idx, pre_order, post_order
)

norm, flat = norm_and_flatten(y, pre_bkg, post_bkg, edge_step, e0_idx)
norm, flat = norm_and_flatten(y, pre_bkg, post_bkg, edge_step, e0_idx) # type: ignore
if output is not None:
return norm, flat, edge_step, pre_bkg, post_bkg

Expand Down
7 changes: 6 additions & 1 deletion src/xas_toolbox/xas/data_generation/fake_scans.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import logging
from operator import itemgetter
from typing import Any

import numpy as np
from xraydb import f2_chantler
from xraydb.xray import xray_edge
from xraylib import AtomicNumberToSymbol, CompoundParser

from xas_toolbox.io import XasMeasurement
from xas_toolbox.utils.scan_data import ElementMeta, ScanData, ScanMeta
from xas_toolbox.xas.edges import find_edges

from .xafs_signal import make_signal
Expand Down Expand Up @@ -264,11 +266,14 @@ def make_fake_spectrum(
nscans=nscans,
)

def _get_fn(valname: str) -> np.ndarray | None:
def _get_fn(
valname: ScanData | ScanMeta | ElementMeta | str,
) -> np.ndarray[tuple[Any, ...], np.dtype[Any]] | list[Any] | None:
if valname == "energy":
return energy
if valname == "mu" or valname == "mutrans":
return xafs
return None

out = XasMeasurement(get_value=_get_fn, mode="transmission")
out.energy = energy
Expand Down
7 changes: 5 additions & 2 deletions src/xas_toolbox/xas/data_generation/mix_spectra.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from typing import Any

import numpy as np

from xas_toolbox.utils.maths.filter import normalise_matrix, resize_with_replacement
from xas_toolbox.xas.alignment.align_stack import get_target_energy, interp_stack


def mix_scans(
profiles: np.ndarray,
absorption: list[np.ndarray],
profiles: np.ndarray[tuple[Any, ...], np.dtype[Any]],
absorption: list[np.ndarray[tuple[Any, ...], np.dtype[Any]]]
| np.ndarray[tuple[Any, ...], np.dtype[Any]],
energy: list[np.ndarray] | np.ndarray,
):
"""
Expand Down
Loading
Loading