% -*- mode: Noweb; noweb-code-mode: python-mode -*- \section{PXD file} \label{sec:pxd-file} <>= from utilities cimport mask, MaskAbstract, cuFloatArray, cuIntArray from atmosphere cimport atmosphere, AtmosphereAbstract from source cimport source, Source, Complex_amplitude from centroiding cimport centroiding, Centroiding from shackHartmann cimport shackHartmann, ShackHartmann from iterativeSolvers cimport iterativeSolvers, IterativeSolvers from aaStats cimport aaStats, paStats, AaStats from BTBT cimport BTBT, BT2 cdef extern from "LMMSE.h": cdef cppclass LMMSE: int NP float *d__phase_est float *d__x iterativeSolvers iSolve aaStats aa BTBT aaCov paStats pa void setup(atmosphere *, source *, source *, float , int , mask *, char *, int) void setup(atmosphere *, source *, float , int , mask *, char *, int, float) void setup(atmosphere *, source *, source *, shackHartmann *, char *) void setup(atmosphere *, source *, source *, shackHartmann *, char *, int, mask *) void cleanup() void estimation(centroiding *) void estimation(shackHartmann *) void reset() @ \subsection{Class definitions} \label{sec:class-definitions} <>= cdef class Lmmse: <> cdef class ALmmse: <> cdef class LmmseSH: cdef LMMSE *_c_LMMSE cdef int N_phase cdef int N_slope @ with <>= cdef LMMSE *_c_LMMSE cdef int N_phase cdef public IterativeSolvers iSolve cdef public AaStats aa cdef public BT2 aaCov cdef public cuFloatArray x @ \section{PYX file} \label{sec:pyx-file} \subsection{Lmmse} \label{sec:lmmse} \index{LMMSE!python!Lmmse} <>= cdef class Lmmse: """ A class for LMMSE reconstructor Parameters ---------- atm : Atmosphere The atmosphere model used to computed the covariance matrices. guide_star : Source The guide stars from which the wavefront gradient is used for the wavefront reconstruction. mmse_star : Source The star in the direction of which the wavefront is reconstructed. sampling : float The sampling step of the wavefront in meters. N : int The number of lenslet across the lenslet array. pupil : a Mask object The binary mask corresponding to the telescope pupil. solver_id: char The name of the iterative solver: MINRES or CG. Returns: out : Lmmse A Lmmse object """ def __cinit__(self,AtmosphereAbstract atm, Source guide_star, Source mmse_star, float sampling, int N, MaskAbstract pupil, str solver_id, int osf=1): self._c_LMMSE = new LMMSE() self._c_LMMSE.setup(atm._c_atmosphere, guide_star._c_source, mmse_star._c_source, sampling, N, pupil._c_mask, solver_id.encode(),osf) <> <> @ with <>= self.iSolve = IterativeSolvers() self.iSolve._c_iterativeSolvers = &(self._c_LMMSE.iSolve) self.aa = AaStats() self.aa.init(&(self._c_LMMSE.aa)) self.aaCov = BT2() self.aaCov.init(&(self._c_LMMSE.aaCov)) self.N_phase = self._c_LMMSE.NP self.x = cuFloatArray(dev_malloc=False) self.x._c_gpu.dev_data = self._c_LMMSE.d__x @ \subsection{ALmmse} \label{sec:almmse} \index{LMMSE!python!ALmmse} <>= cdef class ALmmse: """ A class for LMMSE reconstructor Parameters ---------- atm : Atmosphere The atmosphere model used to computed the covariance matrices. guide_star : Source The guide stars from which the wavefront gradient is used for the wavefront reconstruction. average_z_radius : float The angular radius of the circle that defined the average field of view in radians sampling : float The sampling step of the wavefront in meters. N : int The number of lenslet across the lenslet array. pupil : a Mask object The binary mask corresponding to the telescope pupil. solver_id: char The name of the iterative solver: MINRES or CG. Returns: out : Lmmse A Lmmse object """ def __cinit__(self,AtmosphereAbstract atm, Source guide_star, float average_z_radius, float sampling, int N, MaskAbstract pupil, str solver_id, int osf=1): self._c_LMMSE = new LMMSE() self._c_LMMSE.setup(atm._c_atmosphere, guide_star._c_source, sampling, N, pupil._c_mask, solver_id.encode(),osf, average_z_radius) <> <> @ <>= def __dealloc__(self): self._c_LMMSE.cleanup() def estimation(self, Centroiding cog): """ Computes an estimate of the wavefront corresponding to the centroids in the Centroiding object """ self._c_LMMSE.estimation(cog._c_centroiding) def reset(self): """ Reset the solver vector to zero """ self._c_LMMSE.reset() property phase: def __get__(self): """ Return the phase estimate in a cuFloatArray object """ x = cuFloatArray(shape=(self.N_phase,self.N_phase)) x._c_gpu.dev_data = self._c_LMMSE.d__phase_est return x @ \subsection{LmmseSH} \label{sec:lmmsesh} \index{LMMSE!python!LmmseSH} <>= cdef class LmmseSH: """ A class for LMMSE reconstructor Parameters ---------- atm: an Atmosphere object The atmosphere model used to computed the covariance matrices. guide_star: a Source object The guide stars from which the wavefront gradient is used for the wavefront reconstruction. N_guide_star: an int The number of guide stars. mmse_star: a Source object The star in the direction of which the wavefront is reconstructed. N_mmse_star: an int The number of mmse_star. sampling: float The sampling step of the wavefront in meters. N: int The number of lenslet across the lenslet array. pupil: a Mask object The binary mask corresponding to the telescope pupil. solver_id: char The name of the iterative solver: MINRES or CG. Returns: out : Lmmse A Lmmse object """ def __cinit__(self,AtmosphereAbstract atm, Source guide_star, Source mmse_star, ShackHartmann wfs, str solver_id, int osf=1, MaskAbstract M=None): self._c_LMMSE = new LMMSE() self.N_slope = wfs.N_SIDE_LENSLET*wfs.N_SIDE_LENSLET*2*guide_star._c_source.N_SRC if osf>1: self._c_LMMSE.setup(atm._c_atmosphere, guide_star._c_source, mmse_star._c_source, wfs._c_shackHartmann, solver_id.encode(), osf, M._c_mask) else: self._c_LMMSE.setup(atm._c_atmosphere, guide_star._c_source, mmse_star._c_source, wfs._c_shackHartmann, solver_id.encode()) self.N_phase = self._c_LMMSE.NP def __dealloc__(self): self._c_LMMSE.cleanup() def estimation(self, ShackHartmann wfs): """ Computes an estimate of the wavefront corresponding to the centroids in the Centroiding object """ self._c_LMMSE.estimation(wfs._c_shackHartmann) property phase: def __get__(self): """ Return the phase estimate in a cuFloatArray object """ x = cuFloatArray(shape=(self.N_phase,self.N_phase)) x._c_gpu.dev_data = self._c_LMMSE.d__phase_est return x property solve: def __get__(self): """ Return the solver solution """ x = cuFloatArray(shape=(self.N_slope,1)) x._c_gpu.dev_data = self._c_LMMSE.d__x return x @ \section{Bilinear interpolation} \label{sec:bilin-interp} \subsection{PXD file} \label{sec:pxd-file-1} \index{LMMSE!python!BilinearInterpolation} <>= cdef cppclass bilinearInterpolation: int nnz, NI int *csrColIndH int *csrRowPtrH float *csrValH float *H void setup(int,int) void setup(int,int,mask *,float, float) void cleanup() <> @ \subsubsection{Class definitions} \label{sec:class-definition} <>= cdef class BilinearInterpolation: cdef: bilinearInterpolation *_c_bilinearInterpolation readonly int nnz, NI readonly cuFloatArray csrValH readonly cuIntArray csrColIndH, csrRowPtrH cdef class BilinearInterpolation2: cdef: bilinearInterpolation *_c_bilinearInterpolation readonly int NI @ \subsection{PYX file} \label{sec:pyx-file-1} <>= cdef class BilinearInterpolation: def __cinit__(self,int NI, int NP, Complex_amplitude W=None, float i0=0.0, float j0=0.0): self._c_bilinearInterpolation = new bilinearInterpolation() if W is None: self._c_bilinearInterpolation.setup(NI,NP) else: self._c_bilinearInterpolation.setup(NI,NP,W._c_complex_amplitude.M,i0,j0) self.nnz = self._c_bilinearInterpolation.nnz self.NI = self._c_bilinearInterpolation.NI cdef int n = self.NI*self.NI self.csrValH = cuFloatArray(shape=(self.nnz,1)) self.csrValH._c_gpu.dev_data \ = self._c_bilinearInterpolation.csrValH self.csrColIndH = cuIntArray(shape=(self.nnz,1)) self.csrColIndH._c_gpu.dev_data \ = self._c_bilinearInterpolation.csrColIndH self.csrRowPtrH = cuIntArray(shape=(n+1,1)) self.csrRowPtrH._c_gpu.dev_data \ = self._c_bilinearInterpolation.csrRowPtrH def __dealloc__(self): self._c_bilinearInterpolation.cleanup() property H: def __get__(self): cdef int n = self.NI*self.NI from scipy.sparse import csr_matrix return csr_matrix((self.csrValH.host().ravel(), self.csrColIndH.host().ravel(), self.csrRowPtrH.host().ravel()), shape=(n,n))