bids.ext.reports package¶
Module contents¶
pybids-reports: A tool for building methods sections for BIDS datasets.
- class bids.ext.reports.BIDSReport(layout: BIDSLayout, config: None | str | Path | dict[str, dict[str, str]] = None)[source]¶
Bases:
objectGenerate publication-quality data acquisition section from BIDS dataset.
Parameters¶
- layout
bids.layout.BIDSLayout Layout object for a BIDS dataset.
- config
strordict, optional Configuration info for methods generation. Can be a path to a file (str), a dictionary, or None. If None, loads and uses default configuration information. Keys in the dictionary include:
- ‘dir’: a dictionary for converting encoding direction strings
(e.g., j-) to descriptions (e.g., anterior to posterior)
- ‘seq’: a dictionary of sequence abbreviations (e.g., EP) and
corresponding names (e.g., echo planar)
- ‘seqvar’: a dictionary of sequence variant abbreviations
(e.g., SP) and corresponding names (e.g., spoiled)
Warning¶
pybids’ automatic report generation is experimental and currently under active development, and as such should be used with caution. Please remember to verify any generated report before putting it to use.
Additionally, only MRI datatypes (func, anat, fmap, and dwi) are currently supported.
- generate(**kwargs: Any) Counter[str][source]¶
Generate the methods section.
Parameters¶
- kwargsdict
Keyword arguments passed to BIDSLayout to select subsets of the dataset.
Returns¶
- counter
collections.Counter A dictionary of unique descriptions across subjects in the dataset, along with the number of times each pattern occurred. In cases where all subjects underwent the same protocol, the most common pattern is most likely the most complete. In cases where the dataset contains multiple protocols, each pattern will need to be inspected manually.
- generate_from_files(files: list[BIDSFile]) Counter[str][source]¶
Generate a methods section from a list of files.
Parameters¶
- fileslist of
BIDSImageFileobjects List of files from which to generate methods description.
Returns¶
- counter
collections.Counter A dictionary of unique descriptions across subjects in the file list, along with the number of times each pattern occurred. In cases where all subjects underwent the same protocol, the most common pattern is most likely the most complete. In cases where the file list contains multiple protocols, each pattern will need to be inspected manually.
- fileslist of
- layout
Submodules¶
bids.ext.reports.parameters module¶
Functions for building strings for individual parameters.
- bids.ext.reports.parameters.bvals(bval_file: str | Path) str[source]¶
Generate description of dMRI b-values.
- bids.ext.reports.parameters.duration(all_imgs: list[Nifti1Image], metadata: dict[str, Any]) str[source]¶
Generate general description of scan length from files.
- bids.ext.reports.parameters.echo_time_ms(files: list[BIDSFile]) str[source]¶
Generate description of echo times from metadata field.
Parameters¶
- files
listofbids.layout.models.BIDSFile List of nifti files in layout corresponding to file collection.
Returns¶
- testr
Description of echo times.
- files
- bids.ext.reports.parameters.echo_times_fmap(files: list[BIDSFile]) tuple[float, float][source]¶
Generate description of echo times from metadata field for fmaps.
Parameters¶
- files
listofbids.layout.models.BIDSFile List of nifti files in layout corresponding to file collection.
Returns¶
- te_str :
Description of echo times.
- files
- bids.ext.reports.parameters.field_of_view(img: None | Nifti1Image) str[source]¶
Extract and reformat FOV.
Parameters¶
- img
nibabel.Nifti1Image Image from scan from which to derive parameters.
Returns¶
- fov
str Field of view string (e.g., ‘256x256’)
- img
- bids.ext.reports.parameters.func_duration(nb_vols: int, tr: float) str[source]¶
Generate description of functional run length from repetition time and number of volumes.
- bids.ext.reports.parameters.get_nb_vols(all_imgs: list[Nifti1Image | None]) list[int] | None[source]¶
Get number of volumes from list of files.
If all files have the same nb of vols it will return the number of volumes, otherwise it will return the minimum and maximum number of volumes.
- bids.ext.reports.parameters.get_slice_info(slice_times: list[Any]) str | list[str][source]¶
Extract slice order from slice timing info.
TODO: Be more specific with slice orders. Currently anything where there’s some kind of skipping is interpreted as interleaved of some kind.
Parameters¶
- slice_timesarray-like
A list of slice times in seconds or milliseconds or whatever.
Returns¶
- slice_order_name
str The name of the slice order sequence.
- bids.ext.reports.parameters.intendedfor_targets(metadata: dict[str, Any], layout: BIDSLayout) str[source]¶
Generate description of intended for targets.
- bids.ext.reports.parameters.matrix_size(img: None | Nifti1Image) str[source]¶
Extract and reformat voxel size, matrix size, FOV, and number of slices into strings.
Parameters¶
- img
nibabel.Nifti1Image Image from scan from which to derive parameters.
Returns¶
- matrix_size
str Matrix size string (e.g., ‘128x128’)
- img
- bids.ext.reports.parameters.multi_echo(files: list[BIDSFile]) str[source]¶
Generate description of echo times from metadata field.
Parameters¶
- files
listofbids.layout.models.BIDSFile List of nifti files in layout corresponding to file collection.
Returns¶
- multi_echostr
Whether the data are multi-echo or single-echo.
- files
- bids.ext.reports.parameters.nb_runs(run_list: list[str]) str[source]¶
Generate description of number of runs from list of files.
- bids.ext.reports.parameters.nb_vols(all_imgs: list[Nifti1Image]) str[source]¶
Generate description of number of volumes from files.
- bids.ext.reports.parameters.sequence(metadata: dict[str, Any], config: dict[str, dict[str, str]]) str | list[str][source]¶
Extract and reformat imaging sequence(s) and variant(s) into pretty strings.
Parameters¶
Returns¶
- seqs
str Sequence names.
- seqs
- bids.ext.reports.parameters.slice_order(metadata: dict[str, Any]) str[source]¶
Generate description of slice timing from metadata.
bids.ext.reports.parsing module¶
Parsing functions for generating BIDSReports.
- bids.ext.reports.parsing.anat_info(files: list[BIDSFile], config: dict[str, dict[str, str]], layout: BIDSLayout) str[source]¶
Generate a paragraph describing T1- and T2-weighted structural scans.
Parameters¶
- files
listofbids.layout.models.BIDSFile List of nifti files in layout corresponding to DWI scan.
- config
dict A dictionary with relevant information regarding sequences, sequence variants, phase encoding directions, and task names.
- layout
bids.layout.BIDSLayout Layout object for a BIDS dataset.
Returns¶
- desc
str A description of the scan’s acquisition information.
- files
- bids.ext.reports.parsing.common_mri_desc(img: None | Nifti1Image, metadata: dict[str, Any], config: dict[str, dict[str, str]]) dict[str, Any][source]¶
Extract common MRI parameters from metadata.
- bids.ext.reports.parsing.dwi_info(files: list[BIDSFile], config: dict[str, dict[str, str]], layout: BIDSLayout) str[source]¶
Generate a paragraph describing DWI scan acquisition information.
Parameters¶
- files
listofbids.layout.models.BIDSFile List of nifti files in layout corresponding to DWI scan.
- config
dict A dictionary with relevant information regarding sequences, sequence variants, phase encoding directions, and task names.
- layout
bids.layout.BIDSLayout Layout object for a BIDS dataset.
Returns¶
- desc
str A description of the DWI scan’s acquisition information.
- files
- bids.ext.reports.parsing.files_not_found_warning(files: list[BIDSFile] | BIDSFile) None[source]¶
Warn user that files were not found or empty.
- bids.ext.reports.parsing.final_paragraph(metadata: dict[str, Any]) str[source]¶
Describe dicom-to-nifti conversion process and methods generation.
Parameters¶
- metadata
dict The metadata for the scan.
Returns¶
- desc
str Output string with scanner information.
- metadata
- bids.ext.reports.parsing.fmap_info(files: list[BIDSFile], config: dict[str, dict[str, str]], layout: BIDSLayout) str[source]¶
Generate a paragraph describing field map acquisition information.
Parameters¶
- files
listofbids.layout.models.BIDSFile List of nifti files in layout corresponding to field map scan.
- config
dict A dictionary with relevant information regarding sequences, sequence variants, phase encoding directions, and task names.
- layout
bids.layout.BIDSLayout Layout object for a BIDS dataset.
Returns¶
- desc
str A description of the field map’s acquisition information.
- files
- bids.ext.reports.parsing.func_info(files: list[BIDSFile], config: dict[str, dict[str, str]], layout: BIDSLayout) str[source]¶
Generate a paragraph describing T2*-weighted functional scans.
Parameters¶
- files
listofbids.layout.models.BIDSFile List of nifti files in layout corresponding to DWI scan.
- config
dict A dictionary with relevant information regarding sequences, sequence variants, phase encoding directions, and task names.
- layout
bids.layout.BIDSLayout Layout object for a BIDS dataset.
Returns¶
- desc
str A description of the scan’s acquisition information.
- files
- bids.ext.reports.parsing.meg_info(files: list[BIDSFile]) str[source]¶
Generate a paragraph describing meg acquisition information.
Parameters¶
- files
listofbids.layout.models.BIDSFile List of nifti files in layout corresponding to meg scan.
- config
dict A dictionary with relevant information regarding sequences, sequence variants, phase encoding directions, and task names.
Returns¶
- desc
str A description of the field map’s acquisition information.
- files
- bids.ext.reports.parsing.parse_files(layout: BIDSLayout, data_files: list[BIDSFile], config: dict[str, dict[str, str]]) list[str][source]¶
Loop through files in a BIDSLayout and generate appropriate descriptions.
Then, compile all of the descriptions into a list.
Parameters¶
- layout
bids.layout.BIDSLayout Layout object for a BIDS dataset.
- data_files
listofbids.layout.models.BIDSFile List of nifti files in layout corresponding to subject/session combo.
- config
dict Configuration info for methods generation.
- layout
bids.ext.reports.report module¶
Generate publication-quality data acquisition methods section from BIDS dataset.
- class bids.ext.reports.report.BIDSReport(layout: BIDSLayout, config: None | str | Path | dict[str, dict[str, str]] = None)[source]¶
Bases:
objectGenerate publication-quality data acquisition section from BIDS dataset.
Parameters¶
- layout
bids.layout.BIDSLayout Layout object for a BIDS dataset.
- config
strordict, optional Configuration info for methods generation. Can be a path to a file (str), a dictionary, or None. If None, loads and uses default configuration information. Keys in the dictionary include:
- ‘dir’: a dictionary for converting encoding direction strings
(e.g., j-) to descriptions (e.g., anterior to posterior)
- ‘seq’: a dictionary of sequence abbreviations (e.g., EP) and
corresponding names (e.g., echo planar)
- ‘seqvar’: a dictionary of sequence variant abbreviations
(e.g., SP) and corresponding names (e.g., spoiled)
Warning¶
pybids’ automatic report generation is experimental and currently under active development, and as such should be used with caution. Please remember to verify any generated report before putting it to use.
Additionally, only MRI datatypes (func, anat, fmap, and dwi) are currently supported.
- generate(**kwargs: Any) Counter[str][source]¶
Generate the methods section.
Parameters¶
- kwargsdict
Keyword arguments passed to BIDSLayout to select subsets of the dataset.
Returns¶
- counter
collections.Counter A dictionary of unique descriptions across subjects in the dataset, along with the number of times each pattern occurred. In cases where all subjects underwent the same protocol, the most common pattern is most likely the most complete. In cases where the dataset contains multiple protocols, each pattern will need to be inspected manually.
- generate_from_files(files: list[BIDSFile]) Counter[str][source]¶
Generate a methods section from a list of files.
Parameters¶
- fileslist of
BIDSImageFileobjects List of files from which to generate methods description.
Returns¶
- counter
collections.Counter A dictionary of unique descriptions across subjects in the file list, along with the number of times each pattern occurred. In cases where all subjects underwent the same protocol, the most common pattern is most likely the most complete. In cases where the file list contains multiple protocols, each pattern will need to be inspected manually.
- fileslist of
- layout