Skip to content

Commit f419c26

Browse files
authored
Merge pull request #21 from qpv-research-group/new_tests
New tests
2 parents f60b8c9 + d820421 commit f419c26

File tree

4 files changed

+154
-190
lines changed

4 files changed

+154
-190
lines changed

rayflare/matrix_formalism/ideal_cases.py

+48-56
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,45 @@ def lambertian_matrix(angle_vector, theta_intv, surf_name, structpath,
2323
savepath_RT = os.path.join(structpath, surf_name + front_or_rear + 'RT.npz')
2424
savepath_A = os.path.join(structpath, surf_name + front_or_rear + 'A.npz')
2525

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
2930

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])
3431

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])
3634

37-
# matrix has indexing (out, in): row picks out 'out' entry, column picks out which v0 element
35+
dP = np.cos(theta_values)*dtheta
3836

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
4038

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!
4240

43-
n_phis = [np.sum(angle_vector[:,1] == theta) for theta in theta_values]
41+
# how many phi entries are there for each theta?
4442

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]
4644

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]
4846

49-
# renormalize (rounding errors)
47+
whole_matrix = np.vstack([column]*int(len(angle_vector)/2)).T
5048

51-
whole_matrix_R = whole_matrix/np.sum(whole_matrix,0)
49+
# renormalize (rounding errors)
5250

53-
whole_matrix_T = np.zeros_like(whole_matrix_R)
51+
whole_matrix_R = whole_matrix/np.sum(whole_matrix,0)
5452

55-
whole_matrix = np.vstack([whole_matrix_R, whole_matrix_T])
53+
whole_matrix_T = np.zeros_like(whole_matrix_R)
5654

57-
print(whole_matrix.shape)
55+
whole_matrix = np.vstack([whole_matrix_R, whole_matrix_T])
5856

59-
A_matrix = np.zeros((1,int(len(angle_vector)/2)))
57+
A_matrix = np.zeros((1,int(len(angle_vector)/2)))
6058

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)
6661

62+
if save:
63+
save_npz(savepath_RT, allArray)
64+
save_npz(savepath_A, absArray)
6765

6866
return allArray
6967

@@ -87,53 +85,47 @@ def mirror_matrix(angle_vector, theta_intv, phi_intv, surf_name, options, struct
8785
savepath_RT = os.path.join(structpath, surf_name + front_or_rear + 'RT.npz')
8886
savepath_A = os.path.join(structpath, surf_name + front_or_rear + 'A.npz')
8987

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
9792

98-
angle_vector_th = angle_vector[:int(len(angle_vector)/2),1]
99-
angle_vector_phi = angle_vector[:int(len(angle_vector)/2),2]
10093

101-
phis_out = fold_phi(angle_vector_phi + np.pi, options['phi_symmetry'])
94+
if front_or_rear == "front":
10295

96+
angle_vector_th = angle_vector[:int(len(angle_vector)/2),1]
97+
angle_vector_phi = angle_vector[:int(len(angle_vector)/2),2]
10398

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'])
107100

108-
phis_out = fold_phi(angle_vector_phi + np.pi, options['phi_symmetry'])
109101

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]
111105

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'])
113107

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
115109

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
119111

112+
bin_in = np.arange(len(angle_vector_phi))
120113

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)]
122116

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)))
125118

126-
whole_matrix = np.zeros((len(overall_bin)*2, len(overall_bin)))
119+
whole_matrix[overall_bin, bin_in] = 1
127120

128-
whole_matrix[overall_bin, bin_in] = 1
129121

122+
A_matrix = np.zeros((1, len(overall_bin)))
130123

131-
A_matrix = np.zeros((1, len(overall_bin)))
124+
allArray = COO(whole_matrix)
125+
absArray = COO(A_matrix)
132126

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)
138130

139131
return allArray

0 commit comments

Comments
 (0)