2023-07-10 14:36:01 +02:00
# gevi
2023-07-10 14:47:58 +02:00
## Main files:
Anime.py : Is a class used for displaying 2d Movies from a 3D Matrix.
ImageAlignment.py: Is a class used for aligning two images (move and rotate as well as an unused scale option). This source code is based on https://github.com/matejak/imreg_dft . Is was ported to PyTorch such it can run in GPUs.
DataContailer.py: Main class for data pre-processing of the gevi raw data.
2023-07-10 14:36:01 +02:00
## TODO / Known problems
2023-07-10 14:40:02 +02:00
Support for several part files was included but, due to missing data with several part files, never tested.
2023-07-10 14:42:51 +02:00
## Installation
2023-07-10 14:40:02 +02:00
The code was tested on a Python 3.11.2 (Linux) with the following pip packages installed:
2023-07-10 14:40:22 +02:00
2023-07-10 14:40:47 +02:00
numpy scipy pandas flake8 pep8-naming black matplotlib seaborn ipython jupyterlab mypy dataclasses-json dataconf mat73 ipympl torch torchtext pywavelets scikit-image opencv-python scikit-learn tensorflow_datasets tensorboard tqdm argh sympy jsmin pybind11 pybind11-stubgen pigar asciichartpy torchvision torchaudio tensorflow natsort roipoly
2023-07-10 14:40:22 +02:00
2023-07-10 14:41:36 +02:00
Not all packages are necessary (probably these are enougth: torch torchaudio torchvision roipoly natsort numpy matplotlib) but this is our default in-house installation plus roipoly.
2023-07-10 14:40:02 +02:00
We used a RTX 3090 as test GPU.
2023-07-10 18:23:18 +02:00
## Data processing chain
2023-07-11 01:38:27 +02:00
### SVD (requires donor and acceptor time series) remove_heartbeat: bool = True
2023-07-10 18:23:18 +02:00
- start automatic_load
2023-07-10 18:39:19 +02:00
- try to load previous mask
2023-07-11 01:31:22 +02:00
- start: cleaned_load_data
- start: load_data
2023-07-11 01:37:33 +02:00
- work on XXXX.npy
2023-07-10 18:23:18 +02:00
- np.load
2023-07-11 01:31:22 +02:00
- organize acceptor (move to GPU memory)
- organize donor (move to GPU memory)
2023-07-10 18:39:19 +02:00
- move axis (move the time axis of the tensor)
2023-07-10 18:40:11 +02:00
- move intra timeseries
- donor time series and donor reference image
- acceptor time series and acceptor reference image
2023-07-10 18:23:18 +02:00
- rotate inter timeseries
2023-07-11 01:31:22 +02:00
- acceptor time series and donor reference image
2023-07-10 18:23:18 +02:00
- move inter timeseries
2023-07-11 01:31:22 +02:00
- acceptor time series and donor reference image
- spatial pooling (i.e. 2d average pooling layer)
2023-07-11 01:37:33 +02:00
- acceptor(x,y,t) = acceptor(x,y,t) / acceptor(x,y,t).mean(t) + 1
- donor(x,y,t) = donor(x,y,t) / donor(x,y,t).mean(t) + 1
2023-07-11 01:31:22 +02:00
- remove the heart beat via SVD from donor and acceptor
- copy donor and acceptor and work on the copy with the SVD
- remove the mean (over time)
- use Cholesky whitening on data with SVD
- scale the time series accoring the spatial whitening
- average time series over the spatial dimension (which is the global heart beat)
2023-07-11 01:37:33 +02:00
- use a normalized scalar product for getting spatial scaling factors
2023-07-11 01:31:22 +02:00
- scale the heartbeat with the spatial scaling factors into donor_residuum and acceptor_residuum
- store the heartbeat as well as substract it from the original donor and acceptor timeseries
2023-07-11 01:37:33 +02:00
- remove mean from donor and acceptor timeseries (- mean over time)
- remove linear trends from donor and acceptor timeseries (create a linear function and use a normalized scalar product for getting spatial scaling factors)
2023-07-11 01:31:22 +02:00
- use the SVD heart beat for determining the scaling factors for donor and acceptor (heartbeat_scale)
2023-07-10 18:23:18 +02:00
- apply bandpass donor_residuum (filtfilt)
- apply bandpass acceptor_residuum (filtfilt)
2023-07-11 01:37:33 +02:00
- a normalized scalar product is used to determine the scale factor scale(x,y) between donor_residuum(x,y,t) and acceptor_residuum(x,y,t)
2023-07-11 01:31:22 +02:00
- calculate mask (optional) ; based on the heart beat power at the spatial positions
- scale acceptor signal (heartbeat_scale_a(x,y) * result_a(x,y,t)) and donor signal (heartbeat_scale_d(x,y) * result_d(x,y,t))
- heartbeat_scale_a = torch.sqrt(scale)
- heartbeat_scale_d = 1.0 / (heartbeat_scale_a + 1e-20)
2023-07-10 18:25:50 +02:00
- result(x,y,t) = 1.0 + result_a(x,y,t) - result_d(x,y,t)
2023-07-11 01:31:22 +02:00
- update inital mask (optional)
2023-07-10 18:23:18 +02:00
- end automatic_load
2023-07-11 01:38:27 +02:00
### Classic (requires donor, acceptor, volume, and oxygenation time series) remove_heartbeat: bool = False
2023-07-10 18:33:30 +02:00
- start automatic_load
2023-07-10 18:39:19 +02:00
- try to load previous mask
2023-07-10 18:33:30 +02:00
- start cleaned_load_data
- start load_data
2023-07-11 01:37:33 +02:00
- work on XXXX.npy
- np.load (load one trial)
2023-07-11 01:31:22 +02:00
- organize acceptor (move to GPU memory)
- organize donor (move to GPU memory)
- organize oxygenation (move to GPU memory)
- organize volume (move to GPU memory)
2023-07-10 18:39:19 +02:00
- move axis (move the time axis of the tensor)
2023-07-10 18:33:30 +02:00
- move intra timeseries
2023-07-10 18:40:11 +02:00
- donor time series and donor reference image; transformation also used on volume
- acceptor time series and acceptor reference image; transformation also used on oxygenation
2023-07-10 18:33:30 +02:00
- rotate inter timeseries
2023-07-11 01:31:22 +02:00
- acceptor time series and donor reference image; transformation also used on volume
2023-07-10 18:33:30 +02:00
- move inter timeseries
2023-07-11 01:37:33 +02:00
- acceptor time series and donor reference image; transformation also used on volume
2023-07-11 01:31:22 +02:00
- spatial pooling (i.e. 2d average pooling layer)
2023-07-11 01:37:33 +02:00
- acceptor(x,y,t) = acceptor(x,y,t) / acceptor(x,y,t).mean(t) + 1
- donor(x,y,t) = donor(x,y,t) / donor(x,y,t).mean(t) + 1
- oxygenation(x,y,t) = oxygenation(x,y,t) / oxygenation(x,y,t).mean(t) + 1
- volume(x,y,t) = volume(x,y,t) / volume(x,y,t).mean(t) + 1
2023-07-10 18:33:30 +02:00
- frame shift
2023-07-11 01:31:22 +02:00
- the first frame of donor and acceptor time series is dropped
- the oxygenation and volume time series are interpolated between two frames (to compensate for the 5ms delay)
2023-07-11 01:37:33 +02:00
- measure heart rate (measure_heartbeat_frequency) i.e. find the frequency f_HB(x,y) with the highest power in the frequency band in the volume signal
2023-07-11 01:31:22 +02:00
- use "regression" (i.e. iterative non-orthogonal basis decomposition); remove offset, linear trend, oxygenation and volume timeseries
2023-07-11 01:37:33 +02:00
- donor: measure heart beat spectral power (measure_heartbeat_power) f_HB(x,y) +/- 3Hz; results in power_d(x,y)
- acceptor: measure heart beat spectral power (measure_heartbeat_power) f_HB(x,y) +/- 3Hz ; results in power_a(x,y)
2023-07-11 01:31:22 +02:00
- scale acceptor and donor signals via the powers
2023-07-11 01:37:33 +02:00
- scale(x,y) = power_d(x,y) / (power_a(x,y) + 1e-20)
2023-07-11 01:31:22 +02:00
- heartbeat_scale_a = torch.sqrt(scale)
- heartbeat_scale_d = 1.0 / (heartbeat_scale_a + 1e-20)
2023-07-10 18:33:30 +02:00
- result(x,y,t) = 1.0 + result_a(x,y,t) - result_d(x,y,t)
- end automatic_load