7#ifndef dlDataCollection_hpp
8#define dlDataCollection_hpp
12#include <cuda_runtime_api.h>
18#include <mx/improc/eigenCube.hpp>
19#include <mx/improc/eigenImage.hpp>
21#include "../../libMagAOX/libMagAOX.hpp"
22#include "../../magaox_git_version.h"
24using namespace nvinfer1;
26bool loadCSV(
const std::string& filename,
int numValues,
float*& dest) {
27 std::ifstream file(filename);
29 if (!file.is_open()) {
30 std::cerr <<
"Error opening file!" << std::endl;
37 for (
int i = 0; i < numValues; ++i) {
38 std::getline(file, line);
39 dest[i] = std::stof(line);
56 ImageBuffer(
size_t _num_channels,
size_t _num_rows,
size_t _num_cols,
size_t _num_images)
59 size(_num_channels * _num_rows * _num_cols),
71 void add(
float* image) {
81 void save(
const std::string& filename) {
82 std::ofstream file(filename, std::ios::out | std::ios::binary);
84 std::cerr <<
"Error opening file for writing: " << filename << std::endl;
192 mx::app::appConfigurator &
_config );
257 std::cout <<
"setupConfig()" << std::endl;
260 config.add(
"parameters.dataDirs",
262 "parameters.dataDirs",
268 "The path to the directory with the onnx model." );
270 config.add(
"parameters.ampsDir",
272 "parameters.ampsDir",
278 "The path to the directory with the random amplitudes." );
280 config.add(
"parameters.Nperset",
282 "parameters.Nperset",
288 "Number of images per dataset file" );
290 config.add(
"parameters.Nset",
298 "Number of dataset files to generate" );
300 config.add(
"parameters.NumFrameSkip",
302 "parameters.NumFrameSkip",
308 "Number of frames to skip to ensure latency is not an issue" );
310 config.add(
"parameters.imageNorm",
312 "parameters.imageNorm",
318 "Normalization term for the preprocessed images." );
320 config.add(
"parameters.modalNorm",
322 "parameters.modalNorm",
328 "Normalization term for the modal coefficients." );
330 config.add(
"parameters.channel",
332 "parameters.channel",
338 "The output channel." );
340 config.add(
"parameters.Nmodes",
348 "Number of modes to control." );
350 config.add(
"parameters.m_pupPix",
352 "parameters.m_pupPix",
358 "Number of pixels across a PWFS pupil." );
360 config.add(
"parameters.pup_offset1_x",
362 "parameters.pup_offset1_x",
368 "Horizontal offset to the top left of the closest set op PWFS pupils." );
370 config.add(
"parameters.pup_offset1_y",
372 "parameters.pup_offset1_y",
378 "Vertical offset to the top left of the closest set op PWFS pupils." );
380 config.add(
"parameters.pup_offset2_x",
382 "parameters.pup_offset2_x",
388 "Horizontal offset to the top left of the furthest set op PWFS pupils." );
390 config.add(
"parameters.pup_offset2_y",
392 "parameters.pup_offset2_y",
398 "Vertical offset to the top left of the furthest set op PWFS pupils." );
404 std::cout <<
"loadConfigImpl()" << std::endl;
426 std::cout <<
"Debug configuration loading: " << std::endl;
427 std::cout <<
"dataDirs: " <<
dataDirs << std::endl;
428 std::cout <<
"ampsDir: " <<
ampsDir << std::endl;
429 std::cout <<
"Nperset: " <<
Nperset << std::endl;
430 std::cout <<
"Nset: " <<
Nset << std::endl;
431 std::cout <<
"NumFrameSkip: " <<
NumFrameSkip << std::endl;
432 std::cout <<
"imageNorm: " <<
imageNorm << std::endl;
433 std::cout <<
"modalNorm: " <<
modalNorm << std::endl;
436 std::cout <<
"m_pupPix: " <<
m_pupPix << std::endl;
437 std::cout <<
"pup_offset1_x: " <<
pup_offset1_x << std::endl;
438 std::cout <<
"pup_offset1_y: " <<
pup_offset1_y << std::endl;
439 std::cout <<
"pup_offset2_x: " <<
pup_offset2_x << std::endl;
440 std::cout <<
"pup_offset2_y: " <<
pup_offset2_y << std::endl;
508 std::cout <<
"allocate()" << std::endl;
509 static_cast<void>(
dummy );
527 std::cout <<
"Close shmims" << std::endl;
533 std::cout <<
"Open shmims" << std::endl;
545 std::cout <<
"Done!" << std::endl;
565 std::cout <<
"Loading dataset from: " <<
filename << std::endl;
571 static_cast<void>(
dummy );
618 std::cout <<
"Saving dataset " <<
dataset_i << std::endl;
void save(const std::string &filename)
ImageBuffer(size_t _num_channels, size_t _num_rows, size_t _num_cols, size_t _num_images)
The base-class for MagAO-X applications.
stateCodes::stateCodeT state()
Get the current state code.
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
std::mutex m_indiMutex
Mutex for locking INDI communications.
int appStartup()
Startup function.
uint32_t m_width
The width of the images in the stream.
int setupConfig(mx::app::appConfigurator &config)
Setup the configuration system.
int updateINDI()
Update the INDI properties for this device controller.
int appLogic()
Checks the shmimMonitor thread.
uint32_t m_height
The height of the images in the stream.
int appShutdown()
Shuts down the shmimMonitor thread.
int loadConfig(mx::app::appConfigurator &config)
load the configuration system results
uint8_t m_pwfsDataType
The ImageStreamIO type code.
uint32_t m_modevalHeight
The height of the shmim.
size_t m_pwfsHeight
The height of the image.
virtual int appLogic()
Implementation of the FSM for dlDataCollection.
virtual int appShutdown()
Shutdown the app.
uint32_t m_modevalWidth
The width of the shmim.
virtual void setupConfig()
std::string m_modevalChannel
unsigned long frame_counter
ImageBuffer * imagebuffer
void loadRandomAmps(int dataset_i)
dlDataCollection()
Default c'tor.
eigenImage< realT > m_shaped_command
int loadConfigImpl(mx::app::appConfigurator &_config)
Implementation of loadConfig logic, separated for testing.
virtual int appStartup()
Startup function.
size_t m_modevalTypeSize
The size of the type, in bytes.
float realT
Floating point type in which to do all calculations.
~dlDataCollection() noexcept
D'tor, declared and defined for noexcept.
size_t m_pwfsWidth
The width of the image.
virtual void loadConfig()
size_t m_pwfsTypeSize
The size of the type, in bytes.
friend class dlDataCollection_test
int allocate(const dev::shmimT &dummy)
uint8_t m_modevalDataType
The ImageStreamIO type code.
dev::shmimMonitor< dlDataCollection > shmimMonitorT
int processImage(void *curr_src, const dev::shmimT &dummy)
bool loadCSV(const std::string &filename, int numValues, float *&dest)
@ OPERATING
The device is operating, other than homing.
std::unique_lock< std::mutex > lock(m_indiMutex)
static constexpr logPrioT LOG_NOTICE
A normal but significant condition.