From 7f332a6fa9b3ced8a6a835b4b3e2ad71b86f9a01 Mon Sep 17 00:00:00 2001 From: David Rotermund <54365609+davrot@users.noreply.github.com> Date: Wed, 14 Feb 2024 22:44:15 +0100 Subject: [PATCH] Add files via upload --- reproduction_effort/aligned.py | 21 ++++++++++++++++--- reproduction_effort/make_test_data_aligned.py | 21 +++++++++++++++++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/reproduction_effort/aligned.py b/reproduction_effort/aligned.py index 75ed029..a1d6aea 100644 --- a/reproduction_effort/aligned.py +++ b/reproduction_effort/aligned.py @@ -2,6 +2,7 @@ import scipy.io as sio # type: ignore import torch import numpy as np import matplotlib.pyplot as plt +import json from functions.align_cameras import align_cameras @@ -16,11 +17,23 @@ if __name__ == "__main__": dtype: torch.dtype = torch.float32 filename_raw_json: str = "raw/Exp001_Trial001_Part001_meta.txt" - filename_bin_mat: str = "bin_old/Exp001_Trial001_Part001.mat" + filename_data_binning_replace: str = "bin_old/Exp001_Trial001_Part001.mat" batch_size: int = 200 filename_aligned_mat: str = "aligned_old/Exp001_Trial001_Part001.mat" + with open(filename_raw_json, "r") as file_handle: + metadata: dict = json.load(file_handle) + channels: list[str] = metadata["channelKey"] + + data = torch.tensor( + sio.loadmat(filename_data_binning_replace)["nparray"].astype(np.float32), + dtype=dtype, + device=device, + ) + + ref_image = data[:, :, data.shape[-2] // 2, :].clone() + ( acceptor, donor, @@ -31,13 +44,15 @@ if __name__ == "__main__": angle_refref, tvec_refref, ) = align_cameras( - filename_raw_json=filename_raw_json, - filename_bin_mat=filename_bin_mat, + channels=channels, + data=data, + ref_image=ref_image, device=device, dtype=dtype, batch_size=batch_size, fill_value=-1, ) + del data mat_data = torch.tensor( sio.loadmat(filename_aligned_mat)["data"].astype(dtype=np.float32), diff --git a/reproduction_effort/make_test_data_aligned.py b/reproduction_effort/make_test_data_aligned.py index afdc035..5e9d165 100644 --- a/reproduction_effort/make_test_data_aligned.py +++ b/reproduction_effort/make_test_data_aligned.py @@ -3,6 +3,7 @@ import torchvision as tv # type: ignore import numpy as np import matplotlib.pyplot as plt import scipy.io as sio # type: ignore +import json from functions.align_cameras import align_cameras @@ -143,6 +144,19 @@ sio.savemat(filename_bin_mat_fake, mdic) batch_size: int = 200 filename_raw_json: str = "raw/Exp001_Trial001_Part001_meta.txt" +with open(filename_raw_json, "r") as file_handle: + metadata: dict = json.load(file_handle) +channels: list[str] = metadata["channelKey"] + + +data = torch.tensor( + sio.loadmat(filename_bin_mat_fake)["nparray"].astype(np.float32), + dtype=dtype, + device=device, +) + +ref_image = data[:, :, data.shape[-2] // 2, :].clone() + ( acceptor, donor, @@ -153,13 +167,16 @@ filename_raw_json: str = "raw/Exp001_Trial001_Part001_meta.txt" angle_refref, tvec_refref, ) = align_cameras( - filename_raw_json=filename_raw_json, - filename_bin_mat=filename_bin_mat_fake, + channels=channels, + data=data, + ref_image=ref_image, device=device, dtype=dtype, batch_size=batch_size, fill_value=-1, ) +del data + print("References Acceptor <-> Donor:") print("Rotation:")