From 4c1be20980b1215d45aee5e595b62c14bf2604e2 Mon Sep 17 00:00:00 2001 From: Stefan Appelhoff Date: Mon, 15 Feb 2021 17:41:22 +0100 Subject: [PATCH] ENH: when iEEG coordsys is Pixels, validate units to be pixels (#1189) closes #1148 --- bids-validator/tests/json.spec.js | 18 ++++++++++++++++- .../json/schemas/coordsystem_ieeg.json | 20 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/bids-validator/tests/json.spec.js b/bids-validator/tests/json.spec.js index 1e8158cad..608c1bac0 100644 --- a/bids-validator/tests/json.spec.js +++ b/bids-validator/tests/json.spec.js @@ -284,7 +284,7 @@ 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) { @@ -292,6 +292,22 @@ describe('JSON', function() { }) }) + 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', diff --git a/bids-validator/validators/json/schemas/coordsystem_ieeg.json b/bids-validator/validators/json/schemas/coordsystem_ieeg.json index 824327fbb..45bc4cf2a 100644 --- a/bids-validator/validators/json/schemas/coordsystem_ieeg.json +++ b/bids-validator/validators/json/schemas/coordsystem_ieeg.json @@ -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": { @@ -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"] + } } } }