code: def get_ts_at_all_levels(
      ts_it: Iterator[pd.Series],
      temporal_hierarchy: TemporalHierarchy,
      prediction_length: int,
      target_temporal_hierarchy: TemporalHierarchy,
  ):
      for ts in ts_it:
          for agg_freq, agg_multiple in zip(
              temporal_hierarchy.freq_strs,
              temporal_hierarchy.agg_multiples,
          ):
              if (
                  agg_multiple
                  in target_temporal_hierarchy.agg_multiples
              ):
                  # We need to align the forecast start date for all aggregation levels.
                  # This is possible if the time series length is multiple of `prediction_length`.
                  ts = ts[
                      -(len(ts) // prediction_length)
                      * prediction_length :
                  ]
  
                  agg_ts_values = ts.values.reshape(
                      len(ts) // agg_multiple, agg_multiple
                  ).sum(axis=1)
  
                  # Start date is same for the aggregated frequency:
                  # For example if you aggregate 5-minutes data, that starts at 00:10, to hourly then the index of hourly
                  # data will be 00:10, 01:10, 02:10, ...
                  agg_ts_start_date = ts.index[0]
                  agg_ts_index = pd.period_range(
                      start=agg_ts_start_date,
                      periods=len(agg_ts_values),
                      freq=(agg_multiple * ts.index[0].freq).freqstr,
                  )
                  agg_ts = pd.Series(agg_ts_values, index=agg_ts_index)
  
                  yield agg_ts
  
imports: from typing import Iterator, List
  import numpy
  import pandas
  from gluonts.core.component import validated
  from gluonts.model.forecast import SampleForecast
  from gluonts.mx import Tensor
label_desc: Use image node_id 6 for calling a global function with example usage: get_ts_at_all_levels(ts_it, temporal_hierarchy, prediction_length, target_temporal_hierarchy) without return types