def test_Defaults(self): """ Default tested: array_size = 32 """ expected = tools.txt2np(filepath=EXPECTED_TXT_FP, array_size=32) result = tools.txt2np(filepath=EXPECTED_TXT_FP) expected_frames, _ = expected frames, _ = result self.assertTrue(np.array_equal(frames, expected_frames))
def test_array_size(self): expected_frames_shape = (3, 16, 16) expected_timestamps = [170.093, 170.218, 170.343] result = tools.txt2np(filepath=EXPECTED_TXT_FP, array_size=16) frames, timestamps = result self.assertEqual(timestamps, expected_timestamps) self.assertEqual(frames.shape, expected_frames_shape)
def test_Result(self): expected_frames_shape = (3, 32, 32) expected_timestamps = [170.093, 170.218, 170.343] result = tools.txt2np(filepath=EXPECTED_TXT_FP, array_size=32) frames, timestamps = result self.assertEqual(timestamps, expected_timestamps) self.assertEqual(frames.shape, expected_frames_shape) expected_frames = np.load(EXPECTED_NP_FP) self.assertTrue(np.array_equal(frames, expected_frames))
def txtFunctions(txt_fp, gif=False, csv=False, bmp=False, crop=-1, overwrite=False, **args): def init(txt_fp, ext): parent, txt_fn = os.path.split(txt_fp) fn = txt_fn.split(".TXT")[0] txt_fn = fn + ".TXT" ext_fn = fn + ext ext_fp = os.path.join(parent, ext_fn) if os.path.exists(ext_fp): if not overwrite: print("{} already exists, aborting conversion".format( ext_fn)) return None print("Converting {} to {}".format(txt_fn, ext_fn)) return ext_fp array, timestamps = tools.txt2np(txt_fp) # NO CROPPING HERE! CSV SHOULD NOT BE CROPPED! if csv: csv_fp = init(txt_fp, ".csv") if csv_fp: tools.write_np2csv(csv_fp, array, timestamps) cropped_array = tools.crop_center(array, crop, crop) if gif: gif_fp = init(txt_fp, ".gif") if gif_fp: pc = tools.np2pc(cropped_array) tools.write_pc2gif( pc, gif_fp, duration=tools.timestamps2frame_durations(timestamps)) if bmp: parent, txt_fn = os.path.split(txt_fp) fn = txt_fn.split(".TXT")[0] dest = fn if init(txt_fp, ""): print("Extracting frames...") tools.save_frames(tools.np2pc(cropped_array), os.path.join(parent, dest)) return
def create(self): """ Convert *.TXT and write *.CSV files preserving directory structure """ dataset_path = os.path.join(self.destination_path, self.dataset_name) if not os.path.exists(dataset_path): os.mkdir(dataset_path) for file_path in tqdm(self._text_files): new_relative_path = os.path.relpath( file_path, self._directory_path).replace( '.{}'.format(self._file_extension), '.{}'.format(self._new_file_extension)) new_file_path = os.path.join(self.destination_path, self.dataset_name, new_relative_path) if not os.path.exists(os.path.dirname(new_file_path)): os.mkdir(os.path.dirname(new_file_path)) data = tools.txt2np(file_path) tools.write_np2csv(new_file_path, *data)
def txtFunctions(txt_fp, bmp=False, histogram=False, crop=-1, overwrite=False, bins=None, mu=True, sigma=True, **args): def init(txt_fp, ext, suffix=None): parent, txt_fn = os.path.split(txt_fp) if not suffix: suffix = "" fn = txt_fn.split(".TXT")[0] + suffix txt_fn = fn + ".TXT" ext_fn = fn + ext ext_fp = os.path.join(parent, ext_fn) if os.path.exists(ext_fp): if not overwrite: print("{} already exists, aborting conversion".format( ext_fn)) return None print("Converting {} to {}".format(txt_fn, ext_fn)) return ext_fp array, timestamps = tools.txt2np(txt_fp) cropped_array = tools.crop_center(array, crop, crop) if bmp: bmp_fp = init(txt_fp, ".bmp") if bmp_fp: pc_img = tools.np2pc(cropped_array)[0] cv2.imwrite(bmp_fp, pc_img) if histogram: hist_fp = init(txt_fp, ".png", suffix="_histogram") if hist_fp: tools.save_temperature_histogram(array, fp=hist_fp, bins=bins, mu=mu, sigma=sigma) return
def test_DTYPE(self): expected_dtype = np.dtype(tools.DTYPE) result = tools.txt2np(filepath=EXPECTED_TXT_FP) frames, _ = result self.assertEqual(frames.dtype, expected_dtype)