Closed mateuszpawlik closed 9 months ago
It's stated when you run:
$ bidscoin
usage: bidscoin [-h] [-l] [-p] [-i INSTALL [INSTALL ...]] [-u UNINSTALL [UNINSTALL ...]] [-d DOWNLOAD] [-t [TEST]] [-b BIDSMAPTEST]
[--tracking {yes,no,show}] [-v]
BIDScoin is a toolkit to convert and organize raw data-sets according to the Brain Imaging Data Structure (BIDS)
The basic workflow is to run these two tools:
$ bidsmapper sourcefolder bidsfolder # This produces a study bidsmap and launches a GUI
$ bidscoiner sourcefolder bidsfolder # This converts your data to BIDS according to the study bidsmap
Default settings and template bidsmaps are stored in the ".bidscoin" folder in your home directory (you can modify
them to your needs with any plain text editor)
It's also stated in the docs (at least in the latest), but that can always be improved of course. The path to the config is now defined like this (in __init__.py
):
# Create a BIDScoin user configuration directory if needed and load the BIDScoin user settings
configfile = Path.home()/'.bidscoin'/__version__/'config.toml'
templatefolder = configfile.parent/'templates'
I don't see an easy way to configure the path to the config :-p. Where would you like it? Note that the user specific templates are copied from the central install, so if you change it there then all your users will have that version (and they can modify it individually). Or what is your use case?
I guess I can add a few lines to check if home exists, otherwise use the central location
My use case is a fully containerized conversion pipeline. In Nextflow, the home is not mounted by default and that causes the problem. I can mount it, so you don't have to change anything. I simply wasn't aware of these changes and need to document that myself. Wasn't BIDScoin writing to code
directory before and is it still doing so?
It certainly writes to the code
directory, all the log are stored there (not ideal, but I want to keep that close to the data and then there is no alternative). In fact, you may perhaps like the new bidscoiner.tsv
file in there :-)
Also note that bidscoiner can now run in parallel. I don't know if you already did so in nextflow, but I guess that would lead to concurrency issues (e.g. multiple workers writing to the same participants.tsv
file)
I don't see ant tsv file. Which version introduce it? I'm using 4.2.1. I'm executing it for one participant in isolation.
No, it will be in the upcoming release. Since I plan to release it today or tomorrow, you have to be quick if you want to put something in :-)
Oh. Thanks a lot for this kind offer :-)
With config files, I usually see some priority lists, like config in your home, an env variable set to point to your config, config in /etc/...
, etc. python-gitlab has a nice example: https://python-gitlab.readthedocs.io/en/stable/cli-usage.html#configuration-files
But I don't want to push this one. I simply didn't want to mount the entire home in the container.
That's a good example, I can add a check for environment variable that contains the path to the configuration folder (but the folder needs to be writable)
That was easy :-), you can now use export BIDSCOIN_CONFIG=/writable/path/to/config.toml
if you like to use a different config file
I've seen other files in .bidscoin
directory. Is the change for the config file enough?
/home/mpawlik/.bidscoin/
├── 4.2.1
│ ├── config.toml
│ └── templates
│ ├── bidsmap_dccn.yaml
│ ├── bidsmap_sst.yaml
│ └── schema.json
└── 4.3.0
├── config.toml
├── templates
│ ├── bidsmap_bids2bids.yaml
│ ├── bidsmap_dccn.yaml
│ ├── bidsmap_sst.yaml
│ └── schema.json
└── usage
└── bidscoin_4a39a33d0ba0040bb243175c70854fa5.db
I think so, but I haven't tested it :-)
It seems the configuration consists of more files.
(venv) mpawlik@erdwolf:~/Remote/anc/anc-data-acquisition (main) $ echo $BIDSCOIN_CONFIG
/home/mpawlik/Remote/anc/anc-data-acquisition/assets/bidscoin_config.toml
(venv) mpawlik@erdwolf:~/Remote/anc/anc-data-acquisition (main) $ bidscoin -t assets/bidscoin_map.yaml
Creating BIDScoin configuration:
-> /home/mpawlik/.bidscoin/4.3.0/config.toml
-> /home/mpawlik/.bidscoin/4.3.0/templates/bidsmap_sst.yaml
-> /home/mpawlik/.bidscoin/4.3.0/templates/bidsmap_dccn.yaml
-> /home/mpawlik/.bidscoin/4.3.0/templates/bidscoin_map.yaml
-> /home/mpawlik/.bidscoin/4.3.0/templates/bidsmap_bids2bids.yaml
-> /home/mpawlik/.bidscoin/4.3.0/templates/schema.json
...
I don't like it but I could bind any host directory to $HOME
in the container. This should do the trick. Playing with env variables and container is not optimal but I could also pass that.
It seems the configuration consists of more files.
Yes, but they are all automatically stored in the same folder as the config file. I just tested it and fixed a minor bug (so it should now work)
$ export BIDSCOIN_CONFIG=~/tmp/config.toml
$ bidsmapper raw bids
$ tree ~/tmp
/home/marzwi/tmp
├── config.toml
├── templates
│ ├── bidsmap_bids2bids.yaml
│ ├── bidsmap_dccn.yaml
│ ├── bidsmap_sst.yaml
│ └── schema.json
└── usage
├── bidscoin_2feb5e843ccb54a41416f963a6c88a5d.bak
├── bidscoin_2feb5e843ccb54a41416f963a6c88a5d.dat
└── bidscoin_2feb5e843ccb54a41416f963a6c88a5d.dir
I installed the newest version with pip install --upgrade git+https://github.com/Donders-Institute/bidscoin.git@4f130416305c74d9f7884034e853b89fd6f32ad3
and unfortunately can't reproduce:
(venv) mpawlik@erdwolf:~/Remote/anc/anc-data-acquisition (main) $ echo $BIDSCOIN_CONFIG
/home/mpawlik/Remote/anc/anc-data-acquisition/assets/bidscoin_config.toml
(venv) mpawlik@erdwolf:~/Remote/anc/anc-data-acquisition (main) $ rm -r ~/.bidscoin/
rm: cannot remove '/home/mpawlik/.bidscoin/': No such file or directory
(venv) mpawlik@erdwolf:~/Remote/anc/anc-data-acquisition (main) $ bidscoin --version
Creating BIDScoin configuration:
-> /home/mpawlik/.bidscoin/4.3.0/config.toml
-> /home/mpawlik/.bidscoin/4.3.0/templates/bidsmap_sst.yaml
-> /home/mpawlik/.bidscoin/4.3.0/templates/bidsmap_dccn.yaml
-> /home/mpawlik/.bidscoin/4.3.0/templates/bidscoin_map.yaml
-> /home/mpawlik/.bidscoin/4.3.0/templates/bidsmap_bids2bids.yaml
-> /home/mpawlik/.bidscoin/4.3.0/templates/schema.json
BIDS-version: 1.9.0
BIDScoin-version: 4.3.0, NB: Your BIDScoin version is NOT up-to-date: 4.3.0 -> 4.2.1
(venv) mpawlik@erdwolf:~/Remote/anc/anc-data-acquisition (main) $ tree assets/
assets/
├── a003_bidscoin_map.yaml
├── bidscoin_config.toml
└── bidscoin_map.yaml
Despite the flag, that doesn't upgrade when installing from github (if the version nr doesn't change), try:
pip install --force-reinstall git+https://github.com/Donders-Institute/bidscoin
uninstall and install also didn't help.
generating man/bidscoin.1
Ah, that's due to a bug (not mine) when building manpages (see here) Remove that and it should work?
A fresh venv didn't help and gave the same error. I did:
(venv) mpawlik@erdwolf:~/Remote/anc/anc-data-acquisition (main) $ deactivate
mpawlik@erdwolf:~/Remote/anc/anc-data-acquisition (main) $ rm -rf venv/
mpawlik@erdwolf:~/Remote/anc/anc-data-acquisition (main) $ python3 -m venv venv
mpawlik@erdwolf:~/Remote/anc/anc-data-acquisition (main) $ source venv/bin/activate
(venv) mpawlik@erdwolf:~/Remote/anc/anc-data-acquisition (main) $ pip install git+https://github.com/Donders-Institute/bidscoin
I can't figure out where are the man pages. This is what I should delete, right?
Any of these?
$ man -w
/usr/local/man:/usr/local/share/man:/usr/share/man
Yeah, that's not my expertise either, I think it also depends on your distro. In my case they where build in the cwd (CentOS) or somewhere in my venv (OpenSuse). What if you do:
$ find -name bidscoin.1
I don't find it anywhere in my home :-( Neither /usr/local/
nor /usr/share/
I tried previous commits and pip install git+https://github.com/Donders-Institute/bidscoin.git@8ed9a53ce2202d2ef7520a84eb6642d4e519e91c
succeeds without deleting any man pages, which I cannot find anywhere.
I don't think it's the ma pages issue here. Here's why installing the newest commits is failing:
684e29367c4e1eeb786a14e1ecc8557397283457
File "./bidscoin/__init__.py", line 66, in <module>
templatefolder = configfile.parent/'templates'
AttributeError: 'str' object has no attribute 'parent'
89fb79644327e7876f100a0ef97d276d477d59c1
File "./bidscoin/__init__.py", line 66, in <module>
templatefolder = configfile.parent/'templates'
AttributeError: 'str' object has no attribute 'parent'
4f130416305c74d9f7884034e853b89fd6f32ad3 (newest)
File "./bidscoin/__init__.py", line 79, in <module>
bidsmap_template = Path(config['bidscoin']['bidsmap_template'])
KeyError: 'bidscoin'
And this is because my config file pointed by BIDSCOIN_CONFIG
env variable was empty and therefore KeyError: 'bidscoin'
. It is weird that this error is triggered when installing bidscoin. After filling in my config file, it installs.
AttributeError: 'str' object has no attribute 'parent'
Yes, I saw and fixed that
https://github.com/Donders-Institute/bidscoin/commit/4f130416305c74d9f7884034e853b89fd6f32ad3 (newest)
That bidscoin
key is written in the config.toml
file, could it be that writing the config.toml
file failed?
Ah, you set an empty path, yes, that probably fails. Try unset BIDSCOIN_CONFIG
No, my config.toml
file was empty and therefore the key could not be found in it. Once I added content to my config.toml
file, bidscoin installed. I don't know what happens during installation but the bidscoin code is executed.
I have no idea what happened, but I now added some extra robustness to the code. I hope that solves it :-/
No, my
config.toml
file was empty and therefore the key could not be found in it. Once I added content to myconfig.toml
file, bidscoin installed. I don't know what happens during installation but the bidscoin code is executed.
I'm getting more errors now, like:
$ bidscoin --version
/home/mpawlik/Remote/anc/anc-data-acquisition/venv/lib/python3.9/site-packages/bidscoin/__init__.py:81: RuntimeWarning: Missing template bidsmap: /home/mpawlik/.bidscoin/4.3.0/templates/bidsmap_dccn.yaml (see /home/mpawlik/Remote/anc/anc-data-acquisition/assets/bidscoin_config.toml)
warnings.warn(f"Missing template bidsmap: {bidsmap_template} (see {configfile})", RuntimeWarning)
It still expects files in my home. But the installation copied the template files to the parent directory of BIDSCOIN_CONFIG
. It seems that you copy these files during the installation but later expect the path in home.
I'm sorry for causing all this trouble and thank you for taking care of that so quickly.
No, thanks for testing this, I really appreciate it. I'll have a look
I'm wandering why do you need to copy all these files. The config file should be enough to configure bidscoin. If more files are necessary, how about add their paths to the config file instead of copying them.
In the center where I work, there is a single bidscoin installation that all users share. Copying the default templates to every user's home allows them to edit the default templates to their needs
It seems that you copy these files during the installation but later expect the path in home.
Only if BIDSCOIN_CONFIG
is unset / empty?
When BIDSCOIN_CONFIG
was set before the installation, the template files were copied to the parent directory of the file pointed by BIDSCOIN_CONFIG
. However, errors occurred when executing bidscoin https://github.com/Donders-Institute/bidscoin/issues/226#issuecomment-1941957820
When BIDSCOIN_CONFIG
was NOT set before the installation, the installation created ~/.bidscoin
directory with all the files.
So in my container use case (Apptainer), bidscoin installation in the image created /root/.bidscoin/4.2.1/
) directory with all the files. However, when executed (even with --no-home
), bidscoin expects the files in my home. Shouldn't bidscoin internally use the path where it copies the files to, instead of $HOME
?
Another weird thing is that I get these errors with dicomsort
, which does not rely on .bidscoin
directory.
I'm also confused now. For bidsmapper, should I use the config file to set my custom map file, or the --template
option? What's the priority here?
Just to make sure your expectations are in line, using the environment variable is not permanent, bidscoin only uses that config file when the variable is non-empty, otherwise it will use the default
Another weird thing is that I get these errors with dicomsort, which does not rely on .bidscoin directory.
Perhaps that's a bug, let me check
bidscoin installation in the image created /root/.bidscoin/4.2.1/) directory with all the files.
These file are only created when bidscoin is imported (it is all done in __init__.py
), i.e. when a bidscoin function is run. The pip installation itself really should not create anything? Running apptainer should be no problem if you pass the BIDSCOIN_CONFIG every time you run a bidscoin function
Do you get the same issue if you don't use apptainer?
bidscoin installation in the image created /root/.bidscoin/4.2.1/) directory with all the files.
These file are only created when bidscoin is imported (it is all done in
__init__.py
), i.e. when a bidscoin function is run. The pip installation itself really should not create anything? Running apptainer should be no problem if you pass the BIDSCOIN_CONFIG every time you run a bidscoin function
But it does :thinking:
Bidscoin in Apptainer certainly doesn't remember where it saved the files. It keeps recreating .bidscoin
directory if home is not mounted in. But it tries to do that in $HOME
and errors out. I solved it with --scratch $HOME
Apptainer option.
Relevant Apptainer issue: https://github.com/apptainer/apptainer/issues/388
Do you get the same issue if you don't use apptainer?
Is https://github.com/Donders-Institute/bidscoin/issues/226#issuecomment-1941995188 an answer?
But it does 🤔
Ah, I think building the manpages imports bidscoin, that's when it saves the config file
Nevertheless, it shouldn't matter, you can have multiple locations where config files are stored. As long as there is nothing in the environment, then the home directory is used, otherwise the location from the environment variable is used. Perhaps there is a weird interaction somewhere that I don't see, but otherwise I don't see how this doesn't work. I'll test a bit more.
It seems that my problems were triggered mainly by Apptainer and the hard-coded path to store .bidscoin
directory.
I'll try to summarize a bit.
It seems to work as intended now. Template files are copied to the parent of BIDSCOIN_CONFIG
.
I fix it with --scratch $HOME
when Apptainer is executed with --no-home
, because bidscoin keeps looking up $HOME
although it isn't mounted.
Adding --env BIDSCOIN_CONFIG=/root/.bidscoin/4.3.0/config.toml
to Apptainer command should help, because bidscoin doesn't know where is .bidscoin
without BIDSCOIN_CONFIG
set. If it is not set, bidscoin expects .bidscoin
in HOME
, which for installation in Apptainer is not true (HOME
always points to host home).
If config.toml
needs to be overwritten, it can be mounted additionally (--bind /path/to/my/config.toml:/root/.bidscoin/4.3.0/config.toml
). If BIDSCOIN_CONFIG
is set to something else than /root/.bidscoin/4.3.0/config.toml
, the parent directory has to be mounted.
I should not need to set BIDSCOIN_CONFIG
and care about the .bidscoin
directory, especially if I use bidsmapper
with --template
option. The config file only sets this template file and the tracking. Usually, I can set the options in a config file, or provide them with CLI, with some priorities. Bidscoin could remember where it created .bidscoin
directory, whether BIDSCOIN_CONFIG
is set or not. Then, it could preset the options from the config file in there, and optionally overwrite them with values provided with CLI. This would make the behavior consistent.
Inside of the container
version 4.2.1
I fix it with
--scratch $HOME
when Apptainer is executed with--no-home
, because bidscoin keeps looking up$HOME
although it isn't mounted.
Ok, that's not good, I will make a fallback-fix for this (in $TMPDIR
?)
current master version (cd409e1)
Adding
--env BIDSCOIN_CONFIG=/root/.bidscoin/4.3.0/config.toml
to Apptainer command should help, because bidscoin doesn't know where is.bidscoin
withoutBIDSCOIN_CONFIG
set.
So you pass a config file, that should work, but pointing it to /root
puzzles me.
If it is not set, bidscoin expects
.bidscoin
inHOME
, which for installation in Apptainer is not true (HOME
always points to host home).
If it's not set, then bidscoin will create it in home, but I'll make that fallback-fix that should cover this
If
config.toml
needs to be overwritten, it can be mounted additionally (--bind /path/to/my/config.toml:/root/.bidscoin/4.3.0/config.toml
). IfBIDSCOIN_CONFIG
is set to something else than/root/.bidscoin/4.3.0/config.toml
, the parent directory has to be mounted.
Sorry, I'm not that used to working with containers, but I don't see why you have to bind that root path? Isn't passing --env BIDSCOIN_CONFIG=/some/mounted/folder/bidscoin/config.toml
sufficient?
In general
I should not need to set
BIDSCOIN_CONFIG
and care about the.bidscoin
directory, especially if I usebidsmapper
with--template
option. The config file only sets this template file and the tracking.
I agree that the config folder shouldn't be a user concern and I'm surely open for suggestions to improve things here..
Usually, I can set the options in a config file, or provide them with CLI, with some priorities.
Well, that sounds great but on the other hand, it is also very common for applications to simply keep their settings in a hidden file or directory in home (e.g. dcm2niix).
Bidscoin could remember where it created
.bidscoin
directory, whetherBIDSCOIN_CONFIG
is set or not.
I don't see how bidscoin can remember that without storing it somewhere on disk. Which is what the config file is
Then, it could preset the options from the config file in there, and optionally overwrite them with values provided with CLI. This would make the behavior consistent.
Currently I don't provide a tool or CLI options for editing/overruling the config file, the user needs to do that him/herself using a text editor (which is very easy and works very well). The behaviour should consistently be: Use the default config (in home or /tmp) or use the config specified in the environment variable.
Do you perhaps know what Path.home()
returns in an apptainer that runs without $HOME?
Do you perhaps know what Path.home() returns in an apptainer that runs without $HOME?
Never mind, I found the answer. The problem I have is that tempfile.gettempdir() doesn't necessarily return a usable result...
If your container has a tempdir (doesn't it?) then I hope my last commit works as expected...
I just tested it in my own apptainer and there things now work (latest version from github) without setting any environment variable. So I guess that settles it, or?
General summary I've just realized that the newer BIDScoin hard-codes the path to
.bidscoin
directory to reside in home. What if I don't want it there?Additional detail I came across that when executing BIDScoin (dicomsort tool) in a container without home mounted.
Next steps It's not up to me. Maybe at least an option to configure that? If not, make it more visible in the documentation?