code: def add_spikes(ts: torch.Tensor, only_upper_spikes: bool = False):
      """
      Adds spikes to 15% of the time series in the form of heavy-tailed
      (Generalized Pareto) realizations.
  
      Arguments:
          ts: time series
          only_upper_spikes: boolean to indicate upper-tailed or two-tailed spikes
      """
      num_spikes = int(0.15 * ts.shape[0])
      indices_for_gp_spikes = np.random.choice(
          np.arange(len(ts)), replace=False, size=num_spikes
      )
      spike_direction = np.random.choice(
          [-1, 1], replace=True, size=num_spikes
      )
      if only_upper_spikes:
          spike_direction = np.ones_like(spike_direction)
      spikes = stats.genpareto(1 / 50).rvs(num_spikes) * spike_direction
      ts[indices_for_gp_spikes] += spikes
      return ts
  
file_path: gluonts/src/gluonts/nursery/spliced_binned_pareto/data_functions.py
imports: from typing import List
  import numpy
  from scipy import stats
  import torch
label_desc: Use image node_id 1 for calling a global function with example usage: add_spikes(ts, only_upper_spikes) and returns: ts