Add files via upload
This commit is contained in:
parent
dfa2beae76
commit
37d72264e5
2 changed files with 150 additions and 62 deletions
63
olivia_data_plotter.py
Normal file
63
olivia_data_plotter.py
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import os
|
||||||
|
from functions.create_logger import create_logger
|
||||||
|
from functions.load_config import load_config
|
||||||
|
|
||||||
|
from functions.get_trials import get_trials
|
||||||
|
import h5py # type: ignore
|
||||||
|
|
||||||
|
control_file_handle = h5py.File("ROI_control_49.mat", "r")
|
||||||
|
control_roi = (np.array(control_file_handle["roi"]).T) > 0
|
||||||
|
control_file_handle.close()
|
||||||
|
control_roi = control_roi.reshape((control_roi.shape[0] * control_roi.shape[1]))
|
||||||
|
|
||||||
|
s_darken_file_handle = h5py.File("ROI_sDarken_49.mat", "r")
|
||||||
|
s_darken_roi = (np.array(s_darken_file_handle["roi"]).T) > 0
|
||||||
|
s_darken_file_handle.close()
|
||||||
|
s_darken_roi = s_darken_roi.reshape((s_darken_roi.shape[0] * s_darken_roi.shape[1]))
|
||||||
|
|
||||||
|
mylogger = create_logger(
|
||||||
|
save_logging_messages=True, display_logging_messages=True, log_stage_name="test_xxx"
|
||||||
|
)
|
||||||
|
config = load_config(mylogger=mylogger)
|
||||||
|
|
||||||
|
experiment_id: int = 1
|
||||||
|
|
||||||
|
raw_data_path: str = os.path.join(
|
||||||
|
config["basic_path"],
|
||||||
|
config["recoding_data"],
|
||||||
|
config["mouse_identifier"],
|
||||||
|
config["raw_path"],
|
||||||
|
)
|
||||||
|
|
||||||
|
data_path: str = "output"
|
||||||
|
|
||||||
|
trails = get_trials(path=raw_data_path, experiment_id=experiment_id)
|
||||||
|
for i in range(0, trails.shape[0]):
|
||||||
|
trial_id = int(trails[i])
|
||||||
|
experiment_name: str = f"Exp{experiment_id:03d}_Trial{trial_id:03d}"
|
||||||
|
mylogger.info(f"Loading files for {experiment_name}")
|
||||||
|
|
||||||
|
data = np.load(os.path.join(data_path, f"{experiment_name}_ratio_sequence.npz"))
|
||||||
|
if i == 0:
|
||||||
|
ratio_sequence = data["ratio_sequence"]
|
||||||
|
else:
|
||||||
|
ratio_sequence += data["ratio_sequence"]
|
||||||
|
|
||||||
|
ratio_sequence /= float(trails.shape[0])
|
||||||
|
|
||||||
|
ratio_sequence = ratio_sequence.reshape(
|
||||||
|
(ratio_sequence.shape[0] * ratio_sequence.shape[1], ratio_sequence.shape[2])
|
||||||
|
)
|
||||||
|
|
||||||
|
control = ratio_sequence[control_roi, :].mean(axis=0)
|
||||||
|
s_darken = ratio_sequence[s_darken_roi, :].mean(axis=0)
|
||||||
|
|
||||||
|
t = np.arange(0, control.shape[0]) / 100.0
|
||||||
|
|
||||||
|
plt.plot(t, control, label="control")
|
||||||
|
plt.plot(t, s_darken, label="sDarken")
|
||||||
|
plt.legend()
|
||||||
|
plt.xlabel("Time [sec]")
|
||||||
|
plt.show()
|
|
@ -708,68 +708,77 @@ def process_trial(
|
||||||
mylogger.info("Move time dimensions of data to the last dimension")
|
mylogger.info("Move time dimensions of data to the last dimension")
|
||||||
data = data.movedim(1, -1)
|
data = data.movedim(1, -1)
|
||||||
|
|
||||||
mylogger.info("Regression Acceptor")
|
dual_signal_mode: bool = True
|
||||||
mylogger.info(f"Target: {config['target_camera_acceptor']}")
|
if len(config["target_camera_acceptor"]) > 0:
|
||||||
mylogger.info(
|
mylogger.info("Regression Acceptor")
|
||||||
f"Regressors: constant, linear and {config['regressor_cameras_acceptor']}"
|
mylogger.info(f"Target: {config['target_camera_acceptor']}")
|
||||||
)
|
mylogger.info(
|
||||||
target_id: int = config["required_order"].index(config["target_camera_acceptor"])
|
f"Regressors: constant, linear and {config['regressor_cameras_acceptor']}"
|
||||||
regressor_id: list[int] = []
|
)
|
||||||
for i in range(0, len(config["regressor_cameras_acceptor"])):
|
target_id: int = config["required_order"].index(
|
||||||
regressor_id.append(
|
config["target_camera_acceptor"]
|
||||||
config["required_order"].index(config["regressor_cameras_acceptor"][i])
|
)
|
||||||
|
regressor_id: list[int] = []
|
||||||
|
for i in range(0, len(config["regressor_cameras_acceptor"])):
|
||||||
|
regressor_id.append(
|
||||||
|
config["required_order"].index(config["regressor_cameras_acceptor"][i])
|
||||||
|
)
|
||||||
|
|
||||||
|
data_acceptor, coefficients_acceptor = regression(
|
||||||
|
mylogger=mylogger,
|
||||||
|
target_camera_id=target_id,
|
||||||
|
regressor_camera_ids=regressor_id,
|
||||||
|
mask=mask_negative,
|
||||||
|
data=data,
|
||||||
|
data_filtered=data_filtered,
|
||||||
|
first_none_ramp_frame=int(config["skip_frames_in_the_beginning"]),
|
||||||
)
|
)
|
||||||
|
|
||||||
data_acceptor, coefficients_acceptor = regression(
|
if config["save_regression_coefficients"]:
|
||||||
mylogger=mylogger,
|
temp_path = os.path.join(
|
||||||
target_camera_id=target_id,
|
config["export_path"], experiment_name + "_coefficients_acceptor.npy"
|
||||||
regressor_camera_ids=regressor_id,
|
)
|
||||||
mask=mask_negative,
|
mylogger.info(f"Save acceptor coefficients to {temp_path}")
|
||||||
data=data,
|
np.save(temp_path, coefficients_acceptor.cpu())
|
||||||
data_filtered=data_filtered,
|
del coefficients_acceptor
|
||||||
first_none_ramp_frame=int(config["skip_frames_in_the_beginning"]),
|
|
||||||
)
|
|
||||||
|
|
||||||
if config["save_regression_coefficients"]:
|
mylogger.info("-==- Done -==-")
|
||||||
temp_path = os.path.join(
|
else:
|
||||||
config["export_path"], experiment_name + "_coefficients_acceptor.npy"
|
dual_signal_mode = False
|
||||||
|
|
||||||
|
if len(config["target_camera_donor"]) > 0:
|
||||||
|
mylogger.info("Regression Donor")
|
||||||
|
mylogger.info(f"Target: {config['target_camera_donor']}")
|
||||||
|
mylogger.info(
|
||||||
|
f"Regressors: constant, linear and {config['regressor_cameras_donor']}"
|
||||||
)
|
)
|
||||||
mylogger.info(f"Save acceptor coefficients to {temp_path}")
|
target_id = config["required_order"].index(config["target_camera_donor"])
|
||||||
np.save(temp_path, coefficients_acceptor.cpu())
|
regressor_id = []
|
||||||
del coefficients_acceptor
|
for i in range(0, len(config["regressor_cameras_donor"])):
|
||||||
|
regressor_id.append(
|
||||||
|
config["required_order"].index(config["regressor_cameras_donor"][i])
|
||||||
|
)
|
||||||
|
|
||||||
mylogger.info("-==- Done -==-")
|
data_donor, coefficients_donor = regression(
|
||||||
|
mylogger=mylogger,
|
||||||
mylogger.info("Regression Donor")
|
target_camera_id=target_id,
|
||||||
mylogger.info(f"Target: {config['target_camera_donor']}")
|
regressor_camera_ids=regressor_id,
|
||||||
mylogger.info(
|
mask=mask_negative,
|
||||||
f"Regressors: constant, linear and {config['regressor_cameras_donor']}"
|
data=data,
|
||||||
)
|
data_filtered=data_filtered,
|
||||||
target_id = config["required_order"].index(config["target_camera_donor"])
|
first_none_ramp_frame=int(config["skip_frames_in_the_beginning"]),
|
||||||
regressor_id = []
|
|
||||||
for i in range(0, len(config["regressor_cameras_donor"])):
|
|
||||||
regressor_id.append(
|
|
||||||
config["required_order"].index(config["regressor_cameras_donor"][i])
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data_donor, coefficients_donor = regression(
|
if config["save_regression_coefficients"]:
|
||||||
mylogger=mylogger,
|
temp_path = os.path.join(
|
||||||
target_camera_id=target_id,
|
config["export_path"], experiment_name + "_coefficients_donor.npy"
|
||||||
regressor_camera_ids=regressor_id,
|
)
|
||||||
mask=mask_negative,
|
mylogger.info(f"Save acceptor donor to {temp_path}")
|
||||||
data=data,
|
np.save(temp_path, coefficients_donor.cpu())
|
||||||
data_filtered=data_filtered,
|
del coefficients_donor
|
||||||
first_none_ramp_frame=int(config["skip_frames_in_the_beginning"]),
|
mylogger.info("-==- Done -==-")
|
||||||
)
|
else:
|
||||||
|
dual_signal_mode = False
|
||||||
if config["save_regression_coefficients"]:
|
|
||||||
temp_path = os.path.join(
|
|
||||||
config["export_path"], experiment_name + "_coefficients_donor.npy"
|
|
||||||
)
|
|
||||||
mylogger.info(f"Save acceptor donor to {temp_path}")
|
|
||||||
np.save(temp_path, coefficients_donor.cpu())
|
|
||||||
del coefficients_donor
|
|
||||||
mylogger.info("-==- Done -==-")
|
|
||||||
|
|
||||||
del data
|
del data
|
||||||
del data_filtered
|
del data_filtered
|
||||||
|
@ -783,14 +792,21 @@ def process_trial(
|
||||||
mylogger.info(f"CUDA memory: {free_mem//1024} MByte")
|
mylogger.info(f"CUDA memory: {free_mem//1024} MByte")
|
||||||
|
|
||||||
mylogger.info("Calculate ratio sequence")
|
mylogger.info("Calculate ratio sequence")
|
||||||
if config["classical_ratio_mode"]:
|
if dual_signal_mode:
|
||||||
mylogger.info("via acceptor / donor")
|
if config["classical_ratio_mode"]:
|
||||||
ratio_sequence: torch.Tensor = data_acceptor / data_donor
|
mylogger.info("via acceptor / donor")
|
||||||
mylogger.info("via / mean over time")
|
ratio_sequence: torch.Tensor = data_acceptor / data_donor
|
||||||
ratio_sequence /= ratio_sequence.mean(dim=-1, keepdim=True)
|
mylogger.info("via / mean over time")
|
||||||
|
ratio_sequence /= ratio_sequence.mean(dim=-1, keepdim=True)
|
||||||
|
else:
|
||||||
|
mylogger.info("via 1.0 + acceptor - donor")
|
||||||
|
ratio_sequence = 1.0 + data_acceptor - data_donor
|
||||||
else:
|
else:
|
||||||
mylogger.info("via 1.0 + acceptor - donor")
|
mylogger.info("mono signal model")
|
||||||
ratio_sequence = 1.0 + data_acceptor - data_donor
|
if len(config["target_camera_donor"]) > 0:
|
||||||
|
ratio_sequence = data_donor.clone()
|
||||||
|
else:
|
||||||
|
ratio_sequence = data_acceptor.clone()
|
||||||
|
|
||||||
mylogger.info("Remove nan")
|
mylogger.info("Remove nan")
|
||||||
ratio_sequence = torch.nan_to_num(ratio_sequence, nan=0.0)
|
ratio_sequence = torch.nan_to_num(ratio_sequence, nan=0.0)
|
||||||
|
@ -884,6 +900,15 @@ if (config["save_as_python"] is False) and (config["save_as_matlab"] is False):
|
||||||
mylogger.info("ERROR: STOP!!!")
|
mylogger.info("ERROR: STOP!!!")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
if (len(config["target_camera_donor"]) == 0) and (
|
||||||
|
len(config["target_camera_acceptor"]) == 0
|
||||||
|
):
|
||||||
|
mylogger.info(
|
||||||
|
"Configure at least target_camera_donor or target_camera_acceptor correctly."
|
||||||
|
)
|
||||||
|
mylogger.info("ERROR: STOP!!!")
|
||||||
|
exit()
|
||||||
|
|
||||||
device = get_torch_device(mylogger, config["force_to_cpu"])
|
device = get_torch_device(mylogger, config["force_to_cpu"])
|
||||||
|
|
||||||
mylogger.info(f"Create directory {config['export_path']} in the case it does not exist")
|
mylogger.info(f"Create directory {config['export_path']} in the case it does not exist")
|
||||||
|
|
Loading…
Reference in a new issue