code: def __getitem__(
      self, idx: int
  ) -> Tuple[
      np.ndarray, Optional[np.ndarray], Optional[np.ndarray], np.ndarray
  ]:
      # determine the index of the time series.
      target_idx = idx // self.nr_samples_per_ts
      target_series = self.target_series[target_idx]
      target_vals = target_series.random_component_values(copy=False)
  
      raise_if_not(
          len(target_vals)
          >= (self.lookback + self.max_lh) * self.output_chunk_length,
          "The dataset contains some input/target series that are shorter than "
          "`(lookback + max_lh) * H` ({}-th series)".format(target_idx),
      )
  
      # determine the index lh_idx of the forecasting point (the last point of the input series, before the target)
      # lh_idx should be in [0, self.nr_samples_per_ts)
      lh_idx = idx - (target_idx * self.nr_samples_per_ts)
  
      # determine the index at the end of the output chunk
      end_of_output_idx = len(target_series) - (
          (self.min_lh - 1) * self.output_chunk_length + lh_idx
      )
  
      # optionally, load covariates
      covariate_series = (
          self.covariates[target_idx]
          if self.covariates is not None
          else None
      )
      main_covariate_type = (
          CovariateType.NONE
          if self.covariates is None
          else CovariateType.PAST
      )
  
      shift = self.lookback * self.output_chunk_length
      input_chunk_length = shift
  
      # get all indices for the current sample
      (
          past_start,
          past_end,
          future_start,
          future_end,
          cov_start,
          cov_end,
      ) = self._memory_indexer(
          target_idx=target_idx,
          target_series=target_series,
          shift=shift,
          input_chunk_length=input_chunk_length,
          output_chunk_length=self.output_chunk_length,
          end_of_output_idx=end_of_output_idx,
          covariate_series=covariate_series,
          covariate_type=main_covariate_type,
      )
  
      # extract sample target
      future_target = target_vals[future_start:future_end]
      past_target = target_vals[past_start:past_end]
  
      # optionally, extract sample covariates
      covariate = None
      if self.covariates is not None:
          raise_if_not(
              cov_end <= len(covariate_series),
              f"The dataset contains 'past' covariates that don't extend far enough into the future. "
              f"({idx}-th sample)",
          )
  
          covariate = covariate_series.random_component_values(
              copy=False
          )[cov_start:cov_end]
  
          raise_if_not(
              len(covariate) == len(past_target),
              "The dataset contains 'past' covariates whose time axis doesn't allow to obtain the "
              "input (or output) chunk relative to the target series.",
          )
  
      if self.use_static_covariates:
          static_covariate = target_series.static_covariates_values(
              copy=False
          )
      else:
          static_covariate = None
      return past_target, covariate, static_covariate, future_target
  
file_path: darts/darts/utils/data/horizon_based_dataset.py
imports: from typing import Optional, Sequence, Tuple, Union
  import numpy
  from darts import TimeSeries
  from darts.logging import get_logger, raise_if_not
  from .training_dataset import PastCovariatesTrainingDataset
  from .utils import CovariateType
label_desc: Use image node_id 3 for calling the HorizonBasedDataset obj's underlying member method code with example usage: obj.__getitem__(idx) and returns: past_target,  covariate,  static_covariate,  future_target