From 182cd350ac04a637fd4dc5a81c8aa3b1729c55d9 Mon Sep 17 00:00:00 2001 From: shotgunosine Date: Fri, 6 May 2022 12:44:16 -0500 Subject: [PATCH 1/3] add error message as my flight starts to board --- bids/modeling/statsmodels.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bids/modeling/statsmodels.py b/bids/modeling/statsmodels.py index e9092d1a3..28ea96201 100644 --- a/bids/modeling/statsmodels.py +++ b/bids/modeling/statsmodels.py @@ -288,6 +288,12 @@ def __init__(self, level, name, transformations=None, model=None, group_by.append(self.level) self.group_by = group_by + # Check for intercept only run level model and throw an error + if (self.level == 'run') and (self.model['X'] == [1]): + raise NotImplementedError("Run level intercept only models are not currently supported." + "If this is a feature you need, please leave a comment at" + "https://github.com/bids-standard/pybids/issues/852.") + def __repr__(self): return f"<{self.__class__.__name__}[{self.level}] {self.name}>" From c7c928e23eec890110c020270694f17ddbab1999 Mon Sep 17 00:00:00 2001 From: shotgunosine Date: Fri, 6 May 2022 13:01:50 -0500 Subject: [PATCH 2/3] pass on key error, boarding group B now --- bids/modeling/statsmodels.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bids/modeling/statsmodels.py b/bids/modeling/statsmodels.py index 28ea96201..5a9bf9b9c 100644 --- a/bids/modeling/statsmodels.py +++ b/bids/modeling/statsmodels.py @@ -289,10 +289,15 @@ def __init__(self, level, name, transformations=None, model=None, self.group_by = group_by # Check for intercept only run level model and throw an error - if (self.level == 'run') and (self.model['X'] == [1]): - raise NotImplementedError("Run level intercept only models are not currently supported." - "If this is a feature you need, please leave a comment at" - "https://github.com/bids-standard/pybids/issues/852.") + try: + if (self.level == 'run') and (self.model['X'] == [1]): + raise NotImplementedError("Run level intercept only models are not currently supported." + "If this is a feature you need, please leave a comment at" + "https://github.com/bids-standard/pybids/issues/852.") + except KeyError: + # We talked about X being required, I don't know if we want to throw an error over that requirement here + # though. + pass def __repr__(self): return f"<{self.__class__.__name__}[{self.level}] {self.name}>" From da44817205c0405ce9fc073bd23f753754fc9331 Mon Sep 17 00:00:00 2001 From: shotgunosine Date: Tue, 10 May 2022 10:08:23 -0400 Subject: [PATCH 3/3] add test to verfify intercept only run level model throws a NotImplmentedError --- bids/modeling/statsmodels.py | 2 +- bids/modeling/tests/test_statsmodels.py | 8 +++ ...-005_type-interceptonlyrunlevel_model.json | 60 +++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 bids/tests/data/ds005/models/ds-005_type-interceptonlyrunlevel_model.json diff --git a/bids/modeling/statsmodels.py b/bids/modeling/statsmodels.py index 5a9bf9b9c..279d5b48a 100644 --- a/bids/modeling/statsmodels.py +++ b/bids/modeling/statsmodels.py @@ -290,7 +290,7 @@ def __init__(self, level, name, transformations=None, model=None, # Check for intercept only run level model and throw an error try: - if (self.level == 'run') and (self.model['X'] == [1]): + if (self.level == 'run') and (self.model['x'] == [1]): raise NotImplementedError("Run level intercept only models are not currently supported." "If this is a feature you need, please leave a comment at" "https://github.com/bids-standard/pybids/issues/852.") diff --git a/bids/modeling/tests/test_statsmodels.py b/bids/modeling/tests/test_statsmodels.py index 5035bf276..97ec62631 100644 --- a/bids/modeling/tests/test_statsmodels.py +++ b/bids/modeling/tests/test_statsmodels.py @@ -171,3 +171,11 @@ def test_expand_wildcards(): assert expand_wildcards( ["non_steady_state*"], ["non_steady_state00", "non_steady_state01"] ) == ["non_steady_state00", "non_steady_state01"] + + +def test_interceptonly_runlevel_error(): + layout_path = join(get_test_data_path(), "ds005") + layout = BIDSLayout(layout_path) + json_file = join(layout_path, "models", "ds-005_type-interceptonlyrunlevel_model.json") + with pytest.raises(NotImplementedError): + graph = BIDSStatsModelsGraph(layout, json_file) diff --git a/bids/tests/data/ds005/models/ds-005_type-interceptonlyrunlevel_model.json b/bids/tests/data/ds005/models/ds-005_type-interceptonlyrunlevel_model.json new file mode 100644 index 000000000..46e4e36f1 --- /dev/null +++ b/bids/tests/data/ds005/models/ds-005_type-interceptonlyrunlevel_model.json @@ -0,0 +1,60 @@ +{ + "Name": "ds005_mixedgamblestask", + "Description": "An intercept only run level model to test that an error is correctly thrown.", + "BIDSModelVersion": "1.0.0", + "Input": { + "task": [ + "mixedgamblestask" + ] + }, + "Nodes": [ + { + "Level": "Run", + "Name": "Run", + "GroupBy": [ + "run", + "subject" + ], + "Transformations": { + "Transformer": "pybids-transforms-v1", + "Instructions": [ + { + "Name": "Factor", + "Input": "trial_type" + } + ] + }, + "Model": { + "Type": "glm", + "X": [ + 1 + ], + "HRF": { + "Variables": [ + "trial_type.parametric gain" + ], + "Model": "DoubleGamma", + "Parameters": { + "PeakDelay": 3, + "PeakDispersion": 6, + "UndershootDelay": 10, + "UndershootDispersion": 12, + "PeakUndershootRatio": 0.2 + } + } + }, + "Contrasts": [ + { + "Name": "run_parametric gain", + "ConditionList": [ + "trial_type.parametric gain" + ], + "Weights": [ + 1.0 + ], + "Test": "t" + } + ] + } + ] +} \ No newline at end of file