Location of code folder for sourcedata

I am not sure where the code folder is to be placed for a sourcedata (modality = fnirs).
I would assume that rawdata would be a derivative of the sourcedata and hence, the code to transform sourcedata to rawdata would be located in the rawdata folder.

I believe you are correct. For reference, this is the documentation: Modality agnostic files - Brain Imaging Data Structure v1.6.0-dev

So you would have some root directory and nested in there:

  • rawdata/
  • rawdata/code/
  • sourcedata
  • derivatives

where only rawdata and (optionally) derivatives are organized according to BIDS principles?

I usually do it as follows, which I believe is also valid:

The code to transform sourcedata to raw data is stored in ./code, like this - that is, I have a single root directory in which I nest code, derivatives, etc.

.
├── CHANGES
├── code/ <------------contains the code to go from sourcedata to bids data
├── dataset_description.json
├── derivatives/
├── LICENSE
├── participants.json
├── participants.tsv
├── README
├── sourcedata/
├── sub-01/
├── sub-02/
...