Repository: cpp-lln-lab/bidsMReye (language: python)

Issue:
`ZeroDivisionError: float division by zero` when trying to create sidecar
```
[15:05:09] WARNING  bidsMReye - [15:05:09] - log level: WARNING                                                                                                                        bidsmreye.py:115
Mask 0/2, Sum: 4.379, Mean 0.365, Std 0.423, Median 0.157
Mask 1/2, Sum: 10.109, Mean 0.842, Std 1.176, Median 0.521
Mask 2/2, Sum: -15.330, Mean -1.278, Std 11.405, Median 0.018
[15:05:44] WARNING  bidsMReye - [15:05:44] - Found a repetition time of 0.0 seconds.                                                                                                  bids_utils.py:141
┌─────────────────────────────── Traceback (most recent call last) ────────────────────────────────┐
│ C:\Workdir\MyApps\MyApp\envs\Python391\lib\runpy.py:197 in _run_module_as_main                   │
│                                                                                                  │
│   194 │   main_globals = sys.modules["__main__"].__dict__                                        │
│   195 │   if alter_argv:                                                                         │
│   196 │   │   sys.argv[0] = mod_spec.origin                                                      │
│ > 197 │   return _run_code(code, main_globals, None,                                             │
│   198 │   │   │   │   │    "__main__", mod_spec)                                                 │
│   199                                                                                            │
│   200 def run_module(mod_name, init_globals=None,                                                │
│                                                                                                  │
│ ┌─────────────────────────────────────────── locals ───────────────────────────────────────────┐ │
│ │   alter_argv = False                                                                         │ │
│ │         code = <code object <module> at 0x0000024B56A1D660, file                             │ │
│ │                "C:\Workdir\MyApps\MyApp\envs\Python391\Scripts\bidsmreye.exe\__main__.py",   │ │
│ │                line 2>                                                                       │ │
│ │ main_globals = {                                                                             │ │
│ │                │   '__name__': '__main__',                                                   │ │
│ │                │   '__doc__': None,                                                          │ │
│ │                │   '__package__': '',                                                        │ │
│ │                │   '__loader__': <zipimporter object                                         │ │
│ │                "C:\Workdir\MyApps\MyApp\envs\Python391\Scripts\bidsmreye.exe\">,             │ │
│ │                │   '__spec__': ModuleSpec(name='__main__', loader=<zipimporter object        │ │
│ │                "C:\Workdir\MyApps\MyApp\envs\Python391\Scripts\bidsmreye.exe\">,             │ │
│ │                origin='C:\\Workdir\\MyApps\\MyApp\\envs\\Python391\\Scripts\\bidsmreye.exe\… │ │
│ │                │   '__annotations__': {},                                                    │ │
│ │                │   '__builtins__': <module 'builtins' (built-in)>,                           │ │
│ │                │   '__file__':                                                               │ │
│ │                'C:\\Workdir\\MyApps\\MyApp\\envs\\Python391\\Scripts\\bidsmreye.exe\\__main… │ │
│ │                │   '__cached__':                                                             │ │
│ │                'C:\\Workdir\\MyApps\\MyApp\\envs\\Python391\\Scripts\\bidsmreye.exe\\__pyca… │ │
│ │                │   're': <module 're' from                                                   │ │
│ │                'C:\\Workdir\\MyApps\\MyApp\\envs\\Python391\\lib\\re.py'>,                   │ │
│ │                │   ... +2                                                                    │ │
│ │                }                                                                             │ │
│ │     mod_name = '__main__'                                                                    │ │
│ │     mod_spec = ModuleSpec(name='__main__', loader=<zipimporter object                        │ │
│ │                "C:\Workdir\MyApps\MyApp\envs\Python391\Scripts\bidsmreye.exe\">,             │ │
│ │                origin='C:\\Workdir\\MyApps\\MyApp\\envs\\Python391\\Scripts\\bidsmreye.exe\… │ │
│ └──────────────────────────────────────────────────────────────────────────────────────────────┘ │
│                                                                                                  │
│ C:\Workdir\MyApps\MyApp\envs\Python391\lib\runpy.py:87 in _run_code                              │
│                                                                                                  │
│    84 │   │   │   │   │      __loader__ = loader,                                                │
│    85 │   │   │   │   │      __package__ = pkg_name,                                             │
│    86 │   │   │   │   │      __spec__ = mod_spec)                                                │
│ >  87 │   exec(code, run_globals)                                                                │
│    88 │   return run_globals                                                                     │
│    89                                                                                            │
│    90 def _run_module_code(code, init_globals=None,                                              │
│                                                                                                  │
│ ┌─────────────────────────────────────────── locals ───────────────────────────────────────────┐ │
│ │       cached = 'C:\\Workdir\\MyApps\\MyApp\\envs\\Python391\\Scripts\\bidsmreye.exe\\__pyca… │ │
│ │         code = <code object <module> at 0x0000024B56A1D660, file                             │ │
│ │                "C:\Workdir\MyApps\MyApp\envs\Python391\Scripts\bidsmreye.exe\__main__.py",   │ │
│ │                line 2>                                                                       │ │
│ │        fname = 'C:\\Workdir\\MyApps\\MyApp\\envs\\Python391\\Scripts\\bidsmreye.exe\\__main… │ │
│ │ init_globals = None                                                                          │ │
│ │       loader = <zipimporter object                                                           │ │
│ │                "C:\Workdir\MyApps\MyApp\envs\Python391\Scripts\bidsmreye.exe\">              │ │
│ │     mod_name = '__main__'                                                                    │ │
│ │     mod_spec = ModuleSpec(name='__main__', loader=<zipimporter object                        │ │
│ │                "C:\Workdir\MyApps\MyApp\envs\Python391\Scripts\bidsmreye.exe\">,             │ │
│ │                origin='C:\\Workdir\\MyApps\\MyApp\\envs\\Python391\\Scripts\\bidsmreye.exe\… │ │
│ │     pkg_name = ''                                                                            │ │
│ │  run_globals = {                                                                             │ │
│ │                │   '__name__': '__main__',                                                   │ │
│ │                │   '__doc__': None,                                                          │ │
│ │                │   '__package__': '',                                                        │ │
│ │                │   '__loader__': <zipimporter object                                         │ │
│ │                "C:\Workdir\MyApps\MyApp\envs\Python391\Scripts\bidsmreye.exe\">,             │ │
│ │                │   '__spec__': ModuleSpec(name='__main__', loader=<zipimporter object        │ │
│ │                "C:\Workdir\MyApps\MyApp\envs\Python391\Scripts\bidsmreye.exe\">,             │ │
│ │                origin='C:\\Workdir\\MyApps\\MyApp\\envs\\Python391\\Scripts\\bidsmreye.exe\… │ │
│ │                │   '__annotations__': {},                                                    │ │
│ │                │   '__builtins__': <module 'builtins' (built-in)>,                           │ │
│ │                │   '__file__':                                                               │ │
│ │                'C:\\Workdir\\MyApps\\MyApp\\envs\\Python391\\Scripts\\bidsmreye.exe\\__main… │ │
│ │                │   '__cached__':                                                             │ │
│ │                'C:\\Workdir\\MyApps\\MyApp\\envs\\Python391\\Scripts\\bidsmreye.exe\\__pyca… │ │
│ │                │   're': <module 're' from                                                   │ │
│ │                'C:\\Workdir\\MyApps\\MyApp\\envs\\Python391\\lib\\re.py'>,                   │ │
│ │                │   ... +2                                                                    │ │
│ │                }                                                                             │ │
│ │  script_name = None                                                                          │ │
│ └──────────────────────────────────────────────────────────────────────────────────────────────┘ │
│                                                                                                  │
│ in <module>:7                                                                                    │
│                                                                                                  │
│ C:\Workdir\MyApps\MyApp\envs\Python391\lib\site-packages\bidsmreye\bidsmreye.py:54 in cli        │
│                                                                                                  │
│    51 │   │   log_level = min(len(log_levels()) - 1, max(log_level + adjustment, 0))             │
│    52 │   log_level_name = log_levels()[log_level]                                               │
│    53 │                                                                                          │
│ >  54 │   bidsmreye(                                                                             │
│    55 │   │   bids_dir=args.bids_dir,                                                            │
│    56 │   │   output_dir=args.output_dir,                                                        │
│    57 │   │   analysis_level=args.analysis_level,                                                │
│                                                                                                  │
│ ┌─────────────────────────────────────────── locals ───────────────────────────────────────────┐ │
│ │           args = Namespace(bids_dir='C:\\Workdir\\MyApps\\MRI_data_analysis\\derivatives\\f… │ │
│ │                  output_dir='C:\\Workdir\\MyApps\\MRI_data_analysis\\derivatives\\bidsmreye… │ │
│ │                  analysis_level='participant', action='prepare', participant_label=['999'],  │ │
│ │                  task=None, run=None, space=None, log_level=None, debug=False,               │ │
│ │                  reset_database=False, bids_filter_file=None, non_linear_coreg=False,        │ │
│ │                  model='1to6')                                                               │ │
│ │           argv = [                                                                           │ │
│ │                  │   'C:\\Workdir\\MyApps\\MyApp\\envs\\Python391\\Scripts\\bidsmreye',      │ │
│ │                  │   '--action',                                                             │ │
│ │                  │   'prepare',                                                              │ │
│ │                  │   'C:\\Workdir\\MyApps\\MRI_data_analysis\\derivatives\\fMRIprep',        │ │
│ │                  │   'C:\\Workdir\\MyApps\\MRI_data_analysis\\derivatives\\bidsmreye',       │ │
│ │                  │   'participant',                                                          │ │
│ │                  │   '--participant_label',                                                  │ │
│ │                  │   '999'                                                                   │ │
│ │                  ]                                                                           │ │
│ │      log_level = 2                                                                           │ │
│ │ log_level_name = 'WARNING'                                                                   │ │
│ │         parser = MuhParser(prog='bidsmreye', usage=None, description='BIDS app using         │ │
│ │                  deepMReye to decode eye motion for fMRI time series data.',                 │ │
│ │                  formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', │ │
│ │                  add_help=True)                                                              │ │
│ └──────────────────────────────────────────────────────────────────────────────────────────────┘ │
│                                                                                                  │
│ C:\Workdir\MyApps\MyApp\envs\Python391\lib\site-packages\bidsmreye\bidsmreye.py:129 in bidsmreye │
│                                                                                                  │
│   126 │   if action in {"all", "generalize"} and isinstance(cfg.model_weights_file, str):        │
│   127 │   │   cfg.model_weights_file = download(cfg.model_weights_file)                          │
│   128 │                                                                                          │
│ > 129 │   dispatch(analysis_level=analysis_level, action=action, cfg=cfg)                        │
│   130                                                                                            │
│   131                                                                                            │
│   132 def dispatch(analysis_level: str, action: str, cfg: Config) -> None:                       │
│                                                                                                  │
│ ┌─────────────────────────────────────────── locals ───────────────────────────────────────────┐ │
│ │             action = 'prepare'                                                               │ │
│ │     analysis_level = 'participant'                                                           │ │
│ │           bids_dir = 'C:\\Workdir\\MyApps\\MRI_data_analysis\\derivatives\\fMRIprep'         │ │
│ │        bids_filter = None                                                                    │ │
│ │   bids_filter_file = None                                                                    │ │
│ │                cfg = Config(                                                                 │ │
│ │                      │                                                                       │ │
│ │                      input_dir=WindowsPath('C:/Workdir/MyApps/MRI_data_analysis/derivatives… │ │
│ │                      │                                                                       │ │
│ │                      output_dir=WindowsPath('C:/Workdir/MyApps/MRI_data_analysis/derivative… │ │
│ │                      │   subjects=['999'],                                                   │ │
│ │                      │   space=['MNI152NLin2009cAsym'],                                      │ │
│ │                      │   task=['aestheticlikingjudgement'],                                  │ │
│ │                      │   run=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],                                │ │
│ │                      │   model_weights_file='1to6',                                          │ │
│ │                      │   bids_filter={                                                       │ │
│ │                      │   │   'bold': {                                                       │ │
│ │                      │   │   │   'datatype': 'func',                                         │ │
│ │                      │   │   │   'desc': 'preproc',                                          │ │
│ │                      │   │   │   'suffix': '^bold$',                                         │ │
│ │                      │   │   │   'extension': 'nii.*',                                       │ │
│ │                      │   │   │   'task': '^aestheticlikingjudgement$',                       │ │
│ │                      │   │   │   'space': '^MNI152NLin2009cAsym$',                           │ │
│ │                      │   │   │   'subject': '999',                                           │ │
│ │                      │   │   │   'run': '1|2|3|4|5|6|7|8|9|10'                               │ │
│ │                      │   │   },                                                              │ │
│ │                      │   │   'mask': {'suffix': 'mask', 'extension': 'p'},                   │ │
│ │                      │   │   'no_label': {                                                   │ │
│ │                      │   │   │   'desc': 'nolabel',                                          │ │
│ │                      │   │   │   'suffix': '^bidsmreye$$',                                   │ │
│ │                      │   │   │   'extension': 'npz'                                          │ │
│ │                      │   │   },                                                              │ │
│ │                      │   │   'eyetrack': {'suffix': '^eyetrack$$', 'extension': 'tsv'},      │ │
│ │                      │   │   'eyetrack_qc': {'suffix': '^eyetrack$$', 'extension': 'json'}   │ │
│ │                      │   },                                                                  │ │
│ │                      │   debug=False,                                                        │ │
│ │                      │   reset_database=False,                                               │ │
│ │                      │   non_linear_coreg=False                                              │ │
│ │                      )                                                                       │ │
│ │              debug = False                                                                   │ │
│ │     log_level_name = 'WARNING'                                                               │ │
│ │ model_weights_file = '1to6'                                                                  │ │
│ │   non_linear_coreg = False                                                                   │ │
│ │         output_dir = 'C:\\Workdir\\MyApps\\MRI_data_analysis\\derivatives\\bidsmreye'        │ │
│ │  participant_label = ['999']                                                                 │ │
│ │     reset_database = False                                                                   │ │
│ │                run = None                                                                    │ │
│ │              space = None                                                                    │ │
│ │               task = None                                                                    │ │
│ └──────────────────────────────────────────────────────────────────────────────────────────────┘ │
│                                                                                                  │
│ C:\Workdir\MyApps\MyApp\envs\Python391\lib\site-packages\bidsmreye\bidsmreye.py:145 in dispatch  │
│                                                                                                  │
│   142 │   │   │   prepare_data(cfg)                                                              │
│   143 │   │   │   generalize(cfg)                                                                │
│   144 │   │   elif action == "prepare":                                                          │
│ > 145 │   │   │   prepare_data(cfg)                                                              │
│   146 │   │   elif action == "generalize":                                                       │
│   147 │   │   │   generalize(cfg)                                                                │
│   148 │   │   elif action == "qc":                                                               │
│                                                                                                  │
│ ┌─────────────────────────────────────────── locals ───────────────────────────────────────────┐ │
│ │         action = 'prepare'                                                                   │ │
│ │ analysis_level = 'participant'                                                               │ │
│ │            cfg = Config(                                                                     │ │
│ │                  │                                                                           │ │
│ │                  input_dir=WindowsPath('C:/Workdir/MyApps/MRI_data_analysis/derivatives/fMR… │ │
│ │                  │                                                                           │ │
│ │                  output_dir=WindowsPath('C:/Workdir/MyApps/MRI_data_analysis/derivatives/bi… │ │
│ │                  │   subjects=['999'],                                                       │ │
│ │                  │   space=['MNI152NLin2009cAsym'],                                          │ │
│ │                  │   task=['aestheticlikingjudgement'],                                      │ │
│ │                  │   run=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],                                    │ │
│ │                  │   model_weights_file='1to6',                                              │ │
│ │                  │   bids_filter={                                                           │ │
│ │                  │   │   'bold': {                                                           │ │
│ │                  │   │   │   'datatype': 'func',                                             │ │
│ │                  │   │   │   'desc': 'preproc',                                              │ │
│ │                  │   │   │   'suffix': '^bold$',                                             │ │
│ │                  │   │   │   'extension': 'nii.*',                                           │ │
│ │                  │   │   │   'task': '^aestheticlikingjudgement$',                           │ │
│ │                  │   │   │   'space': '^MNI152NLin2009cAsym$',                               │ │
│ │                  │   │   │   'subject': '999',                                               │ │
│ │                  │   │   │   'run': '1|2|3|4|5|6|7|8|9|10'                                   │ │
│ │                  │   │   },                                                                  │ │
│ │                  │   │   'mask': {'suffix': 'mask', 'extension': 'p'},                       │ │
│ │                  │   │   'no_label': {                                                       │ │
│ │                  │   │   │   'desc': 'nolabel',                                              │ │
│ │                  │   │   │   'suffix': '^bidsmreye$$',                                       │ │
│ │                  │   │   │   'extension': 'npz'                                              │ │
│ │                  │   │   },                                                                  │ │
│ │                  │   │   'eyetrack': {'suffix': '^eyetrack$$', 'extension': 'tsv'},          │ │
│ │                  │   │   'eyetrack_qc': {'suffix': '^eyetrack$$', 'extension': 'json'}       │ │
│ │                  │   },                                                                      │ │
│ │                  │   debug=False,                                                            │ │
│ │                  │   reset_database=False,                                                   │ │
│ │                  │   non_linear_coreg=False                                                  │ │
│ │                  )                                                                           │ │
│ └──────────────────────────────────────────────────────────────────────────────────────────────┘ │
│                                                                                                  │
│ C:\Workdir\MyApps\MyApp\envs\Python391\lib\site-packages\bidsmreye\prepare_data.py:185 in        │
│ prepare_data                                                                                     │
│                                                                                                  │
│   182 │                                                                                          │
│   183 │   for subject_label in subjects:                                                         │
│   184 │   │                                                                                      │
│ > 185 │   │   process_subject(cfg, layout_in, layout_out, subject_label)                         │
│   186                                                                                            │
│                                                                                                  │
│ ┌─────────────────────────────────────────── locals ───────────────────────────────────────────┐ │
│ │           cfg = Config(                                                                      │ │
│ │                 │                                                                            │ │
│ │                 input_dir=WindowsPath('C:/Workdir/MyApps/MRI_data_analysis/derivatives/fMRI… │ │
│ │                 │                                                                            │ │
│ │                 output_dir=WindowsPath('C:/Workdir/MyApps/MRI_data_analysis/derivatives/bid… │ │
│ │                 │   subjects=['999'],                                                        │ │
│ │                 │   space=['MNI152NLin2009cAsym'],                                           │ │
│ │                 │   task=['aestheticlikingjudgement'],                                       │ │
│ │                 │   run=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],                                     │ │
│ │                 │   model_weights_file='1to6',                                               │ │
│ │                 │   bids_filter={                                                            │ │
│ │                 │   │   'bold': {                                                            │ │
│ │                 │   │   │   'datatype': 'func',                                              │ │
│ │                 │   │   │   'desc': 'preproc',                                               │ │
│ │                 │   │   │   'suffix': '^bold$',                                              │ │
│ │                 │   │   │   'extension': 'nii.*',                                            │ │
│ │                 │   │   │   'task': '^aestheticlikingjudgement$',                            │ │
│ │                 │   │   │   'space': '^MNI152NLin2009cAsym$',                                │ │
│ │                 │   │   │   'subject': '999',                                                │ │
│ │                 │   │   │   'run': '1|2|3|4|5|6|7|8|9|10'                                    │ │
│ │                 │   │   },                                                                   │ │
│ │                 │   │   'mask': {'suffix': 'mask', 'extension': 'p'},                        │ │
│ │                 │   │   'no_label': {                                                        │ │
│ │                 │   │   │   'desc': 'nolabel',                                               │ │
│ │                 │   │   │   'suffix': '^bidsmreye$$',                                        │ │
│ │                 │   │   │   'extension': 'npz'                                               │ │
│ │                 │   │   },                                                                   │ │
│ │                 │   │   'eyetrack': {'suffix': '^eyetrack$$', 'extension': 'tsv'},           │ │
│ │                 │   │   'eyetrack_qc': {'suffix': '^eyetrack$$', 'extension': 'json'}        │ │
│ │                 │   },                                                                       │ │
│ │                 │   debug=False,                                                             │ │
│ │                 │   reset_database=False,                                                    │ │
│ │                 │   non_linear_coreg=False                                                   │ │
│ │                 )                                                                            │ │
│ │     layout_in = BIDS Layout: ..._analysis\derivatives\fMRIprep | Subjects: 1 | Sessions: 0 | │ │
│ │                 Runs: 10                                                                     │ │
│ │    layout_out = BIDS Layout: ...erivatives\bidsmreye\bidsmreye | Subjects: 1 | Sessions: 0 | │ │
│ │                 Runs: 1                                                                      │ │
│ │ subject_label = '999'                                                                        │ │
│ │      subjects = ['999']                                                                      │ │
│ └──────────────────────────────────────────────────────────────────────────────────────────────┘ │
│                                                                                                  │
│ C:\Workdir\MyApps\MyApp\envs\Python391\lib\site-packages\bidsmreye\prepare_data.py:155 in        │
│ process_subject                                                                                  │
│                                                                                                  │
│   152 │   │   move_file(deepmreye_mask_name, mask_name)                                          │
│   153 │   │                                                                                      │
│   154 │   │   source = str(Path(img).relative_to(layout_in.root))                                │
│ > 155 │   │   save_sampling_frequency_to_json(layout_out, img=img, source=source)                │
│   156 │   │                                                                                      │
│   157 │   │   combine_data_with_empty_labels(layout_out, mask_name)                              │
│   158                                                                                            │
│                                                                                                  │
│ ┌─────────────────────────────────────────── locals ───────────────────────────────────────────┐ │
│ │                    bf = [                                                                    │ │
│ │                         │                                                                    │ │
│ │                         'C:\\Workdir\\MyApps\\MRI_data_analysis\\derivatives\\fMRIprep\\sub… │ │
│ │                         │                                                                    │ │
│ │                         'C:\\Workdir\\MyApps\\MRI_data_analysis\\derivatives\\fMRIprep\\sub… │ │
│ │                         │                                                                    │ │
│ │                         'C:\\Workdir\\MyApps\\MRI_data_analysis\\derivatives\\fMRIprep\\sub… │ │
│ │                         │                                                                    │ │
│ │                         'C:\\Workdir\\MyApps\\MRI_data_analysis\\derivatives\\fMRIprep\\sub… │ │
│ │                         │                                                                    │ │
│ │                         'C:\\Workdir\\MyApps\\MRI_data_analysis\\derivatives\\fMRIprep\\sub… │ │
│ │                         │                                                                    │ │
│ │                         'C:\\Workdir\\MyApps\\MRI_data_analysis\\derivatives\\fMRIprep\\sub… │ │
│ │                         │                                                                    │ │
│ │                         'C:\\Workdir\\MyApps\\MRI_data_analysis\\derivatives\\fMRIprep\\sub… │ │
│ │                         │                                                                    │ │
│ │                         'C:\\Workdir\\MyApps\\MRI_data_analysis\\derivatives\\fMRIprep\\sub… │ │
│ │                         │                                                                    │ │
│ │                         'C:\\Workdir\\MyApps\\MRI_data_analysis\\derivatives\\fMRIprep\\sub… │ │
│ │                         │                                                                    │ │
│ │                         'C:\\Workdir\\MyApps\\MRI_data_analysis\\derivatives\\fMRIprep\\sub… │ │
│ │                         ]                                                                    │ │
│ │                   cfg = Config(                                                              │ │
│ │                         │                                                                    │ │
│ │                         input_dir=WindowsPath('C:/Workdir/MyApps/MRI_data_analysis/derivati… │ │
│ │                         │                                                                    │ │
│ │                         output_dir=WindowsPath('C:/Workdir/MyApps/MRI_data_analysis/derivat… │ │
│ │                         │   subjects=['999'],                                                │ │
│ │                         │   space=['MNI152NLin2009cAsym'],                                   │ │
│ │                         │   task=['aestheticlikingjudgement'],                               │ │
│ │                         │   run=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],                             │ │
│ │                         │   model_weights_file='1to6',                                       │ │
│ │                         │   bids_filter={                                                    │ │
│ │                         │   │   'bold': {                                                    │ │
│ │                         │   │   │   'datatype': 'func',                                      │ │
│ │                         │   │   │   'desc': 'preproc',                                       │ │
│ │                         │   │   │   'suffix': '^bold$',                                      │ │
│ │                         │   │   │   'extension': 'nii.*',                                    │ │
│ │                         │   │   │   'task': '^aestheticlikingjudgement$',                    │ │
│ │                         │   │   │   'space': '^MNI152NLin2009cAsym$',                        │ │
│ │                         │   │   │   'subject': '999',                                        │ │
│ │                         │   │   │   'run': '1|2|3|4|5|6|7|8|9|10'                            │ │
│ │                         │   │   },                                                           │ │
│ │                         │   │   'mask': {'suffix': 'mask', 'extension': 'p'},                │ │
│ │                         │   │   'no_label': {                                                │ │
│ │                         │   │   │   'desc': 'nolabel',                                       │ │
│ │                         │   │   │   'suffix': '^bidsmreye$$',                                │ │
│ │                         │   │   │   'extension': 'npz'                                       │ │
│ │                         │   │   },                                                           │ │
│ │                         │   │   'eyetrack': {'suffix': '^eyetrack$$', 'extension': 'tsv'},   │ │
│ │                         │   │   'eyetrack_qc': {                                             │ │
│ │                         │   │   │   'suffix': '^eyetrack$$',                                 │ │
│ │                         │   │   │   'extension': 'json'                                      │ │
│ │                         │   │   }                                                            │ │
│ │                         │   },                                                               │ │
│ │                         │   debug=False,                                                     │ │
│ │                         │   reset_database=False,                                            │ │
│ │                         │   non_linear_coreg=False                                           │ │
│ │                         )                                                                    │ │
│ │   deepmreye_mask_name = WindowsPath('C:/Workdir/MyApps/MRI_data_analysis/derivatives/fMRIpr… │ │
│ │ deepmreye_mask_report = WindowsPath('C:/Workdir/MyApps/MRI_data_analysis/derivatives/fMRIpr… │ │
│ │                   img = 'C:\\Workdir\\MyApps\\MRI_data_analysis\\derivatives\\fMRIprep\\sub… │ │
│ │             layout_in = BIDS Layout: ..._analysis\derivatives\fMRIprep | Subjects: 1 |       │ │
│ │                         Sessions: 0 | Runs: 10                                               │ │
│ │            layout_out = BIDS Layout: ...erivatives\bidsmreye\bidsmreye | Subjects: 1 |       │ │
│ │                         Sessions: 0 | Runs: 1                                                │ │
│ │             mask_name = WindowsPath('C:/Workdir/MyApps/MRI_data_analysis/derivatives/bidsmr… │ │
│ │           report_name = WindowsPath('C:/Workdir/MyApps/MRI_data_analysis/derivatives/bidsmr… │ │
│ │                source = 'sub-999\\func\\sub-999_task-aestheticlikingjudgement_run-01_space-… │ │
│ │         subject_label = '999'                                                                │ │
│ │           this_filter = {                                                                    │ │
│ │                         │   'datatype': 'func',                                              │ │
│ │                         │   'desc': 'preproc',                                               │ │
│ │                         │   'suffix': '^bold$',                                              │ │
│ │                         │   'extension': 'nii.*',                                            │ │
│ │                         │   'task': '^aestheticlikingjudgement$',                            │ │
│ │                         │   'space': '^MNI152NLin2009cAsym$',                                │ │
│ │                         │   'subject': '999',                                                │ │
│ │                         │   'run': '1|2|3|4|5|6|7|8|9|10'                                    │ │
│ │                         }                                                                    │ │
│ └──────────────────────────────────────────────────────────────────────────────────────────────┘ │
│                                                                                                  │
│ C:\Workdir\MyApps\MyApp\envs\Python391\lib\site-packages\bidsmreye\bids_utils.py:143 in          │
│ save_sampling_frequency_to_json                                                                  │
│                                                                                                  │
│   140 │   if sampling_frequency <= 1:                                                            │
│   141 │   │   log.warning(f"Found a repetition time of {sampling_frequency} seconds.")           │
│   142 │   create_sidecar(                                                                        │
│ > 143 │   │   layout_out, img, SamplingFrequency=1 / float(sampling_frequency), source=source    │
│   144 │   )                                                                                      │
│   145                                                                                            │
│   146                                                                                            │
│                                                                                                  │
│ ┌─────────────────────────────────────────── locals ───────────────────────────────────────────┐ │
│ │           func_img = <nibabel.nifti1.Nifti1Image object at 0x0000024B1D8B4C70>               │ │
│ │             header = <nibabel.nifti1.Nifti1Header object at 0x0000024B1D8CEA00>              │ │
│ │                img = 'C:\\Workdir\\MyApps\\MRI_data_analysis\\derivatives\\fMRIprep\\sub-99… │ │
│ │         layout_out = BIDS Layout: ...erivatives\bidsmreye\bidsmreye | Subjects: 1 |          │ │
│ │                      Sessions: 0 | Runs: 1                                                   │ │
│ │ sampling_frequency = 0.0                                                                     │ │
│ │             source = 'sub-999\\func\\sub-999_task-aestheticlikingjudgement_run-01_space-MNI… │ │
│ └──────────────────────────────────────────────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────────────────────────────────────────┘
ZeroDivisionError: float division by zero
```


Discussion / hints:
We found the following entry in the [FAQ](https://bidsmreye.readthedocs.io/en/latest/FAQ.html) which you may find helpful:


- [How I should structure my input data?](https://bidsmreye.readthedocs.io/en/latest/FAQ.html#how-i-should-structure-my-input-data)

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by [FAQtory](https://github.com/willmcgugan/faqtory)
Hi,

I am having the same exact issue running bidsmreye using docker on an fmriprep output. Here is what I get with any subject:

```
$ docker run -it --rm -v /data/projects/chess/data/BIDS/derivatives/fmriprep:/data -v /data/projects/chess/temp_bidsmreye:/out cpplab/bidsmreye:latest --action all /data /out participant --participant_label 01

2024-07-15 15:00:10.956530: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 AVX512F AVX512_VNNI FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-07-15 15:00:11.037137: I tensorflow/core/util/port.cc:104] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-07-15 15:00:11.040178: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2024-07-15 15:00:11.040200: I tensorflow/compiler/xla/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2024-07-15 15:00:11.419164: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2024-07-15 15:00:11.419237: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2024-07-15 15:00:11.419245: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.

WARNING
[15:00:40] WARNING  bidsMReye - [15:00:40] - log level: WARNING                                                      bidsmreye.py:112
Mask 0/2, Sum: 3.861, Mean 0.322, Std 0.469, Median 0.003
Mask 1/2, Sum: 13.689, Mean 1.141, Std 1.621, Median 0.556
Mask 2/2, Sum: -12.583, Mean -1.049, Std 2.780, Median -0.009
[15:00:59] WARNING  bidsMReye - [15:00:59] - Found a repetition time of 0.0 seconds.                                                         prepare_data.py:163
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /opt/miniconda-latest/envs/bidsmreye/bin/bidsmreye:8 in <module>                                 │
│                                                                                                  │
│   5 from bidsmreye.bidsmreye import cli                                                          │
│   6 if __name__ == '__main__':                                                                   │
│   7 │   sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])                         │
│ ❱ 8 │   sys.exit(cli())                                                                          │
│   9                                                                                              │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ __annotations__ = {}                                                                         │ │
│ │    __builtins__ = <module 'builtins' (built-in)>                                             │ │
│ │      __cached__ = None                                                                       │ │
│ │         __doc__ = None                                                                       │ │
│ │        __file__ = '/opt/miniconda-latest/envs/bidsmreye/bin/bidsmreye'                       │ │
│ │      __loader__ = <_frozen_importlib_external.SourceFileLoader object at 0x7fd16ac2bc10>     │ │
│ │        __name__ = '__main__'                                                                 │ │
│ │     __package__ = None                                                                       │ │
│ │        __spec__ = None                                                                       │ │
│ │             cli = <function cli at 0x7fd1600a7af0>                                           │ │
│ │              re = <module 're' from                                                          │ │
│ │                   '/opt/miniconda-latest/envs/bidsmreye/lib/python3.9/re.py'>                │ │
│ │             sys = <module 'sys' (built-in)>                                                  │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/miniconda-latest/envs/bidsmreye/lib/python3.9/site-packages/bidsmreye/bidsmreye.py:54 in    │
│ cli                                                                                              │
│                                                                                                  │
│    51 │   │   log_level = min(len(log_levels()) - 1, max(log_level + adjustment, 0))             │
│    52 │   log_level_name = log_levels()[log_level]                                               │
│    53 │                                                                                          │
│ ❱  54 │   bidsmreye(                                                                             │
│    55 │   │   bids_dir=args.bids_dir,                                                            │
│    56 │   │   output_dir=args.output_dir,                                                        │
│    57 │   │   analysis_level=args.analysis_level,                                                │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │           args = Namespace(bids_dir='/data', output_dir='/out',                              │ │
│ │                  analysis_level='participant', action='all', participant_label=['01'],       │ │
│ │                  task=None, run=None, space=None, log_level=None, debug=False,               │ │
│ │                  reset_database=False, bids_filter_file=None, non_linear_coreg=False,        │ │
│ │                  model='1to6')                                                               │ │
│ │           argv = [                                                                           │ │
│ │                  │   '/opt/miniconda-latest/envs/bidsmreye/bin/bidsmreye',                   │ │
│ │                  │   '--action',                                                             │ │
│ │                  │   'all',                                                                  │ │
│ │                  │   '/data',                                                                │ │
│ │                  │   '/out',                                                                 │ │
│ │                  │   'participant',                                                          │ │
│ │                  │   '--participant_label',                                                  │ │
│ │                  │   '01'                                                                    │ │
│ │                  ]                                                                           │ │
│ │      log_level = 2                                                                           │ │
│ │ log_level_name = 'WARNING'                                                                   │ │
│ │         parser = MuhParser(prog='bidsmreye', usage=None, description='BIDS app using         │ │
│ │                  deepMReye to decode eye motion for fMRI time series data.',                 │ │
│ │                  formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', │ │
│ │                  add_help=True)                                                              │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/miniconda-latest/envs/bidsmreye/lib/python3.9/site-packages/bidsmreye/bidsmreye.py:126 in   │
│ bidsmreye                                                                                        │
│                                                                                                  │
│   123 │   if action in {"all", "generalize"} and isinstance(cfg.model_weights_file, str):        │
│   124 │   │   cfg.model_weights_file = download(cfg.model_weights_file)                          │
│   125 │                                                                                          │
│ ❱ 126 │   dispatch(analysis_level=analysis_level, action=action, cfg=cfg)                        │
│   127                                                                                            │
│   128                                                                                            │
│   129 def dispatch(analysis_level: str, action: str, cfg: Config) -> None:                       │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │             action = 'all'                                                                   │ │
│ │     analysis_level = 'participant'                                                           │ │
│ │           bids_dir = '/data'                                                                 │ │
│ │        bids_filter = None                                                                    │ │
│ │   bids_filter_file = None                                                                    │ │
│ │                cfg = Config(                                                                 │ │
│ │                      │   input_dir=PosixPath('/data'),                                       │ │
│ │                      │   output_dir=PosixPath('/out/bidsmreye'),                             │ │
│ │                      │   subjects=['01'],                                                    │ │
│ │                      │   space=['T1w', 'MNI152NLin2009cAsym', 'fsnative'],                   │ │
│ │                      │   task=['exp'],                                                       │ │
│ │                      │   run=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],                                │ │
│ │                      │                                                                       │ │
│ │                      model_weights_file=PosixPath('/home/neuro/bidsMReye/models/dataset_1to… │ │
│ │                      │   bids_filter={                                                       │ │
│ │                      │   │   'bold': {                                                       │ │
│ │                      │   │   │   'datatype': 'func',                                         │ │
│ │                      │   │   │   'suffix': '^bold$',                                         │ │
│ │                      │   │   │   'extension': 'nii.*',                                       │ │
│ │                      │   │   │   'task': '^exp$',                                            │ │
│ │                      │   │   │   'space': '^T1w$|^MNI152NLin2009cAsym$|^fsnative$',          │ │
│ │                      │   │   │   'subject': '01',                                            │ │
│ │                      │   │   │   'run': '1|2|3|4|5|6|7|8|9|10'                               │ │
│ │                      │   │   },                                                              │ │
│ │                      │   │   'mask': {'suffix': 'mask', 'extension': 'p'},                   │ │
│ │                      │   │   'no_label': {                                                   │ │
│ │                      │   │   │   'desc': 'nolabel',                                          │ │
│ │                      │   │   │   'suffix': '^bidsmreye$$',                                   │ │
│ │                      │   │   │   'extension': 'npz'                                          │ │
│ │                      │   │   },                                                              │ │
│ │                      │   │   'eyetrack': {'suffix': '^eyetrack$$', 'extension': 'tsv'},      │ │
│ │                      │   │   'eyetrack_qc': {'suffix': '^eyetrack$$', 'extension': 'json'}   │ │
│ │                      │   },                                                                  │ │
│ │                      │   debug=False,                                                        │ │
│ │                      │   reset_database=False,                                               │ │
│ │                      │   non_linear_coreg=False                                              │ │
│ │                      )                                                                       │ │
│ │              debug = False                                                                   │ │
│ │     log_level_name = 'WARNING'                                                               │ │
│ │ model_weights_file = '1to6'                                                                  │ │
│ │   non_linear_coreg = False                                                                   │ │
│ │         output_dir = '/out'                                                                  │ │
│ │  participant_label = ['01']                                                                  │ │
│ │     reset_database = False                                                                   │ │
│ │                run = None                                                                    │ │
│ │              space = None                                                                    │ │
│ │               task = None                                                                    │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/miniconda-latest/envs/bidsmreye/lib/python3.9/site-packages/bidsmreye/bidsmreye.py:139 in   │
│ dispatch                                                                                         │
│                                                                                                  │
│   136 │                                                                                          │
│   137 │   elif analysis_level == "participant":                                                  │
│   138 │   │   if action == "all":                                                                │
│ ❱ 139 │   │   │   prepare_data(cfg)                                                              │
│   140 │   │   │   generalize(cfg)                                                                │
│   141 │   │   elif action == "prepare":                                                          │
│   142 │   │   │   prepare_data(cfg)                                                              │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │         action = 'all'                                                                       │ │
│ │ analysis_level = 'participant'                                                               │ │
│ │            cfg = Config(                                                                     │ │
│ │                  │   input_dir=PosixPath('/data'),                                           │ │
│ │                  │   output_dir=PosixPath('/out/bidsmreye'),                                 │ │
│ │                  │   subjects=['01'],                                                        │ │
│ │                  │   space=['T1w', 'MNI152NLin2009cAsym', 'fsnative'],                       │ │
│ │                  │   task=['exp'],                                                           │ │
│ │                  │   run=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],                                    │ │
│ │                  │                                                                           │ │
│ │                  model_weights_file=PosixPath('/home/neuro/bidsMReye/models/dataset_1to6.h5… │ │
│ │                  │   bids_filter={                                                           │ │
│ │                  │   │   'bold': {                                                           │ │
│ │                  │   │   │   'datatype': 'func',                                             │ │
│ │                  │   │   │   'suffix': '^bold$',                                             │ │
│ │                  │   │   │   'extension': 'nii.*',                                           │ │
│ │                  │   │   │   'task': '^exp$',                                                │ │
│ │                  │   │   │   'space': '^T1w$|^MNI152NLin2009cAsym$|^fsnative$',              │ │
│ │                  │   │   │   'subject': '01',                                                │ │
│ │                  │   │   │   'run': '1|2|3|4|5|6|7|8|9|10'                                   │ │
│ │                  │   │   },                                                                  │ │
│ │                  │   │   'mask': {'suffix': 'mask', 'extension': 'p'},                       │ │
│ │                  │   │   'no_label': {                                                       │ │
│ │                  │   │   │   'desc': 'nolabel',                                              │ │
│ │                  │   │   │   'suffix': '^bidsmreye$$',                                       │ │
│ │                  │   │   │   'extension': 'npz'                                              │ │
│ │                  │   │   },                                                                  │ │
│ │                  │   │   'eyetrack': {'suffix': '^eyetrack$$', 'extension': 'tsv'},          │ │
│ │                  │   │   'eyetrack_qc': {'suffix': '^eyetrack$$', 'extension': 'json'}       │ │
│ │                  │   },                                                                      │ │
│ │                  │   debug=False,                                                            │ │
│ │                  │   reset_database=False,                                                   │ │
│ │                  │   non_linear_coreg=False                                                  │ │
│ │                  )                                                                           │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/miniconda-latest/envs/bidsmreye/lib/python3.9/site-packages/bidsmreye/prepare_data.py:187   │
│ in prepare_data                                                                                  │
│                                                                                                  │
│   184 │                                                                                          │
│   185 │   for subject_label in subjects:                                                         │
│   186 │   │                                                                                      │
│ ❱ 187 │   │   process_subject(cfg, layout_in, layout_out, subject_label)                         │
│   188                                                                                            │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │           cfg = Config(                                                                      │ │
│ │                 │   input_dir=PosixPath('/data'),                                            │ │
│ │                 │   output_dir=PosixPath('/out/bidsmreye'),                                  │ │
│ │                 │   subjects=['01'],                                                         │ │
│ │                 │   space=['T1w', 'MNI152NLin2009cAsym', 'fsnative'],                        │ │
│ │                 │   task=['exp'],                                                            │ │
│ │                 │   run=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],                                     │ │
│ │                 │                                                                            │ │
│ │                 model_weights_file=PosixPath('/home/neuro/bidsMReye/models/dataset_1to6.h5'… │ │
│ │                 │   bids_filter={                                                            │ │
│ │                 │   │   'bold': {                                                            │ │
│ │                 │   │   │   'datatype': 'func',                                              │ │
│ │                 │   │   │   'suffix': '^bold$',                                              │ │
│ │                 │   │   │   'extension': 'nii.*',                                            │ │
│ │                 │   │   │   'task': '^exp$',                                                 │ │
│ │                 │   │   │   'space': '^T1w$|^MNI152NLin2009cAsym$|^fsnative$',               │ │
│ │                 │   │   │   'subject': '01',                                                 │ │
│ │                 │   │   │   'run': '1|2|3|4|5|6|7|8|9|10'                                    │ │
│ │                 │   │   },                                                                   │ │
│ │                 │   │   'mask': {'suffix': 'mask', 'extension': 'p'},                        │ │
│ │                 │   │   'no_label': {                                                        │ │
│ │                 │   │   │   'desc': 'nolabel',                                               │ │
│ │                 │   │   │   'suffix': '^bidsmreye$$',                                        │ │
│ │                 │   │   │   'extension': 'npz'                                               │ │
│ │                 │   │   },                                                                   │ │
│ │                 │   │   'eyetrack': {'suffix': '^eyetrack$$', 'extension': 'tsv'},           │ │
│ │                 │   │   'eyetrack_qc': {'suffix': '^eyetrack$$', 'extension': 'json'}        │ │
│ │                 │   },                                                                       │ │
│ │                 │   debug=False,                                                             │ │
│ │                 │   reset_database=False,                                                    │ │
│ │                 │   non_linear_coreg=False                                                   │ │
│ │                 )                                                                            │ │
│ │     layout_in = BIDS Layout: .../data | Subjects: 37 | Sessions: 0 | Runs: 327               │ │
│ │    layout_out = BIDS Layout: .../out/bidsmreye | Subjects: 2 | Sessions: 0 | Runs: 2         │ │
│ │ subject_label = '01'                                                                         │ │
│ │      subjects = ['01']                                                                       │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/miniconda-latest/envs/bidsmreye/lib/python3.9/site-packages/bidsmreye/prepare_data.py:153   │
│ in process_subject                                                                               │
│                                                                                                  │
│   150 │   │   deepmreye_mask_name = get_deepmreye_filename(layout_in, img, "mask")               │
│   151 │   │   move_file(deepmreye_mask_name, mask_name)                                          │
│   152 │   │                                                                                      │
│ ❱ 153 │   │   save_sampling_frequency_to_json(layout_out, img)                                   │
│   154 │   │                                                                                      │
│   155 │   │   combine_data_with_empty_labels(layout_out, mask_name)                              │
│   156                                                                                            │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │                    bf = [                                                                    │ │
│ │                         │                                                                    │ │
│ │                         '/data/sub-01/func/sub-01_task-exp_run-1_space-MNI152NLin2009cAsym_… │ │
│ │                         │                                                                    │ │
│ │                         '/data/sub-01/func/sub-01_task-exp_run-1_space-T1w_desc-preproc_bol… │ │
│ │                         │                                                                    │ │
│ │                         '/data/sub-01/func/sub-01_task-exp_run-2_space-MNI152NLin2009cAsym_… │ │
│ │                         │                                                                    │ │
│ │                         '/data/sub-01/func/sub-01_task-exp_run-2_space-T1w_desc-preproc_bol… │ │
│ │                         │                                                                    │ │
│ │                         '/data/sub-01/func/sub-01_task-exp_run-3_space-MNI152NLin2009cAsym_… │ │
│ │                         │                                                                    │ │
│ │                         '/data/sub-01/func/sub-01_task-exp_run-3_space-T1w_desc-preproc_bol… │ │
│ │                         │                                                                    │ │
│ │                         '/data/sub-01/func/sub-01_task-exp_run-4_space-MNI152NLin2009cAsym_… │ │
│ │                         │                                                                    │ │
│ │                         '/data/sub-01/func/sub-01_task-exp_run-4_space-T1w_desc-preproc_bol… │ │
│ │                         │                                                                    │ │
│ │                         '/data/sub-01/func/sub-01_task-exp_run-5_space-MNI152NLin2009cAsym_… │ │
│ │                         │                                                                    │ │
│ │                         '/data/sub-01/func/sub-01_task-exp_run-5_space-T1w_desc-preproc_bol… │ │
│ │                         │   ... +2                                                           │ │
│ │                         ]                                                                    │ │
│ │                   cfg = Config(                                                              │ │
│ │                         │   input_dir=PosixPath('/data'),                                    │ │
│ │                         │   output_dir=PosixPath('/out/bidsmreye'),                          │ │
│ │                         │   subjects=['01'],                                                 │ │
│ │                         │   space=['T1w', 'MNI152NLin2009cAsym', 'fsnative'],                │ │
│ │                         │   task=['exp'],                                                    │ │
│ │                         │   run=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],                             │ │
│ │                         │                                                                    │ │
│ │                         model_weights_file=PosixPath('/home/neuro/bidsMReye/models/dataset_… │ │
│ │                         │   bids_filter={                                                    │ │
│ │                         │   │   'bold': {                                                    │ │
│ │                         │   │   │   'datatype': 'func',                                      │ │
│ │                         │   │   │   'suffix': '^bold$',                                      │ │
│ │                         │   │   │   'extension': 'nii.*',                                    │ │
│ │                         │   │   │   'task': '^exp$',                                         │ │
│ │                         │   │   │   'space': '^T1w$|^MNI152NLin2009cAsym$|^fsnative$',       │ │
│ │                         │   │   │   'subject': '01',                                         │ │
│ │                         │   │   │   'run': '1|2|3|4|5|6|7|8|9|10'                            │ │
│ │                         │   │   },                                                           │ │
│ │                         │   │   'mask': {'suffix': 'mask', 'extension': 'p'},                │ │
│ │                         │   │   'no_label': {                                                │ │
│ │                         │   │   │   'desc': 'nolabel',                                       │ │
│ │                         │   │   │   'suffix': '^bidsmreye$$',                                │ │
│ │                         │   │   │   'extension': 'npz'                                       │ │
│ │                         │   │   },                                                           │ │
│ │                         │   │   'eyetrack': {'suffix': '^eyetrack$$', 'extension': 'tsv'},   │ │
│ │                         │   │   'eyetrack_qc': {                                             │ │
│ │                         │   │   │   'suffix': '^eyetrack$$',                                 │ │
│ │                         │   │   │   'extension': 'json'                                      │ │
│ │                         │   │   }                                                            │ │
│ │                         │   },                                                               │ │
│ │                         │   debug=False,                                                     │ │
│ │                         │   reset_database=False,                                            │ │
│ │                         │   non_linear_coreg=False                                           │ │
│ │                         )                                                                    │ │
│ │   deepmreye_mask_name = PosixPath('/data/sub-01/func/mask_sub-01_task-exp_run-1_space-MNI15… │ │
│ │ deepmreye_mask_report = PosixPath('/data/sub-01/func/report_sub-01_task-exp_run-1_space-MNI… │ │
│ │                   img = '/data/sub-01/func/sub-01_task-exp_run-1_space-MNI152NLin2009cAsym_… │ │
│ │             layout_in = BIDS Layout: .../data | Subjects: 37 | Sessions: 0 | Runs: 327       │ │
│ │            layout_out = BIDS Layout: .../out/bidsmreye | Subjects: 2 | Sessions: 0 | Runs: 2 │ │
│ │             mask_name = PosixPath('/out/bidsmreye/sub-01/func/sub-01_task-exp_run-1_space-M… │ │
│ │           report_name = PosixPath('/out/bidsmreye/sub-01/func/sub-01_task-exp_run-1_space-M… │ │
│ │         subject_label = '01'                                                                 │ │
│ │           this_filter = {                                                                    │ │
│ │                         │   'datatype': 'func',                                              │ │
│ │                         │   'suffix': '^bold$',                                              │ │
│ │                         │   'extension': 'nii.*',                                            │ │
│ │                         │   'task': '^exp$',                                                 │ │
│ │                         │   'space': '^T1w$|^MNI152NLin2009cAsym$|^fsnative$',               │ │
│ │                         │   'subject': '01',                                                 │ │
│ │                         │   'run': '1|2|3|4|5|6|7|8|9|10'                                    │ │
│ │                         }                                                                    │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/miniconda-latest/envs/bidsmreye/lib/python3.9/site-packages/bidsmreye/prepare_data.py:164   │
│ in save_sampling_frequency_to_json                                                               │
│                                                                                                  │
│   161 │   sampling_frequency = header.get_zooms()[3]                                             │
│   162 │   if sampling_frequency <= 1:                                                            │
│   163 │   │   log.warning(f"Found a repetition time of {sampling_frequency} seconds.")           │
│ ❱ 164 │   create_sidecar(layout_out, img, SamplingFrequency=1 / float(sampling_frequency))       │
│   165                                                                                            │
│   166                                                                                            │
│   167 def prepare_data(cfg: Config) -> None:                                                     │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │           func_img = <nibabel.nifti1.Nifti1Image object at 0x7fd0843720a0>                   │ │
│ │             header = <nibabel.nifti1.Nifti1Header object at 0x7fd084372160>                  │ │
│ │                img = '/data/sub-01/func/sub-01_task-exp_run-1_space-MNI152NLin2009cAsym_res… │ │
│ │         layout_out = BIDS Layout: .../out/bidsmreye | Subjects: 2 | Sessions: 0 | Runs: 2    │ │
│ │ sampling_frequency = 0.0                                                                     │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ZeroDivisionError: float division by zero
```
Any ideas why? Everything looks ok in my BOLD JSON sidecar file. including the repetition time field.

Thanks in advance,
Andrea
seems due to the fact that the nifti header does not contain the proper value for the repetition time and contains 0 instead

will fix by relying on the BIDS metadata instead

Fix patch:
diff --git a/bidsmreye/bids_utils.py b/bidsmreye/bids_utils.py
index 2a97344..cc1dfab 100644
--- a/bidsmreye/bids_utils.py
+++ b/bidsmreye/bids_utils.py
@@ -4,8 +4,8 @@
 from pathlib import Path
 from typing import Any
 
-import nibabel as nib
 from bids import BIDSLayout  # type: ignore
+from bids.layout import BIDSFile
 
 from bidsmreye._version import __version__
 from bidsmreye.configuration import (
@@ -143,15 +143,16 @@ def create_sidecar(
 
 
 def save_sampling_frequency_to_json(
-    layout_out: BIDSLayout, img: str, source: str
+    layout_out: BIDSLayout, img: BIDSFile, source: str
 ) -> None:
-    func_img = nib.load(img)
-    header = func_img.header
-    sampling_frequency = header.get_zooms()[3]
-    if sampling_frequency <= 1:
-        log.warning(f"Found a repetition time of {sampling_frequency} seconds.")
+    metadata = img.get_metadata()
+    repetition_time = metadata["RepetitionTime"]
+    # TODO handle rare edge case where preprocessed data
+    # does not contain RepetitionTime metadata
+    if repetition_time <= 1:
+        log.warning(f"Found a repetition time of {repetition_time} seconds.")
     create_sidecar(
-        layout_out, img, SamplingFrequency=1 / float(sampling_frequency), source=source
+        layout_out, img.path, SamplingFrequency=1 / float(repetition_time), source=source
     )
 
 
diff --git a/bidsmreye/generalize.py b/bidsmreye/generalize.py
index 41aefea..45f7b00 100644
--- a/bidsmreye/generalize.py
+++ b/bidsmreye/generalize.py
@@ -158,7 +158,6 @@ def process_subject(cfg: Config, layout_out: BIDSLayout, subject_label: str) ->
     this_filter = set_this_filter(cfg, subject_label, "no_label")
 
     bf = layout_out.get(
-        return_type="filename",
         regex_search=True,
         **this_filter,
     )
@@ -166,11 +165,11 @@ def process_subject(cfg: Config, layout_out: BIDSLayout, subject_label: str) ->
     check_if_file_found(bf, this_filter, layout_out)
 
     for file in bf:
-        log.info(f"Processing file: {Path(file).name}")
+        log.info(f"Processing file: {Path(file.path).name}")
 
         print("\n")
-        generators = data_generator.create_generators([file], [file])
-        generators = (*generators, [file], [file])
+        generators = data_generator.create_generators([file.path], [file.path])
+        generators = (*generators, [file.path], [file.path])
         print("\n")
 
         opts = model_opts.get_opts()
@@ -200,7 +199,7 @@ def process_subject(cfg: Config, layout_out: BIDSLayout, subject_label: str) ->
             percentile_cut=80,
         )
 
-        create_confounds_tsv(layout_out, file, subject_label)
+        create_confounds_tsv(layout_out, file.path, subject_label)
 
 
 def generalize(cfg: Config) -> None:
diff --git a/bidsmreye/prepare_data.py b/bidsmreye/prepare_data.py
index bc983d9..3cba8ca 100644
--- a/bidsmreye/prepare_data.py
+++ b/bidsmreye/prepare_data.py
@@ -8,6 +8,7 @@
 
 import numpy as np
 from bids import BIDSLayout  # type: ignore
+from bids.layout import BIDSFile
 from deepmreye import preprocess
 
 from bidsmreye.bids_utils import (
@@ -131,7 +132,6 @@ def process_subject(
     this_filter = set_this_filter(cfg, subject_label, "bold")
 
     bf = layout_in.get(
-        return_type="filename",
         regex_search=True,
         **this_filter,
     )
@@ -143,12 +143,14 @@ def process_subject(
 
 
 def prepapre_image(
-    cfg: Config, layout_in: BIDSLayout, layout_out: BIDSLayout, img: str
+    cfg: Config, layout_in: BIDSLayout, layout_out: BIDSLayout, img: BIDSFile
 ) -> None:
     """Preprocess a single functional image."""
-    report_name = create_bidsname(layout_out, filename=img, filetype="report")
-    mask_name = create_bidsname(layout_out, filename=img, filetype="mask")
-    output_file = create_bidsname(layout_out, Path(img), "no_label")
+    img_path = img.path
+
+    report_name = create_bidsname(layout_out, filename=img_path, filetype="report")
+    mask_name = create_bidsname(layout_out, filename=img_path, filetype="mask")
+    output_file = create_bidsname(layout_out, Path(img_path), "no_label")
 
     if (
         not cfg.force
@@ -159,21 +161,23 @@ def prepapre_image(
         log.debug(
             "Output for the following file already exists. "
             "Use the '--force' option to overwrite. "
-            f"\n '{Path(img).name}'"
+            f"\n '{Path(img_path).name}'"
         )
         return
 
-    log.info(f"Processing file: {Path(img).name}")
+    log.info(f"Processing file: {Path(img_path).name}")
 
-    coregister_and_extract_data(img, non_linear_coreg=cfg.non_linear_coreg)
+    coregister_and_extract_data(img_path, non_linear_coreg=cfg.non_linear_coreg)
 
-    deepmreye_mask_report = get_deepmreye_filename(layout_in, img=img, filetype="report")
+    deepmreye_mask_report = get_deepmreye_filename(
+        layout_in, img=img_path, filetype="report"
+    )
     move_file(deepmreye_mask_report, report_name)
 
-    deepmreye_mask_name = get_deepmreye_filename(layout_in, img=img, filetype="mask")
+    deepmreye_mask_name = get_deepmreye_filename(layout_in, img=img_path, filetype="mask")
     move_file(deepmreye_mask_name, mask_name)
 
-    source = str(Path(img).relative_to(layout_in.root))
+    source = str(Path(img_path).relative_to(layout_in.root))
     save_sampling_frequency_to_json(layout_out, img=img, source=source)
 
     combine_data_with_empty_labels(layout_out, mask_name)
diff --git a/bidsmreye/quality_control.py b/bidsmreye/quality_control.py
index 5b22719..e8df3ea 100644
--- a/bidsmreye/quality_control.py
+++ b/bidsmreye/quality_control.py
@@ -218,7 +218,6 @@ def qc_subject(
     this_filter = set_this_filter(cfg, subject_label, "eyetrack")
 
     bf = layout_in.get(
-        return_type="filename",
         regex_search=True,
         **this_filter,
     )
@@ -226,7 +225,7 @@ def qc_subject(
     check_if_file_found(bf, this_filter, layout_in)
 
     for file in bf:
-        perform_quality_control(cfg, layout_in, file, layout_out)
+        perform_quality_control(cfg, layout_in, file.path, layout_out)
 
 
 def compute_robust_outliers(
diff --git a/bidsmreye/utils.py b/bidsmreye/utils.py
index be77500..4f66250 100644
--- a/bidsmreye/utils.py
+++ b/bidsmreye/utils.py
@@ -7,6 +7,7 @@
 from typing import Any
 
 from bids import BIDSLayout  # type: ignore
+from bids.layout import BIDSFile
 from rich.progress import (
     BarColumn,
     MofNCompleteColumn,
@@ -63,11 +64,13 @@ def add_sidecar_in_root(layout_out: BIDSLayout) -> None:
     json.dump(content, open(sidecar_name, "w"), indent=4)
 
 
-def check_if_file_found(bf: Any, this_filter: dict[str, Any], layout: BIDSLayout) -> None:
-    if len(bf) == 0:
+def check_if_file_found(
+    bf: list[BIDSFile], this_filter: dict[str, Any], layout: BIDSLayout
+) -> None:
+    if not bf:
         log.warning(f"No file found for filter {this_filter}")
     else:
-        to_print = [str(Path(x).relative_to(layout.root)) for x in bf]
+        to_print = [str(Path(x.path).relative_to(layout.root)) for x in bf]
         log.debug(f"Found files\n{to_print}")
 
 
diff --git a/bidsmreye/visualize.py b/bidsmreye/visualize.py
index c84a6eb..0f19271 100644
--- a/bidsmreye/visualize.py
+++ b/bidsmreye/visualize.py
@@ -54,7 +54,6 @@ def collect_group_qc_data(cfg: Config) -> pd.DataFrame | None:
     this_filter = set_this_filter(cfg, subjects, "eyetrack_qc")
 
     bf = layout.get(
-        return_type="filename",
         regex_search=True,
         **this_filter,
     )
@@ -63,15 +62,15 @@ def collect_group_qc_data(cfg: Config) -> pd.DataFrame | None:
 
     qc_data = None
     for i, file in enumerate(bf):
-        log.info(f"Processing file: {file}")
+        log.info(f"Processing file: {file.path}")
 
-        entities = layout.parse_file_entities(file)
+        entities = layout.parse_file_entities(file.path)
 
-        with open(file) as f:
+        with open(file.path) as f:
             data = json.loads(f.read())
 
         df = pd.json_normalize(data)
-        df["filename"] = Path(file).name
+        df["filename"] = Path(file.path).name
         df["subject"] = entities["subject"]
         qc_data = df if i == 0 else pd.concat([qc_data, df], sort=False)
 
diff --git a/pyproject.toml b/pyproject.toml
index 899b4ea..04fb59c 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -156,6 +156,7 @@ module = [
 ignore_missing_imports = true
 module = [
     'attrs.*',
+    'bids.layout.*',
     "bidsmreye._version",
     'chevron.*',
     'deepmreye.*',


Test patch:
diff --git a/tests/test_bids_utils.py b/tests/test_bids_utils.py
index c0eb310..900fd46 100644
--- a/tests/test_bids_utils.py
+++ b/tests/test_bids_utils.py
@@ -82,13 +82,12 @@ def test_save_sampling_frequency_to_json(data_dir, pybids_test_dataset):
     this_filter = set_this_filter(cfg, "01", "bold")
 
     bf = layout_in.get(
-        return_type="filename",
         regex_search=True,
         **this_filter,
     )
     source = "foo"
     save_sampling_frequency_to_json(layout_in, bf[0], source)
-    sidecar_name = create_bidsname(layout_in, bf[0], "confounds_json")
+    sidecar_name = create_bidsname(layout_in, bf[0].path, "confounds_json")
     with open(sidecar_name) as f:
         content = json.load(f)
     assert content["Sources"][0] == "foo"