Created
December 21, 2015 08:41
-
-
Save adler-j/e25f9917a771794c34d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\Users\Jonas\Desktop> python -m line_profiler gadgetzan.py.lprof | |
Timer unit: 3.00191e-07 s | |
Total time: 8.63965 s | |
File: d:\github\odl\odl\util\phantom.py | |
Function: _phantom_3d at line 231 | |
Line # Hits Time Per Hit % Time Line Contents | |
============================================================== | |
231 @profile | |
232 def _phantom_3d(space, ellipses | |
): | |
233 """Create a phantom in 3d s | |
pace. | |
234 | |
235 Parameters | |
236 ---------- | |
237 space : `DiscreteLp` | |
238 The space the phantom s | |
hould be generated in. | |
239 ellipses : list of lists | |
240 Each row should contain | |
: | |
241 'value', 'axis_1', 'axi | |
s_2', 'axis_2', | |
242 'center_x', 'center_y', | |
'center_z', | |
243 'rotation_phi', 'rotati | |
on_theta', 'rotation_psi' | |
244 The ellipses should be | |
contained the he rectangle | |
245 [-1, -1, -1] x [1, 1, 1 | |
]. | |
246 | |
247 Returns | |
248 ------- | |
249 phantom : `DisceteLpVector` | |
250 The phantom | |
251 """ | |
252 | |
253 # Blank image | |
254 1 35 35.0 0.0 p = np.zeros(space.size) | |
255 | |
256 # Create the pixel grid | |
257 1 3396097 3396097.0 11.8 points = space.points() | |
258 1 41 41.0 0.0 minp = space.grid.min() | |
259 1 16 16.0 0.0 maxp = space.grid.max() | |
260 | |
261 # move points to [-1, 1] | |
262 1 929777 929777.0 3.2 np.subtract(points, (minp + | |
maxp)/2.0, out=points) | |
263 1 1067001 1067001.0 3.7 np.divide(points, (maxp - | |
minp)/2.0, out=points) | |
264 1 73 73.0 0.0 offset_points = np.empty_li | |
ke(points) | |
265 | |
266 # move to [-1, 1] | |
267 | |
268 11 222 20.2 0.0 for ellip in ellipses: | |
269 10 56 5.6 0.0 I = ellip[0] | |
270 10 146 14.6 0.0 a2 = ellip[1] ** 2 | |
271 10 55 5.5 0.0 b2 = ellip[2] ** 2 | |
272 10 49 4.9 0.0 c2 = ellip[3] ** 2 | |
273 10 42 4.2 0.0 x0 = ellip[4] | |
274 10 42 4.2 0.0 y0 = ellip[5] | |
275 10 43 4.3 0.0 z0 = ellip[6] | |
276 10 138 13.8 0.0 phi = ellip[7] * np.pi | |
/ 180 | |
277 10 67 6.7 0.0 theta = ellip[8] * np.p | |
i / 180 | |
278 10 58 5.8 0.0 psi = ellip[9] * np.pi | |
/ 180 | |
279 | |
280 # Create the offset x,y | |
and z values for the grid | |
281 10 11424022 1142402.2 39.7 np.subtract(points, [x | |
0, y0, z0], out=offset_points) | |
282 10 307 30.7 0.0 scales = [1 / a2, 1 / b | |
2, 1 / c2] | |
283 | |
284 10 138 13.8 0.0 if any([phi, theta, psi | |
]): | |
285 # Optimization, onl | |
y rotate if needed. | |
286 2 117 58.5 0.0 cphi = np.cos(phi) | |
287 2 30 15.0 0.0 sphi = np.sin(phi) | |
288 2 15 7.5 0.0 ctheta = np.cos(the | |
ta) | |
289 2 16 8.0 0.0 stheta = np.sin(the | |
ta) | |
290 2 15 7.5 0.0 cpsi = np.cos(psi) | |
291 2 14 7.0 0.0 spsi = np.sin(psi) | |
292 | |
293 2 13 6.5 0.0 scales = [1 / a2, 1 | |
/ b2, 1 / c2] | |
294 2 25 12.5 0.0 mat = [[cpsi * cphi | |
- ctheta * sphi * spsi, | |
295 2 22 11.0 0.0 cpsi * sphi | |
+ ctheta * cphi * spsi, | |
296 2 8 4.0 0.0 spsi * sthe | |
ta], | |
297 2 14 7.0 0.0 [-spsi * cph | |
i - ctheta * sphi * cpsi, | |
298 2 10 5.0 0.0 -spsi * sph | |
i + ctheta * cphi * cpsi, | |
299 2 7 3.5 0.0 cpsi * sthe | |
ta], | |
300 2 6 3.0 0.0 [stheta * sp | |
hi, | |
301 2 8 4.0 0.0 -stheta * c | |
phi, | |
302 2 12 6.0 0.0 ctheta]] | |
303 | |
304 2 2214451 1107225.5 7.7 rotated = np.dot(m | |
at, offset_points.T) | |
305 2 679724 339862.0 2.4 np.square(rotated, | |
out=rotated) | |
306 2 925947 462973.5 3.2 radius = np.dot(sca | |
les, rotated) | |
307 else: | |
308 8 2246663 280832.9 7.8 np.square(offset_po | |
ints.T, out=offset_points.T) | |
309 8 3752264 469033.0 13.0 radius = np.dot(sca | |
les, offset_points.T) | |
310 | |
311 # Find the pixels withi | |
n the ellipse | |
312 10 1034977 103497.7 3.6 inside = radius <= 1 | |
313 | |
314 # Add the ellipse inten | |
sity to those pixels | |
315 10 1100882 110088.2 3.8 p[inside] += I | |
316 | |
317 1 6830 6830.0 0.0 return space.element(p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment