add_volume_timing.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. % Adds a volume timing metadata to the json for each vaso file
  2. %
  3. % requires bids-matlab: https://github.com/bids-standard/bids-matlab
  4. %
  5. % The 5.16 for the repetition time in the JSON file refers to the average.
  6. % The TRs from the oscilloscope were 5.1002 and 5.1999 respectively.
  7. % NOTE:
  8. % For the first 10 TRs, the scanner was a bit slower (0.0025s).
  9. % But I think we can ignore that. One would think that a "realtime system" is more accurate
  10. clear;
  11. root_dir = fullfile(fileparts(mfilename('fullpath')), '..');
  12. % this is hard coded here
  13. % but obviously would have to be adapted dynamically to each file
  14. TRs = [5.1002; 5.1999];
  15. nb_volumes = 200;
  16. %%
  17. BIDS = bids.layout(root_dir, 'use_schema', false);
  18. all_files = bids.query(BIDS, 'data', 'suffix', 'vaso');
  19. all_metadata = bids.query(BIDS, 'metadata', 'suffix', 'vaso');
  20. for i = 1:numel(all_files)
  21. bf = bids.File(all_files{i});
  22. if numel(all_metadata) > 1
  23. metadata = all_metadata{i};
  24. else
  25. metadata = all_metadata;
  26. end
  27. AcquisitionDuration = repmat(TRs, nb_volumes / numel(TRs), 1);
  28. metadata.VolumeTiming = cumsum([0 ; AcquisitionDuration(1:end-1)]);
  29. metadata.AcquisitionDuration = AcquisitionDuration;
  30. output_file = fullfile(BIDS.pth, ...
  31. bf.bids_path, ...
  32. 'func', ...
  33. bf.json_filename);
  34. bids.util.jsonencode(output_file, metadata);
  35. end