docs: def vspec_magic(data):
      """
      Takes average vector of replicate measurements
      """
      vdata, Dirdata, step_meth = [], [], ""
      if len(data) == 0:
          return vdata
      treat_init = ["treatment_temp", "treatment_temp_decay_rate", "treatment_temp_dc_on", "treatment_temp_dc_off", "treatment_ac_field", "treatment_ac_field_decay_rate", "treatment_ac_field_dc_on",
                    "treatment_ac_field_dc_off", "treatment_dc_field", "treatment_dc_field_decay_rate", "treatment_dc_field_ac_on", "treatment_dc_field_ac_off", "treatment_dc_field_phi", "treatment_dc_field_theta"]
      treats = []
  #
  # find keys that are used
  #
      for key in treat_init:
          if key in list(data[0].keys()):
              treats.append(key)  # get a list of keys
      stop = {}
      stop["er_specimen_name"] = "stop"
      for key in treats:
          stop[key] = ""  # tells program when to quit and go home
      data.append(stop)
  #
  # set initial states
  #
      DataState0, newstate = {}, 0
      for key in treats:
          DataState0[key] = data[0][key]  # set beginning treatment
      k, R = 1, 0
      for i in range(k, len(data)):
          FDirdata, Dirdata, DataStateCurr, newstate = [], [], {}, 0
          for key in treats:  # check if anything changed
              DataStateCurr[key] = data[i][key]
              if DataStateCurr[key].strip() != DataState0[key].strip():
                  newstate = 1  # something changed
          if newstate == 1:
              if i == k:  # sample is unique
                  vdata.append(data[i - 1])
              else:  # measurement is not unique
                  # print "averaging: records " ,k,i
                  for l in range(k - 1, i):
                      if 'orientation' in data[l]['measurement_description']:
                          data[l]['measurement_description'] = ""
                      Dirdata.append([float(data[l]['measurement_dec']), float(
                          data[l]['measurement_inc']), float(data[l]['measurement_magn_moment'])])
                      FDirdata.append(
                          [float(data[l]['measurement_dec']), float(data[l]['measurement_inc'])])
                  dir, R = vector_mean(Dirdata)
                  Fpars = fisher_mean(FDirdata)
                  vrec = data[i - 1]
                  vrec['measurement_dec'] = '%7.1f' % (dir[0])
                  vrec['measurement_inc'] = '%7.1f' % (dir[1])
                  vrec['measurement_magn_moment'] = '%8.3e' % (
                      old_div(R, (i - k + 1)))
                  vrec['measurement_csd'] = '%7.1f' % (Fpars['csd'])
                  vrec['measurement_positions'] = '%7.1f' % (Fpars['n'])
                  vrec['measurement_description'] = 'average of multiple measurements'
                  if "magic_method_codes" in list(vrec.keys()):
                      meths = vrec["magic_method_codes"].strip().split(":")
                      if "DE-VM" not in meths:
                          meths.append("DE-VM")
                      methods = ""
                      for meth in meths:
                          methods = methods + meth + ":"
                      vrec["magic_method_codes"] = methods[:-1]
                  else:
                      vrec["magic_method_codes"] = "DE-VM"
                  vdata.append(vrec)
  # reset state to new one
              for key in treats:
                  DataState0[key] = data[i][key]  # set beginning treatment
              k = i + 1
              if data[i]["er_specimen_name"] == "stop":
                  del data[-1]  # get rid of dummy stop sign
                  return vdata, treats