-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
✅ Fix tests broken by #2058 #2059
Conversation
fix: python 2 Function interfaces recompatibility
Revert "fix: python 2 Function interfaces recompatibility"
- Remove unused symbols - Add missing symbols to `__all__`
def get_tr(tr): | ||
"""Method to return TR in seconds.""" | ||
import re | ||
|
||
if tr: | ||
tr = re.search(r"\d+.\d+", str(tr)).group(0) | ||
tr = float(tr) | ||
if tr > 10: | ||
tr = tr / 1000.0 | ||
else: | ||
tr = "" | ||
return tr | ||
|
||
|
||
def check_tr(tr, in_file): | ||
# imageData would have to be the image data from the funcFlow workflow, | ||
# funcFlow outputspec.subject | ||
import nibabel as nib | ||
|
||
img = nib.load(in_file) | ||
|
||
# get header from image data, then extract TR information, TR is fourth | ||
# item in list returned by get_zooms() | ||
imageHeader = img.header | ||
imageZooms = imageHeader.get_zooms() | ||
header_tr = imageZooms[3] | ||
|
||
# If the TR information from header_tr (funcFlow) and convert_tr node | ||
# (TR from config file) do not match, prepare to update the TR information | ||
# from either convert_tr or header_tr using afni 3drefit, then append to | ||
# func_to_mni | ||
if header_tr != tr: | ||
if tr is not None and tr != "": | ||
TR = tr | ||
else: | ||
TR = header_tr | ||
|
||
import warnings | ||
|
||
warnings.warn( | ||
"Warning: The TR information does not match between " | ||
"the config and subject list files." | ||
) | ||
|
||
return TR |
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.
These weren't used anywhere, so I deleted them.
# also write out volumes as individual files | ||
# split = pe.Node(interface=fsl.Split(), name='split_raw_volumes_sca') | ||
# split.inputs.dimension = 't' | ||
# split.inputs.out_base_name = 'sca_' | ||
|
||
# get_roi_num_list = pe.Node(util.Function(input_names=['timeseries_file', | ||
# 'prefix'], | ||
# output_names=['roi_list'], | ||
# function=get_roi_num_list), | ||
# name='get_roi_num_list') | ||
# get_roi_num_list.inputs.prefix = "sca" | ||
|
||
# sca.connect(inputNode, 'timeseries_one_d', get_roi_num_list, | ||
# 'timeseries_file') | ||
|
||
# rename_rois = pe.MapNode(interface=util.Rename(), name='output_rois', | ||
# iterfield=['in_file', 'format_string']) | ||
# rename_rois.inputs.keep_ext = True | ||
|
||
# sca.connect(split, 'out_files', rename_rois, 'in_file') | ||
# sca.connect(get_roi_num_list, 'roi_list', rename_rois, 'format_string') | ||
|
||
sca.connect(corr, "out_file", concat, "in_files") | ||
# sca.connect(concat, 'out_file', split, 'in_file') | ||
sca.connect(concat, "out_file", outputNode, "correlation_stack") | ||
# sca.connect(rename_rois, 'out_file', outputNode, | ||
# 'correlation_files') |
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 think if we want to resurrect this functionality, we can rewrite it at least as easily as we could revive it from the commented-out code, so I deleted the commented-out code.
def get_roi_num_list(timeseries_file, prefix=None): | ||
# extracts the ROI labels from the 3dROIstats output CSV file | ||
with open(timeseries_file, "r") as f: | ||
roi_file_lines = f.read().splitlines() | ||
|
||
roi_err = ( | ||
"\n\n[!] The output of 3dROIstats, used in extracting the " | ||
"timeseries, is either empty, or not in the expected " | ||
"format.\n\nROI output file: {0}\n\nIf there are no rows " | ||
"in the output file, double-check your ROI/mask selection." | ||
"\n\n".format(str(timeseries_file)) | ||
) | ||
|
||
for line in roi_file_lines: | ||
if "Mean_" in line: | ||
try: | ||
roi_list = line.split(",") | ||
# clear out any blank strings/non ROI labels in the list | ||
roi_list = [x for x in roi_list if "Mean" in x] | ||
# rename labels | ||
roi_list = [ | ||
x.replace("Mean", "ROI").replace(" ", "").replace("#", "") | ||
for x in roi_list | ||
] | ||
except: | ||
raise Exception(roi_err) | ||
break | ||
else: | ||
raise Exception(roi_err) | ||
|
||
if prefix: | ||
temp_rois = [] | ||
for roi in roi_list: | ||
roi = prefix + "_" + str(roi) | ||
temp_rois.append(roi) | ||
roi_list = temp_rois | ||
|
||
return roi_list |
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.
This function isn't used anywhere except a commented-out section so I deleted both this function and the commented-out code.
2597c1f
to
ecf36f3
Compare
(some were `nibabel as nb`)
Where reformatting changed things like > ("line 1" > " line 2") to like > "line 1" " line 2" , change to like > "line 1 line 2"
🎨 `print` statements → `log` statements
🎨 PEP8 boolean comparisons
Fixes
Fixes #2058 by @shnizzedy
Related to #2048 by @nx10
Description
CPAC/utils/__init__.py
, which was broken bypre-commit
modificationspre-commit
modificationsCPAC/nuisance/utils/__init__.py
, which was broken bypre-commit
modificationsgit add
ing changed filesrun.py
andrun-with-freesurfer.sh
) from/dev/docker_data
toCPAC/_entrypoints
print
statements tolog
statements where such statements were relevant to testsC-PAC/CPAC/utils/utils.py
Lines 591 to 612 in 2e368b9
C-PAC/CPAC/utils/sklearn.py
Lines 40 to 58 in de50ef3
sets.Set
withset
, which has been built-in since Python 2.4 (November 30, 2004)!repickle
cwas
files involved in what were failing testsorder_by_type
fromtrue
tofalse
as suggested here and re-runspre-commit run --all-files
as @ChildMindInstituteCNL to apply the sorting changeruff
's autofixableflake8-errmsg (EM)
rulesTechnical details
CPAC/utils/__init__.py
CPAC.utils.__init__.__all__
CPAC.utils
repickle
and lintsCPAC.utils.docs
while modifying those sections of codeTSVs and CSVs
pre-commit
modificationstrailing-whitespace
hookend-of-file-fixer
hookCPAC/nuisance/utils/__init__.py
CPAC/nuisance/utils/__init__.py
toCPAC/nuisance/utils/utils.py
CPAC/nuisance/utils/__init__.py
and adds them toCPAC.utils.__init__.__all__
print
statements →log
statementsCPAC/_entrypoints/run.py
CPAC/utils/build_data_config.py
and linted that fileprint
statements that were removed byruff
(🎨print
statements →log
statements #2062)Deprecates
repickle
Instead of linting this function and upgrading its print statements, I thought we could just deprecate it, for the reason given in the deprecation message:
C-PAC/CPAC/utils/utils.py
Lines 1327 to 1331 in 4650f4f
If we don't want this function deprecated, we can upgrade the function and its tests before we cut 1.8.7.
TODO: 📝 Document SOP for deprecating code fcp-indi.github.io#320
Linting some
cwas
filesruff
turnedC-PAC/CPAC/cwas/cwas.py
Line 194 in 7bd4afa
C-PAC/CPAC/cwas/cwas.py
Line 203 in 71c9e6f
np.True_
(array True from NumPy) ≠True
(scalar True from Python), so that broke the reshaping.C-PAC/CPAC/cwas/cwas.py
Line 229 in 4650f4f
== True
/== False
/is True
/is False
s in a subsequent PRStyle changes
order_by_type
order_by_type
was set totrue
because I messed up translating my style suggestions hereflake8-errmsg (EM)
,f-string-missing-placeholders (F541)
,f-string (UP032)
Tests
All the tests that were failing in #2058 are passing here
Checklist
Update index.md
).intial-run/ruff
branch of the repository.Developer Certificate of Origin
Developer Certificate of Origin