Skip to content

Commit

Permalink
add glm contrast option
Browse files Browse the repository at this point in the history
  • Loading branch information
matsvanes committed Jan 7, 2025
1 parent cc44eac commit fb22e87
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions osl_ephys/preprocessing/osl_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,13 +1009,17 @@ def glm_add_contrast(dataset, userargs):
if simple:
dataset['design_config'].add_simple_contrasts()
else:
import re
def string_to_dict(input_string):
# Replace unquoted keys with quoted keys
input_string = re.sub(r'(?<![\w])([a-zA-Z_][a-zA-Z0-9_]*)\s*:', r'"\1":', input_string)
# Evaluate the string as a dictionary
return eval(input_string)
values = string_to_dict(values)
if values == 'unique':
values = np.unique(dataset['covs'][name])
values={f"{name}_{v}": 1/len(values) for v in values}
else:
import re
def string_to_dict(input_string):
# Replace unquoted keys with quoted keys
input_string = re.sub(r'(?<![\w])([a-zA-Z_][a-zA-Z0-9_]*)\s*:', r'"\1":', input_string)
# Evaluate the string as a dictionary
return eval(input_string)
values = string_to_dict(values)
dataset['design_config'].add_contrast(name=name, values=values)

return dataset
Expand Down

0 comments on commit fb22e87

Please sign in to comment.