def write_var_to_flat_binary(self, item, filename, dtype=numpy.float32): """Write multiple variables to disk as one concatenated flat binary file. Data is written incrementally to reduce memory usage. :param item: Variable name to retrieve from these files :param filename: Filename to write to """ # sanity check if len(self) == 0: LOG.error("Can't extract swath data, file reader is empty") raise RuntimeError("Empty file reader") LOG.debug("Writing binary data for '%s' to file '%s'", item, filename) try: with open(filename, "w") as file_obj: file_appender = FileAppender(file_obj, dtype) for file_reader in self.file_readers: single_array = file_reader.get_swath_data(item) file_appender.append(single_array) except StandardError: if os.path.isfile(filename): os.remove(filename) raise LOG.debug("File %s has shape %r", filename, file_appender.shape) return file_appender.shape
def write_var_to_flat_binary(self, item, filename, dtype=numpy.float32): """Write the data from multiple files to one flat binary file. :param item: Variable name to retrieve :param filename: Filename filename if the file should follow traditional FBF naming conventions """ LOG.debug("Writing binary data for %s to file %s", item, filename) try: with open(filename, "w") as file_obj: file_appender = FileAppender(file_obj, dtype) for file_reader in self.file_readers: single_array = file_reader.get_swath_data(item) file_appender.append(single_array) except StandardError: if os.path.isfile(filename): os.remove(filename) raise LOG.debug("File %s has shape %r", filename, file_appender.shape) return file_appender.shape