11 #ifndef __KLIPreduction_hpp__
12 #define __KLIPreduction_hpp__
20 #include "../ipc/ompLoopWatcher.hpp"
21 #include "../math/geo.hpp"
22 #include "../math/eigenLapack.hpp"
52 std::string meansubMethodStr(
int method );
54 int meansubMethodFmStr(
const std::string & method );
65 std::string excludeMethodStr(
int method);
67 int excludeMethodFmStr(
const std::string & method);
79 std::string includeMethodStr(
int method );
81 int includeMethodFmStr(
const std::string & method );
93 template<
typename _realT,
class _derotFunctObj,
typename _evCalcT =
double>
98 typedef Eigen::Array<realT, Eigen::Dynamic, Eigen::Dynamic> eigenImageT;
100 typedef _evCalcT evCalcT;
111 const std::string & prefix,
112 const std::string & ext
129 const std::string & prefix,
130 const std::string & ext,
131 const std::string & RDIdir,
132 const std::string & RDIprefix,
133 const std::string & RDIext=
""
144 const std::string & RDIfileListFile
234 std::vector<realT> & sds
237 std::vector<_realT> m_minr;
238 std::vector<_realT> m_maxr;
239 std::vector<_realT> m_minq;
240 std::vector<_realT> m_maxq;
249 int regions( std::vector<realT> minr,
250 std::vector<realT> maxr,
251 std::vector<realT> minq,
252 std::vector<realT> maxq
268 std::vector<realT> vminr(1, minr);
269 std::vector<realT> vmaxr(1, maxr);
270 std::vector<realT> vminq(1, minq);
271 std::vector<realT> vmaxq(1, maxq);
273 return regions(vminr, vmaxr, vminq, vmaxq);
278 std::vector<size_t> & idx,
285 int processPSFSub(
const std::string & dir,
286 const std::string & prefix,
287 const std::string & ext
290 double t_worker_begin {0};
291 double t_worker_end {0};
299 printf(
"KLIP reduction times: \n");
300 printf(
" Total time: %f sec\n", this->t_end-this->t_begin);
301 printf(
" Loading: %f sec\n", this->t_load_end-this->t_load_begin);
302 printf(
" Fake Injection: %f sec\n", this->t_fake_end-this->t_fake_begin);
303 printf(
" Coadding: %f sec\n", this->t_coadd_end-this->t_coadd_begin);
304 printf(
" Preprocessing: %f sec\n", this->t_preproc_end - this->t_preproc_begin);
305 printf(
" Az USM: %f sec\n", this->t_azusm_end - this->t_azusm_begin);
306 printf(
" Gauss USM: %f sec\n", this->t_gaussusm_end - this->t_gaussusm_begin);
307 printf(
" KLIP algorithm: %f elapsed real sec\n", this->t_worker_end - this->t_worker_begin);
308 double klip_cpu = this->t_eigenv + this->t_klim + this->t_psf;
309 printf(
" EigenDecomposition %f cpu sec (%f%%)\n", this->t_eigenv, this->t_eigenv/klip_cpu*100);
310 printf(
" KL image calc %f cpu sec (%f%%)\n", this->t_klim, this->t_klim/klip_cpu*100);
311 printf(
" PSF calc/sub %f cpu sec (%f%%)\n", this->t_psf, this->t_psf/klip_cpu*100);
312 printf(
" Derotation: %f sec\n", this->t_derotate_end-this->t_derotate_begin);
313 printf(
" Combination: %f sec\n", this->t_combo_end-this->t_combo_begin);
320 template<
typename _realT,
class _derotFunctObj,
typename _evCalcT>
325 template<
typename _realT,
class _derotFunctObj,
typename _evCalcT>
327 const std::string & prefix,
328 const std::string & ext
333 template<
typename _realT,
class _derotFunctObj,
typename _evCalcT>
339 template<
typename _realT,
class _derotFunctObj,
typename _evCalcT>
341 const std::string & prefix,
342 const std::string & ext,
343 const std::string & RDIdir,
344 const std::string & RDIprefix,
345 const std::string & RDIext
346 ) :
ADIobservation<_realT, _derotFunctObj>(dir, prefix, ext, RDIdir, RDIprefix, RDIext)
348 std::cerr <<
"KLIP 6\n";
351 template<
typename _realT,
class _derotFunctObj,
typename _evCalcT>
353 const std::string & RDIfileListFile
354 ) :
ADIobservation<_realT, _derotFunctObj>(fileListFile, RDIfileListFile)
358 template<
typename _realT,
class _derotFunctObj,
typename _evCalcT>
363 template<
typename _realT,
class _derotFunctObj,
typename _evCalcT>
366 std::vector<_realT> & norms
370 norms.resize(ims.planes());
385 for(
int n=0;n<ims.planes(); ++n)
387 ims.
image(n) -= mean;
389 realT immean = ims.
image(n).mean();
390 norms[n] = (ims.
image(n)-immean).matrix().norm();
395 for(
int n=0;n<tims.planes(); ++n)
397 tims.
image(n) -= mean;
404 std::vector<realT> work;
406 for(
int n=0;n<ims.planes(); ++n)
410 mean = ims.
image(n).mean();
417 ims.
image(n) -= mean;
420 realT immean = ims.
image(n).mean();
421 norms[n] = (ims.
image(n)-immean).matrix().norm();
427 for(
int n=0;n<tims.planes(); ++n)
431 mean = tims.
image(n).mean();
438 tims.
image(n) -= mean;
446 template<
typename _realT,
class _derotFunctObj,
typename _evCalcT>
448 std::vector<_realT> maxr,
449 std::vector<_realT> minq,
450 std::vector<_realT> maxq
461 m_maxNmodes = m_Nmodes[0];
462 for(
size_t i = 1; i < m_Nmodes.size(); ++i)
464 if( m_Nmodes[i] > m_maxNmodes) m_maxNmodes = m_Nmodes[i];
467 std::cerr <<
"Beginning\n";
469 if(this->m_imSize == 0)
471 this->m_imSize = 2*(*std::max_element(maxr.begin(),maxr.end()) + m_padSize);
474 if(!this->m_filesRead)
476 if( this->readFiles() < 0)
return -1;
480 if(!this->m_RDIfilesRead && this->m_RDIfileList.size() != 0 )
482 if( this->readRDIFiles() < 0)
return -1;
485 if(this->m_preProcess_only && !this->m_skipPreProcess)
487 std::cerr <<
"Pre-processing complete, stopping.\n";
491 std::cerr <<
"allocating psf subtracted cubes\n";
492 this->m_psfsub.resize(m_Nmodes.size());
493 for(
size_t n=0;n<m_Nmodes.size(); ++n)
495 this->m_psfsub[n].resize(this->m_Nrows, this->m_Ncols, this->m_Nims);
496 this->m_psfsub[n].cube().setZero();
500 eigenImageT rIm(this->m_Nrows,this->m_Ncols);
501 eigenImageT qIm(this->m_Nrows,this->m_Ncols);
503 radAngImage<math::degreesT<realT>>(rIm, qIm, .5*(this->m_Nrows-1), .5*(this->m_Ncols-1));
505 m_imsIncluded.resize(this->m_Nims,this->m_Nims);
506 m_imsIncluded.setConstant(1);
508 std::cerr <<
"starting regions " << minr.size() <<
"\n";
511 for(
size_t regno = 0; regno < minr.size(); ++regno)
513 eigenImageT * maskPtr = 0;
515 if( this->m_mask.rows() == this->m_Nrows && this->m_mask.cols() == this->m_Ncols) maskPtr = &this->m_mask;
517 std::vector<size_t> idx = annulusIndices<math::degreesT<realT>>(rIm, qIm, .5*(this->m_Nrows-1), .5*(this->m_Ncols-1),
518 minr[regno], maxr[regno], minq[regno], maxq[regno], maskPtr);
526 if(this->m_refIms.planes() > 0)
528 rims.resize(idx.size(), 1, this->m_Nims);
532 for(
int i=0;i< this->m_Nims; ++i)
534 auto tim = tims.image(i);
538 for(
int p=0;p<this->m_refIms.planes();++p)
540 auto rim = rims.
image(p);
551 if(this->m_refIms.planes() > 0)
559 dang = fabs(atan(m_minDPx/minr[regno]));
572 dangMax = fabs(atan(m_maxDPx/minr[regno]));
585 if(this->m_refIms.planes() > 0)
587 std::cerr <<
"\n\n******* RDI MODE **********\n\n";
588 worker(rims, tims, idx, dang, dangMax);
592 std::cerr <<
"\n\n******* ADI MODE **********\n\n";
593 worker(tims, tims, idx, dang, dangMax);
595 std::cerr <<
"worker done\n";
600 ffii.
write(
"imsIncluded.fits", m_imsIncluded);
603 if(finalProcess() < 0)
605 std::cerr <<
"Error in final processing\n";
620 bool included {
true};
624 template<
typename eigenT,
typename eigenTin>
625 void extractRowsAndCols(eigenT & out,
const eigenTin & in,
const std::vector<size_t> & idx)
628 out.resize(idx.size(), idx.size());
630 for(
size_t i=0; i< idx.size(); ++i)
632 for(
size_t j=0; j < idx.size(); ++j)
634 out(i,j) = in(idx[i], idx[j]);
640 template<
typename eigenT,
typename eigenTin>
641 void extractCols(eigenT & out,
const eigenTin & in,
const std::vector<size_t> & idx)
644 out.resize(in.rows(), idx.size());
646 for(
size_t i=0; i< idx.size(); ++i)
648 out.col(i) = in.col(idx[i]);
653 template<
typename realT,
typename eigenT,
typename eigenTv,
class derotFunctObj>
654 void collapseCovar( eigenT & cutCV,
656 const std::vector<realT> & sds,
658 const eigenTv & rims,
664 int excludeMethodMax,
666 const derotFunctObj & derotF,
667 eigenImage<int> & imsIncluded
670 std::vector<cvEntry> allidx(Nims);
676 for(
int i=0; i < Nims; ++i)
679 allidx[i].angle = derotF.derotAngle(i);
684 allidx[i].cvVal = CV(imno,i)/(sds[i]*sds[imno]);
688 allidx[i].cvVal = CV(i,imno)/(sds[i]*sds[imno]);
694 for(
size_t j=0; j < Nims; ++j)
696 if( fabs(
math::angleDiff<math::radiansT<realT>>( derotF.derotAngle(j), derotF.derotAngle(imno))) <= dang ) allidx[j].included =
false;
701 for(
size_t j=0; j < Nims; ++j)
703 if( fabs( (
long) j - imno) <= dang ) allidx[j].included =
false;
709 for(
size_t j=0; j < Nims; ++j)
711 if( fabs(
math::angleDiff<math::radiansT<realT>>( derotF.derotAngle(j), derotF.derotAngle(imno))) > dangMax ) allidx[j].included =
false;
716 for(
size_t j=0; j < Nims; ++j)
718 if( fabs( (
long) j - imno) > dangMax ) allidx[j].included =
false;
723 if( includeRefNum > 0 && (
size_t) includeRefNum < allidx.size())
726 for(
size_t j=0; j < Nims; ++j)
728 if(allidx[j].included ==
true) ++kept;
732 std::vector<realT> cvVal;
735 for(
size_t j=0; j < Nims; ++j)
737 if(allidx[j].included ==
true)
739 cvVal[
k] = allidx[j].cvVal;
745 std::nth_element(cvVal.begin(), cvVal.begin()+ (kept-includeRefNum), cvVal.end());
747 realT mincorr = cvVal[kept-includeRefNum];
748 std::cerr <<
" Minimum correlation: " << mincorr <<
"\n";
751 for(
size_t j=0; j < Nims; ++j)
753 if( allidx[j].cvVal < mincorr ) allidx[j].included =
false;
758 std::vector<size_t> keepidx;
759 for(
size_t j=0;j<Nims;++j)
761 imsIncluded(imno,j) = allidx[j].included;
763 if(allidx[j].included) keepidx.push_back(j);
768 if(keepidx.size() == 0)
770 std::cerr <<
"\n\n" << imno <<
"\n\n";
773 extractRowsAndCols(cutCV, CV, keepidx);
774 extractCols(rimsCut, rims, keepidx);
779 template<
typename _realT,
class _derotFunctObj,
typename _evCalcT>
782 std::vector<size_t> & idx,
787 std::cerr <<
"beginning worker\n";
791 std::vector<realT> sds;
796 meanSubtract(rims, tims, sds);
804 ff.
write(
"cv.fits", cv);
808 eigenImageT master_klims;
814 std::cerr << cv.rows() <<
" " << cv.cols() <<
" " << rims.rows() <<
" " << rims.cols() <<
" " << rims.planes() <<
" " << m_maxNmodes <<
"\n";
815 math::calcKLModes<double>(master_klims, cv, rims.
cube(), m_maxNmodes,
nullptr, &teigenv, &tklim);
828 eigenImageT rims_cut;
836 klims = master_klims;
840 for(
int imno = 0; imno < this->m_Nims; ++imno)
845 collapseCovar<realT>( cv_cut, cv, sds, rims_cut, rims.
asVectors(), imno, dang, dangMax, this->m_Nims, this->m_excludeMethod, this->m_excludeMethodMax, this->m_includeRefNum, this->m_derotF, m_imsIncluded);
848 double teigenv, tklim;
853 cfs.resize(1, klims.rows());
858 for(
int j=0; j<cfs.size(); ++j)
860 cfs(j) = klims.row(j).matrix().dot(tims.
cube().col(imno).matrix());
863 for(
size_t mode_i =0; mode_i < m_Nmodes.size(); ++mode_i)
865 psf = cfs(cfs.size()-1)*klims.row(cfs.size()-1);
869 for(
int j=cfs.size()-2; j>=cfs.size()-m_Nmodes[mode_i] && j >= 0; --j)
871 psf += cfs(j)*klims.row(j);
875 insertImageRegion( this->m_psfsub[mode_i].cube().col(imno), tims.
cube().col(imno) - psf.transpose(), idx);
889 template<
typename _realT,
class _derotFunctObj,
typename _evCalcT>
892 if(this->m_postMedSub)
894 std::cerr <<
"Subtracting medians in post\n";
896 for(
size_t n=0; n<this->m_psfsub.size(); ++n)
902 this->m_psfsub[n].median(medim);
905 for(
int i=0; i<this->m_psfsub[n].planes();++i)
907 this->m_psfsub[n].image(i) -= medim;
913 if(this->m_doDerotate)
915 std::cerr <<
"derotating\n";
920 if(this->m_combineMethod > 0)
922 std::cerr <<
"combining\n";
923 this->combineFinim();
927 if(this->m_doWriteFinim ==
true || this->m_doOutputPSFSub ==
true)
929 std::cerr <<
"writing\n";
931 fits::fitsHeader head;
933 this->ADIobservation<_realT, _derotFunctObj>::stdFitsHeader(&head);
935 head.append(
"", fits::fitsCommentType(),
"----------------------------------------");
936 head.append(
"", fits::fitsCommentType(),
"mx::KLIPreduction parameters:");
937 head.append(
"", fits::fitsCommentType(),
"----------------------------------------");
940 head.append(
"MEANSUBM", HCI::meansubMethodStr(m_meanSubMethod),
"PCA mean subtraction method");
943 std::stringstream str;
945 if(m_Nmodes.size() > 0)
947 for(
size_t nm=0;nm < m_Nmodes.size()-1; ++nm) str << m_Nmodes[nm] <<
",";
948 str << m_Nmodes[m_Nmodes.size()-1];
949 head.append<
char *>(
"NMODES", (
char *)str.str().c_str(),
"number of modes");
952 if(m_minr.size() > 0)
955 for(
size_t nm=0;nm < m_minr.size()-1; ++nm) str << m_minr[nm] <<
",";
956 str << m_minr[m_minr.size()-1];
957 head.append<
char *>(
"REGMINR", (
char *)str.str().c_str(),
"region inner edge(s)");
960 if(m_maxr.size() > 0)
963 for(
size_t nm=0;nm < m_maxr.size()-1; ++nm) str << m_maxr[nm] <<
",";
964 str << m_maxr[m_maxr.size()-1];
965 head.append<
char *>(
"REGMAXR", (
char *)str.str().c_str(),
"region outer edge(s)");
968 if(m_minq.size() > 0)
971 for(
size_t nm=0;nm < m_minq.size()-1; ++nm) str << m_minq[nm] <<
",";
972 str << m_minq[m_minq.size()-1];
973 head.append<
char *>(
"REGMINQ", (
char *)str.str().c_str(),
"region minimum angle(s)");
976 if(m_maxq.size() > 0)
979 for(
size_t nm=0;nm < m_maxq.size()-1; ++nm) str << m_maxq[nm] <<
",";
980 str << m_maxq[m_maxq.size()-1];
981 head.append<
char *>(
"REGMAXQ", (
char *)str.str().c_str(),
"region maximum angle(s)");
984 head.append<std::string>(
"EXMTHDMN", HCI::excludeMethodStr(m_excludeMethod),
"exclusion method (min)");
985 head.append<realT>(
"MINDPX", m_minDPx,
"minimum delta (units based on EXMTHDMN)");
987 head.append<std::string>(
"EXMTHDMX", HCI::excludeMethodStr(m_excludeMethodMax),
"exclusion method (max)");
988 head.append<realT>(
"MAXDPX", m_maxDPx,
"maximum delta (units based on EXMTHDMX)");
990 head.append<std::string>(
"INMTHDMX", HCI::includeMethodStr(m_includeMethod),
"inclusion method");
991 head.append<
int>(
"INCLREFN", m_includeRefNum,
"number of images included by INMTHDMX");
993 if(this->m_doWriteFinim ==
true && this->m_combineMethod > 0)
995 this->writeFinim(&head);
998 if(this->m_doOutputPSFSub)
1000 this->outputPSFSub(&head);
1007 template<
typename _realT,
class _derotFunctObj,
typename _evCalcT>
1008 int KLIPreduction<_realT, _derotFunctObj, _evCalcT>::processPSFSub(
const std::string & dir,
1009 const std::string & prefix,
1010 const std::string & ext
1014 std::cerr <<
"Beginning PSF Subtracted Image Processing\n";
1019 fits::fitsHeader fh;
1020 eigenImage<realT> im;
1021 fits::fitsFile<realT> ff;
1023 ff.read(im, fh, flist[0]);
1025 if(fh.count(
"MEANSUBM") == 0)
1027 mxError(
"KLIPReduction", MXE_PARAMNOTSET,
"MEANSUBM not found in FITS header.");
1030 m_meanSubMethod = HCI::meansubMethodFmStr(fh[
"MEANSUBM"].String());
1031 std::cerr <<
"meanSubMethod: " << HCI::meansubMethodStr(m_meanSubMethod) <<
"\n";
1033 if(fh.count(
"NMODES") == 0)
1035 mxError(
"KLIPReduction", MXE_PARAMNOTSET,
"NMODES not found in FITS header.");
1039 if(m_Nmodes.size() == 0)
1041 mxError(
"KLIPReduction", MXE_PARSEERR,
"NMODES vector did not parse correctly.");
1044 std::cerr <<
"nModes: " << fh[
"NMODES"].String() <<
"\n";
1047 if(fh.count(
"REGMINR") == 0)
1049 mxError(
"KLIPReduction", MXE_PARAMNOTSET,
"REGMINR not found in FITS header.");
1053 if(m_minr.size() == 0)
1055 mxError(
"KLIPReduction", MXE_PARSEERR,
"REGMINR vector did not parse correctly.");
1058 std::cerr <<
"minr: " << fh[
"REGMINR"].String() <<
"\n";
1061 if(fh.count(
"REGMAXR") == 0)
1063 mxError(
"KLIPReduction", MXE_PARAMNOTSET,
"REGMAXR not found in FITS header.");
1067 if(m_maxr.size() == 0)
1069 mxError(
"KLIPReduction", MXE_PARSEERR,
"REGMAXR vector did not parse correctly.");
1072 std::cerr <<
"minr: " << fh[
"REGMAXR"].String() <<
"\n";
1076 if(fh.count(
"REGMINQ") == 0)
1078 mxError(
"KLIPReduction", MXE_PARAMNOTSET,
"REGMINQ not found in FITS header.");
1082 if(m_minq.size() == 0)
1084 mxError(
"KLIPReduction", MXE_PARSEERR,
"REGMINQ vector did not parse correctly.");
1087 std::cerr <<
"minq: " << fh[
"REGMINQ"].String() <<
"\n";
1090 if(fh.count(
"REGMAXR") == 0)
1092 mxError(
"KLIPReduction", MXE_PARAMNOTSET,
"REGMAXR not found in FITS header.");
1096 if(m_maxq.size() == 0)
1098 mxError(
"KLIPReduction", MXE_PARSEERR,
"REGMAXR vector did not parse correctly.");
1101 std::cerr <<
"minr: " << fh[
"REGMAXR"].String() <<
"\n";
1103 if(fh.count(
"EXMTHDMN") == 0)
1105 mxError(
"KLIPReduction", MXE_PARAMNOTSET,
"EXMTHDMN not found in FITS header.");
1108 m_excludeMethod = HCI::excludeMethodFmStr(fh[
"EXMTHDMN"].String());
1109 std::cerr <<
"excludeMethod: " << HCI::excludeMethodStr(m_excludeMethod) <<
"\n";
1111 if(fh.count(
"MINDPX") == 0)
1113 mxError(
"KLIPReduction", MXE_PARAMNOTSET,
"MINDPX not found in FITS header.");
1116 m_minDPx = fh[
"MINDPX"].value<realT>();
1117 std::cerr <<
"minDPx: " << m_minDPx <<
"\n";
1119 if(fh.count(
"EXMTHDMX") == 0)
1121 mxError(
"KLIPReduction", MXE_PARAMNOTSET,
"EXMTHDMX not found in FITS header.");
1124 m_excludeMethodMax = HCI::excludeMethodFmStr(fh[
"EXMTHDMX"].String());
1125 std::cerr <<
"excludeMethodMax: " << HCI::excludeMethodStr(m_excludeMethodMax) <<
"\n";
1127 if(fh.count(
"MAXDPX") == 0)
1129 mxError(
"KLIPReduction", MXE_PARAMNOTSET,
"MAXDPX not found in FITS header.");
1132 m_maxDPx = fh[
"MAXDPX"].value<realT>();
1133 std::cerr <<
"maxDPx: " << m_maxDPx <<
"\n";
1135 if(fh.count(
"INMTHDMX") == 0)
1137 mxError(
"KLIPReduction", MXE_PARAMNOTSET,
"INMTHDMX not found in FITS header.");
1140 m_includeMethod = HCI::includeMethodFmStr(fh[
"INMTHDMX"].String());
1141 std::cerr <<
"includeMethod: " << HCI::includeMethodStr(m_includeMethod) <<
"\n";
1143 if(fh.count(
"INCLREFN") == 0)
1145 mxError(
"KLIPReduction", MXE_PARAMNOTSET,
"INCLREFN not found in FITS header.");
1148 m_includeRefNum = fh[
"INCLREFN"].value<
int>();
1149 std::cerr <<
"includedRefNum: " << m_includeRefNum <<
"\n";
1153 this->m_skipPreProcess =
true;
1155 this->m_keywords.clear();
1158 this->readPSFSub(dir, prefix, ext, m_Nmodes.size());
1169 template<
typename realT>
class ADIDerotator;
1171 extern template struct KLIPreduction<float, ADIDerotator<float>,
float>;
1172 extern template struct KLIPreduction<float, ADIDerotator<float>,
double>;
1173 extern template struct KLIPreduction<double, ADIDerotator<double>,
double>;
Defines the ADI high contrast imaging data type.
Class to manage interactions with a FITS file.
int write(const dataT *im, int d1, int d2, int d3, fitsHeader *head)
Write the contents of a raw array to the FITS file.
void median(eigenT &mim)
Calculate the median image of the cube.
Eigen::Map< Eigen::Array< dataT, Eigen::Dynamic, Eigen::Dynamic > > cube()
Returns a 2D Eigen::Eigen::Map pointed at the entire cube.
void mean(eigenT &mim)
Calculate the mean image of the cube.
Eigen::Map< Eigen::Array< dataT, Eigen::Dynamic, Eigen::Dynamic > > asVectors()
Return an Eigen::Eigen::Map of the cube where each image is a vector.
Eigen::Map< Eigen::Array< dataT, Eigen::Dynamic, Eigen::Dynamic > > image(Index n)
Returns a 2D Eigen::Eigen::Map pointed at the specified image.
A class to track the number of iterations in an OMP parallelized loop.
void incrementAndOutputStatus()
Increment and output status.
constexpr units::realT k()
Boltzmann Constant.
Eigen::Array< scalarT, -1, -1 > eigenImage
Definition of the eigenImage type, which is an alias for Eigen::Array.
MXLAPACK_INT calcKLModes(eigenT &klModes, eigenT &cv, const eigenT1 &Rims, int n_modes=0, syevrMem< _evCalcT > *mem=0, double *t_eigenv=nullptr, double *t_klim=nullptr)
Calculate the K-L modes, or principle components, given a covariance matrix.
void eigenSYRK(eigenT1 &cv, const eigenT2 &ims)
Calculates the lower triangular part of the covariance matrix of ims.
std::vector< std::string > getFileNames(const std::string &directory, const std::string &prefix, const std::string &substr, const std::string &extension)
Get a list of file names from the specified directory, specifying a prefix, a substring to match,...
angleT::realT angleDiff(typename angleT::realT q1, typename angleT::realT q2)
Calculate the difference between two angles, correctly across 0/360.
realT dtor(realT q)
Convert from degrees to radians.
includeMethods
Image inclusion methods.
meansubMethods
Mean subtraction methods.
excludeMethods
Image exclusion methods.
@ includeImno
include images which are closest in imno to the target
@ includeTime
include images which are closest in time to the target
@ includeAngle
include images which are closest in angle to the target
@ includeAll
include all images
@ includeCorr
include images which are most correlated with the target
@ imageMode
The mode of each image (within the search region) is subtracted from itself.
@ imageMean
The mean of each image (within the search region) is subtracted from itself.
@ imageMedian
The median of each image (within the search region) is subtracted from itself.
@ meanImage
The mean image of the data is subtracted from each image.
@ medianImage
The median image of the data is subtracted from each image.
@ excludePixel
Exclude by pixels of rotation.
@ excludeAngle
Exclude by angle of roration.
@ excludeImno
Exclude by number of images.
@ excludeNone
Exclude no images.
void cutImageRegion(imageTout &imout, const imageTin &imin, const std::vector< size_t > &idx, bool resize=true)
Cut out a region of an image specified by an index-mask.
void insertImageRegion(imageTout imout, const imageTin &imin, const std::vector< size_t > &idx)
Insert a region of an image specified by an index-mask.
void parseStringVector(std::vector< typeT > &v, const std::string &s, char delim=',')
Parses a string into a vector of tokens delimited by a character.
typeT get_curr_time(timespec &tsp)
Get the current system time in seconds.
Process an angular differential imaging (ADI) observation.
An implementation of the Karhunen-Loeve Image Processing (KLIP) algorithm.
int m_meanSubMethod
Specify how the data are centered for PCA within each search region.
realT m_minDPx
Specify the minimum pixel difference at the inner edge of the search region.
realT m_maxDPx
Specify the maximum pixel difference at the inner edge of the search region.
int regions(std::vector< realT > minr, std::vector< realT > maxr, std::vector< realT > minq, std::vector< realT > maxq)
Run KLIP in a set of geometric search regions.
void meanSubtract(eigenCube< realT > &rims, eigenCube< realT > &tims, std::vector< realT > &sds)
Subtract the basis mean from each of the images.
int m_includeRefNum
Number of reference images to include in the covariance matrix.
void worker(eigenCube< realT > &rims, eigenCube< realT > &tims, std::vector< size_t > &idx, realT dang, realT dangMax)
int m_excludeMethodMax
Controls how reference images are excluded, if at all, from the covariance matrix for each target ima...
std::vector< int > m_Nmodes
Specifies the number of modes to include in the PSF.
int regions(realT minr, realT maxr, realT minq, realT maxq)
Run KLIP in a geometric search region.
KLIPreduction()
Default c'tor.
int m_includeMethod
Controls how number of included images is calculated.
int m_excludeMethod
Controls how reference images are excluded, if at all, from the covariance matrix for each target ima...
A struct to hold the working memory for eigenSYEVR and maintain it between calls if desired.