-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start next stage #672
Start next stage #672
Conversation
5c6c205
to
0df0e53
Compare
0df0e53
to
7d94c0e
Compare
python/bids_import.py
Outdated
scan_data.to_df() | ||
for scan_data in bids_reader.bids_layout.get_collections('session', 'scans') | ||
]) | ||
visit_date = min(scans_data['acq_time']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case scans_data['acq_time'] would be not defined, you could use the get
function.
ex:
scans_data.get('acq_time', datetime.datetime.now())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure I would use time of upload as acq_time
here since a scan can be uploaded at a different date than the upload date. Might be best keeping the acquisition time as undef is that case instead of setting a default date. Unless I am misunderstanding your suggestion @xlecours?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oooh, reading further I am starting to guess that you need a visit date to start a visit. In that case, instead of guessing a date, I would return an error message to the user telling them that they need to provide acquisition dates in the proper BIDS file in order to start the visit. Would that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I makes perfect sense to have a date explicitly provided. I just don't know how it would work. Could it be grep'ed from the BIDS files?
(my original comment was intended to avoid a Python error when lokking for an undefined key)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is what is being done in line 210. I guess the date could also be inside a session level file? I have not looked at the BIDS session spec in a while but it could be feasible. @laemtl thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@laemtl I would tend to put the API config in the database_config file and modify the template file https://github.com/aces/Loris-MRI/blob/main/dicom-archive/database_config_template.py to keep all python related configs in the same file. It will also make the install easier.
Note: if we keep a separate file for the API config, it needs to be taken care of during the install process and a template needs to be provided.
It is a good option but we should probably rename that file then? loris_config? |
@laemtl agreed. Initially, it only contained database credentials but it is becoming more of a general config file now. Could be named |
5f1469e
to
0508917
Compare
43ab615
to
30b057c
Compare
30b057c
to
2390bd3
Compare
@cmadjar Ready. |
2ec26a7
to
0186020
Compare
35f0e49
to
e04c0eb
Compare
e04c0eb
to
0673182
Compare
Added the blocked label as it needs this PR to be merged on the LORIS side: aces/Loris#7479 |
""" | ||
|
||
# database connection | ||
db = Database(config_file.mysql, verbose) | ||
db.connect() | ||
|
||
# api connection | ||
api = Api(config_file.api, verbose) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a check should be added to check whether the api config was set in loris_config.py.
else: | ||
self.token = resp_json.get('token') | ||
except Exception: | ||
print("An error occured. Can't login.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested giving bad credentials and I do not have that error printed on the terminal and it does not exit either.
# stored in the Config module) | ||
visit_date = None | ||
if startvisit: | ||
scans_data = pd.concat([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I run the script with -n
option, I get the follow error originating from here:
warnings.warn("Derivative indexing was requested, but no valid "
Traceback (most recent call last):
File "/Users/cmadjar/Development/Github/loris-mri/python/bids_import.py", line 513, in <module>
main()
File "/Users/cmadjar/Development/Github/loris-mri/python/bids_import.py", line 82, in main
read_and_insert_bids(bids_dir, config_file, verbose, createcand, createvisit, startvisit)
File "/Users/cmadjar/Development/Github/loris-mri/python/bids_import.py", line 212, in read_and_insert_bids
scans_data = pd.concat([
File "/Users/cmadjar/Development/python_venv/python_intel_3.9.4/loris-mri-venv/lib/python3.9/site-packages/pandas/core/reshape/concat.py", line 285, in concat
op = _Concatenator(
File "/Users/cmadjar/Development/python_venv/python_intel_3.9.4/loris-mri-venv/lib/python3.9/site-packages/pandas/core/reshape/concat.py", line 342, in __init__
raise ValueError("No objects to concatenate")
ValueError: No objects to concatenate
This was due to the fact I did not have a scans.tsv in my dataset. Might be good to add a check before the if startvisit:
to check if proper BIDS files were present.
) | ||
|
||
if (resp.status_code and resp.status_code == 200): | ||
print("Next stage successfully started.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get Next stage successfully started.
but when I look at the information in the session table or the timepoint list module, it does not look like anything happened:
2171 167830 3 1 NULL V1 2 N Not Started NULL NULL NULL NULL NULL NULL NULL Y NULL NULL NULL 2021-10-22 10:14:17 - NULL NULL NULL NULL NULL N NULL NULL false NULL
2172 896706 3 1 NULL V1 2 N Not Started NULL NULL NULL NULL NULL NULL NULL Y NULL NULL NULL 2021-10-22 10:14:17 - NULL NULL NULL NULL NULL N NULL NULL false NULL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A successful response will return 204
as of aces/Loris@c7a83f7
This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 20 days. |
This PR adds support for a -n flag for bids_import to start the visit stage.
python3 bids_import.py -d '/test/' -p loris_config.py -csvn
This implementation uses a basic API class to make use of the next stage API endpoint (see #470)
An API config data is required in dicom-archive/.loris-mri/loris_config.py with the following content: