docs: def collapseTs(ts=None):
      """
      Collapse a time series back into LiPD record form.
  
      | Example
      | 1. D = lipd.readLipd()
      | 2. ts = lipd.extractTs(D)
      | 3. New_D = lipd.collapseTs(ts)
  
      _timeseries_data is sorted by time_id, and then by dataSetName
      _timeseries_data[10103341]["ODP1098B"] = {data}
  
      :param list ts: Time series
      :return dict: Metadata
      """
      # Retrieve the associated raw data according to the "time_id" found in each object. Match it in _timeseries_data
      global _timeseries_data
      _d = {}
      if not ts:
          print("Error: Time series data not provided. Pass time series into the function.")
      else:
          # Send time series list through to be collapsed.
          try:
              _raw = _timeseries_data[ts[0]["time_id"]]
              print(mode_ts("collapse", mode="", ts=ts))
              _d = collapse(ts, _raw)
              _d = rm_empty_fields(_d)
          except Exception as e:
              print("Error: Unable to collapse the time series: {}".format(e))
              logger_start.error("collapseTs: unable to collapse the time series: {}".format(e))
      return _d