code: def loadFromTemplate(template, stim=None):
          
          if stim is None:
              stim = StimulusModel()
          stim.setRepCount(template['reps'])
          stim.setUserTag(template.get('user_tag', ''))
          # don't set calibration details - this should be the same application wide
          component_classes = get_stimuli_models()
          for comp_doc in template['components']:
              comp = get_component(comp_doc['stim_type'], component_classes)
              comp.loadState(comp_doc) # ignore extra dict entries
              stim.insertComponent(comp, *comp_doc['index'])
  
          # revert from location based selection to component list
          autoparams = template['autoparameters']
          for p in autoparams:
              selection = p['selection']
              component_selection = []
              for index in selection:
                  component = stim.component(*index)
                  component_selection.append(component)
              p['selection'] = component_selection
  
          stim.autoParams().setParameterList(autoparams)
          stim.setReorderFunc(order_function(template['reorder']), template['reorder'])
          stim.setStimType(template['testtype'])
          return stim
docs: Loads the stimlus to the state provided by a template
  
          :param template: dict that includes all info nesessary to recreate stim
          :type template: dict
          :param stim: Stimulus to apply to, creates a new model if None
          :type stim: StimulusModel