Skip to content
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

[WIP] Attempt on validator #15

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/plot_validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os.path as op

from mne_bids.validator import validate_meg

# test an _meg.json file:
json_fname = op.join('.', 'sub-01_task-audiovisual_meg.json')

validate_meg(json_fname)

# test an _fid.json file:
json_fname = op.join('.', 'sub-testme01_meg_fid.json')

validate_meg(json_fname)
26 changes: 26 additions & 0 deletions examples/sub-01_task-audiovisual_meg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"TaskName": "audiovisual",
"SamplingFrequency": 600.614990234,
"Manufacturer": "Elekta",
"ManufacturerModelName": "Neuromag Vectorview 306",
"TaskDescription": "In this experiment, checkerboard patterns were presented to the subject into the left and right visual field, interspersed by tones to the left or right ear. The interval between the stimuli was 750 ms. Occasionally a smiley face was presented at the center of the visual field. The subject was asked to press a key with the right index finger as soon as possible after the appearance of the face.",
"MEGChannelCount": 306,
"MEGREFChannelCount": 0,
"EEGChannelCount": 60,
"EOGChannelCount": 1,
"ECGChannelCount": 0,
"EMGChannelCount": 0,
"MiscChannelCount": 0,
"TriggerChannelCount": 9,
"PowerLineFrequency": 60,
"HLCFrequency": [],
"EEGReference": "nose",
"MEGPosition": "upright",
"OnlineFilters": "0.10000000149 Hz high-pass, 172.176300049 Hz low-pass",
"RecordingType": "continuous",
"EyesClosed": "false",
"ContinuousHeadLocalization": "false",
"DigitizedLandmarks": "true",
"DigitizedHeadPoints": "true",
"SubjectArtefactDescription": "false"
}
24 changes: 24 additions & 0 deletions examples/sub-testme01_meg_fid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"MEGCoordinateSystem": "not_empty",
"MEGCoordinateUnits": "not_empty",
"MEGCoordinateSystemDescription": "",
"EEGCoordinateSystem": "not_empty",
"EEGCoordinateUnits": "not_empty",
"EEGCoordinateSystemDescription": "",
"IntendedFor": "not_empty",
"AnatomicalMRICoordinateSystem": "not_empty",
"AnatomicalMRICoordinateUnits": "not_empty",
"AnatomicalMRICoordinateSystemDescription": "",
"CoilCoordinates": "not_empty",
"CoilCoordinateSystem": "not_empty",
"CoilCoordinateUnits": "not_empty",
"CoilCoordinateSystemDescription": "",
"LandmarkCoordinates": "not_empty",
"LandmarkCoordinateSystem": "not_empty",
"LandmarkCoordinateUnits": "not_empty",
"LandmarkCoordinateSystemDescription": "",
"DigitizedHeadPoints": "",
"DigitizedHeadPointsCoordinateSystem": "",
"DigitizedHeadPointsCoordinateUnits": "",
"DigitizedHeadPointsCoordinateSystemDescription": ""
}
50 changes: 50 additions & 0 deletions mne_bids/jsonschemas/schema_meg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"type": "object",
"properties": {
"TaskName": {"type": "string","minLength": 1},
"Manufacturer": {"type": "string","minLength": 1},
"ManufacturerModelName": {"type": "string"},
"TaskDescription": {"type": "string"},
"Instructions": {"type": "string"},
"SamplingFrequency": {"type": "number"},
"CogAtlasID": {"type": "string"},
"CogPOID": {"type": "string"},
"InstitutionName": {"type": "string"},
"InstitutionAddress": {"type": "string"},
"DeviceSerialNumber": {"type": "string"},
"MEGChannelCount": {"type": "integer"},
"MEGREFChannelCount": {"type": "integer"},
"EEGChannelCount": {"type" : "integer"},
"EOGChannelCount": {"type" : "integer"},
"ECGChannelCount": {"type" : "integer"},
"EMGChannelCount": {"type" : "integer"},
"MiscChannelCount": {"type" : "integer"},
"TriggerChannelCount": {"type" : "integer"},
"PowerLineFrequency": {"type" : "number"},
"EEGPlacementScheme": {"type" : "string"},
"EEGReference": {"type" : "string"},
"DewarPosition": {"type" : "string"},
"SoftwareFilters": {"type" : "string"},
"RecordingDuration": {"type" : "number"},
"RecordingType": {"type" : "string"},
"EpochLength": {"type" : ["number","string"]},
"DeviceSoftwareVersion": {"type" : "string"},
"ContinuousHeadLocalization": {"type" : "string"},
"CoilFrequency": {"type" : "number"},
"MaxMovement": {"type" : "number"},
"SubjectArtefactDescription": {"type" : "string"},
"DigitizedLandmarks": {"type" : "string"},
"DigitizedHeadPoints": {"type" : "string"}
},
"required": [ "TaskName",
"Manufacturer",
"SamplingFrequency",
"MEGChannelCount",
"MEGREFChannelCount",
"EEGChannelCount",
"EOGChannelCount",
"ECGChannelCount",
"EMGChannelCount",
"MiscChannelCount",
"TriggerChannelCount"]
}
41 changes: 41 additions & 0 deletions mne_bids/jsonschemas/schema_meg_fid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"type": "object",
"properties": {
"MEGCoordinateSystem": {"type": "string","minLength": 1},
"MEGCoordinateUnits": {"type": "string","minLength": 1},
"MEGCoordinateSystemDescription": {"type": "string"},
"EEGCoordinateSystem": {"type": "string","minLength": 1},
"EEGCoordinateUnits": {"type": "string","minLength": 1},
"EEGCoordinateSystemDescription": {"type": "string"},
"IntendedFor": {"type": "string","minLength": 1},
"AnatomicalMRICoordinateSystem": {"type": "string","minLength": 1},
"AnatomicalMRICoordinateUnits": {"type": "string","minLength": 1},
"AnatomicalMRICoordinateSystemDescription": {"type": "string"},
"CoilCoordinates": {"type": "string","minLength": 1},
"CoilCoordinateSystem": {"type": "string","minLength": 1},
"CoilCoordinateUnits": {"type": "string","minLength": 1},
"CoilCoordinateSystemDescription": {"type": "string"},
"LandmarkCoordinates": {"type": "string","minLength": 1},
"LandmarkCoordinateSystem": {"type": "string","minLength": 1},
"LandmarkCoordinateUnits": {"type": "string","minLength": 1},
"LandmarkCoordinateSystemDescription": {"type": "string"},
"DigitizedHeadPoints": {"type": "string"},
"DigitizedHeadPointsCoordinateSystem": {"type": "string"},
"DigitizedHeadPointsCoordinateUnits": {"type": "string"},
"DigitizedHeadPointsCoordinateSystemDescription": {"type": "string"}
},
"required": ["MEGCoordinateSystem",
"MEGCoordinateUnits",
"EEGCoordinateSystem",
"EEGCoordinateUnits",
"IntendedFor",
"AnatomicalMRICoordinateSystem",
"AnatomicalMRICoordinateUnits",
"CoilCoordinates",
"CoilCoordinateSystem",
"CoilCoordinateUnits",
"LandmarkCoordinates",
"LandmarkCoordinateSystem",
"LandmarkCoordinateUnits"
]
}
27 changes: 27 additions & 0 deletions mne_bids/validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os.path as op
import inspect

import json
from jsonschema import validate

FILE = inspect.getfile(inspect.currentframe())
base_dir = op.join(op.dirname(op.abspath(FILE)), 'jsonschemas')


def validate_meg(fname):
# get the correct schema
if fname.endswith('_meg.json'):
schema_fname = 'schema_meg.json'
elif fname.endswith('_fid.json'):
schema_fname = 'schema_meg_fid.json'

# open the schema
with open(op.join(base_dir, schema_fname)) as json_data:
schema = json.load(json_data)

# open the BIDS json file to validate
with open(fname) as json_data:
test_json = json.load(json_data)

# validate it
validate(test_json, schema)