Skip to content

Commit e5bad02

Browse files
DOC: Update type hints and documentation for utils and tracer modules
1 parent 8d38f8d commit e5bad02

3 files changed

Lines changed: 120 additions & 95 deletions

File tree

docs/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
"Callable": "collections.abc.Callable",
161161
"MutableMapping": "collections.abc.MutableMapping",
162162
"ArrayLike": "numpy.typing.ArrayLike",
163+
"Sequence": "collections.abc.Sequence",
163164
}
164165

165166
# ------------------------------------------------------------------------------

mapflpy/tracer.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from typing import Iterable, Optional, Tuple, Callable, Literal
2828

2929
import numpy as np
30-
from numpy._typing import NDArray
30+
from numpy.typing import ArrayLike, NDArray
3131

3232
from psi_io import read_hdf_data
3333

@@ -355,7 +355,7 @@ class _Tracer(MutableMapping, ABC):
355355
356356
Other Parameters
357357
----------------
358-
**mapfl_params : dict
358+
**mapfl_params
359359
Additional parameters forwarded to :func:`mapflpy_fortran.mapfl.run`.
360360
These override defaults in :data:`~mapflpy.typing.DEFAULT_PARAMS`.
361361
@@ -368,13 +368,13 @@ class _Tracer(MutableMapping, ABC):
368368
369369
Raises
370370
------
371-
:class:`ValueError`
371+
ValueError
372372
If an invalid value is provided for magnetic field components.
373-
:class:`TypeError`
373+
TypeError
374374
If values are not of the expected type (``tuple`` or ``str``).
375-
:class:`FileNotFoundError`
375+
FileNotFoundError
376376
If provided file paths do not exist.
377-
:class:`ImportError`
377+
ImportError
378378
If :mod:`mapflpy_fortran` cannot be imported (shared library missing or not built).
379379
"""
380380

@@ -606,18 +606,18 @@ def _get_field(self,
606606
return self._mapfl_params[key], *[self._mapfl_params[f"{key}_{dim}"] for dim in 'rtp']
607607

608608
def _parse_launch_points(self,
609-
lps: Optional[Iterable[float]],
609+
lps: Optional[ArrayLike],
610610
**kwargs
611611
) -> ArrayType:
612612
"""
613613
Parse or generate launch points for tracing.
614614
615615
Parameters
616616
----------
617-
lps : array-like, optional
617+
lps : ArrayLike | None
618618
Launch points of shape (3, N) in spherical coordinates (r, t, p).
619619
kwargs : dict
620-
If `lps` is None, these are passed to `fetch_default_launch_points`.
620+
If `lps` is None, these are passed to :func:`~mapflpy.utils.fetch_default_launch_points`.
621621
622622
Returns
623623
-------
@@ -658,7 +658,7 @@ def run(self) -> None:
658658

659659
@flush_state
660660
def trace(self,
661-
launch_points: Optional[Iterable[float]] = None,
661+
launch_points: Optional[ArrayLike] = None,
662662
buffer_size: int = DEFAULT_BUFFER_SIZE,
663663
**kwargs
664664
) -> Traces:
@@ -667,11 +667,11 @@ def trace(self,
667667
668668
Parameters
669669
----------
670-
launch_points : ndarray, optional
670+
launch_points : Arraylike | None, optional
671671
Array of shape (3, N) for r, t, p coordinates. If None, uses defaults.
672672
buffer_size : int
673673
Maximum number of steps per fieldline.
674-
kwargs : dict
674+
**kwargs
675675
Extra arguments passed to default launch point generator if ``launch_points`` is None.
676676
677677
Returns
@@ -847,14 +847,14 @@ def _run(self) -> None:
847847
return self._mapfl.run(**self._mapfl_params)
848848

849849
def _trace(self,
850-
lps: NDArray[np.float64],
850+
lps: ArrayLike,
851851
buff: int) -> Traces:
852852
"""
853853
Run fieldline tracing from a set of launch points.
854854
855855
Parameters
856856
----------
857-
lps : ndarray
857+
lps : ArrayLike
858858
Launch points in shape (3, N), in Fortran (column-major) order.
859859
Each column corresponds to a (r, t, p) coordinate.
860860
buff : int

0 commit comments

Comments
 (0)