9 #ifndef __ADIobservation_hpp__
10 #define __ADIobservation_hpp__
11 #include "../ioutils/fileUtils.hpp"
14 #include "../ioutils/fits/fitsHeader.hpp"
92 template<
typename _realT,
class _derotFunctObj>
96 typedef _derotFunctObj derotFunctObj;
97 typedef Eigen::Array<realT, Eigen::Dynamic, Eigen::Dynamic> eigenImageT;
99 derotFunctObj m_derotF;
101 derotFunctObj m_RDIderotF;
103 bool m_doDerotate {
true};
105 bool m_postMedSub {
false};
110 const std::string &prefix,
111 const std::string &ext
117 const std::string &prefix,
118 const std::string &ext,
119 const std::string &RDIdir,
120 const std::string &RDIprefix,
121 const std::string &RDIext=
""
125 const std::string & RDIfileListFile
160 const std::string & prefix,
161 const std::string & ext,
184 std::vector<std::string> & fileList,
185 derotFunctObj & derotF,
211 double t_fake_begin {0};
212 double t_fake_end {0};
214 double t_derotate_begin {0};
215 double t_derotate_end {0};
219 template<
typename _realT,
class _derotFunctObj>
220 ADIobservation<_realT, _derotFunctObj>::ADIobservation()
224 template<
typename _realT,
class _derotFunctObj>
226 const std::string & prefix,
227 const std::string & ext
232 template<
typename _realT,
class _derotFunctObj>
237 template<
typename _realT,
class _derotFunctObj>
239 const std::string & prefix,
240 const std::string & ext,
241 const std::string & RDIdir,
242 const std::string & RDIprefix,
243 const std::string & RDIext
244 ) :
HCIobservation<realT>(dir,prefix,ext, RDIdir, RDIprefix, RDIext)
248 template<
typename _realT,
class _derotFunctObj>
250 const std::string & RDIfileListFile
255 template<
typename _realT,
class _derotFunctObj>
258 this->m_keywords.clear();
260 if(!m_derotF.isSetup())
262 mxError(
"ADIobservation::readFiles", MXE_PARAMNOTSET,
"Derotator is not configured.");
268 for(
size_t i=0;i<m_derotF.m_keywords.size();++i)
270 this->m_keywords.push_back(m_derotF.m_keywords[i]);
278 template<
typename _realT,
class _derotFunctObj>
281 m_derotF.extractKeywords(this->m_heads);
283 if(m_fakeFileName !=
"" && !this->m_skipPreProcess)
285 std::cerr <<
"Injecting fakes in target images...\n";
286 if( injectFake(this->m_tgtIms, this->m_fileList, m_derotF, 1, 1) < 0)
return -1;
292 template<
typename _realT,
class _derotFunctObj>
295 m_derotF.extractKeywords(this->m_heads);
299 template<
typename _realT,
class _derotFunctObj>
302 this->m_RDIkeywords.clear();
304 if(!m_RDIderotF.isSetup())
306 mxError(
"ADIobservation::readRDIFiles", MXE_PARAMNOTSET,
"Derotator is not configured.");
312 for(
size_t i=0;i<m_RDIderotF.m_keywords.size();++i)
314 this->m_RDIkeywords.push_back(m_RDIderotF.m_keywords[i]);
322 template<
typename _realT,
class _derotFunctObj>
325 m_RDIderotF.extractKeywords(this->m_RDIheads);
335 template<
typename _realT,
class _derotFunctObj>
338 m_RDIderotF.extractKeywords(this->m_RDIheads);
345 template<
typename _realT,
class _derotFunctObj>
347 const std::string & prefix,
348 const std::string & ext,
359 ff.
read(im, fh, flist[0]);
361 if(!m_derotF.isSetup())
363 mxError(
"ADIobservation::readFiles", MXE_PARAMNOTSET,
"Derotator is not configured.");
367 if(fh.
count(
"POSTMEDS") != 0)
369 m_postMedSub = fh[
"POSTMEDS"].Int();
370 std::cerr <<
"postMedSub: " << m_postMedSub <<
"\n";
373 if(fh.
count(
"FAKEFILE") != 0)
375 m_fakeFileName = fh[
"FAKEFILE"].String();
376 std::cerr <<
"fakeFileName: " << m_fakeFileName <<
"\n";
379 if(fh.
count(
"FAKESCFL") != 0)
381 m_fakeScaleFileName = fh[
"FAKESCFL"].String();
382 std::cerr <<
"fakeScaleFileName: " << m_fakeScaleFileName <<
"\n";
385 if(fh.
count(
"FAKESEP") != 0)
389 if(m_fakeSep.size() == 0)
391 mxError(
"KLIPReduction", MXE_PARSEERR,
"FAKESEP vector did not parse correctly.");
394 std::cerr <<
"fakeSep: " << fh[
"FAKESEP"].String() <<
"\n";
397 if(fh.
count(
"FAKEPA") != 0)
401 if(m_fakePA.size() == 0)
403 mxError(
"KLIPReduction", MXE_PARSEERR,
"FAKEPA vector did not parse correctly.");
406 std::cerr <<
"fakePA: " << fh[
"FAKEPA"].String() <<
"\n";
409 if(fh.
count(
"FAKECONT") != 0)
413 if(m_fakeContrast.size() == 0)
415 mxError(
"KLIPReduction", MXE_PARSEERR,
"FAKECONT vector did not parse correctly.");
418 std::cerr <<
"fakeContrast: " << fh[
"FAKECONT"].String() <<
"\n";
424 for(
size_t i=0;i<m_derotF.m_keywords.size();++i)
426 this->m_keywords.push_back(m_derotF.m_keywords[i]);
432 m_derotF.extractKeywords(this->m_heads);
437 template<
typename _realT,
class _derotFunctObj>
439 std::vector<std::string> & fileList,
440 derotFunctObj & derotF,
449 std::vector<std::string> fakeFiles;
452 std::ifstream scaleFin;
456 std::vector<realT> fakeScale(ims.planes(), 1.0);
457 if(m_fakeScaleFileName !=
"")
459 std::vector<std::string> sfileNames;
460 std::vector<realT> imS;
465 if(sfileNames.size() != imS.size())
467 std::cerr <<
"fake scale file must be two columns of: fileName scale\n";
470 std::map<std::string, realT> scales;
471 for(
size_t i=0;i<sfileNames.size();++i) scales[
ioutils::pathFilename(sfileNames[i].c_str())] = imS[i];
473 for(
size_t i=0; i<fileList.size(); ++i)
481 std::cerr <<
"File name not found in fakeScaleFile:\n";
490 if( ff.
read( fakePSF, m_fakeFileName ) < 0)
return -1;
498 for(
int i=0; i<ims.planes(); ++i)
502 ff.
read(fakePSF, fakeFiles[i]);
505 for(
size_t j=0;j<m_fakeSep.size(); ++j)
507 if( injectFake(fakePSF, ims, i, derotF.derotAngle(i), m_fakePA[j], m_fakeSep[j], m_fakeContrast[j], fakeScale[j], RDIFluxScale, RDISepScale) < 0)
return -1;
518 template<
typename _realT,
class _derotFunctObj>
532 if( (fakePSF.rows() < ims.rows() && fakePSF.cols() >= ims.cols()) ||
533 (fakePSF.rows() >= ims.rows() && fakePSF.cols() < ims.cols()))
535 mxThrowException(
err::sizeerr,
"ADIobservation::injectFake",
"fake PSF has different dimensions and can't be sized properly");
539 if(fakePSF.rows() < ims.rows() && fakePSF.cols() < ims.cols())
541 eigenImageT pfake(ims.rows(), ims.cols());
542 padImage(pfake, fakePSF, 0.5*(ims.rows()-fakePSF.rows()), 0);
547 if(fakePSF.rows() > ims.rows() && fakePSF.cols() > ims.cols())
549 eigenImageT cfake(ims.rows(), ims.cols());
550 cutPaddedImage(cfake, fakePSF, 0.5*(fakePSF.rows() - ims.rows()));
554 if(fakePSF.rows() != ims.rows() || fakePSF.cols() != ims.cols())
556 mxThrowException(err::sizeerr,
"ADIobservation::injectFake",
"fake PSF has different dimensions and can't be sized properly (is it even in rows and cols?)");
561 eigenImageT shiftFake(fakePSF.rows(), fakePSF.cols());
568 dx = sep * RDISepScale * sin(ang);
569 dy = sep * RDISepScale * cos(ang);
572 imageShift(shiftFake, fakePSF, dx, dy, cubicConvolTransform<realT>());
574 ims.
image(image_i) = ims.
image(image_i) + shiftFake*scale*RDIFluxScale*contrast;
580 template<
typename _realT,
class _derotFunctObj>
583 if( this->m_mask.rows() != this->m_Nrows || this->m_mask.cols() != this->m_Ncols)
585 std::cerr <<
"\nMask is not the same size as images.\n\n";
589 this->m_maskCube.resize( this->m_Nrows, this->m_Ncols, this->m_Nims);
596 for(
int i=0; i< this->m_Nims; ++i)
598 rotateMask( rm, this->m_mask, m_derotF.derotAngle(i));
599 this->m_maskCube.image(i) = rm;
604 ff.
write(
"maskCube.fits", this->m_maskCube);
607 template<
typename _realT,
class _derotFunctObj>
612 for(
size_t n=0; n<this->m_psfsub.size(); ++n)
620 for(
int i=0; i<this->m_psfsub[n].planes();++i)
622 derot = m_derotF.derotAngle(i);
626 this->m_psfsub[n].image(i) = rotim;
638 template<
typename _realT,
class _derotFunctObj>
641 if(head == 0)
return;
643 head->
append(
"", fits::fitsCommentType(),
"----------------------------------------");
644 head->
append(
"", fits::fitsCommentType(),
"mx::ADIobservation parameters:");
645 head->
append(
"", fits::fitsCommentType(),
"----------------------------------------");
647 head->
append(
"POSTMEDS", m_postMedSub,
"median subtraction after processing");
649 if(m_fakeFileName !=
"")
650 head->
append(
"FAKEFILE", m_fakeFileName,
"name of fake planet PSF file");
652 if(m_fakeScaleFileName !=
"")
653 head->
append(
"FAKESCFL", m_fakeScaleFileName,
"name of fake planet scale file name");
655 std::stringstream str;
657 if(m_fakeSep.size() > 0)
659 for(
size_t nm=0;nm < m_fakeSep.size()-1; ++nm) str << m_fakeSep[nm] <<
",";
660 str << m_fakeSep[m_fakeSep.size()-1];
661 head->
append<
char *>(
"FAKESEP", (
char *)str.str().c_str(),
"separation of fake planets");
664 if(m_fakePA.size() > 0 )
667 for(
size_t nm=0;nm < m_fakePA.size()-1; ++nm) str << m_fakePA[nm] <<
",";
668 str << m_fakePA[m_fakePA.size()-1];
669 head->
append<
char *>(
"FAKEPA", (
char *)str.str().c_str(),
"PA of fake planets");
672 if( m_fakeContrast.size() > 0)
675 for(
size_t nm=0;nm < m_fakeContrast.size()-1; ++nm) str << m_fakeContrast[nm] <<
",";
676 str << m_fakeContrast[m_fakeContrast.size()-1];
677 head->
append<
char *>(
"FAKECONT", (
char *)str.str().c_str(),
"Contrast of fake planets");
681 template<
typename realT>
class ADIDerotator;
683 extern template class ADIobservation<float, ADIDerotator<float>>;
684 extern template class ADIobservation<double, ADIDerotator<double>>;
Defines the basic high contrast imaging data type.
mxException for a size error
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.
int read(dataT *data)
Read the contents of the FITS file into an array.
Eigen::Map< Eigen::Array< dataT, Eigen::Dynamic, Eigen::Dynamic > > image(Index n)
Returns a 2D Eigen::Eigen::Map pointed at the specified image.
int readColumns(const std::string &fname, arrTs &... arrays)
Read in columns from a text file.
Eigen::Array< scalarT, -1, -1 > eigenImage
Definition of the eigenImage type, which is an alias for Eigen::Array.
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,...
std::string pathFilename(const std::string &fname)
Get the base filename.
realT dtor(realT q)
Convert from degrees to radians.
fakeMethods
Fake injection PSF file specification methods.
@ single
A single PSF is used.
@ list
A list of PSF files, one per input image, is used.
int padImage(imOutT &imOut, imInT &imIn, unsigned int padSz, typename imOutT::Scalar value)
Pad an image with a constant value.
int cutPaddedImage(imOutT &imOut, const imInT &imIn, unsigned int padSz)
Cut down a padded image.
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.
void rotateMask(imageT &rotMask, imageT &mask, typename imageT::Scalar angle)
Rotate a binary mask.
int fakeMethodFmStr(const std::string &method)
Get the fake injection method from its string name.
std::string fakeMethodsStr(int method)
Get the string name of a fake injection method.
Process an angular differential imaging (ADI) observation.
int readRDIFiles()
Read in the RDI files.
virtual int postRDIReadFiles()
Post reference read actions, including fake injection.
int injectFake(eigenCube< realT > &ims, std::vector< std::string > &fileList, derotFunctObj &derotF, realT RDIfluxScale, realT RDISepScale)
Inect the fake plants.
std::vector< realT > m_fakeSep
Separation(s) of the fake planet(s)
realT m_RDIFluxScale
Flux scaling to apply to fake planets injected in RDI. Would depend on the assumed spectrum in SDI.
virtual int postReadFiles()
Post target read actions, including fake injection.
virtual void makeMaskCube()
Populate the mask cube which is used for post-processing. Derived classes can do this as appropriate,...
int readFiles()
Read in the target files.
std::vector< realT > m_fakePA
Position angles(s) of the fake planet(s)
std::vector< realT > m_fakeContrast
Contrast(s) of the fake planet(s)
virtual int postRDICoadd()
Post reference coadd actions.
void derotate()
De-rotate the PSF subtracted images.
std::string m_fakeScaleFileName
One-column text file containing a scale factor for each point in time.
realT m_RDISepScale
Scaling to apply to fake planet separation in RDI. Would be ratio of wavelengths for SDI.
std::string m_fakeFileName
FITS file containing the fake planet PSF to inject or a list of fake images.
int m_fakeMethod
Method for reading fake files, either HCI::single or HCI::list.
virtual int postCoadd()
Post target coadd actions.
int readPSFSub(const std::string &dir, const std::string &prefix, const std::string &ext, size_t nReductions)
Read in already PSF-subtracted files.
The basic high contrast imaging data type.