11from experiments .utils .exp_setup import DlStreamConfigWriter
22import click
33
4-
5- def design_experiment ():
6-
4+ @ click . command ()
5+ @ click . option ( '--default' , 'default' , is_flag = True )
6+ def design_experiment ( default ):
77 config = DlStreamConfigWriter ()
88 input_dict = dict (EXPERIMENT = None ,
99 TRIGGER = None ,
1010 PROCESS = None ,
1111 STIMULATION = None )
12- available_process_types = ['switch' , 'supply' ]
13-
14- for input_type in input_dict .keys ():
15- if input_dict ['EXPERIMENT' ] == 'BaseOptogeneticExperiment' and input_type == 'STIMULATION' :
16- input_dict [input_type ] = 'BaseStimulation'
17-
18- click .echo (f'Available { input_type } s are: ' + ', ' .join (config .get_available_module_names (input_type )))
19- input_value = click .prompt (f'Enter a base { input_type } module' , type = str )
20-
21- while not config .check_if_default_exists (input_value , input_type ):
22- click .echo (f'{ input_type } { input_value } does not exists.' )
23- input_value = click .prompt (f'Enter a base { input_type } module' , type = str )
24-
25- input_dict [input_type ] = input_value
26- click .echo (f'{ input_type } set to { input_value } .' )
2712
28- if input_dict ['EXPERIMENT' ] == 'BaseTrialExperiment' :
29- valid_input = False
13+ def get_input (input_name ):
14+ click .echo (f'Choosing { input_name } ... \n Available { input_name } s are: ' + ', ' .join (config .get_available_module_names (input_name )))
15+ input_value = click .prompt (f'Enter a base { input_name } module' ,type = str )
16+ while not config .check_if_default_exists (input_value ,input_name ):
17+ click .echo (f'{ input_name } { input_value } does not exists.' )
18+ input_value = click .prompt (f'Enter a base { input_name } module' ,type = str )
19+ return input_value
20+ """Experiment"""
21+
22+ input_value = get_input ('EXPERIMENT' )
23+ input_dict ['EXPERIMENT' ] = input_value
24+ if input_value == 'BaseOptogeneticExperiment' :
25+ input_dict ['STIMULATION' ] = 'BaseStimulation'
26+ input_dict ['PROCESS' ] = 'BaseProtocolProcess'
27+
28+ elif input_value == 'BaseTrialExperiment' :
3029 click .echo (f'Available Triggers are: ' + ', ' .join (config .get_available_module_names ('TRIGGER' )))
3130 click .echo ('Note, that you cannot select the same Trigger as selected in TRIGGER.' )
3231
@@ -38,62 +37,77 @@ def design_experiment():
3837 input_dict ['TRIAL_TRIGGER' ] = input_value
3938 click .echo (f'TRIAL_TRIGGER for BaseTrialExperiment set to { input_value } .' )
4039
40+ """TRIGGER"""
4141
42- # TODO: Make adaptive for multiple Triggers
43- if input_dict ['EXPERIMENT' ] == 'BaseTrialExperiment' :
44- config .import_default (experiment_name = input_dict ['EXPERIMENT' ], trigger_name = input_dict ['TRIGGER' ],
45- process_name = input_dict ['PROCESS' ], stimulation_name = input_dict ['STIMULATION' ],
46- trial_trigger_name = input_dict ['TRIAL_TRIGGER' ])
42+ input_value = get_input ('TRIGGER' )
43+ input_dict ['TRIGGER' ] = input_value
4744
48- config ._change_parameter (module_name = input_dict ['EXPERIMENT' ], parameter_name = 'TRIAL_TRIGGER' ,
49- parameter_value = input_dict ['TRIAL_TRIGGER' ])
5045
51- if input_dict ['PROCESS' ] == 'BaseProtocolProcess' :
52- config ._change_parameter (module_name = input_dict ['PROCESS' ], parameter_name = 'TYPE' ,
53- parameter_value = 'trial' )
46+ """Process"""
5447
55- if input_dict ['EXPERIMENT ' ] == 'BaseOptogeneticExperiment' :
56- config . import_default ( experiment_name = input_dict [ 'EXPERIMENT' ], trigger_name = input_dict [ 'TRIGGER' ],
57- process_name = input_dict ['PROCESS' ], stimulation_name = input_dict [ 'STIMULATION' ])
48+ if input_dict ['PROCESS ' ] is None :
49+ input_value = get_input ( 'PROCESS' )
50+ input_dict ['PROCESS' ] = input_value
5851
59- if input_dict ['PROCESS' ] == 'BaseProtocolProcess' :
60- config ._change_parameter (module_name = input_dict ['PROCESS' ], parameter_name = 'TYPE' ,
61- parameter_value = 'switch' )
52+ """STIMULATION"""
53+ if input_dict ['STIMULATION' ] is None :
54+ input_value = get_input ('STIMULATION' )
55+ input_dict ['STIMULATION' ] = input_value
6256
57+ """Setting Process Type"""
58+
59+ if input_dict ['EXPERIMENT' ] == 'BaseTrialExperiment' :
60+ input_dict ['PROCESS_TYPE' ] = 'trial'
61+ elif input_dict ['STIMULATION' ] == 'BaseStimulation' :
62+ input_dict ['PROCESS_TYPE' ] = 'switch'
63+ elif input_dict ['STIMULATION' ] == 'ScreenStimulation' or input_dict ['STIMULATION' ] == 'RewardDispenser' :
64+ input_dict ['PROCESS_TYPE' ] = 'supply'
65+
66+
67+ if input_dict ['EXPERIMENT' ] == 'BaseTrialExperiment' :
68+ config .import_default (experiment_name = input_dict ['EXPERIMENT' ], trigger_name = input_dict ['TRIGGER' ],
69+ process_name = input_dict ['PROCESS' ], stimulation_name = input_dict ['STIMULATION' ],
70+ trial_trigger_name = input_dict ['TRIAL_TRIGGER' ])
6371
6472 else :
6573 config .import_default (experiment_name = input_dict ['EXPERIMENT' ], trigger_name = input_dict ['TRIGGER' ],
66- process_name = input_dict ['PROCESS' ], stimulation_name = input_dict ['STIMULATION' ])
67-
68- if input_dict ['PROCESS' ] == 'BaseProtocolProcess' and input_dict ['EXPERIMENT' ] != 'BaseTrialExperiment' and \
69- input_dict ['EXPERIMENT' ] != 'BaseOptogeneticExperiment' :
70- valid_input = False
71-
72- click .echo (f'Available types are: ' + ', ' .join (available_process_types ))
73- input_value = click .prompt (f'Enter a type for BaseProtocolProcess' , type = str )
74- if input_value in available_process_types :
75- valid_input = True
76- while not valid_input :
77- click .echo (f'{ input_type } { input_value } does not exists.' )
78- input_value = click .prompt (f'Enter a valid type for BaseProtocolProcess' , type = str )
79- if input_value in available_process_types :
80- valid_input = True
81-
82- input_dict ['PROCESS_TYPE' ] = input_value
83- click .echo (f'BaseProtocolProcess type set to { input_value } .' )
84- config ._change_parameter (module_name = input_dict ['PROCESS' ], parameter_name = 'TYPE' ,
85- parameter_value = input_dict ['PROCESS_TYPE' ])
86-
87-
88- #Name of experimentor
89- experimenter = click .prompt ('Enter an experimenter name' , type = str )
74+ process_name = input_dict ['PROCESS' ], stimulation_name = input_dict ['STIMULATION' ])
75+
76+ if 'PROCESS_TYPE' in input_dict .keys ():
77+ config ._change_parameter (module_name = input_dict ['PROCESS' ],parameter_name = 'TYPE' ,
78+ parameter_value = input_dict ['PROCESS_TYPE' ])
79+
80+
81+ if click .confirm ('Do you want to set parameters as well (Not recommended)? \n Note, that you can change them in the created file later.' ):
82+ current_config = config .get_current_config ()
83+ ignore_list = ['EXPERIMENT' , 'BaseProtocolProcess' ]
84+ inner_ignore_list = ['EXPERIMENTER' , 'PROCESS' , 'STIMULATION' , 'TRIGGER' , 'DEBUG' ]
85+ try :
86+ for module in current_config .keys ():
87+ parameter_dict = config .get_parameters (module )
88+ if module not in ignore_list :
89+ for input_key in parameter_dict .keys ():
90+ if input_key not in inner_ignore_list :
91+ click .echo (f'Default { input_key } is: ' + str (parameter_dict [input_key ]))
92+ input_value = click .prompt (f'Enter new value: ' ,type = str )
93+ config ._change_parameter (module_name = module ,parameter_name = input_key ,
94+ parameter_value = input_value )
95+ except :
96+ click .echo ('Failed to set individual parameters. Please change them later in the config file...' )
97+ else :
98+ click .echo ('Skipping parameters. Experiment config will be created with default values...' )
99+ """Finish up"""
100+ # Name of experimentor
101+ experimenter = click .prompt ('Enter an experimenter name' ,type = str )
90102 click .echo (f'Experimenter set to { experimenter } .' )
91103 config .set_experimenter (experimenter )
92104
93- click .echo ('Current modules are:\n BaseExperiment: {}\n Trigger: {}\n Process: {} \n Stimulation: {}' .format (input_dict ['EXPERIMENT' ],
94- input_dict ['TRIGGER' ],
95- input_dict ['PROCESS' ],
96- input_dict ['STIMULATION' ]))
105+ click .echo ('Current modules are:\n BaseExperiment: {}\n Trigger: {}\n Process: {} \n Stimulation: {}' .format (
106+ input_dict ['EXPERIMENT' ],
107+ input_dict ['TRIGGER' ],
108+ input_dict ['PROCESS' ],
109+ input_dict ['STIMULATION' ]))
110+
97111
98112 if click .confirm ('Do you want to continue?' ):
99113 config .write_ini ()
@@ -102,4 +116,3 @@ def design_experiment():
102116
103117if __name__ == '__main__' :
104118 design_experiment ()
105-
0 commit comments