LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
LSSTDataManagementBasePackage
Namespaces | Functions
lsst.afw.display Namespace Reference

Namespaces

 ds9
 
 utils
 

Functions

template<typename ImageT >
void writeBasicFits (int fd, ImageT const &data, image::Wcs const *Wcs, char const *title)
 
template<typename ImageT >
void writeBasicFits (std::string const &filename, ImageT const &data, image::Wcs const *Wcs, char const *title)
 

Function Documentation

template<typename ImageT >
void lsst::afw::display::writeBasicFits ( int  fd,
ImageT const &  data,
image::Wcs const *  Wcs,
char const *  title 
)

Definition at line 361 of file simpleFits.cc.

365  {
366  /*
367  * Allocate cards for FITS headers
368  */
369  std::list<Card> cards;
370  /*
371  * What sort if image is it?
372  */
373  int bitpix = lsst::afw::fits::getBitPix<typename ImageT::Pixel>();
374  if (bitpix == 20) { // cfitsio for "Unsigned short"
375  cards.push_back(Card("BZERO", 32768.0, ""));
376  cards.push_back(Card("BSCALE", 1.0, ""));
377  bitpix = 16;
378  } else if (bitpix == 0) {
379  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unsupported image type");
380  }
381  /*
382  * Generate WcsA, pixel coordinates, allowing for X0 and Y0
383  */
384  std::string wcsName = "A";
385  cards.push_back(Card(str(boost::format("CRVAL1%s") % wcsName),
386  data.getX0(), "(output) Column pixel of Reference Pixel"));
387  cards.push_back(Card(str(boost::format("CRVAL2%s") % wcsName),
388  data.getY0(), "(output) Row pixel of Reference Pixel"));
389  cards.push_back(Card(str(boost::format("CRPIX1%s") % wcsName), 1.0,
390  "Column Pixel Coordinate of Reference"));
391  cards.push_back(Card(str(boost::format("CRPIX2%s") % wcsName), 1.0, "Row Pixel Coordinate of Reference"));
392  cards.push_back(Card(str(boost::format("CTYPE1%s") % wcsName), "LINEAR", "Type of projection"));
393  cards.push_back(Card(str(boost::format("CTYPE1%s") % wcsName), "LINEAR", "Type of projection"));
394  cards.push_back(Card(str(boost::format("CUNIT1%s") % wcsName), "PIXEL", "Column unit"));
395  cards.push_back(Card(str(boost::format("CUNIT2%s") % wcsName), "PIXEL", "Row unit"));
396  /*
397  * Now WcsB, so that pixel (0,0) is correctly labelled (but ignoring XY0)
398  */
399  wcsName = "B";
400  cards.push_back(Card(str(boost::format("CRVAL1%s") % wcsName), 0,
401  "(output) Column pixel of Reference Pixel"));
402  cards.push_back(Card(str(boost::format("CRVAL2%s") % wcsName), 0,
403  "(output) Row pixel of Reference Pixel"));
404  cards.push_back(Card(str(boost::format("CRPIX1%s") % wcsName), 1.0,
405  "Column Pixel Coordinate of Reference"));
406  cards.push_back(Card(str(boost::format("CRPIX2%s") % wcsName), 1.0, "Row Pixel Coordinate of Reference"));
407  cards.push_back(Card(str(boost::format("CTYPE1%s") % wcsName), "LINEAR", "Type of projection"));
408  cards.push_back(Card(str(boost::format("CTYPE1%s") % wcsName), "LINEAR", "Type of projection"));
409  cards.push_back(Card(str(boost::format("CUNIT1%s") % wcsName), "PIXEL", "Column unit"));
410  cards.push_back(Card(str(boost::format("CUNIT2%s") % wcsName), "PIXEL", "Row unit"));
411 
412  if (title) {
413  cards.push_back(Card("OBJECT", title, "Image being displayed"));
414  }
415  /*
416  * Was there something else?
417  */
418  if (Wcs != NULL) {
419  typedef std::vector<std::string> NameList;
420 
421  image::Wcs::Ptr newWcs = Wcs->clone(); //Create a copy
422  newWcs->shiftReferencePixel(-data.getX0(), -data.getY0());
423 
424  lsst::daf::base::PropertySet::Ptr metadata = newWcs->getFitsMetadata();
425 
426  NameList paramNames = metadata->paramNames();
427 
428  for (NameList::const_iterator i = paramNames.begin(), end = paramNames.end(); i != end; ++i) {
429  if (*i == "SIMPLE" ||
430  *i == "BITPIX" ||
431  *i == "NAXIS" ||
432  *i == "NAXIS1" ||
433  *i == "NAXIS2" ||
434  *i == "XTENSION" ||
435  *i == "PCOUNT" ||
436  *i == "GCOUNT"
437  ) {
438  continue;
439  }
440  std::type_info const &type = metadata->typeOf(*i);
441  if (type == typeid(bool)) {
442  cards.push_back(Card(*i, metadata->get<bool>(*i)));
443  } else if (type == typeid(int)) {
444  cards.push_back(Card(*i, metadata->get<int>(*i)));
445  } else if (type == typeid(float)) {
446  cards.push_back(Card(*i, metadata->get<float>(*i)));
447  } else if (type == typeid(double)) {
448  cards.push_back(Card(*i, metadata->get<double>(*i)));
449  } else {
450  cards.push_back(Card(*i, metadata->get<std::string>(*i)));
451  }
452  }
453  }
454  /*
455  * Basic FITS stuff
456  */
457  const int naxis = 2; // == NAXIS
458  int naxes[naxis]; /* values of NAXIS1 etc */
459  naxes[0] = data.getWidth();
460  naxes[1] = data.getHeight();
461 
462  write_fits_hdr(fd, bitpix, naxis, naxes, cards, 1);
463  for (int y = 0; y != data.getHeight(); ++y) {
464  if (write_fits_data(fd, bitpix, (char *)(data.row_begin(y)), (char *)(data.row_end(y))) < 0){
465  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
466  (boost::format("Error writing data for row %d") % y).str());
467  }
468  }
469 
470  pad_to_fits_record(fd, data.getWidth()*data.getHeight(), bitpix);
471 }
int y
boost::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:90
virtual Ptr clone(void) const
Definition: Wcs.cc:562
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
boost::shared_ptr< Wcs > Ptr
Definition: Wcs.h:113
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
template<typename ImageT >
void lsst::afw::display::writeBasicFits ( std::string const &  filename,
ImageT const &  data,
image::Wcs const *  Wcs,
char const *  title 
)

Definition at line 476 of file simpleFits.cc.

480  {
481  int fd;
482  if ((filename.c_str())[0] == '|') { // a command
483  const char *cmd = filename.c_str() + 1;
484  while (isspace(*cmd)) {
485  cmd++;
486  }
487 
488  fd = fileno(popen(cmd, "w"));
489  } else {
490  fd = creat(filename.c_str(), 777);
491  }
492 
493  if (fd < 0) {
494  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
495  (boost::format("Cannot open \"%s\"") % filename).str());
496  }
497 
498  try {
499  writeBasicFits(fd, data, Wcs, title);
501  (void)close(fd);
502  throw;
503  }
504 
505  (void)close(fd);
506 }
void writeBasicFits(int fd, ImageT const &data, image::Wcs const *Wcs, char const *title)
Definition: simpleFits.cc:361
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46