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,12 +708,16 @@ def process_trial(
|
|||
mylogger.info("Move time dimensions of data to the last dimension")
|
||||
data = data.movedim(1, -1)
|
||||
|
||||
dual_signal_mode: bool = True
|
||||
if len(config["target_camera_acceptor"]) > 0:
|
||||
mylogger.info("Regression Acceptor")
|
||||
mylogger.info(f"Target: {config['target_camera_acceptor']}")
|
||||
mylogger.info(
|
||||
f"Regressors: constant, linear and {config['regressor_cameras_acceptor']}"
|
||||
)
|
||||
target_id: int = config["required_order"].index(config["target_camera_acceptor"])
|
||||
target_id: int = config["required_order"].index(
|
||||
config["target_camera_acceptor"]
|
||||
)
|
||||
regressor_id: list[int] = []
|
||||
for i in range(0, len(config["regressor_cameras_acceptor"])):
|
||||
regressor_id.append(
|
||||
|
@ -739,7 +743,10 @@ def process_trial(
|
|||
del coefficients_acceptor
|
||||
|
||||
mylogger.info("-==- Done -==-")
|
||||
else:
|
||||
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(
|
||||
|
@ -770,6 +777,8 @@ def process_trial(
|
|||
np.save(temp_path, coefficients_donor.cpu())
|
||||
del coefficients_donor
|
||||
mylogger.info("-==- Done -==-")
|
||||
else:
|
||||
dual_signal_mode = False
|
||||
|
||||
del data
|
||||
del data_filtered
|
||||
|
@ -783,6 +792,7 @@ def process_trial(
|
|||
mylogger.info(f"CUDA memory: {free_mem//1024} MByte")
|
||||
|
||||
mylogger.info("Calculate ratio sequence")
|
||||
if dual_signal_mode:
|
||||
if config["classical_ratio_mode"]:
|
||||
mylogger.info("via acceptor / donor")
|
||||
ratio_sequence: torch.Tensor = data_acceptor / data_donor
|
||||
|
@ -791,6 +801,12 @@ def process_trial(
|
|||
else:
|
||||
mylogger.info("via 1.0 + acceptor - donor")
|
||||
ratio_sequence = 1.0 + data_acceptor - data_donor
|
||||
else:
|
||||
mylogger.info("mono signal model")
|
||||
if len(config["target_camera_donor"]) > 0:
|
||||
ratio_sequence = data_donor.clone()
|
||||
else:
|
||||
ratio_sequence = data_acceptor.clone()
|
||||
|
||||
mylogger.info("Remove nan")
|
||||
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!!!")
|
||||
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"])
|
||||
|
||||
mylogger.info(f"Create directory {config['export_path']} in the case it does not exist")
|
||||
|
|
Loading…
Reference in a new issue