code: def statistics():
      """Compute statistics of real-world datasets."""
  
      path_to_data = Path.home() / ".mxnet" / "gluon-ts" / "datasets"
      path_save_plots = Path.home() / "data" / "plots"
  
      datasets = DATASETS_FILTERED
  
      dataset_stats = {}
      for dataset in tqdm(datasets):
          dm = get_data_module(
              name="dm_" + dataset,
              dataset_name=dataset,
              context_length_multiple=4,
              support_length_multiple=4,
              support_set_size=1,
          )
          dm.setup()
          train_file_size = os.path.getsize(
              path_to_data / dataset / "train" / "data.json"
          )
  
          dataset_stats[dataset] = {
              "length": len(dm.splits.train().data()),
              "n_total_observations": dm.splits.train()
              .data()
              .number_of_time_steps,
              "freq": dm.meta.freq,
              "train_file_size": train_file_size,
              "prediction_length": dm.meta.prediction_length,
          }
  
      lengths = np.asarray(
          [dataset_stats[d]["length"] for d in datasets]
      )
      lengths_normalized = lengths / sum(lengths)
  
      n_total = np.asarray(
          [dataset_stats[d]["n_total_observations"] for d in datasets]
      )
      n_total_normalized = n_total / sum(n_total)
  
      datasets, lengths_normalized, n_total_normalized = zip(
          *(
              sorted(
                  list(
                      zip(
                          datasets,
                          lengths_normalized,
                          n_total_normalized,
                      )
                  ),
                  key=lambda x: x[1],
                  reverse=True,
              )
          )
      )
  
      x = np.arange(len(datasets))
  
      # -------- plot without logarithmic y-axis ------
      fig, ax = plt.subplots(figsize=[25, 8])
      width = 0.35  # the width of the bars
      rects1 = ax.bar(
          x - width / 2, lengths_normalized, width, label="number of ts"
      )
      rects2 = ax.bar(
          x + width / 2,
          n_total_normalized,
          width,
          label="total number of time steps",
      )
  
      # Add some text for labels, title and custom x-axis tick labels, etc.
      ax.set_ylabel("normalized size")
      ax.set_title("Datasets")
      ax.set_xticks(x)
      ax.set_xticklabels(datasets, rotation=90)
      ax.legend()
      fig.tight_layout()
      fig.savefig(
          path_save_plots / "datasets.png",
          bbox_inches="tight",
      )
      plt.show()
      plt.close(fig)
  
      # -------- plot with logarithmic y-axis ------
  
      fig, ax = plt.subplots(figsize=[25, 8])
      width = 0.35  # the width of the bars
      rects1 = ax.bar(
          x - width / 2, lengths_normalized, width, label="number of ts"
      )
      rects2 = ax.bar(
          x + width / 2,
          n_total_normalized,
          width,
          label="total number of time steps",
      )
      ax.set_yscale("log")
      # Add some text for labels, title and custom x-axis tick labels, etc.
      ax.set_ylabel("normalized size")
      ax.set_title("Datasets")
      ax.set_xticks(x)
      ax.set_xticklabels(datasets, rotation=90)
      ax.legend()
      fig.tight_layout()
      fig.savefig(
          path_save_plots / "datasets_log_scale.png",
          bbox_inches="tight",
      )
      plt.show()
      plt.close(fig)
  
      # ----- print some statistics ---------
  
      print(f"total number of time series: {sum(lengths)}")
      print(f"total number of time observations: {sum(n_total)}")
  
      f_size = sum(
          [dataset_stats[d]["train_file_size"] for d in datasets]
      )
      print(f"training set memory size: {f_size / float(1<<30)} GB")
  
      prediction_lengths = np.asarray(
          [dataset_stats[d]["prediction_length"] for d in datasets]
      )
      print(f"max prediction length is {np.max(prediction_lengths)}")
  
file_path: gluonts/src/gluonts/nursery/few_shot_prediction/src/scripts/data.py
imports: import os
  from pathlib import Path
  import itertools
  import yaml
  from tqdm.auto import tqdm
  import matplotlib.pyplot
  import numpy
  import click
  import torch
  from meta.datasets import get_data_module, DATASETS_FILTERED
  from meta.datasets.cheat import CheatMetaData
  from meta.common.torch import tensor_to_np
  import pandas
label_desc: Use image node_id 4 for calling a global function with example usage: statistics() without return types