From 014a57db1ada537a82039e8a30c4139571df7e77 Mon Sep 17 00:00:00 2001 From: Kay Robbins <1189050+VisLab@users.noreply.github.com> Date: Mon, 6 May 2024 08:29:12 -0500 Subject: [PATCH 1/3] Added struct to get_temporal_obj --- hedmat/hed_wrappers/get_tabular_obj.m | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hedmat/hed_wrappers/get_tabular_obj.m b/hedmat/hed_wrappers/get_tabular_obj.m index e568974..e51897f 100644 --- a/hedmat/hed_wrappers/get_tabular_obj.m +++ b/hedmat/hed_wrappers/get_tabular_obj.m @@ -1,9 +1,10 @@ -function tabular_obj = get_tabular_obj(events, sidecar) +function tabular_obj = get_tabular_obj(events, sidecar, sampling_rate) % Returns a HED TabularInput object representing events or other columnar item. % % Parameters: % events - string, struct, or TabularInput for tabular data. % sidecar - Sidecar object, string, or struct or py.None +% sampling_rate - optional sampling rate if struct doesn't have onset % % Returns: % tabular_obj - HEDTools TabularInput object representing tabular data. @@ -19,7 +20,13 @@ else sidecar_obj = get_sidecar_obj(sidecar); end - if ischar(events) || isstring(events) + if nargin == 1 + sampling_rate = NaN; + end + if isstruct(events) + events = struct2string(rectify_events(events, sampling_rate)); + tabular_obj = umod.str_to_tabular(events, sidecar_obj); + elseif ischar(events) || isstring(events) tabular_obj = umod.str_to_tabular(events, sidecar_obj); else throw(MException('getTabularInput:Invalid input')) From f8200d1d083f637345867c456987e7e4c86e36b8 Mon Sep 17 00:00:00 2001 From: Kay Robbins <1189050+VisLab@users.noreply.github.com> Date: Wed, 8 May 2024 21:20:09 -0500 Subject: [PATCH 2/3] minor updates to directory structure --- tests/test_hed_wrappers/TestGetHedFactor.m | 2 +- tests/test_hed_wrappers/TestGetStringObjs.m | 2 +- tests/test_hed_wrappers/TestGetTabularObj.m | 2 +- tests/test_hed_wrappers/TestValidateEvents.m | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_hed_wrappers/TestGetHedFactor.m b/tests/test_hed_wrappers/TestGetHedFactor.m index c332038..120bcfe 100644 --- a/tests/test_hed_wrappers/TestGetHedFactor.m +++ b/tests/test_hed_wrappers/TestGetHedFactor.m @@ -16,7 +16,7 @@ function importPythonModules(testCase) json_path = fullfile(data_path, filesep, ... 'task-FacePerception_events.json'); events_path = fullfile(data_path, filesep, 'sub-002', ... - filesep, 'ses-1', filesep, 'EEG', filesep,... + filesep, 'ses-1', filesep, 'eeg', filesep,... 'sub-002_ses-1_task-FacePerception_run-1_events.tsv'); events = fileread(events_path); sidecar = fileread(json_path); diff --git a/tests/test_hed_wrappers/TestGetStringObjs.m b/tests/test_hed_wrappers/TestGetStringObjs.m index 70ef475..0617f66 100644 --- a/tests/test_hed_wrappers/TestGetStringObjs.m +++ b/tests/test_hed_wrappers/TestGetStringObjs.m @@ -19,7 +19,7 @@ function importPythonModules(testCase) json_path = fullfile(data_path, filesep, ... 'task-FacePerception_events.json'); events_path = fullfile(data_path, filesep, 'sub-002', ... - filesep, 'ses-1', filesep, 'EEG', filesep,... + filesep, 'ses-1', filesep, 'eeg', filesep,... 'sub-002_ses-1_task-FacePerception_run-1_events.tsv'); events = fileread(events_path); sidecar = fileread(json_path); diff --git a/tests/test_hed_wrappers/TestGetTabularObj.m b/tests/test_hed_wrappers/TestGetTabularObj.m index 636b536..25569b4 100644 --- a/tests/test_hed_wrappers/TestGetTabularObj.m +++ b/tests/test_hed_wrappers/TestGetTabularObj.m @@ -16,7 +16,7 @@ function importPythonModules(testCase) testCase.json_path = fullfile(data_path, filesep, ... 'task-FacePerception_events.json'); testCase.events_path = fullfile(data_path, filesep, 'sub-002', ... - filesep, 'ses-1', filesep, 'EEG', filesep,... + filesep, 'ses-1', filesep, 'eeg', filesep,... 'sub-002_ses-1_task-FacePerception_run-1_events.tsv'); end end diff --git a/tests/test_hed_wrappers/TestValidateEvents.m b/tests/test_hed_wrappers/TestValidateEvents.m index b08668f..91a1dc7 100644 --- a/tests/test_hed_wrappers/TestValidateEvents.m +++ b/tests/test_hed_wrappers/TestValidateEvents.m @@ -23,7 +23,7 @@ function importPythonModules(testCase) testCase.bad_sidecar = testCase.hmod.Sidecar(bpath); epath = fullfile(data_path, ... filesep, 'eeg_ds003645s_hed_demo', filesep, 'sub-002', ... - filesep, 'ses-1', filesep, 'EEG', filesep,... + filesep, 'ses-1', filesep, 'eeg', filesep,... 'sub-002_ses-1_task-FacePerception_run-1_events.tsv'); testCase.event_string = fileread(epath); From cf93d34fccec8aee444594640122405de217bb39 Mon Sep 17 00:00:00 2001 From: Kay Robbins <1189050+VisLab@users.noreply.github.com> Date: Tue, 14 May 2024 12:58:36 -0500 Subject: [PATCH 3/3] Updated the tests for the matlab --- hedmat/hed_wrappers/get_schema_obj.m | 15 +++++++-------- hedmat/hed_wrappers/get_string_objs.m | 6 +++--- hedmat/hed_wrappers/validate_bids.m | 5 +++-- tests/test_hed_wrappers/TestGetHedFactor.m | 3 +-- tests/test_hed_wrappers/TestGetSchemaObj.m | 12 ++++++++++-- tests/test_hed_wrappers/TestGetStringObjs.m | 3 +-- tests/test_hed_wrappers/TestValidateBids.m | 2 -- 7 files changed, 25 insertions(+), 21 deletions(-) diff --git a/hedmat/hed_wrappers/get_schema_obj.m b/hedmat/hed_wrappers/get_schema_obj.m index 447d20f..66ff974 100644 --- a/hedmat/hed_wrappers/get_schema_obj.m +++ b/hedmat/hed_wrappers/get_schema_obj.m @@ -8,15 +8,14 @@ % Returns: % schema_obj - A hedSchema object % - hedModule = py.importlib.import_module('hed'); - - if py.isinstance(schema, hedModule.HedSchema) || ... - py.isinstance(schema, hedModule.HedSchemaGroup) - schema_obj = schema; - elseif ischar(schema) - schema_obj = hedModule.schema.load_schema_version(schema); + hmod = py.importlib.import_module('hed'); + if ischar(schema) + schema_obj = hmod.load_schema_version(schema); elseif iscell(schema) - schema_obj = hedModule.schema.load_schema_version(py.list(schema)); + schema_obj = hmod.load_schema_version(py.list(schema)); + elseif py.isinstance(schema, hmod.HedSchema) || ... + py.isinstance(schema, hmod.HedSchemaGroup) + schema_obj = schema; else schema_obj = py.None; end \ No newline at end of file diff --git a/hedmat/hed_wrappers/get_string_objs.m b/hedmat/hed_wrappers/get_string_objs.m index 4348846..1d34ea1 100644 --- a/hedmat/hed_wrappers/get_string_objs.m +++ b/hedmat/hed_wrappers/get_string_objs.m @@ -16,9 +16,9 @@ % To manipulate directly in MATLAB -- convert to a cell array of char % using string(cell(hedObjs)) - amod = py.importlib.import_module('hed.tools.analysis'); - event_manager = amod.event_manager.EventManager(events, schema); - tag_manager = amod.hed_tag_manager.HedTagManager(event_manager, ... + hmod = py.importlib.import_module('hed'); + event_manager = hmod.EventManager(events, schema); + tag_manager = hmod.HedTagManager(event_manager, ... py.list(remove_types)); hed_string_objs = ... tag_manager.get_hed_objs(include_context, replace_defs); diff --git a/hedmat/hed_wrappers/validate_bids.m b/hedmat/hed_wrappers/validate_bids.m index acf2fb9..4354c6a 100644 --- a/hedmat/hed_wrappers/validate_bids.m +++ b/hedmat/hed_wrappers/validate_bids.m @@ -8,7 +8,8 @@ % issue_string - A string with the validation issues suitable for % printing (has newlines). % - py.importlib.import_module('hed'); - bids = py.hed.tools.BidsDataset(data_root); + hed = py.importlib.import_module('hed') + % amod = py.importlib.import_module('hed.tools.analysis.annotation_util'); + bids = hed.get_bids_dataset(data_root); issues = bids.validate(); issue_string = string(py.hed.get_printable_issue_string(issues)); diff --git a/tests/test_hed_wrappers/TestGetHedFactor.m b/tests/test_hed_wrappers/TestGetHedFactor.m index 120bcfe..12a52b4 100644 --- a/tests/test_hed_wrappers/TestGetHedFactor.m +++ b/tests/test_hed_wrappers/TestGetHedFactor.m @@ -21,8 +21,7 @@ function importPythonModules(testCase) events = fileread(events_path); sidecar = fileread(json_path); testCase.tabular_obj = get_tabular_obj(events, sidecar); - testCase.schema = ... - testCase.hmod.schema.load_schema_version('8.2.0'); + testCase.schema = testCase.hmod.load_schema_version('8.2.0'); end end diff --git a/tests/test_hed_wrappers/TestGetSchemaObj.m b/tests/test_hed_wrappers/TestGetSchemaObj.m index 86485d3..5e388e3 100644 --- a/tests/test_hed_wrappers/TestGetSchemaObj.m +++ b/tests/test_hed_wrappers/TestGetSchemaObj.m @@ -11,13 +11,21 @@ function importPythonModules(testCase) end methods (Test) + function testAlreadySchema(testCase) + schema = testCase.hmod.load_schema_version('8.2.0'); + schema1 = get_schema_obj(schema); + testCase.assertTrue(py.isinstance(schema, ... + testCase.hmod.HedSchema)) + testCase.assertTrue(py.isinstance(schema1, ... + testCase.hmod.HedSchema)) + end function testSimpleVersion(testCase) % Test single version version = '8.2.0'; schema = get_schema_obj(version); assertTrue(testCase, py.isinstance(schema, ... - testCase.hmod.schema.HedSchema), ... + testCase.hmod.HedSchema), ... 'The object is not an instance of HedSchema.'); version = char(schema.version); testCase.verifyEqual(version, '8.2.0', ... @@ -29,7 +37,7 @@ function testMultipleVersions(testCase) version = {'ts:8.2.0', 'score_1.1.0'}; schema = get_schema_obj(version); assertTrue(testCase, py.isinstance(schema, ... - testCase.hmod.schema.HedSchemaGroup), ... + testCase.hmod.HedSchemaGroup), ... 'The object is not an instance of HedSchemaGroup.'); versions = cell(schema.get_schema_versions()); testCase.verifyEqual(char(versions{1}), 'ts:8.2.0', ... diff --git a/tests/test_hed_wrappers/TestGetStringObjs.m b/tests/test_hed_wrappers/TestGetStringObjs.m index 0617f66..3c39c15 100644 --- a/tests/test_hed_wrappers/TestGetStringObjs.m +++ b/tests/test_hed_wrappers/TestGetStringObjs.m @@ -24,8 +24,7 @@ function importPythonModules(testCase) events = fileread(events_path); sidecar = fileread(json_path); testCase.tabular_obj = get_tabular_obj(events, sidecar); - testCase.schema = ... - testCase.hmod.schema.load_schema_version('8.2.0'); + testCase.schema = testCase.hmod.load_schema_version('8.2.0'); end end diff --git a/tests/test_hed_wrappers/TestValidateBids.m b/tests/test_hed_wrappers/TestValidateBids.m index 5aee49b..2629ea7 100644 --- a/tests/test_hed_wrappers/TestValidateBids.m +++ b/tests/test_hed_wrappers/TestValidateBids.m @@ -1,13 +1,11 @@ classdef TestValidateBids < matlab.unittest.TestCase properties - hmod data_root end methods (TestClassSetup) function importPythonModules(testCase) - testCase.hmod = py.importlib.import_module('hed'); [cur_dir, ~, ~] = fileparts(mfilename("fullpath")); testCase.data_root = fullfile(cur_dir, filesep, '..', ... filesep, '..', filesep, 'data', filesep, ...