Skip to content

Commit 470b76a

Browse files
committed
Enh/bumpversion (#67)
* ENH: Add parameterized tests for ASLData input values (ld, pld, te) * ENH: Add 'AAT2022' to parameterized atlas names for testing BrainAtlas creation * ENH: Add GitHub Actions workflow for version bumping and publishing to PyPI * ENH: Add bump2version configuration for automated versioning and tagging * ENH: Remove bumpversion configuration from pyproject.toml * ENH: Add validation for bump_type input in GitHub Actions workflow * WIP: Add download_brain_atlas function to download Cucaracha models from a given URL * WIP: Implement brain normalization function for image registration using ANTsPy * ENH: Add multiple brain atlas JSON files with metadata and descriptions * ENH: Add multiple brain atlas JSON files with metadata and descriptions * ENH: Add unit tests for BrainAtlas class to validate atlas listing and URL retrieval * STY: Clean up whitespace and ensure consistent formatting in download_brain_atlas function * ENH: Remove unused kaggle_tools.py file and associated download_brain_atlas function * ENH: Refactor brain normalization function to space normalization, improve template image handling from BrainAtlas, and enhance registration process with console status updates * ENH: Implement space normalization function and head movement correction, refactor registration methods, and remove obsolete files * ENH: Refactor registration tests to improve error handling and add comprehensive tests for rigid body and space normalization functions * ENH: Add tests for error handling in setting atlas and retrieving URL and labels for known atlases * ENH: Add LGPHCC2022 brain atlas JSON file and remove obsolete LGPHCCxxxx file * ENH: Add AICHA2021 brain atlas JSON file and remove obsolete AICHAxxxx file * ENH: Add AAL32024 brain atlas JSON file and remove obsolete AAL2015 file * ENH: Add additional metadata fields to brain atlas JSON files for CAPRSC, DKA, and HA * ENH: Add JHA2005 brain atlas JSON file and remove obsolete JHAxxxx file * ENH: Add FCA7N2011 brain atlas JSON file and remove obsolete FCA7Nxxxx file * ENH: Update description in MA2012 brain atlas JSON file for clarity * ENH: Remove deprecated brain atlas JSON files and add updated versions for DKA2006, HA2003, and MA2012 * ENH: Add unit tests for BrainAtlas class functionality * ENH: Implement ASL data registration with normalization and error handling * ENH: Add tests for apply_transformation function to validate output and error handling * ENH: Refactor asl_template_registration to improve normalization process and update ASLData handling * BUG: Fix linter * WIP: Fixing asl_template_normalization to use M0 volume first * ENH: Refactor asl_template_registration to prioritize M0 image for normalization and improve atlas integration * ENH: Add tests for apply_transformation with BrainAtlas reference input handling * STY: Refactor asl_template_registration for improved readability and structure * REF: Update import paths and replace ants.image_read with load_image for atlas image loading in asl_template_registration * ENH: Add unit tests for rigid body registration and head movement correction * WIP: Implement initial structure for ASLRegistration class with pipeline comments * ENH: Improve ASL template registration by normalizing pcasl volumes and updating progress reporting * ENH: Fix linter and merge conflicts * ENH: Remove unused parameter from asl_template_registration and delete obsolete test file * WIP: Update test_space_normalization_success to use actual ASLData paths and add new test for transform type Affine * Add T2Scalar_ASLMapping to __all__ in __init__.py * Add unit tests for MultiTE and T2Scalar ASL mapping functionalities - Created `test_multi_te_mapping.py` to test MultiTE_ASLMapping class, including methods for setting brain masks, CBF and ATT maps, and creating maps. - Implemented tests for error handling when ASLData is incomplete or when invalid parameters are provided. - Added `test_te_mapping.py` for T2Scalar_ASLMapping class, verifying initialization, error handling for missing TE and PLD values, and successful T2 map creation. - Removed the outdated `test_reconstruction.py` file to streamline test organization and improve maintainability. * Remove unused import of asl_t2_scalar_multi_te from t2_mapping.py * Refactor T2Scalar_ASLMapping: improve multiprocessing handling, enhance T2 fitting logic, and add unit tests for initialization and error scenarios * DOC: Add Copilot instructions and code commit guidelines * ENH: Implement image loading test for M0 using numpy array * DOC: Update copilot instructions with detailed commit message guidelines and prefix patterns * ENH: Refactor image loading and saving in tests, add error handling for invalid image inputs * ENH: Enhance head movement correction by adding flexible reference volume selection and transformation proportion calculations * Add T2Scalar_ASLMapping to __all__ in __init__.py * Add unit tests for MultiTE and T2Scalar ASL mapping functionalities - Created `test_multi_te_mapping.py` to test MultiTE_ASLMapping class, including methods for setting brain masks, CBF and ATT maps, and creating maps. - Implemented tests for error handling when ASLData is incomplete or when invalid parameters are provided. - Added `test_te_mapping.py` for T2Scalar_ASLMapping class, verifying initialization, error handling for missing TE and PLD values, and successful T2 map creation. - Removed the outdated `test_reconstruction.py` file to streamline test organization and improve maintainability. * Refactor T2Scalar_ASLMapping: improve multiprocessing handling, enhance T2 fitting logic, and add unit tests for initialization and error scenarios * DOC: Add Copilot instructions and code commit guidelines * Add T2Scalar_ASLMapping to __all__ in __init__.py * Add unit tests for MultiTE and T2Scalar ASL mapping functionalities - Created `test_multi_te_mapping.py` to test MultiTE_ASLMapping class, including methods for setting brain masks, CBF and ATT maps, and creating maps. - Implemented tests for error handling when ASLData is incomplete or when invalid parameters are provided. - Added `test_te_mapping.py` for T2Scalar_ASLMapping class, verifying initialization, error handling for missing TE and PLD values, and successful T2 map creation. - Removed the outdated `test_reconstruction.py` file to streamline test organization and improve maintainability. * Refactor T2Scalar_ASLMapping: improve multiprocessing handling, enhance T2 fitting logic, and add unit tests for initialization and error scenarios * Add T2Scalar_ASLMapping to __all__ in __init__.py * WIP: Add T2Scalar_ASLMapping initial implementation * Add unit tests for MultiTE and T2Scalar ASL mapping functionalities - Created `test_multi_te_mapping.py` to test MultiTE_ASLMapping class, including methods for setting brain masks, CBF and ATT maps, and creating maps. - Implemented tests for error handling when ASLData is incomplete or when invalid parameters are provided. - Added `test_te_mapping.py` for T2Scalar_ASLMapping class, verifying initialization, error handling for missing TE and PLD values, and successful T2 map creation. - Removed the outdated `test_reconstruction.py` file to streamline test organization and improve maintainability. * WIP: Refactor T2Scalar_ASLMapping: streamline initialization, enhance T2 fitting process, and improve error handling for TE and PLD values * Refactor T2Scalar_ASLMapping: improve multiprocessing handling, enhance T2 fitting logic, and add unit tests for initialization and error scenarios * Add T2Scalar_ASLMapping to __all__ in __init__.py * WIP: Add T2Scalar_ASLMapping initial implementation * Add unit tests for MultiTE and T2Scalar ASL mapping functionalities - Created `test_multi_te_mapping.py` to test MultiTE_ASLMapping class, including methods for setting brain masks, CBF and ATT maps, and creating maps. - Implemented tests for error handling when ASLData is incomplete or when invalid parameters are provided. - Added `test_te_mapping.py` for T2Scalar_ASLMapping class, verifying initialization, error handling for missing TE and PLD values, and successful T2 map creation. - Removed the outdated `test_reconstruction.py` file to streamline test organization and improve maintainability. * WIP: Refactor T2Scalar_ASLMapping: streamline initialization, enhance T2 fitting process, and improve error handling for TE and PLD values * Refactor T2Scalar_ASLMapping: improve multiprocessing handling, enhance T2 fitting logic, and add unit tests for initialization and error scenarios * ENH: Implement image loading test for M0 using numpy array * ENH: Add test for creating ASLData object with PCASL as numpy array and validate head movement correction output * ENH: Implement image loading test for M0 using numpy array * ENH: Implement image loading test for M0 using numpy array * STY: Fix linter * DEL: Remove copilot instructions document * STY: Fix linter * BUG: Update ASLData initialization in space normalization test for consistency
1 parent e8dd960 commit 470b76a

File tree

9 files changed

+257
-3209
lines changed

9 files changed

+257
-3209
lines changed

.bumpversion.cfg

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[bumpversion]
2+
current_version = 0.6.0
3+
commit = True
4+
tag = True
5+
tag_name = v{new_version}
6+
7+
[bumpversion:file:pyproject.toml]
8+
search = version = "{current_version}"
9+
replace = version = "{new_version}"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Release & Publish to PyPI
2+
3+
on:
4+
workflow_dispatch: # Manual trigger only
5+
inputs:
6+
bump_type:
7+
description: "Version bump type (patch, minor, major)"
8+
required: true
9+
default: "patch"
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Validate bump_type input
17+
run: |
18+
if [[ ! "${{ github.event.inputs.bump_type }}" =~ ^(patch|minor|major)$ ]]; then
19+
echo "Invalid bump_type: ${{ github.event.inputs.bump_type }}. Must be one of: patch, minor, major."
20+
exit 1
21+
fi
22+
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: '3.9'
30+
31+
- name: Install Poetry
32+
run: pip install poetry
33+
34+
- name: Install bumpversion
35+
run: pip install bump2version
36+
37+
- name: Install project dependencies
38+
run: poetry install
39+
40+
- name: Bump version
41+
run: |
42+
bump2version ${{ github.event.inputs.bump_type }}
43+
44+
- name: Push version bump and tags to repo
45+
run: |
46+
git config user.name "github-actions[bot]"
47+
git config user.email "github-actions[bot]@users.noreply.github.com"
48+
git push
49+
git push --tags
50+
51+
- name: Build package
52+
run: poetry build
53+
54+
- name: Publish to PyPI
55+
env:
56+
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
57+
run: poetry publish

asltk/registration/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ def __init__(self):
2121
pass
2222

2323

24+
# TODO Montar classe para fazer o coregistro de ASL
25+
class ASLRegistration:
26+
27+
# Pipeline
28+
# inputs: ASLData (com m0 e pcasl), BrainAtlas, resolution (1 or 2 mm)
29+
# Tomar m0 e comparar orientação com o template
30+
# Se necessário, corrigir orientação do template para estar coerente com o m0 (salvar a transformação e aplicar para os labels)
31+
# Realizar o registro do m0 no template
32+
# com a transformação do m0, deixar salvo como parametro do objeto da classe
33+
# Ter metodos para aplicar transformação para o pcasl, ou mapas gerados pelo CBFMapping, MultiTE, etc.
34+
35+
def __init__(self):
36+
pass
37+
38+
2439
def space_normalization(
2540
moving_image: np.ndarray,
2641
template_image: BrainAtlas,

asltk/registration/asl_normalization.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,114 @@ def norm_function(vol, _):
127127
return new_asl, trans_m0_mtx
128128

129129

130+
def asl_template_registration(
131+
asl_data: ASLData,
132+
asl_data_mask: np.ndarray = None,
133+
atlas_name: str = 'MNI2009',
134+
verbose: bool = False,
135+
):
136+
"""
137+
Register ASL data to common atlas space.
138+
139+
This function applies a elastic normalization to fit the subject head
140+
space into the atlas template space.
141+
142+
143+
Note:
144+
This method takes in consideration the ASLData object, which contains
145+
the pcasl and/or m0 image. The registration is performed using primarily
146+
the `m0`image if available, otherwise it uses the `pcasl` image.
147+
Therefore, choose wisely the `ref_vol` parameter, which should be a valid index
148+
for the best `pcasl`volume reference to be registered to the atlas.
149+
150+
Args:
151+
asl_data: ASLData
152+
The ASLData object containing the pcasl and/or m0 image to be corrected.
153+
ref_vol: (int, optional)
154+
The index of the reference volume to which all other volumes will be registered.
155+
Defaults to 0.
156+
asl_data_mask: np.ndarray
157+
A single volume image mask. This can assist the normalization method to converge
158+
into the atlas space. If not provided, the full image is adopted.
159+
atlas_name: str
160+
The atlas type to be considered. The BrainAtlas class is applied, then choose
161+
the `atlas_name` based on the ASLtk brain atlas list.
162+
verbose: (bool, optional)
163+
If True, prints progress messages. Defaults to False.
164+
165+
Raises:
166+
TypeError: If the input is not an ASLData object.
167+
ValueError: If ref_vol is not a valid index.
168+
RuntimeError: If an error occurs during registration.
169+
170+
Returns:
171+
tuple: ASLData object with corrected volumes and a list of transformation matrices.
172+
"""
173+
if not isinstance(asl_data, ASLData):
174+
raise TypeError('Input must be an ASLData object.')
175+
176+
# if not isinstance(ref_vol, int) or ref_vol < 0:
177+
# raise ValueError('ref_vol must be a non-negative integer.')
178+
179+
total_vols, orig_shape = collect_data_volumes(asl_data('pcasl'))
180+
# if ref_vol >= len(total_vols):
181+
# raise ValueError(
182+
# 'ref_vol must be a valid index based on the total ASL data volumes.'
183+
# )
184+
185+
if asl_data('m0') is None:
186+
raise ValueError(
187+
'M0 image is required for normalization. Please provide an ASLData with a valid M0 image.'
188+
)
189+
190+
atlas = BrainAtlas(atlas_name)
191+
# atlas_img = ants.image_read(atlas.get_atlas()['t1_data']).numpy()
192+
atlas_img = load_image(atlas.get_atlas()['t1_data'])
193+
194+
def norm_function(vol, _):
195+
return space_normalization(
196+
moving_image=vol,
197+
template_image=atlas,
198+
moving_mask=asl_data_mask,
199+
template_mask=None,
200+
transform_type='Affine',
201+
check_orientation=True,
202+
orientation_verbose=verbose,
203+
)
204+
205+
# Create a new ASLData to allocate the normalized image
206+
new_asl = asl_data.copy()
207+
208+
tmp_vol_list = [asl_data('m0')]
209+
orig_shape = asl_data('m0').shape
210+
211+
m0_vol_corrected, trans_m0_mtx = __apply_array_normalization(
212+
tmp_vol_list, 0, orig_shape, norm_function, verbose
213+
)
214+
new_asl.set_image(m0_vol_corrected[0], 'm0')
215+
216+
# Apply the normalization transformation to all pcasl volumes
217+
pcasl_vols, _ = collect_data_volumes(asl_data('pcasl'))
218+
normalized_pcasl_vols = []
219+
with Progress() as progress:
220+
task = progress.add_task(
221+
'[green]Applying normalization to pcasl volumes...',
222+
total=len(pcasl_vols),
223+
)
224+
for vol in pcasl_vols:
225+
norm_vol = apply_transformation(
226+
moving_image=vol,
227+
reference_image=atlas_img,
228+
transforms=trans_m0_mtx,
229+
)
230+
normalized_pcasl_vols.append(norm_vol)
231+
progress.update(task, advance=1)
232+
233+
new_asl.set_image(normalized_pcasl_vols, 'pcasl')
234+
235+
return new_asl, trans_m0_mtx
236+
237+
130238
def head_movement_correction(
131239
asl_data: ASLData,
132240
ref_vol: np.ndarray = None,

0 commit comments

Comments
 (0)