Skip to content

Commit 0a0b659

Browse files
committed
FIX: Cordon off .dtseries.json contents
1 parent 48a9cd9 commit 0a0b659

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

niworkflows/interfaces/bids.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,24 @@ def _run_interface(self, runtime):
653653
}
654654
)
655655
if self._metadata:
656-
sidecar = Path(self._results["out_file"][0]).parent / (
657-
"%s.json" % _splitext(self._results["out_file"][0])[0]
658-
)
656+
out_file = self._results["out_file"][0]
657+
# 1.3.x hack
658+
# For dtseries, we have been generating weird non-BIDS JSON files.
659+
# We can safely keep producing them to avoid breaking derivatives, but
660+
# only the existing keys should keep going into them.
661+
if out_file.endswith(".dtseries.nii"):
662+
legacy_metadata = {}
663+
for key in ("grayordinates", "space", "surface", "surface_density", "volume"):
664+
if key in self._metadata:
665+
legacy_metadata[key] = self._metadata.pop(key)
666+
if legacy_metadata:
667+
sidecar = Path(self._results["out_file"][0]).parent / (
668+
"%s.json" % _splitext(self._results["out_file"][0])[0]
669+
)
670+
sidecar.write_text(dumps(legacy_metadata, sort_keys=True, indent=2))
671+
# The future: the extension is the first . and everything after
672+
out_path = Path(out_file)
673+
sidecar = out_path.parent / f"{out_path.name.split('.', 1)[0]}.json"
659674
sidecar.write_text(dumps(self._metadata, sort_keys=True, indent=2))
660675
self._results["out_meta"] = str(sidecar)
661676
return runtime

0 commit comments

Comments
 (0)