-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotIntensityfromCSV.py
More file actions
75 lines (65 loc) · 2.13 KB
/
plotIntensityfromCSV.py
File metadata and controls
75 lines (65 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
"""
Created on Tues Jan 27 2026
@author: Lauren Takiguchi
Purpose: batch intensity profiles for viewing traces from bulk recruitment/single molecule assays
Input: folder of CSVs (each with data of plotted z profile from Fiji)
Output: simple intensity vs frame traces for each CSV
Example usage: python3 plotIntensityfromCSV.py /Users/laurentakiguchi/Desktop/Light-Powered-Motors/Analysis/251126/pLT003/0mMimidazole
"""
import argparse
from pathlib import Path
import pandas as pd
import matplotlib.pyplot as plt
def plot_csv_folder(folder: Path, x_col: str, y_col: str, dpi: int):
if not folder.exists() or not folder.is_dir():
raise ValueError(f"Invalid folder: {folder}")
csv_files = sorted(folder.glob("*.csv"))
if not csv_files:
print("No CSV files found.")
return
for csv_path in csv_files:
df = pd.read_csv(csv_path)
if not {x_col, y_col}.issubset(df.columns):
print(f"Skipping {csv_path.name} (missing {x_col}/{y_col}).")
continue
plt.figure(figsize=(6, 4))
plt.plot(df[x_col], df[y_col], linewidth=2)
plt.xlabel(x_col)
plt.ylabel(y_col)
plt.title(csv_path.stem)
plt.grid(True)
plt.tight_layout()
out_path = csv_path.with_suffix(".png")
plt.savefig(out_path, dpi=dpi)
plt.close()
print(f"Saved: {out_path}")
def main():
parser = argparse.ArgumentParser(
description="Batch-plot CSV files in a folder."
)
parser.add_argument(
"folder",
type=Path,
help="Path to folder containing CSV files"
)
parser.add_argument(
"--x-col",
default="Slice",
help="Column name for x-axis (default: Slice)"
)
parser.add_argument(
"--y-col",
default="Mean",
help="Column name for y-axis (default: Mean)"
)
parser.add_argument(
"--dpi",
type=int,
default=300,
help="Output image DPI (default: 300)"
)
args = parser.parse_args()
plot_csv_folder(args.folder, args.x_col, args.y_col, args.dpi)
if __name__ == "__main__":
main()