nodes: 0, module; 1, function_definition; 2, function_name:collapseTs; 3, parameters; 4, block; 5, default_parameter; 6, expression_statement; 7, comment:# Retrieve the associated raw data according to the "time_id" found in each object. Match it in _timeseries_data; 8, global_statement; 9, expression_statement; 10, if_statement; 11, return_statement; 12, identifier:ts; 13, None; 14, comment:"""
      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
      """; 15, identifier:_timeseries_data; 16, assignment; 17, not_operator; 18, block; 19, else_clause; 20, identifier:_d; 21, identifier:_d; 22, dictionary; 23, identifier:ts; 24, expression_statement; 25, comment:# Send time series list through to be collapsed.; 26, block; 27, call; 28, try_statement; 29, identifier:print; 30, argument_list; 31, block; 32, except_clause; 33, string:"Error: Time series data not provided. Pass time series into the function."; 34, expression_statement; 35, expression_statement; 36, expression_statement; 37, expression_statement; 38, as_pattern; 39, block; 40, assignment; 41, call; 42, assignment; 43, assignment; 44, identifier:Exception; 45, as_pattern_target; 46, expression_statement; 47, expression_statement; 48, identifier:_raw; 49, subscript; 50, identifier:print; 51, argument_list; 52, identifier:_d; 53, call; 54, identifier:_d; 55, call; 56, identifier:e; 57, call; 58, call; 59, identifier:_timeseries_data; 60, subscript; 61, call; 62, identifier:collapse; 63, argument_list; 64, identifier:rm_empty_fields; 65, argument_list; 66, identifier:print; 67, argument_list; 68, attribute; 69, argument_list; 70, subscript; 71, string:"time_id"; 72, identifier:mode_ts; 73, argument_list; 74, identifier:ts; 75, identifier:_raw; 76, identifier:_d; 77, call; 78, identifier:logger_start; 79, identifier:error; 80, call; 81, identifier:ts; 82, integer:0; 83, string:"collapse"; 84, keyword_argument; 85, keyword_argument; 86, attribute; 87, argument_list; 88, attribute; 89, argument_list; 90, identifier:mode; 91, string:""; 92, identifier:ts; 93, identifier:ts; 94, string:"Error: Unable to collapse the time series: {}"; 95, identifier:format; 96, identifier:e; 97, string:"collapseTs: unable to collapse the time series: {}"; 98, identifier:format; 99, identifier:e
code: 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