class_docstr: Wrapper to load datasets found in the Numenta Anomaly Benchmark
  (https://github.com/numenta/NAB).
  
  The NAB contains a range of datasets and are categorized by their domains.
class_docstr_tok: ["Wrapper","to","load","datasets","found","in","the","Numenta","Anomaly","Benchmark","(","https",":","\/\/github.com\/numenta\/NAB",")",".","The","NAB","contains","a","range","of","datasets","and","are","categorized","by","their","domains","."]
code: def download(self, rootdir, subsets):
      csvs = [
          "artificialNoAnomaly/art_daily_no_noise.csv",
          "artificialNoAnomaly/art_daily_perfect_square_wave.csv",
          "artificialNoAnomaly/art_daily_small_noise.csv",
          "artificialNoAnomaly/art_flatline.csv",
          "artificialNoAnomaly/art_noisy.csv",
          "artificialWithAnomaly/art_daily_flatmiddle.csv",
          "artificialWithAnomaly/art_daily_jumpsdown.csv",
          "artificialWithAnomaly/art_daily_jumpsup.csv",
          "artificialWithAnomaly/art_daily_nojump.csv",
          "artificialWithAnomaly/art_increase_spike_density.csv",
          "artificialWithAnomaly/art_load_balancer_spikes.csv",
          "realAWSCloudwatch/ec2_cpu_utilization_24ae8d.csv",
          "realAWSCloudwatch/ec2_cpu_utilization_53ea38.csv",
          "realAWSCloudwatch/ec2_cpu_utilization_5f5533.csv",
          "realAWSCloudwatch/ec2_cpu_utilization_77c1ca.csv",
          "realAWSCloudwatch/ec2_cpu_utilization_825cc2.csv",
          "realAWSCloudwatch/ec2_cpu_utilization_ac20cd.csv",
          "realAWSCloudwatch/ec2_cpu_utilization_c6585a.csv",
          "realAWSCloudwatch/ec2_cpu_utilization_fe7f93.csv",
          "realAWSCloudwatch/ec2_disk_write_bytes_1ef3de.csv",
          "realAWSCloudwatch/ec2_disk_write_bytes_c0d644.csv",
          "realAWSCloudwatch/ec2_network_in_257a54.csv",
          "realAWSCloudwatch/ec2_network_in_5abac7.csv",
          "realAWSCloudwatch/elb_request_count_8c0756.csv",
          "realAWSCloudwatch/grok_asg_anomaly.csv",
          "realAWSCloudwatch/iio_us-east-1_i-a2eb1cd9_NetworkIn.csv",
          "realAWSCloudwatch/rds_cpu_utilization_cc0c53.csv",
          "realAWSCloudwatch/rds_cpu_utilization_e47b3b.csv",
          "realAdExchange/exchange-2_cpc_results.csv",
          "realAdExchange/exchange-2_cpm_results.csv",
          "realAdExchange/exchange-3_cpc_results.csv",
          "realAdExchange/exchange-3_cpm_results.csv",
          "realAdExchange/exchange-4_cpc_results.csv",
          "realAdExchange/exchange-4_cpm_results.csv",
          "realKnownCause/ambient_temperature_system_failure.csv",
          "realKnownCause/cpu_utilization_asg_misconfiguration.csv",
          "realKnownCause/ec2_request_latency_system_failure.csv",
          "realKnownCause/machine_temperature_system_failure.csv",
          "realKnownCause/nyc_taxi.csv",
          "realKnownCause/rogue_agent_key_hold.csv",
          "realKnownCause/rogue_agent_key_updown.csv",
          "realTraffic/TravelTime_387.csv",
          "realTraffic/TravelTime_451.csv",
          "realTraffic/occupancy_6005.csv",
          "realTraffic/occupancy_t4013.csv",
          "realTraffic/speed_6005.csv",
          "realTraffic/speed_7578.csv",
          "realTraffic/speed_t4013.csv",
          "realTweets/Twitter_volume_AAPL.csv",
          "realTweets/Twitter_volume_AMZN.csv",
          "realTweets/Twitter_volume_CRM.csv",
          "realTweets/Twitter_volume_CVS.csv",
          "realTweets/Twitter_volume_FB.csv",
          "realTweets/Twitter_volume_GOOG.csv",
          "realTweets/Twitter_volume_IBM.csv",
          "realTweets/Twitter_volume_KO.csv",
          "realTweets/Twitter_volume_PFE.csv",
          "realTweets/Twitter_volume_UPS.csv",
      ]
  
      labelfile = "labels/combined_windows.json"
      path = os.path.join(rootdir, labelfile)
      if not os.path.isfile(path):
          print("Downloading label file...")
          os.makedirs(os.path.dirname(path), exist_ok=True)
          url = f"https://github.com/numenta/NAB/raw/master/{labelfile}"
          r = requests.get(url, stream=True)
          with open(path, "wb") as f:
              for chunk in r.iter_content(chunk_size=16 * 1024**2):
                  if chunk:  # filter out keep-alive new chunks
                      f.write(chunk)
                      f.flush()
  
      csvs = [
          f
          for f in csvs
          if not os.path.isfile(os.path.join(rootdir, f))
          and f.split("/")[0] in subsets
      ]
      for csv in tqdm.tqdm(
          csvs, desc="NAB Download", disable=len(csvs) == 0
      ):
          path = os.path.join(rootdir, csv)
          if not os.path.isfile(path):
              os.makedirs(os.path.dirname(path), exist_ok=True)
              url = f"https://github.com/numenta/NAB/raw/master/data/{csv}"
              r = requests.get(url, stream=True)
              with open(path, "wb") as f:
                  for chunk in r.iter_content(
                      chunk_size=16 * 1024**2
                  ):
                      if chunk:  # filter out keep-alive new chunks
                          f.write(chunk)
                          f.flush()
  
file_path: merlion/ts_datasets/ts_datasets/anomaly/nab.py
imports: import datetime
  import glob
  import json
  import logging
  import os
  import re
  import requests
  import numpy
  import pandas
  import tqdm
  from ts_datasets.anomaly.base import TSADBaseDataset
label_desc: Use image node_id 4 for calling the NAB obj's underlying member method code with example usage: obj.download(rootdir, subsets) without return types