From 28eb9bf5fef72d3effa5408c2aeb9ec3237868b7 Mon Sep 17 00:00:00 2001 From: Jonathan Lin Date: Thu, 19 Oct 2023 09:37:47 -1000 Subject: [PATCH] some cleaning and spec norm func --- .../scexao-NIRPL-conf/scripts/normspectra | 22 +++ AOloopControl_IOtools/AOloopControl_IOtools.c | 6 +- AOloopControl_IOtools/CMakeLists.txt | 6 +- AOloopControl_IOtools/extract_spectra.c | 2 +- .../{pl_trace_renorm.c => norm_spectra.c} | 54 ++++---- AOloopControl_IOtools/norm_spectra.h | 6 + AOloopControl_IOtools/pl_column_sum.c | 129 ------------------ AOloopControl_IOtools/pl_column_sum.h | 6 - AOloopControl_IOtools/pl_trace_renorm.h | 6 - 9 files changed, 63 insertions(+), 174 deletions(-) create mode 100644 AOloopControl/examples/scexao-NIRPL-conf/scripts/normspectra rename AOloopControl_IOtools/{pl_trace_renorm.c => norm_spectra.c} (74%) create mode 100644 AOloopControl_IOtools/norm_spectra.h delete mode 100644 AOloopControl_IOtools/pl_column_sum.c delete mode 100644 AOloopControl_IOtools/pl_column_sum.h delete mode 100644 AOloopControl_IOtools/pl_trace_renorm.h diff --git a/AOloopControl/examples/scexao-NIRPL-conf/scripts/normspectra b/AOloopControl/examples/scexao-NIRPL-conf/scripts/normspectra new file mode 100644 index 00000000..043f236f --- /dev/null +++ b/AOloopControl/examples/scexao-NIRPL-conf/scripts/normspectra @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# add column_sum function to fpsCTRL + +source ./scripts/fps-utility + +# name of function to setup +fname="norm_spectra" + +# add to fpsCTRL, start tmux, start conf, turn on procinfo +setupfps "${fname}" + +# procinfo specific stuff +sendFPScmd "setval ${fname}-${CACAO_LOOPNUMBER}.procinfo.triggermode 3" +sendFPScmd "setval ${fname}-${CACAO_LOOPNUMBER}.procinfo.loopcntMax -1" +sendFPScmd "setval ${fname}-${CACAO_LOOPNUMBER}.procinfo.triggersname aol${CACAO_LOOPNUMBER}_imWFS2" + +# setting input and output streams +sendFPScmd "setval ${fname}-${CACAO_LOOPNUMBER}.wfsin aol${CACAO_LOOPNUMBER}_imWFS2" +sendFPScmd "setval ${fname}-${CACAO_LOOPNUMBER}.wfsout aol6_imWFS2_norm" + +sendFPScmd "confwupdate ${fname}-${CACAO_LOOPNUMBER}" diff --git a/AOloopControl_IOtools/AOloopControl_IOtools.c b/AOloopControl_IOtools/AOloopControl_IOtools.c index e26022bc..35f3d999 100644 --- a/AOloopControl_IOtools/AOloopControl_IOtools.c +++ b/AOloopControl_IOtools/AOloopControl_IOtools.c @@ -34,9 +34,8 @@ #include "WFScamsim.h" #include "WFSmap.h" #include "ao188_preprocessor.h" -#include "pl_trace_renorm.h" -#include "pl_column_sum.h" #include "extract_spectra.h" +#include "norm_spectra.h" @@ -60,9 +59,8 @@ static errno_t init_module_CLI() CLIADDCMD_AOloopControl_IOtools__WFSmap(); CLIADDCMD_AOloopControl_IOtools__findspots(); CLIADDCMD_AOloopControl_IOtools__AO188Preproc(); - CLIADDCMD_AOloopControl_IOtools__PLtracerenorm(); - CLIADDCMD_AOloopControl_IOtools__PLcolumnsum(); CLIADDCMD_AOloopControl_IOtools__extractspectra(); + CLIADDCMD_AOloopControl_IOtools__normspectra(); // add atexit functions here // atexit((void*) myfunc); diff --git a/AOloopControl_IOtools/CMakeLists.txt b/AOloopControl_IOtools/CMakeLists.txt index 198a348d..c4a9b21a 100644 --- a/AOloopControl_IOtools/CMakeLists.txt +++ b/AOloopControl_IOtools/CMakeLists.txt @@ -10,12 +10,11 @@ set(SOURCEFILES ${SRCNAME}.h acquireWFSim.c ao188_preprocessor.c - pl_trace_renorm.c - pl_column_sum.c findspots.c WFScamsim.c WFSmap.c extract_spectra.c + norm_spectra.c ) set(INCLUDEFILES @@ -23,12 +22,11 @@ set(INCLUDEFILES AOloopControl_IOtools.h acquireWFSim.h ao188_preprocessor.h - pl_trace_renorm.h - pl_column_sum.h findspots.h WFScamsim.h WFSmap.h extract_spectra.h + norm_spectra.h ) diff --git a/AOloopControl_IOtools/extract_spectra.c b/AOloopControl_IOtools/extract_spectra.c index 85119b82..9b475679 100644 --- a/AOloopControl_IOtools/extract_spectra.c +++ b/AOloopControl_IOtools/extract_spectra.c @@ -137,7 +137,7 @@ static errno_t compute_function() INSERT_STD_FPSCLIfunctions // Register function in CLI -errno_t CLIADDCMD_AOloopControl_IOtools__extractspectra() +errno_t CLIADDCMD_AOloopControl_IOtools__normpectra() { CLIcmddata.FPS_customCONFsetup = customCONFsetup; diff --git a/AOloopControl_IOtools/pl_trace_renorm.c b/AOloopControl_IOtools/norm_spectra.c similarity index 74% rename from AOloopControl_IOtools/pl_trace_renorm.c rename to AOloopControl_IOtools/norm_spectra.c index cb0247b3..f0242270 100644 --- a/AOloopControl_IOtools/pl_trace_renorm.c +++ b/AOloopControl_IOtools/norm_spectra.c @@ -1,6 +1,6 @@ /** - * @file pl_trace_renorm.c - * @brief acquire and normalize spectra of 3-port PL + * @file norm_spectra.c + * @brief normalize spectra * * * @@ -8,6 +8,7 @@ #include #include "CommandLineInterface/CLIcore.h" +#include "COREMOD_tools/COREMOD_tools.h" // Local variables pointers static char *input_shm_name; // input shared memory @@ -16,8 +17,8 @@ static long fpi_inputshmname; static char *output_shm_name; // output shared memory static long fpi_outputshmname; -static int64_t *compWFSnormalize; // spec norm toggle (lifted this from acquireWFSim.c heh) -static long fpi_compWFSnormalize; +static int64_t *compWFSnormalize; // toggle for normalization +static long fpi_compWFSnormalize; static CLICMDARGDEF farg[] = { @@ -30,6 +31,15 @@ static CLICMDARGDEF farg[] = (void **) &input_shm_name, &fpi_inputshmname }, + { + CLIARG_ONOFF, + ".comp.WFSnormalize", + "normalize spectral traces", + "1", + CLIARG_HIDDEN_DEFAULT, + (void **) &compWFSnormalize, + &fpi_compWFSnormalize + }, { CLIARG_STR, ".wfsout", @@ -39,15 +49,6 @@ static CLICMDARGDEF farg[] = (void **) &output_shm_name, &fpi_outputshmname }, - { - CLIARG_ONOFF, - ".comp.WFSnormalize", - "normalize WFS frames", - "1", - CLIARG_HIDDEN_DEFAULT, - (void **) &compWFSnormalize, - &fpi_compWFSnormalize - }, }; // Optional custom configuration setup. @@ -73,7 +74,7 @@ static errno_t customCONFcheck() static CLICMDDATA CLIcmddata = { - "spectra_renorm", "normalize spectral traces", CLICMD_FIELDS_DEFAULTS + "norm_spectra", "normalize spectra", CLICMD_FIELDS_DEFAULTS }; @@ -93,17 +94,15 @@ static errno_t compute_function() uint32_t sizeoutx = wfsin.size[0]; uint32_t sizeouty = wfsin.size[1]; - uint32_t sizeout = sizeoutx * sizeouty; - // Create output - // trying to copy shape of wfsin. Assume a structure 3 rows x N columns, N goes along wavelength + // Create output, same size as input IMGID wfsout; wfsout = - stream_connect_create_2D(output_shm_name, sizeoutx, sizeouty, _DATATYPE_FLOAT); + stream_connect_create_2D(output_shm_name,sizeoutx,sizeouty,_DATATYPE_FLOAT); // This is the while(True) { - //INSERT_STD_PROCINFO_COMPUTEFUNC_INIT - INSERT_STD_PROCINFO_COMPUTEFUNC_START + INSERT_STD_PROCINFO_COMPUTEFUNC_INIT + INSERT_STD_PROCINFO_COMPUTEFUNC_LOOPSTART { // JON YOU GET TO WORK HERE if(data.fpsptr->parray[fpi_compWFSnormalize].fpflag & FPFLAG_ONOFF) { @@ -112,10 +111,17 @@ static errno_t compute_function() double tot = 0.0; int i; for (i = 0; i < sizeoutx; i++) { - tot += wfsin.im->array.F[i*sizeouty+j]; + tot += wfsin.im->array.F[j*sizeoutx + i]; + } + double normval; + if (tot <= 0){ + normval = 0; + } + else { + normval = 1/tot; } for (i = 0; i < sizeoutx; i++) { - wfsout.im->array.F[i*sizeouty+j] = wfsin.im->array.F[i*sizeouty+j]/tot; + wfsout.im->array.F[j*sizeoutx + i] = wfsin.im->array.F[j*sizeoutx + i]*normval; } } } @@ -124,7 +130,7 @@ static errno_t compute_function() wfsin.im->array.F, sizeof(float) * sizeout); } - + // Done and post downstream. processinfo_update_output_stream(processinfo, wfsout.ID); } @@ -139,7 +145,7 @@ static errno_t compute_function() INSERT_STD_FPSCLIfunctions // Register function in CLI -errno_t CLIADDCMD_AOloopControl_IOtools__PLtracerenorm() +errno_t CLIADDCMD_AOloopControl_IOtools__normspectra() { CLIcmddata.FPS_customCONFsetup = customCONFsetup; diff --git a/AOloopControl_IOtools/norm_spectra.h b/AOloopControl_IOtools/norm_spectra.h new file mode 100644 index 00000000..1055284e --- /dev/null +++ b/AOloopControl_IOtools/norm_spectra.h @@ -0,0 +1,6 @@ +#ifndef AOLOOPCONTROL_IOTOOLS_NORMSPECTRA_H +#define AOLOOPCONTROL_IOTOOLS_NORMSPECTRA_H + +errno_t CLIADDCMD_AOloopControl_IOtools__normspectra(); + +#endif \ No newline at end of file diff --git a/AOloopControl_IOtools/pl_column_sum.c b/AOloopControl_IOtools/pl_column_sum.c deleted file mode 100644 index ccd6a558..00000000 --- a/AOloopControl_IOtools/pl_column_sum.c +++ /dev/null @@ -1,129 +0,0 @@ -/** - * @file pl_column_sum.c - * @brief sum the columns of input shm - * - * - * - */ - -#include -#include "CommandLineInterface/CLIcore.h" -#include "COREMOD_tools/COREMOD_tools.h" - -// Local variables pointers -static char *input_shm_name; // input shared memory -static long fpi_inputshmname; - -static char *output_shm_name; // output shared memory -static long fpi_outputshmname; - -static CLICMDARGDEF farg[] = -{ - { - CLIARG_IMG, - ".wfsin", - "Wavefront sensor input", - "wfsin", - CLIARG_VISIBLE_DEFAULT, - (void **) &input_shm_name, - &fpi_inputshmname - }, - { - CLIARG_STR, - ".wfsout", - "Wavefront sensor output", - "wfsim", - CLIARG_VISIBLE_DEFAULT, - (void **) &output_shm_name, - &fpi_outputshmname - }, -}; - -// Optional custom configuration setup. -// Runs once at conf startup -// -static errno_t customCONFsetup() -{ - if(data.fpsptr != NULL) - { - - } - - return RETURN_SUCCESS; -} - -// Optional custom configuration checks. -// Runs at every configuration check loop iteration -// -static errno_t customCONFcheck() -{ - return RETURN_SUCCESS; -} - -static CLICMDDATA CLIcmddata = -{ - "column_sum", "sum columns", CLICMD_FIELDS_DEFAULTS -}; - - -// detailed help -static errno_t help_function() -{ - return RETURN_SUCCESS; -} - -static errno_t compute_function() -{ - DEBUG_TRACE_FSTART(); - // JON YOU GET TO INIT HERE - - IMGID wfsin = mkIMGID_from_name(input_shm_name); - resolveIMGID(&wfsin, ERRMODE_ABORT); - - uint32_t sizeoutx = wfsin.size[0]; - uint32_t sizeouty = wfsin.size[1]; - - // Create output - IMGID wfsout; - wfsout = - stream_connect_create_2D(output_shm_name, sizeoutx,1, _DATATYPE_FLOAT); - - // This is the while(True) { - INSERT_STD_PROCINFO_COMPUTEFUNC_INIT - INSERT_STD_PROCINFO_COMPUTEFUNC_LOOPSTART - { - // JON YOU GET TO WORK HERE - uint32_t i; - for (i = 0; i < sizeoutx; i++){ - float tot = 0.0; - uint32_t j; - for (j = 0; j < sizeouty; j++) { - uint64_t pixindex = j * sizeoutx + i; //i * sizeouty + j; - tot += wfsin.im->array.UI16[pixindex]; - } - wfsout.im->array.F[i] = tot; - } - - // Done and post downstream. - processinfo_update_output_stream(processinfo, wfsout.ID); - } - INSERT_STD_PROCINFO_COMPUTEFUNC_END // } // while (true) - - DEBUG_TRACE_FEXIT(); - - return RETURN_SUCCESS; -} - - -INSERT_STD_FPSCLIfunctions - -// Register function in CLI -errno_t CLIADDCMD_AOloopControl_IOtools__PLcolumnsum() -{ - - CLIcmddata.FPS_customCONFsetup = customCONFsetup; - CLIcmddata.FPS_customCONFcheck = customCONFcheck; - INSERT_STD_CLIREGISTERFUNC - - return RETURN_SUCCESS; -} diff --git a/AOloopControl_IOtools/pl_column_sum.h b/AOloopControl_IOtools/pl_column_sum.h deleted file mode 100644 index 9a9e3aa5..00000000 --- a/AOloopControl_IOtools/pl_column_sum.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef AOLOOPCONTROL_IOTOOLS_PLCOLUMNSUM_H -#define AOLOOPCONTROL_IOTOOLS_PLCOLUMNSUM_H - -errno_t CLIADDCMD_AOloopControl_IOtools__PLcolumnsum(); - -#endif diff --git a/AOloopControl_IOtools/pl_trace_renorm.h b/AOloopControl_IOtools/pl_trace_renorm.h deleted file mode 100644 index de9cfec2..00000000 --- a/AOloopControl_IOtools/pl_trace_renorm.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef AOLOOPCONTROL_IOTOOLS_PLTRACERENORM_H -#define AOLOOPCONTROL_IOTOOLS_PLTRACERENORM_H - -errno_t CLIADDCMD_AOloopControl_IOtools__PLtracerenorm(); - -#endif