@@ -23,47 +23,45 @@ def lambertian_matrix(angle_vector, theta_intv, surf_name, structpath,
23
23
savepath_RT = os .path .join (structpath , surf_name + front_or_rear + 'RT.npz' )
24
24
savepath_A = os .path .join (structpath , surf_name + front_or_rear + 'A.npz' )
25
25
26
- if os .path .isfile (savepath_RT ) and save :
27
- print ('Existing angular redistribution matrices found' )
28
- allArray = load_npz (savepath_RT )
26
+ if os .path .isfile (savepath_RT ):
27
+ print ('Existing angular redistribution matrices found' )
28
+ allArray = load_npz (savepath_RT )
29
+ return allArray
29
30
30
- else :
31
-
32
- theta_values = np .unique (angle_vector [angle_vector [:,1 ] < np .pi / 2 ,1 ])
33
- dtheta = np .diff (theta_intv [theta_intv <= np .pi / 2 ])
34
31
35
- dP = np .cos (theta_values )* dtheta
32
+ theta_values = np .unique (angle_vector [angle_vector [:,1 ] < np .pi / 2 ,1 ])
33
+ dtheta = np .diff (theta_intv [theta_intv <= np .pi / 2 ])
36
34
37
- # matrix has indexing (out, in): row picks out 'out' entry, column picks out which v0 element
35
+ dP = np . cos ( theta_values ) * dtheta
38
36
39
- # since it doesn't matter what the incidence angle is for Lambertian scattering, all the columns rows be identical!
37
+ # matrix has indexing (out, in): row picks out 'out' entry, column picks out which v0 element
40
38
41
- # how many phi entries are there for each theta?
39
+ # since it doesn't matter what the incidence angle is for Lambertian scattering, all the columns rows be identical!
42
40
43
- n_phis = [ np . sum ( angle_vector [:, 1 ] == theta ) for theta in theta_values ]
41
+ # how many phi entries are there for each theta?
44
42
45
- column = [x for sublist in [[ dP [ i1 ] / n ] * n for i1 , n in enumerate ( n_phis )] for x in sublist ]
43
+ n_phis = [np . sum ( angle_vector [:, 1 ] == theta ) for theta in theta_values ]
46
44
47
- whole_matrix = np . vstack ([ column ] * int ( len ( angle_vector ) / 2 )). T
45
+ column = [ x for sublist in [[ dP [ i1 ] / n ] * n for i1 , n in enumerate ( n_phis )] for x in sublist ]
48
46
49
- # renormalize (rounding errors)
47
+ whole_matrix = np . vstack ([ column ] * int ( len ( angle_vector ) / 2 )). T
50
48
51
- whole_matrix_R = whole_matrix / np . sum ( whole_matrix , 0 )
49
+ # renormalize (rounding errors )
52
50
53
- whole_matrix_T = np .zeros_like ( whole_matrix_R )
51
+ whole_matrix_R = whole_matrix / np .sum ( whole_matrix , 0 )
54
52
55
- whole_matrix = np .vstack ([ whole_matrix_R , whole_matrix_T ] )
53
+ whole_matrix_T = np .zeros_like ( whole_matrix_R )
56
54
57
- print ( whole_matrix . shape )
55
+ whole_matrix = np . vstack ([ whole_matrix_R , whole_matrix_T ] )
58
56
59
- A_matrix = np .zeros ((1 ,int (len (angle_vector )/ 2 )))
57
+ A_matrix = np .zeros ((1 ,int (len (angle_vector )/ 2 )))
60
58
61
- allArray = COO (whole_matrix )
62
- absArray = COO (A_matrix )
63
- if save :
64
- save_npz (savepath_RT , allArray )
65
- save_npz (savepath_A , absArray )
59
+ allArray = COO (whole_matrix )
60
+ absArray = COO (A_matrix )
66
61
62
+ if save :
63
+ save_npz (savepath_RT , allArray )
64
+ save_npz (savepath_A , absArray )
67
65
68
66
return allArray
69
67
@@ -87,53 +85,47 @@ def mirror_matrix(angle_vector, theta_intv, phi_intv, surf_name, options, struct
87
85
savepath_RT = os .path .join (structpath , surf_name + front_or_rear + 'RT.npz' )
88
86
savepath_A = os .path .join (structpath , surf_name + front_or_rear + 'A.npz' )
89
87
90
- if os .path .isfile (savepath_RT ) and save :
91
- print ('Existing angular redistribution matrices found' )
92
- allArray = load_npz (savepath_RT )
93
-
94
- else :
95
-
96
- if front_or_rear == "front" :
88
+ if os .path .isfile (savepath_RT ):
89
+ print ('Existing angular redistribution matrices found' )
90
+ allArray = load_npz (savepath_RT )
91
+ return allArray
97
92
98
- angle_vector_th = angle_vector [:int (len (angle_vector )/ 2 ),1 ]
99
- angle_vector_phi = angle_vector [:int (len (angle_vector )/ 2 ),2 ]
100
93
101
- phis_out = fold_phi ( angle_vector_phi + np . pi , options [ 'phi_symmetry' ])
94
+ if front_or_rear == "front" :
102
95
96
+ angle_vector_th = angle_vector [:int (len (angle_vector )/ 2 ),1 ]
97
+ angle_vector_phi = angle_vector [:int (len (angle_vector )/ 2 ),2 ]
103
98
104
- else :
105
- angle_vector_th = angle_vector [int (len (angle_vector ) / 2 ):, 1 ]
106
- angle_vector_phi = angle_vector [int (len (angle_vector ) / 2 ):, 2 ]
99
+ phis_out = fold_phi (angle_vector_phi + np .pi , options ['phi_symmetry' ])
107
100
108
- phis_out = fold_phi (angle_vector_phi + np .pi , options ['phi_symmetry' ])
109
101
110
- # matrix will be all zeros with just one '1' in each column/row. Just need to determine where it goes
102
+ else :
103
+ angle_vector_th = angle_vector [int (len (angle_vector ) / 2 ):, 1 ]
104
+ angle_vector_phi = angle_vector [int (len (angle_vector ) / 2 ):, 2 ]
111
105
112
- binned_theta = np .digitize ( angle_vector_th , theta_intv , right = True ) - 1
106
+ phis_out = fold_phi ( angle_vector_phi + np .pi , options [ 'phi_symmetry' ])
113
107
114
- # print(binned_theta_out, theta_out, theta_intv)
108
+ # matrix will be all zeros with just one '1' in each column/row. Just need to determine where it goes
115
109
116
- # print(binned_theta_in)
117
- # print(binned_theta_out)
118
- # -1 to give the correct index for the bins in phi_intv
110
+ binned_theta = np .digitize (angle_vector_th , theta_intv , right = True ) - 1
119
111
112
+ bin_in = np .arange (len (angle_vector_phi ))
120
113
121
- bin_in = np .arange (len (angle_vector_phi ))
114
+ phi_ind = [np .digitize (phi , phi_intv [binned_theta [i1 ]], right = True ) - 1 for i1 , phi in enumerate (phis_out )]
115
+ overall_bin = [np .argmin (abs (angle_vector [:,0 ] - binned_theta [i1 ])) + phi_i for i1 , phi_i in enumerate (phi_ind )]
122
116
123
- phi_ind = [np .digitize (phi , phi_intv [binned_theta [i1 ]], right = True ) - 1 for i1 , phi in enumerate (phis_out )]
124
- overall_bin = [np .argmin (abs (angle_vector [:,0 ] - binned_theta [i1 ])) + phi_i for i1 , phi_i in enumerate (phi_ind )]
117
+ whole_matrix = np .zeros ((len (overall_bin )* 2 , len (overall_bin )))
125
118
126
- whole_matrix = np . zeros (( len ( overall_bin ) * 2 , len ( overall_bin )))
119
+ whole_matrix [ overall_bin , bin_in ] = 1
127
120
128
- whole_matrix [overall_bin , bin_in ] = 1
129
121
122
+ A_matrix = np .zeros ((1 , len (overall_bin )))
130
123
131
- A_matrix = np .zeros ((1 , len (overall_bin )))
124
+ allArray = COO (whole_matrix )
125
+ absArray = COO (A_matrix )
132
126
133
- allArray = COO (whole_matrix )
134
- absArray = COO (A_matrix )
135
- if save :
136
- save_npz (savepath_RT , allArray )
137
- save_npz (savepath_A , absArray )
127
+ if save :
128
+ save_npz (savepath_RT , allArray )
129
+ save_npz (savepath_A , absArray )
138
130
139
131
return allArray
0 commit comments