Skip to content

Commit

Permalink
version, empty metadata removal and \n removal in reference field
Browse files Browse the repository at this point in the history
  • Loading branch information
laemtl committed Sep 30, 2021
1 parent 60bc3d2 commit 91be7f2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
11 changes: 6 additions & 5 deletions python/eeg2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import json

# EEG2BIDS Wizard version
appVersion = '1.0.1'
appVersion = '1.0.4'

# LORIS credentials of user
lorisCredentials = {
Expand Down Expand Up @@ -124,8 +124,6 @@ def create_candidate_and_visit(sid, data):
data['site'],
)

print(new_candidate)

if new_candidate['CandID']:
print('create_visit')
loris_api.create_visit(new_candidate['CandID'], data['visit'], data['site'], data['project'],
Expand Down Expand Up @@ -215,10 +213,13 @@ def get_bids_metadata(sid, data):
with open(data['file_path']) as fd:
try:
metadata = json.load(fd)
diff = list(set(metadata.keys()) - set(metadata_fields[data['modality']]))
empty_values = [k for k in metadata if metadata[k].strip() == '']
diff = list(set(metadata.keys()) - set(metadata_fields[data['modality']]) - set(empty_values))
ignored_keys = empty_values + diff

response = {
'metadata': metadata,
'invalid_keys': diff,
'ignored_keys': ignored_keys,
}
except ValueError as e:
print(e)
Expand Down
10 changes: 4 additions & 6 deletions python/libs/Modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def modify_dataset_description_json(self):
with open(file_path, "r") as fp:
file_data = json.load(fp)
file_data['PreparedBy'] = self.data['preparedBy']
file_data['Eeg2bidsVersion'] = self.data['appVersion']

with open(file_path, "w") as fp:
json.dump(file_data, fp, indent=4)
Expand Down Expand Up @@ -157,9 +158,6 @@ def modify_participants_json(self):
},
'project': {
'Description': "Project of the participant"
},
'debug': {
'Version': self.data['appVersion']
}
}
json_data.update(user_data)
Expand Down Expand Up @@ -300,11 +298,11 @@ def modify_eeg_json(self):
else:
referenceField = 'EGGReference'

file_data[referenceField] = self.data['reference']
file_data[referenceField] = " ".join(self.data['reference'].split())

if 'metadata' in self.data['bidsMetadata'] and 'invalid_keys' in self.data['bidsMetadata']:
if 'metadata' in self.data['bidsMetadata'] and 'ignored_keys' in self.data['bidsMetadata']:
for key in self.data['bidsMetadata']['metadata']:
if key not in self.data['bidsMetadata']['invalid_keys']:
if key not in self.data['bidsMetadata']['ignored_keys']:
file_data[key] = self.data['bidsMetadata']['metadata'][key]

with open(file_path, "w") as fp:
Expand Down
16 changes: 8 additions & 8 deletions src/jsx/Configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ const Configuration = (props) => {

const validateRecordingParameters = () => {
const result = [];
let invalidKeyFound = false;
let ignoredKeyFound = false;

if (!appContext.getFromTask('bidsMetadata')) {
return formatWarning('No EEG Parameter metadata file selected');
Expand All @@ -620,18 +620,18 @@ const Configuration = (props) => {
}

const metadata = appContext.getFromTask('bidsMetadata')?.metadata;
const invalidKeys = appContext.getFromTask('bidsMetadata')?.invalid_keys;
const ignoredKeys = appContext.getFromTask('bidsMetadata')?.ignored_keys;

if (!metadata || !invalidKeys || metadata.length < 1) {
if (!metadata || !ignoredKeys || metadata.length < 1) {
return formatWarning(
'An error occured while processing ' +
'the recording parameters file selected.',
);
}

Object.keys(metadata).map((key) => {
if (invalidKeys.indexOf(key) > -1) {
invalidKeyFound = true;
if (ignoredKeys.indexOf(key) > -1) {
ignoredKeyFound = true;
result.push(
<div key={key}>
{formatWarning(`${key}: ${metadata[key]}`)}
Expand All @@ -649,12 +649,12 @@ const Configuration = (props) => {
}
});

if (invalidKeyFound) {
if (ignoredKeyFound) {
result.push(
<p key="message">
<span className='warning'>&#x26A0;</span>
Note: if invalid or extra parameters are found
in the .json file, they are ignored.
Note: invalid or extra parameters, as well as
parameters with empty values are ignored.
</p>,
);
}
Expand Down

0 comments on commit 91be7f2

Please sign in to comment.