Skip to content

Commit

Permalink
Add script to merge csv and tiff files
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraporta committed Mar 26, 2024
1 parent a4e43df commit 644a764
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions examples/join_incremental_and_full_video.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import sys
from pathlib import Path

import numpy as np
import pandas as pd
import tifffile as tiff


def join_incremental_and_full_video(dataset_path, new_folder):
incremental_video = tiff.imread(
f"{dataset_path}/derotated_image_stack_incremental.tif"
)
full_video = tiff.imread(f"{dataset_path}/derotated_image_stack_full.tif")

joined_video = np.concatenate((incremental_video, full_video), axis=0)

tiff.imsave(
f"{new_folder}/derotated_image_stack_full_and_incremental.tif",
joined_video,
)


def join_csv_files(dataset_path, new_folder):
incremental_csv = pd.read_csv(
f"{dataset_path}/derotated_image_stack_incremental.csv", delimiter=","
)
full_csv = pd.read_csv(
f"{dataset_path}/derotated_image_stack_full.csv", delimiter=","
)

latest_frame = incremental_csv["frame"].iloc[-1]
# update the frame number in the incremental csv
full_csv["frame"] = full_csv["frame"] + latest_frame

joined_csv = pd.concat([incremental_csv, full_csv], ignore_index=True)

joined_csv.to_csv(
f"{new_folder}/derotated_image_stack_full_and_incremental.csv",
index=False,
)


if __name__ == "__main__":
dataset_path = sys.argv[1]
new_folder = Path(dataset_path) / "merged"
new_folder.mkdir(exist_ok=True)
join_incremental_and_full_video(dataset_path, new_folder)
join_csv_files(dataset_path, new_folder)

0 comments on commit 644a764

Please sign in to comment.