code: def _valuePivot(self, session, mapTable, contaminant, replaceParaFile):
          indexes = session.query(MTIndex). \
              join(MTValue.index). \
              filter(MTValue.mapTable == mapTable). \
              filter(MTValue.contaminant == contaminant). \
              order_by(MTIndex.index). \
              all()
          layer_indices = [0]
          if mapTable.name in ('MULTI_LAYER_SOIL', 'RICHARDS_EQN_INFILTRATION_BROOKS'):
              layer_indices = range(3)
          lines = []
          values = {}
          for idx in indexes:
              for layer_index in layer_indices:
                  values = session.query(MTValue). \
                           filter(MTValue.mapTable == mapTable). \
                           filter(MTValue.contaminant == contaminant). \
                           filter(MTValue.index == idx). \
                           filter(MTValue.layer_id == layer_index). \
                           order_by(MTValue.id). \
                           all()
                  valString = ''
                  for val in values:
                      if val.value <= -9999:
                          continue
                      processedValue = vwp(val.value, replaceParaFile)
                      try:
                          numString = '%.6f' % processedValue
                      except:
                          numString = '%s' % processedValue
                      valString = '%s%s%s' % (valString, numString, ' ' * 3)
                  spacing1 = max(1, 6 - len(str(idx.index)))
                  spacing2 = max(1, 40 - len(idx.description1))
                  spacing3 = max(1, 40 - len(idx.description2))
                  if layer_index == 0:
                      line = '%s%s%s%s%s%s%s\n' % (
                          idx.index, ' ' * spacing1, idx.description1, ' ' * spacing2, idx.description2, ' ' * spacing3, valString)
                  else:
                      num_prepend_spaces = len(str(idx.index)) + spacing1 + len(idx.description1) \
                                           + spacing2 + len(idx.description2) + spacing3
                      line = '{0}{1}\n'.format(' ' * num_prepend_spaces, valString)
                  lines.append(line)
          varString = ''
          for idx, val in enumerate(values):
              if val.variable == 'XSEDIMENT':
                  if idx >= len(values) - 1:
                      varString = '%s%s%s%s' % (varString, mapTable.numSed, ' SEDIMENTS....', ' ' * 2)
              else:
                  varString = '%s%s%s' % (varString, val.variable, ' ' * 2)
          header = 'ID%sDESCRIPTION1%sDESCRIPTION2%s%s\n' % (' ' * 4, ' ' * 28, ' ' * 28, varString)
          lines.insert(0, header)
          return lines