Skip to content

Commit

Permalink
Add codespell support (config, workflow to detect/not fix) and make i…
Browse files Browse the repository at this point in the history
…t fix few typos (#313)

* Add github action to codespell main on push and PRs

* Add rudimentary codespell config

* Ignore PROMIS

* [DATALAD RUNCMD] Some custom ambigous fixes

=== Do not change lines below ===
{
 "chain": [],
 "cmd": "git-sedi 'thes frame' 'the frame'; git-sedi labled labeled",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [],
 "outputs": [],
 "pwd": "."
}
^^^ Do not change lines above ^^^

* [DATALAD RUNCMD] run codespell throughout fixing typos automagically (but ignoring overall fail due to ambigous ones)

=== Do not change lines below ===
{
 "chain": [
  "ae0c26e93ede67f21c604113cbb8265efdc32c8f"
 ],
 "cmd": "codespell -w || :",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [],
 "outputs": [],
 "pwd": "."
}
^^^ Do not change lines above ^^^

* [DATALAD RUNCMD] Do interactive fixing of some ambigous typos

=== Do not change lines below ===
{
 "chain": [],
 "cmd": "codespell -w -i 3 -C 2",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [],
 "outputs": [],
 "pwd": "."
}
^^^ Do not change lines above ^^^
  • Loading branch information
yarikoptic authored Jun 14, 2024
1 parent c90be5e commit f6e221b
Show file tree
Hide file tree
Showing 46 changed files with 135 additions and 103 deletions.
7 changes: 7 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[codespell]
# Ref: https://github.com/codespell-project/codespell#using-a-config-file
skip = .git*,*.pdf,*.lock,.codespellrc
check-hidden = true
# Some domain specific variables, names, and some specific variable choices
ignore-regex = \b(TE|PROMIS|Claus|nam|bais)\b
# ignore-words-list =
25 changes: 25 additions & 0 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Codespell configuration is within .codespellrc
---
name: Codespell

on:
push:
branches: [main]
pull_request:
branches: [main]

permissions:
contents: read

jobs:
codespell:
name: Check for spelling errors
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Annotate locations with typos
uses: codespell-project/codespell-problem-matcher@v1
- name: Codespell
uses: codespell-project/actions-codespell@v2
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ No matter the way you prefer inputting metadata (passing all arguments, using tx

### ecat_validation

This folder contains code generating Siemens HRRT scanner data using ecat file format and validating the matlab and python conversion tools (i.e. giving the data generated as ecat, do our nifti images reflect acurately the data).
This folder contains code generating Siemens HRRT scanner data using ecat file format and validating the matlab and python conversion tools (i.e. giving the data generated as ecat, do our nifti images reflect accurately the data).

## Citation

Expand Down
10 changes: 5 additions & 5 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

*Thank you considering contributing to the project.*

This guideline is designed to make clear how anyone can contibute, become team member, and get rewarded for it.
This guideline is designed to make clear how anyone can contribute, become team member, and get rewarded for it.
If you have any questions please [get in touch]([email protected]).

## Table of contents
Expand All @@ -14,16 +14,16 @@ If you have any questions please [get in touch]([email protected]).

## Joining the project

PET2BIDS is an open source and open developpment project focusing on the curation brain PET data using the [Brain Imaging Data Structure standard](https://github.com/bids-standard).
PET2BIDS is an open source and open development project focusing on the curation brain PET data using the [Brain Imaging Data Structure standard](https://github.com/bids-standard).
It is required that all contributions **adhere to our [Code of Conduct](code_of_conduct.md)**.

How do you know that you joined? well, you're here and you likely used PET2BIDS and started doing something beyond just using and want to push, add you bug fixes / code / documentation / examples .. or have your own extension - Welcome! you are now part of the project.

## Contributing without writing a line of code

There are many ways you can contribute to the project without having to wite a single line of code!
- editing and updating the help/documetation is a fantastic contribution.
- making any tutorials, exemples available is great too
There are many ways you can contribute to the project without having to write a single line of code!
- editing and updating the help/documentation is a fantastic contribution.
- making any tutorials, examples available is great too

## Contributing through code

Expand Down
2 changes: 1 addition & 1 deletion docs/about.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ About
**What does this tool do?**

PET2BIDS accepts PET imaging and blood data as inputs (e.g. dicom, ecat, spreadsheets)
and delivers BIDS fomatted outputs (e.g. nifti, json, and tsv files). See the below diagram:
and delivers BIDS formatted outputs (e.g. nifti, json, and tsv files). See the below diagram:

.. image:: media/pypet2bids_floow.drawio.png

Expand Down
2 changes: 1 addition & 1 deletion docs/spreadsheets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Handled Types of Spreadsheets (known)
- Here is an example of a
`Many Subject Spreadsheet <https://github.com/OpenNeuroPET/PET2BIDS/spreadsheet_conversion/many_subjects_sheet/subjects_metadata_example.xlsx>`_
paired with a `single subject spreadsheet <https://github.com/OpenNeuroPET/PET2BIDS/spreadsheet_conversion/many_subjects_sheet/subject_>`_
these can be used when updating BIDS datasets w/ homogenous scanner/experiment data along with heterogeneous (subject)
these can be used when updating BIDS datasets w/ homogeneous scanner/experiment data along with heterogeneous (subject)
data.

**Some more notes/quirks about Excel:**
Expand Down
4 changes: 2 additions & 2 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Matlab

**Read and write raw scanner files as nifti + json**

BIDS requires nifti files and json. While json can be writen be hand, this is more convenient to populate them as one
BIDS requires nifti files and json. While json can be written be hand, this is more convenient to populate them as one
reads data. One issue is that some information is not encoded in ecat/dicom headers and thus needs to be created
otherwise.

Expand Down Expand Up @@ -174,7 +174,7 @@ ecatpet2bids for converting ecat data into nii & json
--nifti file_name, -n file_name
Name of nifti output file
--subheader, -s Display subheaders
--sidecar Output a bids formatted sidecar for pairing witha nifti.
--sidecar Output a bids formatted sidecar for pairing with a nifti.
--kwargs [KWARGS ...], -k [KWARGS ...]
Include additional values int the nifti sidecar json or override values extracted from the supplied nifti. e.g. including `--kwargs TimeZero='12:12:12'` would override the
calculated TimeZero. Any number of additional arguments can be supplied after --kwargs e.g. `--kwargs BidsVariable1=1 BidsVariable2=2` etc etc.
Expand Down
14 changes: 7 additions & 7 deletions ecat_testing/ints/nii_tool.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
% parameter/value pairs. See nii_tool('RGBstyle') for meaning of rgb_dim.
%
% Note that the setting will be saved for future use. If one wants to change the
% settting temporarily, it is better to return the oldVal, and to restore it
% setting temporarily, it is better to return the oldVal, and to restore it
% after done:
%
% oldVal = nii_tool('default', 'version', 2); % set version 2 as default
Expand Down Expand Up @@ -251,7 +251,7 @@
% 160531 fopen uses 'W' for 'w': performance benefit according to Yair.
% 160701 subFuncHelp: bug fix for mfile case.
% 161018 gunzipOS: use unique name for outName, to avoid problem with parfor.
% 161025 Make included linux pigz executible; fix "dd" for windows.
% 161025 Make included linux pigz executable; fix "dd" for windows.
% 161031 gunzip_mem(), nii_bytes() for hdr/ext read: read uint8 then parse;
% Replace hdr.machine with hdr.swap_endian.
% 170212 Extract decode_ext() from 'ext' cmd so call it in 'update' cmd.
Expand All @@ -260,7 +260,7 @@
% 170410 read_img(): turn off auto RGB dim detection, and use rgb_dim.
% 170714 'save': force to version 2 if img dim exceeds 2^15-1.
% 170716 Add functionSignatures.json file for tab auto-completion.
% 171031 'LocalFunc' makes eaiser to call local functions.
% 171031 'LocalFunc' makes easier to call local functions.
% 171206 Allow file name ext other than .nii, .hdr, .img.
% 180104 check_gzip: add /usr/local/bin to PATH for unix if needed.
% 180119 use jsystem for better speed.
Expand Down Expand Up @@ -314,7 +314,7 @@
else
error('Provide a valid file name as the third input');
end
if ~ispc && strncmp(fname, '~/', 2) % matlab may err with this abbrevation
if ~ispc && strncmp(fname, '~/', 2) % matlab may err with this abbreviation
fname = [getenv('HOME') fname(2:end)];
end
[pth, fname, fext] = fileparts(fname);
Expand Down Expand Up @@ -519,7 +519,7 @@
if isempty(hdr.extension) || hdr.extension(1)==0
varargout{1} = [];
else
if hdr.vox_offset>0, nByte = hdr.vox_offset + 64; % .nii arbituary +64
if hdr.vox_offset>0, nByte = hdr.vox_offset + 64; % .nii arbitrary +64
else, nByte = inf;
end
b = nii_bytes(fname, nByte);
Expand Down Expand Up @@ -875,7 +875,7 @@ function gzipOS(fname)
m_dir = fileparts(mfilename('fullpath'));
if strcmpi(pwd, m_dir), cd ..; clnObj = onCleanup(@() cd(m_dir)); end
[err, ~] = jsystem({'dd' '--version'});
if ~err, dd = 'dd'; return; end % dd with linix/mac, and maybe windows
if ~err, dd = 'dd'; return; end % dd with linux/mac, and maybe windows

if ispc % rename it as exe
dd = [m_dir '\dd'];
Expand Down Expand Up @@ -1025,7 +1025,7 @@ function gzipOS(fname)
ind = [-2 ind]; % -2+3=1: start of first para
for k = 1:numel(ind)-1
a = str(ind(k)+3 : ind(k+1));
a(a==0) = []; % to be safe. strtrim wont remove null
a(a==0) = []; % to be safe. strtrim won't remove null
a = strtrim(a);
if isempty(a), continue; end
try
Expand Down
4 changes: 2 additions & 2 deletions ecat_validation/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ write_ecat(ecat_file=int_golden_ecat_path,
### Results

The validation ecat2nii_test.m then read the .v, convert to .nii, and reread the .nii. It then compares the reread values to
expected ones (from the .mat). Ideally we would have the same values but (1) we have different dymamic range
expected ones (from the .mat). Ideally we would have the same values but (1) we have different dynamic range
(here only 1 out of 16bits ~0.0003) because ecat2nii rescale your data to 16bits and (2) precisions around 0 differs as
well, some small changes are expected. This can be seen in the figure below. Reread vs Original show a
perfect correlation, but with an average difference of -0.000001 with min -05 and max 0.5
Expand All @@ -97,7 +97,7 @@ The ecat file ECAT7_multiframe.v was converted here as a test, with ecat2nii.m a

```matlab
file = fullfile(pwd,'ECAT7_multiframe.v.gz'); % edit with the right path
meta.TimeZero = datestr(now,'hh:mm:ss'); % that metadata cannnot be skipped
meta.TimeZero = datestr(now,'hh:mm:ss'); % that metadata cannot be skipped
ecat2nii(file,meta)
```

Expand Down
2 changes: 1 addition & 1 deletion matlab/Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Read and write raw scanner files as nifti + json

BIDS requires nifti files and json. While json can be writen be hand, this is more convenient to populate them as one reads data. One issue is that some information is not encoded in ecat/dicom headers and thus needs to be created overwise.
BIDS requires nifti files and json. While json can be written be hand, this is more convenient to populate them as one reads data. One issue is that some information is not encoded in ecat/dicom headers and thus needs to be created otherwise.

## Dependencies

Expand Down
6 changes: 3 additions & 3 deletions matlab/dcm2niix4pet.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function dcm2niix4pet(FolderList,MetaList,varargin)
%.. note::
%
% See also get_pet_metadata.m to generate the metadata structure
% updatejsonpetfile to see how the json file gets updated and checked agains DICOM tags
% updatejsonpetfile to see how the json file gets updated and checked against DICOM tags
%
% | *Cyril Pernet 2022*
% | *Copyright Open NeuroPET team*
Expand Down Expand Up @@ -159,7 +159,7 @@ function dcm2niix4pet(FolderList,MetaList,varargin)
elseif strcmpi(varargin{var},'d')
d = varargin{var+1};
if ~num(d)
error('invalid compression experession, not a numeric');
error('invalid compression expression, not a numeric');
elseif d>9
error('invalid compression value, must be between 0 and 9');
end
Expand Down Expand Up @@ -266,7 +266,7 @@ function dcm2niix4pet(FolderList,MetaList,varargin)
delete(fullfile(outputdir{folder},'*dcm'))
end

% rename if BIDS folfer sub-
% rename if BIDS folder sub-
if contains(outputdir{folder},'sub-')
if strcmpi(z,'y')
data = dir(fullfile(outputdir{folder},'*.nii.gz'));
Expand Down
6 changes: 3 additions & 3 deletions matlab/ecat2nii.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
%% defaults
% ---------

warning on % set to off to ignore our usefull warnings
warning on % set to off to ignore our useful warnings
sifout = false; % 0/1 to indicate if sif file are also created
gz = true; % compress nifti
savemat = false; % save ecat data as .mat
Expand Down Expand Up @@ -162,7 +162,7 @@
end
Nframes = mh.num_frames;

% Create data reading 1 frame at a time - APLYING THE SCALE FACTOR
% Create data reading 1 frame at a time - APPLYING THE SCALE FACTOR
img_temp = zeros(sh{1}.x_dimension,sh{1}.y_dimension,sh{1}.z_dimension,Nframes);
for i=Nframes:-1:1
fprintf('Working at frame: %i\n',i);
Expand Down Expand Up @@ -494,7 +494,7 @@
FileListOut{j} = sprintf('%s failed to convert:%s',FileListIn{j},conversionerr.message, conversionerr.stack.line);
end

if exist('newfile','var') % i.e. decompresed .nii.gz
if exist('newfile','var') % i.e. decompressed .nii.gz
delete(newfile{1});
end
end
2 changes: 1 addition & 1 deletion matlab/first_middle_last_frames_to_text.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function [output_folder, step_name] = first_middle_last_frames_to_text(four_d_array_like_object,output_folder, step_name)
%takes a times series of 3d images and writes out sub sections of that time
%series as 2D frames. Frames are labled as zero indexed to aligne with
%series as 2D frames. Frames are labeled as zero indexed to align with
%python conventions. Up to 3 frames are selected from the time series
%corresponding to the first, middle, and last frames.
% four_d_array_like_object: input time series
Expand Down
2 changes: 1 addition & 1 deletion matlab/first_middle_last_frames_to_text_cell.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function [output_folder, step_name] = first_middle_last_frames_to_text(four_d_array_like_object,output_folder, step_name)
%takes a times series of 3d images and writes out sub sections of that time
%series as 2D frames. Frames are labled as zero indexed to aligne with
%series as 2D frames. Frames are labeled as zero indexed to align with
%python conventions. Up to 3 frames are selected from the time series
%corresponding to the first, middle, and last frames.
% four_d_array_like_object: input time series
Expand Down
2 changes: 1 addition & 1 deletion matlab/flattenstruct.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
% :format: - structout = flattenstruct(structin)
%
% :param structin: a structure with nested fields
% :returns structout: a flat sructure with all the fields
% :returns structout: a flat structure with all the fields
%
%.. note::
%
Expand Down
8 changes: 4 additions & 4 deletions matlab/get_pet_metadata.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
% converters, ecat2nii.m or dcm2niix4pet.m allowing to produce a .nii
% file with a BIDS compliant json file.
%
% :param Default: \(aquisition and reconstruction parameters\) can be
% :param Default: \(acquisition and reconstruction parameters\) can be
% stored in a \*_parameters.txt seating on disk next to this function
% or passed as argument in. Replace \* by the name of your scanner \- for now we
% tested 'SiemensBiograph', 'SiemensHRRT', 'GEAdvance', 'PhillipsVereos',
Expand All @@ -15,7 +15,7 @@
% all info is necessarily needed\)
% :param inputs: a series of key/value pairs are expected
% :returns metadata: a structure with BIDS fields filled \(such structure is ready
% to be writen as json file using e.g. the bids matlab jsonwrite
% to be written as json file using e.g. the bids matlab jsonwrite
% function, typically associated with the \*_pet.nii file\)
%
% :format: metadata = get_pet_metadata(key,value)
Expand Down Expand Up @@ -233,7 +233,7 @@
for opt = 1:length(setmetadata)
if contains(setmetadata{opt},'=')
try
eval(setmetadata{opt}); % shoul evaluate the = sign, creating name/value pairs
eval(setmetadata{opt}); % should evaluate the = sign, creating name/value pairs
if isempty(setmetadata{opt})
error('''%s'' from %sparameters.txt is empty\n',optional{opt},Scanner)
end
Expand Down Expand Up @@ -265,7 +265,7 @@

%% make the metadata structure

% this part is not really usefull for BIDS, but helps users know which
% this part is not really useful for BIDS, but helps users know which
% scanner we tested --
if contains(Scanner,'Siemens','IgnoreCase',true)
metadata.Manufacturer = 'Siemens';
Expand Down
14 changes: 7 additions & 7 deletions matlab/nii_tool.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
% parameter/value pairs. See nii_tool('RGBstyle') for meaning of rgb_dim.
%
% Note that the setting will be saved for future use. If one wants to change the
% settting temporarily, it is better to return the oldVal, and to restore it
% setting temporarily, it is better to return the oldVal, and to restore it
% after done:
%
% oldVal = nii_tool('default', 'version', 2); % set version 2 as default
Expand Down Expand Up @@ -251,7 +251,7 @@
% 160531 fopen uses 'W' for 'w': performance benefit according to Yair.
% 160701 subFuncHelp: bug fix for mfile case.
% 161018 gunzipOS: use unique name for outName, to avoid problem with parfor.
% 161025 Make included linux pigz executible; fix "dd" for windows.
% 161025 Make included linux pigz executable; fix "dd" for windows.
% 161031 gunzip_mem(), nii_bytes() for hdr/ext read: read uint8 then parse;
% Replace hdr.machine with hdr.swap_endian.
% 170212 Extract decode_ext() from 'ext' cmd so call it in 'update' cmd.
Expand All @@ -260,7 +260,7 @@
% 170410 read_img(): turn off auto RGB dim detection, and use rgb_dim.
% 170714 'save': force to version 2 if img dim exceeds 2^15-1.
% 170716 Add functionSignatures.json file for tab auto-completion.
% 171031 'LocalFunc' makes eaiser to call local functions.
% 171031 'LocalFunc' makes easier to call local functions.
% 171206 Allow file name ext other than .nii, .hdr, .img.
% 180104 check_gzip: add /usr/local/bin to PATH for unix if needed.
% 180119 use jsystem for better speed.
Expand Down Expand Up @@ -314,7 +314,7 @@
else
error('Provide a valid file name as the third input');
end
if ~ispc && strncmp(fname, '~/', 2) % matlab may err with this abbrevation
if ~ispc && strncmp(fname, '~/', 2) % matlab may err with this abbreviation
fname = [getenv('HOME') fname(2:end)];
end
[pth, fname, fext] = fileparts(fname);
Expand Down Expand Up @@ -519,7 +519,7 @@
if isempty(hdr.extension) || hdr.extension(1)==0
varargout{1} = [];
else
if hdr.vox_offset>0, nByte = hdr.vox_offset + 64; % .nii arbituary +64
if hdr.vox_offset>0, nByte = hdr.vox_offset + 64; % .nii arbitrary +64
else, nByte = inf;
end
b = nii_bytes(fname, nByte);
Expand Down Expand Up @@ -875,7 +875,7 @@ function gzipOS(fname)
m_dir = fileparts(mfilename('fullpath'));
if strcmpi(pwd, m_dir), cd ..; clnObj = onCleanup(@() cd(m_dir)); end
[err, ~] = jsystem({'dd' '--version'});
if ~err, dd = 'dd'; return; end % dd with linix/mac, and maybe windows
if ~err, dd = 'dd'; return; end % dd with linux/mac, and maybe windows

if ispc % rename it as exe
dd = [m_dir '\dd'];
Expand Down Expand Up @@ -1025,7 +1025,7 @@ function gzipOS(fname)
ind = [-2 ind]; % -2+3=1: start of first para
for k = 1:numel(ind)-1
a = str(ind(k)+3 : ind(k+1));
a(a==0) = []; % to be safe. strtrim wont remove null
a(a==0) = []; % to be safe. strtrim won't remove null
a = strtrim(a);
if isempty(a), continue; end
try
Expand Down
4 changes: 2 additions & 2 deletions matlab/readECAT7.m
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@
fprintf(step_2_file, '%s', sub_header_json);
fclose(step_2_file);

% write out endianess and datatype of the pixel data matrix
% write out endianness and datatype of the pixel data matrix
step_3_struct = {};
x.data_type = class(data{1});
x.endianess = file_endianess;
x.endianness = file_endianess;
step_3_json = (jsonencode(x, PrettyPrint=true));
step_3_file = fopen([ecat_save_steps_dir filesep '3_determine_data_type_matlab.json'], 'w');
fprintf(step_3_file, '%s', step_3_json);
Expand Down
2 changes: 1 addition & 1 deletion matlab/run_m2docgen_example.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
'outputFolder', ['/Users/galassiae/Projects/PET2BIDS/matlab/docs'], ...
'excludeFolder', ["m2docgen_documentation"], ...
'excludeFile', ["/Users/galassiae/Projects/PET2BIDS/matlab/check_metaradioinputs.m"], ...
'htmlMetaFolder', "ressources", ...
'htmlMetaFolder', "resources", ...
'htmlTemplate', "m2doc-standard", ...
'startPage', ["m2docgen_PET2BIDS.html"], ...
'toc', [], ...
Expand Down
Loading

0 comments on commit f6e221b

Please sign in to comment.