docs: def find_dmag_rec(s, data, **kwargs):
      """
      Returns demagnetization data for specimen s from the data. Excludes other
      kinds of experiments and "bad" measurements
  
      Parameters
      __________
      s : specimen name
      data : DataFrame with measurement data
      **kwargs :
          version : if not 3, assume data model = 2.5
      Returns
      ________
      datablock : nested list of data for zijderveld plotting
           [[tr, dec, inc, int, ZI, flag],...]
           tr : treatment step
           dec : declination
           inc : inclination
           int : intensity
           ZI : whether zero-field first or infield-first step
           flag : g or b , default is set to 'g'
       units : list of units found ['T','K','J'] for tesla, kelvin or joules
      """
      if 'version' in list(kwargs.keys()) and kwargs['version'] == 3:
          # convert dataframe to list of dictionaries
          data = data.to_dict('records')
          spec_key, dec_key, inc_key = 'specimen', 'dir_dec', 'dir_inc'
          flag_key, temp_key, ac_key = 'flag', 'treat_temp', 'treat_ac_field'
          meth_key = 'method_codes'
          power_key, time_key = 'treat_mw_power', 'treat_mw_time'
          Mkeys = ['magn_moment', 'magn_volume', 'magn_mass', 'magnitude']
          # just look in the intensity column
          inst_key = 'instrument_codes'
      else:
          spec_key, dec_key, inc_key = 'er_specimen_name', 'measurement_dec', 'measurement_inc'
          flag_key = 'measurement_flag'
          flag_key, temp_key, ac_key = 'measurement_flag', 'treatment_temp', 'treatment_ac_field'
          meth_key = 'magic_method_codes'
          power_key, time_key = 'treatment_mw_power', 'treatment_mw_time'
          Mkeys = ['measurement_magn_moment', 'measurement_magn_volume',
                   'measurement_magn_mass', 'measurement_magnitude']
          inst_key = 'magic_instrument_codes'
  
      EX = ["LP-AN-ARM", "LP-AN-TRM", "LP-ARM-AFD", "LP-ARM2-AFD", "LP-TRM-AFD",
            "LP-TRM", "LP-TRM-TD", "LP-X"]  # list of excluded lab protocols
      INC = ["LT-NO", "LT-AF-Z", "LT-T-Z",
             "LT-M-Z", "LP-PI-TRM-IZ", "LP-PI-M-IZ"]
      datablock, tr = [], ""
      therm_flag, af_flag, mw_flag = 0, 0, 0
      units = []
      spec_meas = get_dictitem(data, spec_key, s, 'T')
      for rec in spec_meas:
          if flag_key not in list(rec.keys()):
              rec[flag_key] = 'g'
          skip = 1
          tr = ""
          meths = rec[meth_key].split(":")
          methods = []
          for m in meths:
              methods.append(m.strip())  # get rid of the stupid spaces!
          for meth in methods:
              if meth.strip() in INC:
                  skip = 0
          for meth in EX:
              if meth in methods:
                  skip = 1
          if skip == 0:
              if "LT-NO" in methods:
                  tr = float(rec[temp_key])
              if "LT-AF-Z" in methods:
                  af_flag = 1
                  try:
                      tr = float(rec[ac_key])
                  except (KeyError, ValueError):
                      tr = 0
                  if "T" not in units:
                      units.append("T")
              if "LT-T-Z" in methods:
                  therm_flag = 1
                  tr = float(rec[temp_key])
                  if "K" not in units:
                      units.append("K")
              if "LT-M-Z" in methods:
                  mw_flag = 1
                  tr = float(rec[power_key]) * float(rec[time_key])
                  if "J" not in units:
                      units.append("J")
              # looking for in-field first thellier or microwave data -
              # otherwise, just ignore this
              if "LP-PI-TRM-IZ" in methods or "LP-PI-M-IZ" in methods:
                  ZI = 0
              else:
                  ZI = 1
              if tr != "":
                  dec, inc, int = "", "", ""
                  if dec_key in list(rec.keys()) and cb.not_null(rec[dec_key], False):
                      dec = float(rec[dec_key])
                  if inc_key in list(rec.keys()) and cb.not_null(rec[inc_key], False):
                      inc = float(rec[inc_key])
                  for key in Mkeys:
                      if key in list(rec.keys()) and cb.not_null(rec[key], False):
                          int = float(rec[key])
                  if inst_key not in list(rec.keys()):
                      rec[inst_key] = ''
                  datablock.append(
                      [tr, dec, inc, int, ZI, rec[flag_key], rec[inst_key]])
      if therm_flag == 1:
          for k in range(len(datablock)):
              if datablock[k][0] == 0.:
                  datablock[k][0] = 273.
      if af_flag == 1:
          for k in range(len(datablock)):
              if datablock[k][0] >= 273 and datablock[k][0] <= 323:
                  datablock[k][0] = 0.
      meas_units = ""
      if len(units) > 0:
          for u in units:
              meas_units = meas_units + u + ":"
          meas_units = meas_units[:-1]
      return datablock, meas_units