Skip to content

Commit

Permalink
minor patch to respect user ordering of ids in groups
Browse files Browse the repository at this point in the history
  • Loading branch information
donishadsmith committed Jun 24, 2024
1 parent 440233c commit f133d6b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ noted in the changelog (i.e new functions or parameters, changes in parameter de
- *.patch* : Contains no new features, simply fixes any identified bugs.
- *.postN* : Consists of only metadata-related changes, such as updates to type hints or doc strings/documentation.

## [0.11.2] - 2024-06-23
### ♻ Changed
- Changed how ids are organized in respective group when initializing the `CAP` class. In version 0.11.1, the ids are
sorted lexicographically:
```python3
self._groups[group] = sorted(list(set(self._groups[group])))
```
This doesn't affect functionality but it may be better to respect the original user ordering.This is no longer the case.

## [0.11.1] - 2024-06-23
### 🐛 Fixes
- Fix for python 3.12 when using `CAP.caps2surf()`.
Expand All @@ -53,14 +62,15 @@ noted in the changelog (i.e new functions or parameters, changes in parameter de
implementing this fix.

```python3
# Fix for python 3.12, saving stat_map so that it is path instead of a NifTI

# Fix for python 3.12, saving stat map so that it is path instead of a NifTi
try:
gii_lh, gii_rh = mni152_to_fslr(stat_map, method=method, fslr_density=fslr_density)
except TypeError:
# Create temp
temp_nifti = tempfile.NamedTemporaryFile(delete=False, suffix=".nii.gz")
warnings.warn(textwrap.dedent(f"""
Error potentially due to change in pathlib.py in python 3.12 causing the error
Potential error due to changes in pathlib.py in Python 3.12 causing the error
message to output as "not 'Nifti1Image'" instead of "not Nifti1Image", which
neuromaps uses to determine if the input is a Nifti1Image object.
Converting stat_map into a temporary nii.gz file (which will be automatically
Expand Down
2 changes: 1 addition & 1 deletion neurocaps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__all__=["analysis", "extraction"]
# Version in a single place
__version__ = "0.11.1"
__version__ = "0.11.2"
20 changes: 10 additions & 10 deletions neurocaps/analysis/cap.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class CAP(_CAPGetter):
groups : :obj:`dict[str, list]` or :obj:`None`, default=None
A mapping of group names to subject IDs. Each group contains subject IDs for separate CAP analysis.
Additionally, IDs should not be duplicated across groups or else a warning will be raised. Duplicate IDs in the
same groups will be removed and in the case of IDs duplicated across groups, only the first instance is retained.
This parameter is used to create ``self.subject_table``, which is used for concatenating data and calculating
metrics. This is done to avoid issues with duplicate IDs. If ``groups`` left as None, CAPs are not separated by
group and are performed on all subjects. The structure should be as follows:
Additionally, if duplicate IDs are detected within or across groups, a warning is issued and only the first
instance is retained. This parameter is used to create a dictionary (``self.subject_table``), which pairs each
subject ID (keys) with their group name (values) and is used for concatenating data and calculating metrics.
This is done to avoid issues with duplicate IDs. If ``groups`` left as None, CAPs are not separated by group
and are performed on all subjects. The structure should be as follows:
::
{
Expand All @@ -69,10 +69,11 @@ class CAP(_CAPGetter):
is used.
parcel_approach : :obj:`dict[str, dict]`
Nested dictionary containing information about the parcellation. Can also be used as a setter. If "Schaefer"
or "AAL" was specified during initialization of the ``TimeseriesExtractor`` class, then
``nilearn.datasets.fetch_atlas_schaefer_2018`` and ``nilearn.datasets.fetch_atlas_aal`` will be used to obtain
the "maps" and the "nodes". Then string splitting is used on the "nodes" to obtain the "regions":
Nested dictionary containing information about the parcellation. Can also be used as a setter, which accepts
a dictionary or a dictionary saved as a pickle file. If "Schaefer" or "AAL" was specified during initialization
of the ``TimeseriesExtractor`` class, then ``nilearn.datasets.fetch_atlas_schaefer_2018`` and
``nilearn.datasets.fetch_atlas_aal`` will be used to obtain the "maps" and the "nodes". Then string splitting
is used on the "nodes" to obtain the "regions":
::
{
Expand Down Expand Up @@ -322,7 +323,6 @@ def __init__(self, parcel_approach: dict[str, dict]=None, groups: dict[str, list
for group in self._groups:
self._groups[group] = [str(subj_id) if not isinstance(subj_id,str)
else subj_id for subj_id in self._groups[group]]
self._groups[group] = sorted(list(set(self._groups[group])))

if parcel_approach is not None:
parcel_approach = _check_parcel_approach(parcel_approach=parcel_approach, call="CAP")
Expand Down
2 changes: 1 addition & 1 deletion neurocaps/analysis/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def merge_dicts(subject_timeseries_list: Union[list[dict[str, dict[str, np.ndarray]]], list[os.PathLike]],
return_combined_dict: bool=True, return_reduced_dicts: bool=False,
output_dir: Optional[Union[str, os.PathLike]]=None,
file_name: Optional[str]=None) -> dict[str, dict[str, np.ndarray]]:
file_name: Optional[str]=None) -> Union[dict[str, dict[str, np.ndarray]], dict[str, dict[str, dict[str, np.ndarray]]]]:
"""
**Merge Subject Timeseries**
Expand Down

0 comments on commit f133d6b

Please sign in to comment.