-
Notifications
You must be signed in to change notification settings - Fork 21
Improve typing consistency in codebase #1311
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
Merged
SylviaWhittle
merged 37 commits into
AFM-SPM:main
from
ubdbra001:i1299-improve-typing-consistency
Jun 17, 2026
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
9b22f18
update doctring typehints for MatchedBranch
ubdbra001 da0dd7d
update type hints for UnMatchedBranch
ubdbra001 676b9e9
set molecule_data outside then inside if-statement
ubdbra001 9cd75f9
correct return type hint for remove_common_values
ubdbra001 aed52e7
updating OrderedTrace doctsrings
ubdbra001 1cb93c1
add error to collate_molecule_statistics
ubdbra001 1398614
update str dunder for when images are None
ubdbra001 d27c270
update type hints for GrainCrop image get & set
ubdbra001 67da943
update return type hint for calculate_region_connection_regions
ubdbra001 9e66b26
Set directories to Path types in process_scan
ubdbra001 05f8e38
update param type and dir type in process_filters
ubdbra001 d403998
update param type and dir type in process_grains
ubdbra001 e9248fa
update return type and dir type in process_grainstats
ubdbra001 7e447bf
[pre-commit.ci] Fixing issues with pre-commit
pre-commit-ci[bot] 2b25eb4
Update run_nodestats_tracing docstring
ubdbra001 67baf5f
Update docstring for process_grainstats
ubdbra001 1333866
Update return description for process_grainstats docstring
ubdbra001 a8c39f2
Update return typehint for order_from_end
ubdbra001 305ac95
Update identify_writhes return type hints
ubdbra001 eb68419
Update param type hints in Filters class and methods
ubdbra001 879fc64
[pre-commit.ci] Fixing issues with pre-commit
pre-commit-ci[bot] 9fa544c
update typehints in theme module
ubdbra001 480363e
update return type hint for remove_scars
ubdbra001 2bec3a7
add inline typehints for image dict values
ubdbra001 22951a3
update typing for bound_padded_coordinates_to_image and check functions
ubdbra001 ab6ebcb
update type hints for threshold functions
ubdbra001 15b5d60
convert return val of triangle height to float
ubdbra001 0fbbef8
update return type hints for min_max_feret and get_feret_from_mask
ubdbra001 09a4faa
[pre-commit.ci] Fixing issues with pre-commit
pre-commit-ci[bot] 66e74f1
use NDArray not ArrayLike
ubdbra001 f627bd9
update doctrings for topostats_objects input arguments
ubdbra001 dc4a239
Merge branch 'main' into i1299-improve-typing-consistency
ubdbra001 88895ef
update remove_common_values input args
ubdbra001 2134a1f
updates to remove_scars
ubdbra001 a9bedc2
update return docstrings for feret functions
ubdbra001 9db4b99
address sylvia's feedback
ubdbra001 86492cf
[pre-commit.ci] Fixing issues with pre-commit
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -201,7 +201,7 @@ def __str__(self) -> str: | |
| ) | ||
|
|
||
| @property | ||
| def image(self) -> npt.NDArray[float]: | ||
| def image(self) -> npt.NDArray[np.floating]: | ||
| """ | ||
| Getter for the ``image`` attribute. | ||
|
|
||
|
|
@@ -213,7 +213,7 @@ def image(self) -> npt.NDArray[float]: | |
| return self._image | ||
|
|
||
| @image.setter | ||
| def image(self, value: npt.NDArray[float]): | ||
| def image(self, value: npt.NDArray[np.floating]): | ||
| """ | ||
| Setter for the ``image`` attribute. | ||
|
|
||
|
|
@@ -892,21 +892,21 @@ class MatchedBranch: | |
|
|
||
| Attributes | ||
| ---------- | ||
| ordered_coords : npt.NDArray[np.int32] | ||
| ordered_coords : npt.NDArray[np.int32], optional | ||
| Numpy array of ordered coordinates. | ||
| heights : npt.NDArray[np.number] | ||
| heights : npt.NDArray[np.number], optional | ||
| Numpy array of heights. | ||
| distances : npt.NDArray[np.number] | ||
| distances : npt.NDArray[np.number], optional | ||
| Numpy array of distances. | ||
| fwhm : float | ||
| fwhm : float, optional | ||
| Full-width half maximum. | ||
| fwhm_half_maxs : list[float] | ||
| fwhm_half_maxs : list[float], optional | ||
| Half-maximums from a matched branch. | ||
| fwhm_peaks : list[int | float] | ||
| fwhm_peaks : list[float], optional | ||
| Peaks from a matched branch. | ||
| angles : float | ||
| angles : float | list[float], optional | ||
| Angle between branches. | ||
| branch_statistics : dict[str, float | int | list[Any] | str] | ||
| branch_statistics : dict[str, float | int | list[Any] | str], optional | ||
| Dictionary of branch statistics, ``fwhm``, ``fwhm_half_maxs`` and ``fwhm_peaks``. | ||
| """ | ||
|
|
||
|
|
@@ -971,11 +971,11 @@ class UnMatchedBranch: | |
|
|
||
| Attributes | ||
| ---------- | ||
| angles : float | ||
| angles : float | list[float] | ||
| Angle between branches. | ||
| """ | ||
|
|
||
| angles: float | list[float] | None = None | ||
| angles: float | list[float] | ||
|
|
||
| def __str__(self) -> str: | ||
| """ | ||
|
|
@@ -1061,23 +1061,23 @@ class OrderedTrace: | |
| """ | ||
| Class for Ordered Trace data and attributes. | ||
|
|
||
| molecule_data : dict[int, Molecule] | ||
| molecule_data : dict[int, Molecule], optional | ||
| Dictionary of ``Molecule`` objects indexed by molecule number. | ||
| tracing_stats : dict | None | ||
| tracing_stats : dict, optional | ||
| Tracing statistics. | ||
| grain_molstats : Any | None | ||
| grain_molstats : Any, optional | ||
| Grain molecule statistics. | ||
| molecules : int | ||
| molecules : int, optional | ||
| Number of molecules within the grain. | ||
| writhe : str | ||
| writhe : str, optional | ||
| The writhe sign, can be either `+`, `-` or `0` for positive, negative or no writhe. | ||
| pixel_to_nm_scaling: np.float64 | None | ||
| pixel_to_nm_scaling: np.float64, optional | ||
| Pixel to nm scaling. | ||
| images: dict[str, npt.NDArray] | None | ||
| images: dict[str, npt.NDArray], optional | ||
| Diagnostic images produced during processing. | ||
| error: bool | None | ||
| error: bool, optional | ||
| Errors encountered? | ||
| molecule_statistics : dict[int, dict[str, bool | str | float | None]] | None | ||
| molecule_statistics : dict[int, dict[str, bool | str | float | None]], optional | ||
| Dictionary of molecule statistics, with one entry for each molecule. | ||
| """ | ||
|
|
||
|
|
@@ -1104,7 +1104,7 @@ def __str__(self) -> str: | |
| writhe = {"+": "positive", "-": "negative", "0": "no writhe"}.get(self.writhe) | ||
| return ( | ||
| f"number of molecules : {self.molecules}\n" | ||
| f"number of images : {len(self.images)}\n" | ||
| f"number of images : {len(self.images) if self.images is not None else 'None'}\n" | ||
| f"writhe : {writhe}\n" | ||
| f"pixel to nm scaling : {self.pixel_to_nm_scaling}\n" | ||
| f"error : {self.error}" | ||
|
|
@@ -1128,17 +1128,20 @@ def require_molecule_data(self) -> dict[int, Molecule]: | |
| raise RuntimeError("molecule_data is None") | ||
| return self.molecule_data | ||
|
|
||
| def collate_molecule_statistics(self) -> dict[int, dict[str, bool | int | str | None]]: | ||
| def collate_molecule_statistics(self) -> dict[int, dict[str, bool | int | str | float | None]]: | ||
| """ | ||
| Collate molecule statistics for all molecules to dictionary. | ||
|
|
||
| The resulting dictionary can be easily converted to Pandas Dataframes for writing to CSV. | ||
|
|
||
| Returns | ||
| ------- | ||
| dict[int, dict[str, bool | int | str | None]] | ||
| dict[int, dict[str, bool | int | str float | None]] | ||
| Dictionary, indexed by molecule where the value is the molecules statistics for the given molecule. | ||
| """ | ||
| if self.molecule_data is None: | ||
| raise ValueError("No molecule data found") | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me know if you'd like me to change this to something else |
||
|
|
||
| self.molecule_statistics = { | ||
| molecule_number: molecule.collate_molecule_statistics() | ||
| for molecule_number, molecule in self.molecule_data.items() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have been going around replacing
| Nonewith, optionalin the docstrings. Probably doesn't have a real impact but I thought I'd make it all consistent.Let me know if you'd prefer to retain
| None