-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05-1-log-downsize-factors.py
40 lines (28 loc) · 1.17 KB
/
05-1-log-downsize-factors.py
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
import pandas as pd
import palom
from palom.cli import align_he
def get_downsize_factors(
ref_file_path: str,
moving_file_path: str,
ref_thumbnail_level: int = 0,
):
r1 = align_he.get_reader(ref_file_path)(ref_file_path)
r2 = align_he.get_reader(moving_file_path)(moving_file_path)
matched_levels = palom.align_multi_res.match_levels(r1, r2)
affine_level1, affine_level2 = matched_levels[ref_thumbnail_level]
out_level1, out_level2 = 0, 0
d_moving = r2.level_downsamples[affine_level2] / r2.level_downsamples[out_level2]
d_ref = r1.level_downsamples[affine_level1] / r1.level_downsamples[out_level1]
return d_ref, d_moving
REF_DOWISIZE_FACTOR = 4
files = r"X:\cycif-production\110-BRCA-Mutant-Ovarian-Precursors\HE\registered\script\files-all.csv"
df = pd.read_csv(files)
d_factors = df[["p1", "p2"]].apply(
lambda x: get_downsize_factors(x["p1"], x["p2"], REF_DOWISIZE_FACTOR), axis=1
)
df["ref-downsize-factor-roi"] = [dd[0] for dd in d_factors]
df["moving-downsize-factor-roi"] = [dd[1] for dd in d_factors]
df.to_csv(
r"X:\cycif-production\110-BRCA-Mutant-Ovarian-Precursors\HE\registered\script\files-all.csv",
index=False,
)