1
+ from cmath import phase
2
+ from acpreprocessing .utils import io
3
+ import argschema
4
+ from argschema .fields import Str
5
+ import os
6
+ import matplotlib .pyplot as plt
7
+ import numpy as np
8
+
9
+ example_input = {
10
+ "stitchDir" : "/ACdata/processed/iSPIM2/MN8_S10_220211_high_res/stitch-s3/iter0" ,
11
+ "filename" : "pairwise-stitched.json" ,
12
+ "d_name" : "MN8_S10_220211_high_res" ,
13
+ "save_dir" : "/ACdata/processed/iSPIM2/MN8_S10_220211_high_res/stitch-s3/stitching_eval/"
14
+ }
15
+
16
+ def normalize (data ):
17
+ norm_data = []
18
+ dmin , dmax = min (data ), max (data )
19
+ for i , val in enumerate (data ):
20
+ norm_data .append ((val - dmin ) / (dmax - dmin ))
21
+ return norm_data
22
+
23
+ class GraphStitchCorr (argschema .ArgSchema ):
24
+ stitchDir = Str (required = True , description = 'stitch iter directory' )
25
+ filename = Str (required = False , default = "pairwise-stitched.json" , description = 'which json file to grab stitch data from' )
26
+ d_name = Str (required = True , description = 'dataset name' )
27
+
28
+ class GraphStitchCorr (argschema .ArgSchemaParser ):
29
+ default_schema = GraphStitchCorr
30
+
31
+ def run (self ):
32
+ pairwise = io .read_json (os .path .join (self .args ['stitchDir' ], self .args ["filename" ]))
33
+ n_pairs = len (pairwise )
34
+ labels = []
35
+ corrs = []
36
+ variances = []
37
+ displacement_z = []
38
+ # displacement_x = []
39
+ # displacement_y = []
40
+ # phase_corrs = []
41
+ for pair in pairwise :
42
+ pair_label = "{}&{}" .format (pair [0 ]["tilePair" ]["tilePair" ][0 ]["index" ],pair [0 ]["tilePair" ]["tilePair" ][1 ]["index" ])
43
+ labels .append (pair_label )
44
+ variances .append (pair [0 ]["variance" ])
45
+ corrs .append (pair [0 ]["crossCorrelation" ])
46
+ # displacement_x.append(abs(pair[0]["displacement"][0]))
47
+ # displacement_y.append(abs(pair[0]["displacement"][1]))
48
+ displacement_z .append (abs (pair [0 ]["displacement" ][2 ]))
49
+ # phase_corrs.append(pair[0]["phaseCorrelation"])
50
+
51
+
52
+ norm_var = normalize (variances )
53
+ # norm_displ_x = normalize(displacement_x)
54
+ # norm_displ_y = normalize(displacement_y)
55
+ norm_displ_z = normalize (displacement_z )
56
+ # norm_phase = normalize(phase_corrs)
57
+
58
+ plt .plot (labels , corrs , linestyle = '--' , marker = 'x' , label = "cross correlation" )
59
+ plt .legend (loc = "upper left" )
60
+ plt .xticks (rotation = 90 )
61
+ plt .xlabel ("Tile Pair" )
62
+ plt .ylabel ("Cross Correlation" )
63
+ plt .title ("Cross correlation for {}" .format (self .args ['d_name' ]))
64
+ plt .savefig (self .args ["save_dir" ]+ 'crossCorr.png' , bbox_inches = "tight" )
65
+
66
+ plt .figure (2 )
67
+ plt .plot (labels , corrs , linestyle = '--' , marker = 'x' , label = "cross correlation" )
68
+ # plt.plot(labels, norm_displ_x, linestyle='--', marker='+', label="norm displacement x")
69
+ # plt.plot(labels, norm_displ_y, linestyle='--', marker='+', label="norm displacement y")
70
+ plt .plot (labels , norm_displ_z , linestyle = '--' , marker = '+' , label = "norm displacement z" )
71
+ plt .legend (loc = "upper left" )
72
+ plt .xticks (rotation = 90 )
73
+ plt .xlabel ("Tile Pair" )
74
+ plt .ylabel ("Values 0-1" )
75
+ plt .title ("Cross correlation and Z Normalized Displacements for {}" .format (self .args ['d_name' ]))
76
+ plt .savefig (self .args ["save_dir" ]+ 'with_z_displ.png' , bbox_inches = "tight" )
77
+
78
+ plt .figure (3 )
79
+ plt .plot (labels , corrs , linestyle = '--' , marker = 'x' , label = "cross correlation" )
80
+ plt .plot (labels , norm_var , linestyle = '--' , marker = '.' , label = "norm variance" )
81
+ plt .legend (loc = "lower left" )
82
+ plt .xticks (rotation = 90 )
83
+ plt .xlabel ("Tile Pair" )
84
+ plt .ylabel ("Values 0-1" )
85
+ plt .title ("Cross correlation and Normalized Variance for {}" .format (self .args ['d_name' ]))
86
+ plt .savefig (self .args ["save_dir" ]+ 'with_norm_vars.png' , bbox_inches = "tight" )
87
+
88
+ # plt.figure(4)
89
+ # plt.plot(labels, corrs, linestyle='--', marker='x', label="cross correlation")
90
+ # plt.plot(labels, phase_corrs, linestyle='--', marker='.', label="phase correlation")
91
+ # plt.legend(loc="upper left")
92
+ # plt.xticks(rotation = 90)
93
+ # plt.xlabel("Tile Pair")
94
+ # plt.ylabel("Values 0-1")
95
+ # plt.title("Cross correlation and Phase Correlation for {}".format(self.args['d_name']))
96
+ # plt.savefig(self.args["save_dir"]+'with_norm_phase.png', bbox_inches = "tight")
97
+
98
+
99
+ if __name__ == '__main__' :
100
+ mod = GraphStitchCorr (example_input )
101
+ mod .run ()
0 commit comments