Created
December 22, 2015 21:33
-
-
Save adler-j/ec5010fabdd865ef8170 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
277 # Blank image | |
278 1 71 71.0 0.0 p = np.zeros(space.shape) | |
279 | |
280 # Create the pixel grid | |
281 1 318 318.0 0.0 grid_in = space.grid.meshgr | |
id() | |
282 1 26 26.0 0.0 minp = space.grid.min() | |
283 1 18 18.0 0.0 maxp = space.grid.max() | |
284 | |
285 # move points to [-1, 1] | |
286 1 4 4.0 0.0 grid = [] | |
287 4 20 5.0 0.0 for i in range(3): | |
288 3 23 7.7 0.0 meani = (minp[i] + maxp | |
[i]) / 2.0 | |
289 3 17 5.7 0.0 diffi = (maxp[i] - minp | |
[i]) / 2.0 | |
290 3 94 31.3 0.0 grid += [(grid_in[i] - | |
meani) / diffi] | |
291 | |
292 11 125 11.4 0.0 for ellip in ellipses: | |
293 10 48 4.8 0.0 I = ellip[0] | |
294 10 96 9.6 0.0 a2 = ellip[1] ** 2 | |
295 10 53 5.3 0.0 b2 = ellip[2] ** 2 | |
296 10 50 5.0 0.0 c2 = ellip[3] ** 2 | |
297 10 44 4.4 0.0 x0 = ellip[4] | |
298 10 41 4.1 0.0 y0 = ellip[5] | |
299 10 39 3.9 0.0 z0 = ellip[6] | |
300 10 111 11.1 0.0 phi = ellip[7] * np.pi | |
/ 180 | |
301 10 54 5.4 0.0 theta = ellip[8] * np.p | |
i / 180 | |
302 10 48 4.8 0.0 psi = ellip[9] * np.pi | |
/ 180 | |
303 | |
304 10 94 9.4 0.0 scales = [1 / a2, 1 / b | |
2, 1 / c2] | |
305 | |
306 # Create the offset x,y | |
and z values for the grid | |
307 10 103 10.3 0.0 if any([phi, theta, psi | |
]): | |
308 # Rotate the points | |
to the expected coordinate system. | |
309 2 86 43.0 0.0 cphi = np.cos(phi) | |
310 2 27 13.5 0.0 sphi = np.sin(phi) | |
311 2 36 18.0 0.0 ctheta = np.cos(the | |
ta) | |
312 2 19 9.5 0.0 stheta = np.sin(the | |
ta) | |
313 2 18 9.0 0.0 cpsi = np.cos(psi) | |
314 2 18 9.0 0.0 spsi = np.sin(psi) | |
315 | |
316 2 28 14.0 0.0 mat = np.array([[cp | |
si * cphi - ctheta * sphi * spsi, | |
317 2 15 7.5 0.0 cp | |
si * sphi + ctheta * cphi * spsi, | |
318 2 10 5.0 0.0 sp | |
si * stheta], | |
319 2 14 7.0 0.0 [-s | |
psi * cphi - ctheta * sphi * cpsi, | |
320 2 13 6.5 0.0 -s | |
psi * sphi + ctheta * cphi * cpsi, | |
321 2 8 4.0 0.0 cp | |
si * stheta], | |
322 2 8 4.0 0.0 [st | |
heta * sphi, | |
323 2 9 4.5 0.0 -s | |
theta * cphi, | |
324 2 87 43.5 0.0 ct | |
heta]]) | |
325 | |
326 # Calculate the poi | |
nts that could possibly be inside the volume | |
327 # Since the points | |
are rotated, we cannot do anything directional | |
328 # without more logi | |
c | |
329 2 99 49.5 0.0 center = (np.array( | |
[x0, y0, z0]) + 1.0) / 2.0 | |
330 2 221 110.5 0.0 max_radius = np.sqr | |
t(np.abs(mat).dot([a2, b2, c2])) | |
331 2 470 235.0 0.0 idx, shapes = _gets | |
hapes(center, max_radius, space.shape) | |
332 | |
333 8 91 11.4 0.0 subgrid = [g[idi] f | |
or g, idi in zip(grid, shapes)] | |
334 2 8 4.0 0.0 offset_points = [ve | |
c * (xi - x0i)[..., np.newaxis] | |
335 2 8 4.0 0.0 fo | |
r xi, vec, x0i in zip(subgrid, | |
336 2 17 8.5 0.0 | |
mat.T, | |
337 8 405 50.6 0.0 | |
[x0, y0, z0])] | |
338 2 79684 39842.0 7.9 rotated = offset_po | |
ints[0] + offset_points[1] + offset_points[2] | |
339 2 10117 5058.5 1.0 np.square(rotated, | |
out=rotated) | |
340 2 174504 87252.0 17.3 radius = np.dot(rot | |
ated, scales) | |
341 else: | |
342 # Calculate the poi | |
nts that could possibly be inside the volume | |
343 8 410 51.2 0.0 center = (np.array( | |
[x0, y0, z0]) + 1.0) / 2.0 | |
344 8 195 24.4 0.0 max_radius = np.sqr | |
t([a2, b2, c2]) | |
345 8 1710 213.8 0.2 idx, shapes = _gets | |
hapes(center, max_radius, space.shape) | |
346 | |
347 32 286 8.9 0.0 subgrid = [g[idi] f | |
or g, idi in zip(grid, shapes)] | |
348 8 32 4.0 0.0 squared_dist = [ai | |
* (xi - x0i)**2 | |
349 8 33 4.1 0.0 for | |
xi, ai, x0i in zip(subgrid, | |
350 8 31 3.9 0.0 | |
scales, | |
351 32 835 26.1 0.1 | |
[x0, y0, z0])] | |
352 | |
353 # Parentisis to get | |
best order for broadcasting | |
354 8 192615 24076.9 19.1 radius = squared_di | |
st[0] + (squared_dist[1] + squared_dist[2]) | |
355 | |
356 # Find the pixels withi | |
n the ellipse | |
357 10 93261 9326.1 9.3 inside = radius <= 1 | |
358 | |
359 # Add the ellipse inten | |
sity to those pixels | |
360 10 417375 41737.5 41.5 p[idx][inside] += I | |
361 | |
362 1 32038 32038.0 3.2 return space.element(p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment