Skip to content

Commit

Permalink
ENH: when iEEG coordsys is Pixels, validate units to be pixels (#1189)
Browse files Browse the repository at this point in the history
closes #1148
  • Loading branch information
sappelhoff authored Feb 15, 2021
1 parent a02ccd8 commit 4c1be20
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
18 changes: 17 additions & 1 deletion bids-validator/tests/json.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,30 @@ describe('JSON', function() {
it('iEEG *_coordsystem.json files should have required key/value pairs', function() {
var jsonObj = {
iEEGCoordinateSystem: 'Pixels',
iEEGCoordinateUnits: 'mm',
iEEGCoordinateUnits: 'pixels',
}
jsonDict[ieeg_coordsystem_file.relativePath] = jsonObj
validate.JSON(ieeg_coordsystem_file, jsonDict, function(issues) {
assert(issues.length === 0)
})
})

it('If iEEG CoordinateSystem is "Pixels", then CoordinateUnits must be "pixels"', function() {
var jsonObj = {
iEEGCoordinateSystem: 'Pixels',
iEEGCoordinateUnits: 'mm',
}
jsonDict[ieeg_coordsystem_file.relativePath] = jsonObj
validate.JSON(ieeg_coordsystem_file, jsonDict, function(issues) {
assert(issues.length === 2)
assert(
issues[0].evidence ==
'.iEEGCoordinateUnits should be equal to one of the allowed values',
)
assert(issues[1].evidence == ' should match "then" schema')
})
})

it('iEEG *_coordsystem.json schema should require *Description if *Coordsystem is "Other"', function() {
var jsonObj = {
iEEGCoordinateSystem: 'Other',
Expand Down
20 changes: 19 additions & 1 deletion bids-validator/validators/json/schemas/coordsystem_ieeg.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"required": ["iEEGCoordinateSystem", "iEEGCoordinateUnits"],
"additionalProperties": false,
"allOf": [
{ "$ref": "#/dependency-definitions/if-iEEGCoordinateSystem-is-Other-then-Description-is-required" }
{ "$ref": "#/dependency-definitions/if-iEEGCoordinateSystem-is-Other-then-Description-is-required" },
{ "$ref": "#/dependency-definitions/if-iEEGCoordinateSystem-is-Pixels-then-iEEGCoordinateUnits-must-be-pixels" }

],
"dependency-definitions": {
"if-iEEGCoordinateSystem-is-Other-then-Description-is-required": {
Expand All @@ -27,6 +29,22 @@
"required": ["iEEGCoordinateSystem"]
},
"then": { "required": ["iEEGCoordinateSystemDescription"] }
},
"if-iEEGCoordinateSystem-is-Pixels-then-iEEGCoordinateUnits-must-be-pixels": {
"if": {
"type": "object",
"properties": {
"iEEGCoordinateSystem": { "const": "Pixels" }
},
"required": ["iEEGCoordinateSystem"]
},
"then": {
"type": "object",
"properties": {
"iEEGCoordinateUnits": { "type": "string", "enum": ["pixels"] }
},
"required": ["iEEGCoordinateUnits"]
}
}
}
}

0 comments on commit 4c1be20

Please sign in to comment.