Get subject, session from directory in heudiconv


I’m having some difficulty getting started with heudiconv. Unfortunately, I find the documentation a bit lacking, at least for someone like me not too familiar with python. At first, I expected the subject and sessions to be automatically extracted from the {subject} and {session} placeholders in the directory template, but that’s not the case. If I don’t want to supply them manually, I think I need to write a infotoids function, but I’m not sure if I have access to the input path to extract them, or how else to achieve this.

I saw in a heuristic example from another post:

allowed template fields - follow python string module:
item: index within category
subject: participant id
seqitem: run number during scanning
subindex: sub index within group

And elsewhere

Are these things documented somewhere? Or do I have to take the plunge and read the code?

Edit: I managed to get it working (with extra parsing before calling heudiconv). But there’s an inconsistency in how the sub- and ses- prefixes are treated. If I call for example:
heudiconv -d './{subject}/{session}/* -s 'A', -ss 'B' ...
Then I need (explicit sub-, but implicit ses-) in the conversion key:
To properly obtain: sub-A/ses-B/...