docstr: Interesting question: Should all passed data_groups be assumed to have equal size? Nothing about hdf5 requires that, but it makes things a lot easier to assume.
          
docstr_tok: ["Interesting","question",":","Should","all","passed","data_groups","be","assumed","to","have","equal","size","?","Nothing","about","hdf5","requires","that",",","but","it","makes","things","a","lot","easier","to","assume","."]
code: def write_data_to_file(
      self, output_filepath=None, data_group_labels=None
  ):
      """Interesting question: Should all passed data_groups be assumed to have equal size? Nothing about hdf5 requires that, but it makes things a lot easier to assume."""
  
      # Sanitize Inputs
      if data_group_labels is None:
          data_group_labels = list(self.data_groups.keys())
      if output_filepath is None:
          raise ValueError(
              "No output_filepath provided; data cannot be written."
          )
  
      # Create Data File. Exception catching is not perfect here -- file could remain open in create func.
      try:
          hdf5_file = self.create_hdf5_file(
              output_filepath, data_group_labels=data_group_labels
          )
  
          # Write data
          self.write_image_data_to_storage(data_group_labels)
  
          hdf5_file.close()
  
      except Exception as e:
          try:
              hdf5_file.close()
              os.remove(output_filepath)
          except:
              pass
          raise e
  
      newDataCollection = DataCollection(
          data_sources={"hdf5": output_filepath}
      )
      self.__dict__.update(newDataCollection.__dict__)
  
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 18 for calling the DataCollection obj's underlying member method code with example usage: obj.write_data_to_file(output_filepath, data_group_labels) without return types