mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
pyramidSensor_test.cpp
Go to the documentation of this file.
1/** \file pyramidSensor_test.cpp
2 * \brief Tests CPU and CUDA pyramid-sensor simulations.
3 */
4#include "../../../catch2/catch.hpp"
5#ifdef MXLIB_CUDA
6#include "../../../cudaTestUtils.hpp"
7#endif
8
9#define MX_NO_ERROR_REPORTS
10
11// #define DEBUG
12
15using namespace mx::AO::sim;
16
19// #include <mx/improc/milkImage.hpp>
20// #include <mx/improc/eigenCube.hpp>
21using namespace mx::improc;
22
23/// Simulate a pyramid sensor on CPU
24/**
25 * \ingroup pyramidSensor_unit_tests
26 */
27TEST_CASE( "Simulate a pyramid sensor on CPU", "[ao::sim]" )
28{
29 typedef float realT;
30
31 uint32_t pupSz = 56.0;
32 uint32_t wfSz = 256.0;
33
35
36 eigenImage<realT> pupil, fm;
37 pupil.resize( pupSz, pupSz );
38 pupil.setConstant( 0 );
39 maskCircle( pupil, 0.5 * ( 1.0 * pupSz - 1 ), 1 );
40
42 realT nphperpix = 1e10 / pupil.sum();
43
44 wf.setAmplitude( pupil * sqrt( nphperpix ) );
45
46 fm.resize( pupSz, pupSz );
47
48 pwfs.D( 6.5 );
49 pwfs.pupilSz( pupSz );
50 pwfs.wfSz( wfSz );
51 pwfs.pupilSep( 1 + 4.1 / 56. );
52
53 pwfs.perStep( 0.5 );
54 pwfs.modRadius( 3 );
55
56 pwfs.detSize( 120, 120 );
57 pwfs.detector.noNoise( true );
58 pwfs.detector.expTime( 1 );
59
60 pwfs.lambda( 850e-9 );
61
62 wf.setPhase( fm * 0 );
63
64 pwfs.senseWavefrontCal( wf );
65
66 size_t N = 10;
67 double t0 = mx::sys::get_curr_time();
68 for( size_t n = 0; n < N; ++n )
69 {
70 pwfs.senseWavefrontCal( wf );
71 }
72 double t1 = mx::sys::get_curr_time();
73
74 std::cerr << "\nCPU: " << 1.0 * N / ( t1 - t0 ) << " fps\n\n";
75
76 eigenImage<realT> ref = pwfs.detectorImage.image();
77
78 realT s = ref.sum();
79 std::cout << s << '\n';
80
81 REQUIRE( s > 9.9e9 );
82}
83
84#if defined( MXLIB_CUDA ) || defined( __DOXY_ONLY__ )
85/// Simulate a pyramid sensor on GPU
86/**
87 * \ingroup pyramidSensor_unit_tests
88 */
89TEST_CASE( "Simulate a pyramid sensor on GPU", "[ao::sim]" )
90{
91 if( !mxlibTest::cudaDeviceAvailable() )
92 {
93 WARN( "CUDA runtime is available but no CUDA device is present" );
94 return;
95 }
96
97 typedef float realT;
98
99 uint32_t pupSz = 56.0;
100 uint32_t wfSz = 256.0;
101
103
104 eigenImage<realT> pupil, fm;
105 pupil.resize( pupSz, pupSz );
106 pupil.setConstant( 0 );
107 maskCircle( pupil, 0.5 * ( 1.0 * pupSz - 1 ), 1 );
108
110 realT nphperpix = 1e10 / pupil.sum();
111
112 wf.setAmplitude( pupil * sqrt( nphperpix ) );
113
114 fm.resize( pupSz, pupSz );
115
116 pwfs.D( 6.5 );
117 pwfs.pupilSz( pupSz );
118 pwfs.wfSz( wfSz );
119 pwfs.pupilSep( 1 + 4.1 / 56. );
120
121 pwfs.perStep( 0.5 );
122 pwfs.modRadius( 3 );
123
124 pwfs.detSize( 120, 120 );
125 pwfs.detector.noNoise( true );
126 pwfs.detector.expTime( 1 );
127
128 pwfs.lambda( 850e-9 );
129
130 wf.setPhase( fm * 0 );
131
132 pwfs.senseWavefrontCal( wf );
133
134 size_t N = 10;
135 double t0 = mx::sys::get_curr_time();
136 for( size_t n = 0; n < N; ++n )
137 {
138 pwfs.senseWavefrontCal( wf );
139 }
140 double t1 = mx::sys::get_curr_time();
141
142 std::cerr << "\nGPU: " << 1.0 * N / ( t1 - t0 ) << " fps\n\n";
143
144 eigenImage<realT> ref = pwfs.detectorImage.image();
145
146 realT s = ref.sum();
147 std::cout << s << '\n';
148
149 REQUIRE( s > 9.9e9 );
150}
151#endif // MXLIB_CUDA
Provides a class to simulate a CCD.
A Pyramid Sensor Simulation.
realT perStep()
Get the minimum number of modulation steps.
realT lambda()
Get the PyWFS central wavelength.
int wfSz()
Get the wavefront size in pixels.
void detSize(const uint32_t &nrows, const uint32_t &ncols)
Set the detector columns in pixels.
wfsImageT< realT > detectorImage
The image on the detector, resized from m_wfsImage.
detectorT detector
The WFS detector.
realT modRadius()
Get the radius of modulation.
bool senseWavefrontCal(wavefrontT &pupilPlane)
Sense the wavefront aberrations in calibration mode.
uint32_t pupilSz()
Get the pupil size in pixels.
realT D()
Get the telescope diameter.
Tools for using the eigen library for image processing.
Eigen::Array< scalarT, -1, -1 > eigenImage
Definition of the eigenImage type, which is an alias for Eigen::Array.
void maskCircle(arrayT &m, typename arrayT::Scalar xcen, typename arrayT::Scalar ycen, typename arrayT::Scalar rad, typename arrayT::Scalar val, typename arrayT::Scalar pixbuf=0.5)
Mask a circle in an image.
TEST_CASE("Simulate a pyramid sensor on CPU", "[ao::sim]")
Simulate a pyramid sensor on CPU.
typeT get_curr_time()
Get the current system time in seconds.
Declares and defines functions to work with image masks.
Declaration and definition of a standard 4 quadrant pyramid WFS.
Structure containing the phase and amplitude of a wavefront.
Definition wavefront.hpp:24