docstr: Populates data collection variables from either a directory structure or an hdf5 file.
          
docstr_tok: ["Populates","data","collection","variables","from","either","a","directory","structure","or","an","hdf5","file","."]
code: def fill_data_groups(self):
      """Populates data collection variables from either a directory structure or an hdf5 file."""
  
      # Create all data groups
      for data_type in self.data_types:
          if self.data_sources[data_type] is None:
              continue
  
          if data_type in ["file", "numpy"]:
              # Create DataGroups for this DataCollection.
              for data_group_name in self.data_sources[data_type]:
                  if (
                      data_group_name
                      not in list(self.data_groups.keys())
                      and data_group_name != "directories"
                  ):
                      self.data_groups[data_group_name] = DataGroup(
                          data_group_name
                      )
                      self.data_groups[
                          data_group_name
                      ].source = data_type
  
          # This is a little fragile
          elif data_type == "directories":
              for directory in self.data_sources[data_type]:
                  for data_group_name in self.data_sources[data_type][
                      directory
                  ]:
                      if (
                          data_group_name
                          not in list(self.data_groups.keys())
                          and data_group_name != "directories"
                      ):
                          self.data_groups[data_group_name] = DataGroup(
                              data_group_name
                          )
                          self.data_groups[
                              data_group_name
                          ].source = data_type
  
          elif data_type == "hdf5":
              self.open_hdf5 = tables.open_file(
                  self.data_sources[data_type], "r"
              )
              for data_group in self.open_hdf5.root._f_iter_nodes():
                  if (
                      "_affines" not in data_group.name
                      and "_casenames" not in data_group.name
                  ):
                      self.data_groups[data_group.name] = DataGroup(
                          data_group.name
                      )
                      self.data_groups[
                          data_group.name
                      ].data = data_group
                      self.data_groups[
                          data_group.name
                      ].source = data_type
  
          elif data_type == "csv":
              with open(self.data_sources[data_type], "r") as infile:
                  csv_reader = csv.reader(infile)
                  for data_group_name in next(csv_reader):
                      if data_group_name != "casename":
                          if data_group_name not in list(
                              self.data_groups.keys()
                          ):
                              self.data_groups[
                                  data_group_name
                              ] = DataGroup(data_group_name)
                              self.data_groups[
                                  data_group_name
                              ].source = data_type
  
      # Load data into groups. Replace with dictionary at some point?
      for data_type in self.data_types:
          if self.data_sources[data_type] is None:
              continue
  
          if data_type == "file":
              parse_filepaths(
                  self,
                  self.data_sources[data_type],
                  case_list=self.case_list,
                  recursive=self.recursive,
                  file_identifying_chars=self.file_identifying_chars,
              )
              self.source = "directories"
  
          if data_type == "directories":
              parse_directories(
                  self,
                  self.data_sources[data_type],
                  case_list=self.case_list,
              )
              self.source = "directories"
  
          if data_type == "numpy":
              raise NotImplementedError
              parse_numpy(
                  self,
                  self.data_sources[data_type],
                  case_list=self.case_list,
              )
  
          if data_type == "hdf5":
              parse_hdf5(
                  self,
                  self.data_sources[data_type],
                  case_list=self.case_list,
              )
  
              """ An existing problem with DeepNeuro is that loading from filepaths and
                      loading from HDF5s are fundamentally different, but this difference is
                      encoded in a very slapdash way, like with the "source" parameter below.
                  """
  
              self.source = "hdf5"
  
          if data_type == "csv":
              parse_csv(
                  self,
                  self.data_sources[data_type],
                  case_list=self.case_list,
              )
              self.source = "directories"
  
      self.total_cases = len(self.cases)
  
      if self.total_cases == 0:
          print(
              "Found zero cases. Are you sure you have entered your data sources correctly?"
          )
      else:
          print(("Found", self.total_cases, "cases.."))
  
imports: import os
  import csv
  import numpy
  import tables
  import copy
  from tqdm import tqdm
  from deepneuro.augmentation.augment import Copy
  from deepneuro.utilities.conversion import read_image_files
  from deepneuro.data.data_group import DataGroup
  from deepneuro.data.data_load import parse_directories, parse_filepaths, parse_hdf5, parse_csv, parse_numpy
  from deepneuro.utilities.util import add_parameter
label_desc: Use image node_id 4 for calling the DataCollection obj's underlying member method code with example usage: obj.fill_data_groups() without return types