Coverage for steam_pysigma\plotters\PlotterPysigma.py: 65%

99 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-12-16 17:09 +0100

1# STEAM PySigma is a python wrapper of STEAM-SIGMA written in Java. 

2# Copyright (C) 2023, CERN, Switzerland. All rights reserved. 

3# 

4# This program is free software: you can redistribute it and/or modify 

5# it under the terms of the GNU General Public License as published by 

6# the Free Software Foundation, version 3 of the License. 

7# 

8# This program is distributed in the hope that it will be useful, 

9# but WITHOUT ANY WARRANTY; without even the implied warranty of 

10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

11# GNU General Public License for more details. 

12# 

13# You should have received a copy of the GNU General Public License 

14# along with this program. If not, see <https://www.gnu.org/licenses/>. 

15 

16import matplotlib.lines as lines 

17import matplotlib.patches as patches 

18import numpy as np 

19from matplotlib import pyplot as plt 

20 

21from steam_pysigma.utils.Utils import displayWaitAndClose 

22 

23 

24def plot_multiple_areas(ax, areas, color=None): 

25 """ 

26 Functions takes in a list of area objects and plot them on axis ax. 

27 :param ax: Axis to create plots. 

28 :param areas: list of SIGMA area objects. 

29 :param color: Color of the object 

30 :return: 

31 """ 

32 for area in areas: 

33 if color: 

34 plot_area(ax, area, color) 

35 else: 

36 plot_area(ax, area) 

37 

38def plot_area(ax, area, color=None): 

39 """ 

40 Plots one SIGMA area object on axis ax 

41 :param ax: Axis to create plots. 

42 :param area: SIGMA area object. 

43 :param color: Color of the object 

44 :return: 

45 """ 

46 if not color: 

47 color = 'black' 

48 points = [] 

49 hls = area.getHyperLines() 

50 for hl in hls: 

51 last_dot_index = hl.toString().rfind('.') 

52 at_index = hl.toString().find('@') 

53 class_name = hl.toString()[last_dot_index + 1:at_index] 

54 if class_name == 'Line': 

55 points.append([hl.getKp1().getX(), hl.getKp1().getY()]) 

56 points.append([hl.getKp2().getX(), hl.getKp2().getY()]) 

57 ax.add_line(lines.Line2D([hl.getKp1().getX(), hl.getKp2().getX()], [hl.getKp1().getY(), hl.getKp2().getY()], color=color)) 

58 elif class_name == 'Arc': 

59 start_angle = np.arctan2(hl.getKp1().getY() - hl.getKpc().getY(), 

60 hl.getKp1().getX() - hl.getKpc().getX()) * 180 / np.pi 

61 end_angle = start_angle + hl.getDTheta() * 180 / np.pi 

62 r = np.sqrt((hl.getKp1().getY() - hl.getKpc().getY()) ** 2 + (hl.getKp1().getX() - hl.getKpc().getX()) ** 2) 

63 ax.add_patch(patches.Arc( 

64 [hl.getKpc().getX(), hl.getKpc().getY()], 

65 2 * r, 

66 2 * r, 

67 angle=0, 

68 theta1=min(start_angle, end_angle), 

69 theta2=max(start_angle, end_angle), 

70 color=color 

71 )) 

72 elif class_name == 'Circumference': 

73 r = hl.getRadius() 

74 ax.add_patch(patches.Arc( 

75 [hl.getCenter().getX(), hl.getCenter().getY()], 

76 2 * r, 

77 2 * r, 

78 angle=0, 

79 theta1=0, 

80 theta2=360 

81 )) 

82 

83 elif class_name == 'EllipticArc': 

84 pt1 = (hl.getKp1().getX(), hl.getKp1().getY()) 

85 ptc = (hl.getKpc().getX(), hl.getKpc().getY()) 

86 dTheta = hl.getDTheta()*180/np.pi 

87 a, b = hl.getA(), hl.getB() 

88 

89 start_angle = float(np.degrees(np.arctan2(pt1[1] - ptc[1], pt1[0] - ptc[0]))) 

90 

91 arc = patches.Arc(ptc, 2 * a, 2 * b, angle=0, theta1=start_angle, theta2=start_angle + dTheta,color=color ) 

92 

93 ax.add_patch(arc) 

94 else: 

95 raise ValueError('Not supported Hyperline object!') 

96 # try: 

97 # ax.add_line(lines.Line2D([points[0][0], points[3][0]], [points[0][1], points[3][1]], color=color)) 

98 # ax.add_line(lines.Line2D([points[1][0], points[2][0]], [points[1][1], points[2][1]], color=color)) 

99 # except: print("couldn't plot line") 

100 

101 

102# def write_result_summary(df, n1, n2): 

103# with open("error_summary.txt", "a") as myfile: 

104# mean_Bmod_error = (df["Bmod_error"]).mean() * 1000 

105# abs_mean_Bmod_error = abs(df["Bmod_error"]).mean() * 1000 

106# std_Bmod_error = (df["Bmod_error"]).std() * 1000 

107# max_Bmod_error = abs(df["Bmod_error"]).max() * 1000 

108# min_Bmod_error = abs(df["Bmod_error"]).min() * 1000 

109# myfile.write(f"{n1*n2} {mean_Bmod_error} {std_Bmod_error} {abs_mean_Bmod_error} {max_Bmod_error} {min_Bmod_error}\n") 

110# max_index = abs(df["Bmod_error"]).idxmax() 

111# print(f"Absolute Bmod error mean: {abs_mean_Bmod_error}") 

112# 

113# print(f"Absolute Bmod error mean max index : {max_index}") 

114# 

115# def plot_Bmod(df, map2d_name1, map2d_name2, fig, ax, type, cmap='plasma'): 

116# fig.suptitle(f"Bmod: {map2d_name1} and {map2d_name2} (mT)") 

117# ax[0, 0].set_title(f"Bmod: {map2d_name1} (mT)") 

118# ax[0, 0].set_xlabel('x-coordinate/mm') 

119# ax[0, 0].set_ylabel('y-coordinate/mm') 

120# ax[0, 1].set_title(f"Bmod: {map2d_name2} (mT)") 

121# ax[0, 1].set_xlabel('x-coordinate/mm') 

122# ax[0, 1].set_ylabel('y-coordinate/mm') 

123# ax[1, 0].plot(df["Bmod1"] * 1000, '.') 

124# ax[1, 0].set_title(f"Bmod scatter: {map2d_name1} (mT)") 

125# ax[1, 0].set_xlabel('Strand number') 

126# ax[1, 0].set_ylabel(f'Bmod scatter: {map2d_name1} (mT)') 

127# ax[1, 1].plot(df["Bmod2"] * 1000, '.') 

128# ax[1, 1].set_xlabel('Strand number') 

129# ax[1, 1].set_ylabel('Scatter Bmod (mT)') 

130# ax[1, 1].set_title(f"Bmod scatter: {map2d_name2} (mT)") 

131# ax[0, 0].set_aspect("equal") 

132# ax[0, 1].set_aspect("equal") 

133# if(type=="coil"): 

134# f11 = ax[0, 0].scatter(df["x"], df['y'], c=df["Bmod1"] * 1000, cmap=cmap) 

135# f12 = ax[0, 1].scatter(df["x"], df['y'], c=df["Bmod2"] * 1000, cmap=cmap) 

136# fig.colorbar(f11, ax=ax[0, 0]) 

137# fig.colorbar(f12, ax=ax[0, 1]) 

138# elif(type=="mesh"): 

139# x = np.array(df['x'].tolist()) 

140# y = np.array(df['y'].tolist()) 

141# z1 = np.array(df['Bmod1'].tolist())*1000 

142# z2 = np.array(df['Bmod2'].tolist())*1000 

143# np.random.seed(1234) # fix seed for reproducibility 

144# 

145# tpc1 = ax[0, 0].tripcolor(x, y, z1, shading='gouraud', cmap=cmap) 

146# tpc2 = ax[0, 1].tripcolor(x, y, z2, shading='gouraud', cmap=cmap) 

147# 

148# fig.colorbar(tpc1) 

149# fig.colorbar(tpc2) 

150 

151 

152 

153# def plot_B_mod_error(df, map2d_name1, map2d_name2, fig, ax, type, cmap='winter'): 

154# fig.suptitle(f"Bmod error: {map2d_name1} - {map2d_name2} (mT)") 

155# ax[0].set_title(f"Bmod error (mT)") 

156# ax[0].set_xlabel('x-coordinate/mm', fontsize=9) 

157# ax[0].set_ylabel('y-coordinate/mm', fontsize=9) 

158# ax[0].set_aspect("equal") 

159# ax[1].set_title(f"Bmod error scatter (mT)") 

160# 

161# ax[1].set_xlabel('x') 

162# ax[1].set_ylabel('y') 

163# ax[1].plot(df["Bmod_error"] * 1000, '.') 

164# if(type=="coil"): 

165# f11 = ax[0].scatter(df["x"], df['y'], c=df["Bmod_error"] * 1000, cmap=cmap) 

166# fig.colorbar(f11, ax=ax[0]) 

167# elif(type=="mesh"): 

168# x = np.array(df['x'].tolist()) 

169# y = np.array(df['y'].tolist()) 

170# z1 = np.array(df['Bmod_error'].tolist())*1000 

171# 

172# np.random.seed(1234) # fix seed for reproducibility 

173# 

174# tpc = ax[0].tripcolor(x, y, z1, shading='gouraud', cmap=cmap) 

175# fig.colorbar(tpc) 

176 

177 

178# def plot_relative_error_x_y(df, map2d_name1, map2d_name2, fig, ax, type, cmap='CMRmap'): 

179# fig.suptitle(f"Relative error: {map2d_name1} and {map2d_name2} (T)") 

180# ax[0, 0].set_aspect("equal") 

181# ax[0, 1].set_aspect("equal") 

182# 

183# ax[0, 0].set_title(f"Relative error Bx %") 

184# ax[0, 0].set_xlabel('x-coordinate/mm') 

185# ax[0, 0].set_ylabel('y-coordinate/mm') 

186# ax[0, 1].set_title(f"Relative error By %") 

187# ax[0, 1].set_xlabel('x-coordinate/mm') 

188# ax[0, 1].set_ylabel('y-coordinate/mm') 

189# 

190# ax[1, 0].plot(df["rel_err_x"] * 100, '.') 

191# ax[1, 0].set_title(f"Scatter Relative error Bx %") 

192# ax[1, 0].set_xlabel('Strand number') 

193# ax[1, 0].set_ylabel('Relative error Bx %') 

194# ax[1, 1].plot(df["rel_err_y"] * 100, '.') 

195# ax[1, 1].set_xlabel('Strand number') 

196# ax[1, 1].set_ylabel('Relative error By %') 

197# ax[1, 1].set_title(f"Scatter Relative error By %") 

198# if(type=="coil"): 

199# f31 = ax[0, 0].scatter(df["x"], df['y'], c=df["rel_err_x"] * 100, cmap=cmap) 

200# f32 = ax[0, 1].scatter(df["x"], df['y'], c=df["rel_err_y"] * 100, cmap=cmap) 

201# fig.colorbar(f31, ax=ax[0, 0]) 

202# fig.colorbar(f32, ax=ax[0, 1]) 

203# elif(type=="mesh"): 

204# x = np.array(df['x'].tolist()) 

205# y = np.array(df['y'].tolist()) 

206# z1 = np.array(df['rel_err_x'].tolist())*100 

207# z2 = np.array(df['rel_err_y'].tolist())*100 

208# np.random.seed(1234) # fix seed for reproducibility 

209# 

210# tpc1 = ax[0, 0].tripcolor(x, y, z1, shading='gouraud', cmap=cmap) 

211# tpc2 = ax[0, 1].tripcolor(x, y, z2, shading='gouraud', cmap=cmap) 

212# 

213# fig.colorbar(tpc1) 

214# fig.colorbar(tpc2) 

215 

216 

217# def plot_Bx_By(df, map2d_name1, map2d_name2, fig, ax, type, cmap='seismic', plot_coil=False): 

218# fig.suptitle(f"Bx and By field: {map2d_name1} and {map2d_name2} (mT)", fontsize=12) 

219# 

220# ax[0, 0].set_title(f"Bx {map2d_name1} (mT)", fontsize=10) 

221# ax[0, 0].set_ylabel('y-coordinate/mm', fontsize=9) 

222# ax[0, 0].set_aspect("equal") 

223# ax[0, 1].set_aspect("equal") 

224# ax[1, 0].set_aspect("equal") 

225# ax[1, 1].set_aspect("equal") 

226# ax[0, 1].set_title(f"By {map2d_name1} (mT)", fontsize=10) 

227# ax[0, 1].set_ylabel('y-coordinate/mm', fontsize=9) 

228# 

229# ax[1, 0].set_title(f"Bx {map2d_name2} (mT)", fontsize=10) 

230# ax[1, 0].set_xlabel('x-coordinate/mm', fontsize=9) 

231# ax[1, 0].set_ylabel('y-coordinate/mm', fontsize=9) 

232# ax[1, 1].set_title(f"By {map2d_name2} (mT)", fontsize=10) 

233# ax[1, 1].set_xlabel('x-coordinate/mm', fontsize=9) 

234# ax[1, 1].set_ylabel('y-coordinate/mm', fontsize=9) 

235# ax[2, 0].set_title(f"Bx scatter (mT)", fontsize=14, loc='left') 

236# ax[2, 0].set_ylabel('Bx scatter (mT)', fontsize=9) 

237# ax[2, 0].plot(df["Bx1"] * 1000, '.', color='b', label=f"{map2d_name1}") 

238# ax[2, 0].plot(df["Bx2"] * 1000, '.', color='r', label=f"{map2d_name2}") 

239# ax[2, 1].set_title(f"By scatter (mT)", fontsize=14, loc='left') 

240# ax[2, 1].set_ylabel('By scatter (mT)', fontsize=9) 

241# 

242# ax[2, 1].plot(df["By1"] * 1000, '.', color='b', label=f"{map2d_name1}") 

243# ax[2, 1].plot(df["By2"] * 1000, '.', color='r', label=f"{map2d_name2}") 

244# ax[2, 0].legend() 

245# ax[2, 1].legend() 

246# 

247# if(type == "coil"): 

248# f41 = ax[0, 0].scatter(df["x"], df['y'], c=df["Bx1"] * 1000, cmap=cmap) 

249# f42 = ax[0, 1].scatter(df["x"], df['y'], c=df["By1"] * 1000, cmap=cmap) 

250# f43 = ax[1, 0].scatter(df["x"], df['y'], c=df["Bx2"] * 1000, cmap=cmap) 

251# f44 = ax[1, 1].scatter(df["x"], df['y'], c=df["By2"] * 1000, cmap=cmap) 

252# fig.colorbar(f41, ax=ax[0, 0]) 

253# fig.colorbar(f42, ax=ax[0, 1]) 

254# fig.colorbar(f43, ax=ax[1, 0]) 

255# fig.colorbar(f44, ax=ax[1, 1]) 

256# elif(type=="mesh"): 

257# x = np.array(df['x'].tolist()) 

258# y = np.array(df['y'].tolist()) 

259# Bx1 = np.array(df['Bx1'].tolist())*1000 

260# By1 = np.array(df['By1'].tolist())*1000 

261# Bx2 = np.array(df['Bx2'].tolist())*1000 

262# By2 = np.array(df['By2'].tolist())*1000 

263# np.random.seed(1234) # fix seed for reproducibility 

264# 

265# tpc1 = ax[0, 0].tripcolor(x, y, Bx1, shading='gouraud', cmap=cmap) 

266# tpc2 = ax[0, 1].tripcolor(x, y, By1, shading='gouraud', cmap=cmap) 

267# tpc3 = ax[1, 0].tripcolor(x, y, Bx2, shading='gouraud', cmap=cmap) 

268# tpc4 = ax[1, 1].tripcolor(x, y, By2, shading='gouraud', cmap=cmap) 

269# 

270# fig.colorbar(tpc1, ax=ax[0, 0]) 

271# fig.colorbar(tpc2, ax=ax[0, 1]) 

272# fig.colorbar(tpc3, ax=ax[1, 0]) 

273# fig.colorbar(tpc4, ax=ax[1, 1]) 

274# 

275# 

276# def plot_difference_Bx_By(df, map2d_name1, map2d_name2, fig, ax, type, cmap='seismic', plot_coil=False): 

277# fig.suptitle(f"Difference: {map2d_name1} - {map2d_name2} (mT)") 

278# ax[0, 0].set_title(f"Difference Bx (mT)") 

279# ax[0, 0].set_xlabel('x-coordinate/mm') 

280# ax[0, 0].set_ylabel('y-coordinate/mm') 

281# ax[0, 1].set_title(f"Difference By (mT)") 

282# ax[0, 1].set_xlabel('x-coordinate/mm') 

283# ax[0, 1].set_ylabel('y-coordinate/mm') 

284# ax[1, 0].plot(df["diff_x"] * 1000, '.') 

285# ax[1, 0].set_title(f"Scatter difference Bx (mT)") 

286# ax[1, 0].set_xlabel('Strand number') 

287# ax[1, 0].set_ylabel('Difference Bx (mT)') 

288# ax[1, 1].plot(df["diff_y"] * 1000, '.') 

289# ax[1, 1].set_xlabel('Strand number') 

290# ax[1, 1].set_ylabel('Scatter difference By (mT)') 

291# ax[1, 1].set_title(f"Scatter difference By (mT)") 

292# ax[0, 0].set_aspect("equal") 

293# ax[0, 1].set_aspect("equal") 

294# if(type=="coil"): 

295# f11 = ax[0, 0].scatter(df["x"], df['y'], c=df["diff_x"] * 1000, cmap=cmap) 

296# f12 = ax[0, 1].scatter(df["x"], df['y'], c=df["diff_y"] * 1000, cmap=cmap) 

297# fig.colorbar(f11, ax=ax[0, 0]) 

298# fig.colorbar(f12, ax=ax[0, 1]) 

299# elif(type=="mesh"): 

300# 

301# x = np.array(df['x'].tolist()) 

302# y = np.array(df['y'].tolist()) 

303# diff_x = np.array(df['diff_x'].tolist())*1000 

304# diff_y = np.array(df['diff_y'].tolist())*1000 

305# 

306# np.random.seed(1234) # fix seed for reproducibility 

307# tpc1 = ax[0, 0].tripcolor(x, y, diff_x, shading='gouraud', cmap=cmap) 

308# tpc2 = ax[0, 1].tripcolor(x, y, diff_y, shading='gouraud', cmap=cmap) 

309# 

310# fig.colorbar(tpc1, ax=ax[0, 0]) 

311# fig.colorbar(tpc2, ax=ax[0, 1]) 

312# 

313# 

314 

315# def get_df_map2d(map2d_file_path1, map2d_file_path2): 

316# 

317# df1 = pd.read_csv(map2d_file_path1, delim_whitespace=True) 

318# df2 = pd.read_csv(map2d_file_path2, delim_whitespace=True) 

319# df = pd.DataFrame() 

320# df['x'] = df1["X-POS/MM"] 

321# df['y'] = df1["Y-POS/MM"] 

322# df["Bx1"] = df1["BX/T"] 

323# df["By1"] = df1["BY/T"] 

324# 

325# df["Bx2"] = df2["BX/T"] 

326# df["By2"] = df2["BY/T"] 

327# df = df.apply(pd.to_numeric) 

328# df["diff_x"] = df["Bx1"] - df["Bx2"] 

329# df["diff_y"] = df["By1"] - df["By2"] 

330# df["rel_err_x"] = abs((df["Bx1"] - df["Bx2"]) / df["Bx2"]) 

331# df["rel_err_y"] = abs((df["By1"] - df["By2"]) / df["By2"]) 

332# df["abs_err_x"] = abs(df["Bx1"] - df["Bx2"]) 

333# df["abs_err_y"] = abs(df["By1"] - df["By2"]) 

334# df["Bmod1"] = np.sqrt(df["Bx1"] ** 2 + df["By1"] ** 2) 

335# df["Bmod2"] = np.sqrt(df["Bx2"] ** 2 + df["By2"] ** 2) 

336# df["Bmod_error"] = df["Bmod1"] - df["Bmod2"] 

337# return df 

338# 

339# def generate_report_from_map2d(working_dir_path, map2d_file_path1, map2d_name1, map2d_file_path2, map2d_name2, type, save=False): 

340# """ 

341# Generate plots for comparing two map2d files. Method generates the following plots: 

342# Bmod fields, Bmod error, relative error Bx/By, Bx/By field, Bx/By error, absolut difference Bx/By 

343# :param map2d_file_path1: Path to map2d file nr 1 

344# :param map2d_name1: String name of map2d nr 1 (e.g SIGMA/ROXIE) 

345# :param map2d_file_path2: Path to map2d file nr 2 

346# :param map2d_name2: String name of map2d nr 1 (e.g SIGMA/ROXIE) 

347# :return: 

348# """ 

349# df=get_df_map2d(map2d_file_path1, map2d_file_path2) 

350# fig1, ax1 = plt.subplots(2, 2, figsize=(12, 12)) 

351# fig2, ax2 = plt.subplots(1, 2, figsize=(12, 12)) 

352# fig3, ax3 = plt.subplots(3, 2, figsize=(12, 12)) 

353# fig4, ax4 = plt.subplots(2, 2, figsize=(12, 12)) 

354# fig5, ax5 = plt.subplots(2, 2, figsize=(12, 12)) 

355# plot_Bmod(df, map2d_name1, map2d_name2, fig1, ax1, type) 

356# plot_B_mod_error(df,map2d_name1, map2d_name2, fig2, ax2, type) 

357# plot_Bx_By(df, map2d_name1, map2d_name2, fig3, ax3, type) 

358# try: 

359# plot_relative_error_x_y(df, map2d_name1, map2d_name2, fig4, ax4, type) 

360# except: 

361# print("Couldn't generate relative error plots.") 

362# plot_difference_Bx_By(df, map2d_name1, map2d_name2, fig5, ax5, type) 

363# print("----Bmod error description----- ") 

364# print(df["Bmod_error"].describe()) 

365# print(df["Bmod_error"].nlargest(10)) 

366# 

367# print("----Rel error x description----- ") 

368# print(df["rel_err_x"].describe()) 

369# print(df["rel_err_x"].nlargest(10)) 

370# print("----Rel error y description----- ") 

371# print(df["rel_err_y"].describe()) 

372# print(df["rel_err_y"].nlargest(10)) 

373# if save: 

374# fig1.savefig(os.path.join(working_dir_path, "plot_Bmod.png")) 

375# fig2.savefig(os.path.join(working_dir_path,"plot_B_mod_error.png")) 

376# fig3.savefig(os.path.join(working_dir_path,"plot_Bx_By.png")) 

377# fig4.savefig(os.path.join(working_dir_path,"plot_relative_error_x_y.png")) 

378# fig5.savefig(os.path.join(working_dir_path,"plot_difference_Bx_By.png")) 

379# 

380# displayWaitAndClose(waitTimeBeforeMessage=.1, waitTimeAfterMessage=10) 

381 

382def plot_roxie_coil(roxie_data): 

383 xPos = [] 

384 yPos = [] 

385 xBarePos = [] 

386 yBarePos = [] 

387 iPos = [] 

388 for coil_nr, coil in roxie_data.coil.coils.items(): 

389 for pole_nr, pole in coil.poles.items(): 

390 for layer_nr, layer in pole.layers.items(): 

391 for winding_key, winding in layer.windings.items(): 

392 for block_key, block in winding.blocks.items(): 

393 for halfTurn_nr, halfTurn in block.half_turns.items(): 

394 insu = halfTurn.corners.insulated 

395 bare = halfTurn.corners.bare 

396 xPos.append([insu.iH.x, insu.oH.x, insu.oLA.x, insu.iLA.x]) 

397 yPos.append([insu.iH.y, insu.oH.y, insu.oLA.y, insu.iLA.y]) 

398 xBarePos.append([bare.iH.x, bare.oH.x, bare.oLA.x, bare.iLA.x]) 

399 yBarePos.append([bare.iH.y, bare.oH.y, bare.oLA.y, bare.iLA.y]) 

400 iPos.append(block.current_sign) 

401 return (xPos, yPos, xBarePos, yBarePos, iPos) 

402 

403def plotEdges(xPos, yPos, xBarePos, yBarePos, iPos, ax): 

404 # Plot edges 

405 for c, (cXPos, cYPos) in enumerate(zip(xPos, yPos)): 

406 pt1, pt2, pt3, pt4 = [cXPos[0]*1000, cYPos[0]*1000], [cXPos[1]*1000, cYPos[1]*1000], [cXPos[2]*1000, cYPos[2]*1000], [cXPos[3]*1000, cYPos[3]*1000] 

407 points = [pt1, pt2, pt3, pt4]*1000 

408 if iPos[c] > 0: 

409 line = patches.Polygon(points, facecolor='k', zorder=1, fill=False) 

410 else: 

411 line = patches.Polygon(points, facecolor='k', zorder=1, fill=False) 

412 ax.add_patch(line) 

413 

414 for c, (cXBarePos, cYBarePos) in enumerate(zip(xBarePos, yBarePos)): 

415 pt1, pt2, pt3, pt4 = [cXBarePos[0]*1000, cYBarePos[0]*1000], [cXBarePos[1]*1000, cYBarePos[1]*1000], \ 

416 [cXBarePos[2]*1000, cYBarePos[2]*1000],[cXBarePos[3]*1000, cYBarePos[3]*1000] 

417 points = [pt1, pt2, pt3, pt4] 

418 if iPos[c] > 0: 

419 line = patches.Polygon(points, facecolor='k', zorder=1, fill=False) 

420 else: 

421 line = patches.Polygon(points, facecolor='k', zorder=1, fill=False) 

422 ax.add_patch(line) 

423 

424 

425def plot_magnet(iron_yoke_areas, wedge_areas, roxie_data): 

426 """ 

427 Plot blocks and halfturns for the roxie model data 

428 :return: None 

429 """ 

430 fig = plt.figure(figsize=(10, 10)) 

431 ax = plt.axes() 

432 ax.set_xlim(0., 0.2) 

433 ax.set_ylim(-.1, 0.1) 

434 show_halfTurns = True 

435 # p.plot_multiple_areas(ax, self.air_far_field_areas) # air far field 

436 # p.plot_multiple_areas(ax, self.air_areas) # air 

437 plot_multiple_areas(ax, iron_yoke_areas) # iron yoke 

438 plot_multiple_areas(ax, wedge_areas) # wedges 

439 if show_halfTurns: 

440 for coil_nr, coil in roxie_data.coil.coils.items(): 

441 for pole_nr, pole in coil.poles.items(): 

442 for layer_nr, layer in pole.layers.items(): 

443 for winding_key, winding in layer.windings.items(): 

444 for block_key, block in winding.blocks.items(): 

445 for halfTurn_nr, halfTurn in block.half_turns.items(): 

446 iH = halfTurn.corners.insulated.iH 

447 iL = halfTurn.corners.insulated.iL 

448 oH = halfTurn.corners.insulated.oH 

449 oL = halfTurn.corners.insulated.oL 

450 ax.add_line(lines.Line2D([iH.x, iL.x], [iH.y, iL.y], color='red')) 

451 ax.add_line(lines.Line2D([oH.x, oL.x], [oH.y, oL.y], color='red')) 

452 ax.add_line(lines.Line2D([oL.x, iL.x], [oL.y, iL.y], color='red')) 

453 ax.add_line(lines.Line2D([iH.x, oH.x], [iH.y, oH.y], color='red')) 

454 #p.plot_multiple_areas(ax, self.coil_areas) 

455 displayWaitAndClose(waitTimeBeforeMessage=0.1, waitTimeAfterMessage=10)