Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yt-project
GitHub Repository: yt-project/yt
Path: blob/main/doc/source/analyzing/_static/axes_calculator.pyx
928 views
1
import numpy as np
2
cimport numpy as np
3
4
5
cdef extern from "axes.h":
6
ctypedef struct ParticleCollection:
7
long npart
8
double *xpos
9
double *ypos
10
double *zpos
11
12
void calculate_axes(ParticleCollection *part,
13
double *ax1, double *ax2, double *ax3)
14
15
def examine_axes(np.ndarray[np.float64_t, ndim=1] xpos,
16
np.ndarray[np.float64_t, ndim=1] ypos,
17
np.ndarray[np.float64_t, ndim=1] zpos):
18
cdef double ax1[3]
19
cdef double ax2[3]
20
cdef double ax3[3]
21
cdef ParticleCollection particles
22
cdef int i
23
24
particles.npart = len(xpos)
25
particles.xpos = <double *> xpos.data
26
particles.ypos = <double *> ypos.data
27
particles.zpos = <double *> zpos.data
28
29
for i in range(particles.npart):
30
particles.xpos[i] = xpos[i]
31
particles.ypos[i] = ypos[i]
32
particles.zpos[i] = zpos[i]
33
34
calculate_axes(&particles, ax1, ax2, ax3)
35
36
return ( (ax1[0], ax1[1], ax1[2]),
37
(ax2[0], ax2[1], ax2[2]),
38
(ax3[0], ax3[1], ax3[2]) )
39
40