% -*- mode: Noweb; noweb-code-mode: python-mode -*- \section{PXD file} \label{sec:pxd-file} <>= from utilities cimport cuFloatArray, mask, MaskAbstract cdef extern from "centroiding.h": cdef cppclass centroiding: float *d__c float *d__mass char *lenslet_mask void setup(int, int) void fried_geometry(mask *, mask *, int , float) void get_data(float *, int) void get_data(float *, int, float , float , float); void get_data(float *, int , float *, float *, float , char *); void reset(); void filter(float *); void noisify(float); void cleanup() <> @ \subsection{Class definitions} \label{sec:class-definitions} <>= from utilities cimport cuFloatArray, Mask cdef class Centroiding: cdef: centroiding *_c_centroiding readonly int N_SIDE_LENSLET, N_SOURCE readonly cuFloatArray flux, c readonly Mask lenslet_mask char isPtr cdef void set_ptr(Centroiding, centroiding *) @ \section{PYX file} \label{sec:pyx-file} \index{centroiding!python!Centroiding} <>= cdef class Centroiding: """ Create a centroiding container Parameters ---------- N_SIDE_LENSLET : int 1 The linear size of the lenslet array (>=1) N_SOURCE : int, optional The number of guide stars (>=1); default: 1 Attributes ---------- N_SIDE_LENSLET : int The linear size of the lenslet array (>=1) N_SOURCE : int The number of guide stars (>=1) flux : cuFloatArray The map of flux per lenset c: cuFloatArray The centroid vector of length `N_SOURCE`x`N_SIDE_LENSLET`**2 See also -------- cuFloatArray: class acting as the interface between GPU host and device """ def __cinit__(self, int N_SIDE_LENSLET, int N_SOURCE=1, char isPtr=0): self._c_centroiding = new centroiding() self.N_SIDE_LENSLET = N_SIDE_LENSLET """ if wfs is not None: self.isPtr = 1 self.N_SOURCE = wfs.N_GS self._c_centroiding = &(wfs._c_shackHartmann.data_proc) elif gwfs is not None: self.isPtr = 1 self.N_SOURCE = gwfs.N_GS self._c_centroiding = &(gwfs._c_shackHartmann.data_proc) elif pym is not None: self.isPtr = 1 self.N_SOURCE = N_SOURCE self._c_centroiding = &(pym._c_pyramid.data) else: self.isPtr = 0 self.N_SOURCE = N_SOURCE self._c_centroiding.setup(self.N_SIDE_LENSLET,self.N_SOURCE) """ self.isPtr = isPtr self.N_SOURCE = N_SOURCE self.flux = cuFloatArray(shape=(self.N_SOURCE*self.N_SIDE_LENSLET, self.N_SIDE_LENSLET)) self.c = cuFloatArray(shape=(self.N_SOURCE,(self.N_SIDE_LENSLET**2)*2)) if not self.isPtr: self._c_centroiding.setup(self.N_SIDE_LENSLET,self.N_SOURCE) self.flux._c_gpu.dev_data = self._c_centroiding.d__mass self.c._c_gpu.dev_data = self._c_centroiding.d__c self.lenslet_mask = Mask(self.N_SIDE_LENSLET*self.N_SIDE_LENSLET) cdef void set_ptr(self, centroiding *data_proc_ptr): self._c_centroiding = data_proc_ptr self.flux._c_gpu.dev_data = self._c_centroiding.d__mass self.c._c_gpu.dev_data = self._c_centroiding.d__c def __dealloc__(self): if not self.isPtr: self._c_centroiding.cleanup() def fried_geometry(self,MaskAbstract dm, MaskAbstract pupil, int n, float threshold): self._c_centroiding.fried_geometry(dm._c_mask, pupil._c_mask, n, threshold) self.lenslet_mask._c_mask.reset() self.lenslet_mask._c_mask.add(self._c_centroiding.lenslet_mask, self.N_SIDE_LENSLET*self.N_SIDE_LENSLET) def get_data(self, cuFloatArray frame, int N): self._c_centroiding.get_data(frame._c_gpu.dev_data,N) def reset(self): self._c_centroiding.reset() def filter(self, cuFloatArray F): self._c_centroiding.filter(F._c_gpu.dev_data) def noisify(self, float stddev): self._c_centroiding.noisify(stddev)