|
import argparse |
|
import os |
|
from pathlib import Path |
|
import numpy as np |
|
import pandas as pd |
|
|
|
def main(): |
|
parser = argparse.ArgumentParser() |
|
parser.add_argument('-i', type = str, help ="Input directory") |
|
parser.add_argument('-o', type = str, help="Output directory") |
|
parser.add_argument('-file_format', default = "*.npy", type = str, help = "File to open") |
|
|
|
args = parser.parse_args() |
|
|
|
if not args.o: |
|
args.o = args.i |
|
|
|
if not os.path.exists(args.o): |
|
os.makedirs(args.o) |
|
|
|
input_list = _get_file_paths(args.i, args.file_format) |
|
|
|
offset_x, offset_y = _get_x_y_offsets(input_list) |
|
|
|
_save_csv(args.o, offset_x, "x_offsets") |
|
|
|
_save_csv(args.o, offset_y, "y_offsets") |
|
|
|
def _get_file_paths(input_dir, img_format): |
|
input_dir = Path(input_dir) |
|
path_list = [str(path) for path in list(sorted(input_dir.rglob(img_format)))] |
|
return path_list |
|
|
|
def _save_csv(output_dir, df, name): |
|
df.to_csv(output_dir+"/"+name+".csv") |
|
|
|
|
|
def _get_x_y_offsets(input_list): |
|
nFOV = len(input_list) |
|
num_datachannels = 16 |
|
|
|
offset_array_x = np.zeros(shape = (nFOV, num_datachannels+1)) |
|
offset_array_y = np.zeros(shape = (nFOV, num_datachannels+1)) |
|
|
|
|
|
for fov in range(nFOV): |
|
tnx = np.load(input_list[fov], allow_pickle = True) |
|
offset_array_x[fov,0] = int(fov+1) |
|
offset_array_y[fov,0] = int(fov+1) |
|
for j in range(num_datachannels): |
|
offset_array_x[fov,j+1] = tnx[j].params[0][-1] |
|
offset_array_y[fov,j+1] = tnx[j].params[1][-1] |
|
|
|
pd_columns = ['FOV', |
|
'Offset b/w IR1 & IR 1', |
|
'Offset b/w IR1 & IR 2', |
|
'Offset b/w IR1 & IR 3', |
|
'Offset b/w IR1 & IR 4', |
|
'Offset b/w IR1 & IR 5', |
|
'Offset b/w IR1 & IR 6', |
|
'Offset b/w IR1 & IR 7', |
|
'Offset b/w IR1 & IR 8'] |
|
|
|
offset_pd_x = pd.DataFrame(offset_array_x[:, ::2], columns=pd_columns) |
|
offset_pd_y = pd.DataFrame(offset_array_y[:, ::2], columns=pd_columns) |
|
|
|
return offset_pd_x, offset_pd_y |
|
|
|
|
|
if __name__ == '__main__': |
|
main() |
|
|
|
|