LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Namespaces | Typedefs | Functions | Variables
lsst.afw.display Namespace Reference

Namespaces

 ds9
 
 ds9Regions
 
 interface
 
 rgb
 
 utils
 
 virtualDevice
 

Typedefs

typedef
detection::FootprintSet::FootprintList 
FootprintList
 

Functions

 if (width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
 
SetPixels< typename
ImageT::Image > setR * 
rim ()), setG(*gim.getImage()), setB(*bim.getImage()
 
sat merge (detection::FootprintSet(*gim.getMask(), satThresh, npixMin))
 
 for (FootprintList::const_iterator ptr=feet->begin(), end=feet->end();ptr!=end;++ptr)
 
template void replaceSaturatedPixels (image::MaskedImage< float > &rim, image::MaskedImage< float > &gim, image::MaskedImage< float > &bim, int borderWidth, float saturatedPixelValue)
 
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)
 

Variables

template<typename ImageT >
void ImageT & gim
 
template<typename ImageT >
void ImageT ImageT & bim
 
template<typename ImageT >
void ImageT ImageT int borderWidth = 2
 
template<typename ImageT >
void ImageT ImageT int float saturatedPixelValue
 
template<typename ImageT >
void ImageT ImageT int float
saturatedPixelValue int const 
width = rim.getWidth()
 
template<typename ImageT >
void ImageT ImageT int float
saturatedPixelValue int const 
height = rim.getHeight()
 
int const x0 = rim.getX0()
 
int const y0 = rim.getY0()
 
bool const useMaxPixel = !utils::isfinite(saturatedPixelValue)
 
int const npixMin = 1
 
afw::image::MaskPixel const SAT = rim.getMask()->getPlaneBitMask("SAT")
 
detection::Threshold const satThresh (SAT, detection::Threshold::BITMASK)
 
boost::shared_ptr< FootprintListfeet = sat.getFootprints()
 

Typedef Documentation

Examples:
spatialCellExample.cc.

Definition at line 80 of file saturated.cc.

Function Documentation

lsst::afw::display::for ( FootprintList::const_iterator  ptr = feet->begin(),
end  = feet->end(); ptr != end; ++ptr 
)
Examples:
spatialCellExample.cc.

Definition at line 82 of file saturated.cc.

82  {
83  PTR(detection::Footprint) const foot = *ptr;
84  PTR(detection::Footprint) const bigFoot = growFootprint(*foot, borderWidth);
85 
86  double sumR = 0, sumG = 0, sumB = 0; // sum of all non-saturated adjoining pixels
87  double maxR = 0, maxG = 0, maxB = 0; // maximum of non-saturated adjoining pixels
88 
89  for (detection::Footprint::SpanList::const_iterator sptr = bigFoot->getSpans().begin(),
90  send = bigFoot->getSpans().end(); sptr != send; ++sptr) {
91  PTR(detection::Span) const span = *sptr;
92 
93  int const y = span->getY() - y0;
94  if (y < 0 || y >= height) {
95  continue;
96  }
97  int sx0 = span->getX0() - x0;
98  if (sx0 < 0) {
99  sx0 = 0;
100  }
101  int sx1 = span->getX1() - x0;
102  if (sx1 >= width) {
103  sx1 = width - 1;
104  }
105 
106  for (typename ImageT::iterator
107  rptr = rim.at(sx0, y),
108  rend = rim.at(sx1 + 1, y),
109  gptr = gim.at(sx0, y),
110  bptr = bim.at(sx0, y); rptr != rend; ++rptr, ++gptr, ++bptr) {
111  if (!((rptr.mask() | gptr.mask() | bptr.mask()) & SAT)) {
112  float val = rptr.image();
113  sumR += val;
114  if (val > maxR) {
115  maxR = val;
116  }
117 
118  val = gptr.image();
119  sumG += val;
120  if (val > maxG) {
121  maxG = val;
122  }
123 
124  val = bptr.image();
125  sumB += val;
126  if (val > maxB) {
127  maxB = val;
128  }
129  }
130  }
131  }
132  // OK, we have the mean fluxes for the pixels surrounding this set of saturated pixels
133  // so we can figure out the proper values to use for the saturated ones
134  float R = 0, G = 0, B = 0; // mean intensities
135  if (sumR + sumB + sumG > 0) {
136  if (sumR > sumG) {
137  if (sumR > sumB) {
138  R = useMaxPixel ? maxR : saturatedPixelValue;
139 
140  G = (R*sumG)/sumR;
141  B = (R*sumB)/sumR;
142  } else {
143  B = useMaxPixel ? maxB : saturatedPixelValue;
144  R = (B*sumR)/sumB;
145  G = (B*sumG)/sumB;
146  }
147  } else {
148  if (sumG > sumB) {
149  G = useMaxPixel ? maxG : saturatedPixelValue;
150  R = (G*sumR)/sumG;
151  B = (G*sumB)/sumG;
152  } else {
153  B = useMaxPixel ? maxB : saturatedPixelValue;
154  R = (B*sumR)/sumB;
155  G = (B*sumG)/sumB;
156  }
157  }
158  }
159  // Now that we know R, G, and B we can fix the values
160  setR.setValue(R); setR.apply(*foot);
161  setG.setValue(G); setG.apply(*foot);
162  setB.setValue(B); setB.apply(*foot);
163  }
int y
for(FootprintList::const_iterator ptr=feet->begin(), end=feet->end();ptr!=end;++ptr)
Definition: saturated.cc:82
#define PTR(...)
Definition: base.h:41
int const x0
Definition: saturated.cc:45
bool val
boost::shared_ptr< Footprint > growFootprint(Footprint const &foot, int nGrow, bool isotropic=true)
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
afw::image::MaskPixel const SAT
Definition: saturated.cc:73
if(width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
Definition: saturated.cc:47
A set of pixels in an Image.
Definition: Footprint.h:62
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
void ImageT & gim
Definition: Rgb.h:9
void ImageT ImageT int float saturatedPixelValue
Definition: Rgb.h:12
lsst::afw::detection::Footprint Footprint
Definition: Source.h:61
void ImageT ImageT & bim
Definition: Rgb.h:9
bool const useMaxPixel
Definition: saturated.cc:64
int const y0
Definition: saturated.cc:45
SetPixels< typename ImageT::Image > setR * rim()), setG(*gim.getImage()), setB(*bim.getImage()
void ImageT ImageT int borderWidth
Definition: Rgb.h:11
lsst::afw::display::if ( width!  = gim.getWidth() || height != gim.getHeight() || x0 != gim.getX0() || y0 != gim.getY0())

Definition at line 47 of file saturated.cc.

47  {
48  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
49  str(boost::format("R image has different size/origin from G image "
50  "(%dx%d+%d+%d v. %dx%d+%d+%d") %
51  width % height % x0 % y0 %
52  gim.getWidth() % gim.getHeight() % gim.getX0() % gim.getY0()));
53 
54  }
int const x0
Definition: saturated.cc:45
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
void ImageT & gim
Definition: Rgb.h:9
int const y0
Definition: saturated.cc:45
sat lsst::afw::display::merge ( detection::FootprintSet(*.  getMask,
satThresh  ,
npixMin   
)
template void lsst::afw::display::replaceSaturatedPixels ( image::MaskedImage< float > &  rim,
image::MaskedImage< float > &  gim,
image::MaskedImage< float > &  bim,
int  borderWidth,
float  saturatedPixelValue 
)
detection::FootprintSet sat * lsst::afw::display::rim ( )
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:552
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

Variable Documentation

template<typename ImageT >
void ImageT ImageT & lsst::afw::display::bim

Definition at line 9 of file Rgb.h.

template<typename ImageT >
void ImageT ImageT int lsst::afw::display::borderWidth = 2

Definition at line 11 of file Rgb.h.

boost::shared_ptr< FootprintList > lsst::afw::display.feet = sat.getFootprints()
Examples:
footprintFunctor.cc.

Definition at line 81 of file saturated.cc.

template<typename ImageT >
void ImageT & lsst::afw::display::gim

Definition at line 9 of file Rgb.h.

template<typename ImageT >
void ImageT ImageT int float saturatedPixelValue int const lsst::afw::display.height = rim.getHeight()

Definition at line 44 of file saturated.cc.

int const lsst::afw::display.npixMin = 1
Examples:
spatialCellExample.cc.

Definition at line 72 of file saturated.cc.

afw::image::MaskPixel const lsst::afw::display.SAT = rim.getMask()->getPlaneBitMask("SAT")

Definition at line 73 of file saturated.cc.

detection::Threshold const lsst::afw::display.satThresh(SAT, detection::Threshold::BITMASK)
template<typename ImageT >
void ImageT ImageT int float lsst::afw::display.saturatedPixelValue
Initial value:
= 65535
)

Definition at line 12 of file Rgb.h.

bool const lsst::afw::display.useMaxPixel = !utils::isfinite(saturatedPixelValue)

Definition at line 64 of file saturated.cc.

template<typename ImageT >
void ImageT ImageT int float saturatedPixelValue int const lsst::afw::display.width = rim.getWidth()

Definition at line 44 of file saturated.cc.

int const lsst::afw::display.x0 = rim.getX0()
Examples:
imageStatistics.cc.

Definition at line 45 of file saturated.cc.

int const lsst::afw::display.y0 = rim.getY0()

Definition at line 45 of file saturated.cc.