コード例 #1
0
 def read_mdrs(self):
     mdr_record_positions = [i for i in range(self.n_of_records) if self.__record_list[i].type == "MDR"]
     giadr = self.get_giadr_scalefactors()
     for i in mdr_record_positions:
         mdr_record = self.__record_list[i]
         new_content = MDR.read(mdr_record.content, mdr_record.grh, giadr)
         self.__record_list[i] = Record(mdr_record.grh, new_content)
     self.__data_read = True
コード例 #2
0
    def split(self, threshold, split_files_names="split_$F", output_dir=".", temp_name="temp"):
        # Get the size of the non-mdr part of the file
        non_mdr_list = [r for r in self if r.type != "MDR"]
        non_mdr_size = sum([r.size for r in non_mdr_list])

        # Get the size of the biggest mdr record
        mdr_list = [r for r in self if r.type == "MDR"]
        msr_max_size = max([r.size for r in mdr_list])

        if threshold < non_mdr_size + msr_max_size:
            raise TooSmallThresholdException("The file can not be splitted in the " "desidered size")
        split_file_index = 0
        file_times = []

        # Prepare the first file
        file_size = 0
        current_file = open(join(output_dir, temp_name), "w")
        for r in non_mdr_list:
            current_file.write(r.raw)
            file_size += r.size

        for mdr_record in mdr_list:
            if file_size + mdr_record.size > threshold:
                current_file.close()
                file_start_time = min(file_times)
                file_end_time = max(file_times)

                file_name = split_files_names.replace("$F", str(split_file_index))
                file_name = file_name.replace("$SD", file_start_time.strftime("%Y%m%d%H%M%S") + "Z")
                file_name = file_name.replace("$ED", file_end_time.strftime("%Y%m%d%H%M%S") + "Z")
                rename(join(output_dir, temp_name), join(output_dir, file_name))
                file_size = 0
                file_times = []
                split_file_index += 1
                current_file = open(join(output_dir, temp_name), "w")
                for r in non_mdr_list:
                    current_file.write(r.raw)
                    file_size += r.size

            interpreted_mdr = MDR.read(mdr_record.content.raw, mdr_record.grh, self.get_giadr_scalefactors())
            file_times.extend(interpreted_mdr.get_times())
            current_file.write(mdr_record.raw)
            file_size += mdr_record.size

        current_file.close()
        file_start_time = min(file_times)
        file_end_time = max(file_times)
        file_name = split_files_names.replace("$F", str(split_file_index))
        file_name = file_name.replace("$SD", file_start_time.strftime("%Y%m%d%H%M%S") + "Z")
        file_name = file_name.replace("$ED", file_end_time.strftime("%Y%m%d%H%M%S") + "Z")
        rename(join(output_dir, temp_name), join(output_dir, file_name))