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
ShapeletInterpolation.cc
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
29 
30 namespace lsst {
31 namespace meas {
32 namespace algorithms {
33 
36  {
37  public :
41 
43  std::vector<ShapeletPsfCandidate*>& cand,
44  std::vector<Position>& pos,
45  std::vector<BVec>& psf,
46  std::vector<double>& nu,
47  std::vector<long>& flags
48  ) :
49  _cand(cand), _pos(pos), _psf(psf), _nu(nu), _flags(flags)
50  {}
51 
52  void reset() { }
53 
55  {
56  ShapeletPsfCandidate* psfCand =
57  dynamic_cast<ShapeletPsfCandidate*>(cand);
58  Assert(psfCand);
59  _cand.push_back(psfCand);
60  _pos.push_back(Position(psfCand->getX(),psfCand->getY()));
61  _psf.push_back(psfCand->getShapelet()->viewAsBVec());
62  // We already calculated nu for the rating...
63  _nu.push_back(psfCand->getCandidateRating());
64  _flags.push_back(long(0));
65  }
66 
67  std::vector<ShapeletPsfCandidate*>& _cand;
68  std::vector<Position>& _pos;
69  std::vector<BVec>& _psf;
70  std::vector<double>& _nu;
71  std::vector<long>& _flags;
72  };
73 
74  // All of the functionality is imported from shapelet::BVec
75  // Just repeat the constructors, destructors, and op=
77  {
78  public :
79  typedef float PixelT;
84 
86 
88  {
89  shapelet::ConfigFile params;
90  params["psf_order"] = policy.getInt("shapeletOrder");
91  params["fitpsf_order"] = policy.getInt("interpOrder");
92  params["fitpsf_nsigma_outlier"] = policy.getDouble("interpNSigmaClip");
93  params["fitpsf_pca_thresh"] = policy.getDouble("pcaThresh");
94  _fit.reset(new FittedPsf(params));
95  _nStarsPerCell = policy.getInt("nStarsPerCell");
96  }
97 
98  int getOrder() const { return _fit->getPsfOrder(); }
99 
100  int getFitOrder() const { return _fit->getFitOrder(); }
101 
102  double getSigma() const { return _fit->getSigma(); }
103 
104  int getSize() const { return (getOrder()+1)*(getOrder()+2)/2; }
105 
106  int getFitSize() const { return (getFitOrder()+1)*(getFitOrder()+2)/2; }
107 
108  void setSigma(double sigma) { _fit->setSigma(sigma); }
109 
110  void calculate(
111  SpatialCellSet::Ptr cellSet,
112  const Exposure& exposure)
113  {
114  using shapelet::Position;
115  using shapelet::BVec;
116 
117  std::vector<ShapeletPsfCandidate*> cand;
118  std::vector<Position> pos;
119  std::vector<BVec> psf;
120  std::vector<double> nu;
121  std::vector<long> flags;
122 
123  LoadCandidatesVisitor visitor(cand, pos, psf, nu, flags);
124  cellSet->visitCandidates(&visitor, _nStarsPerCell);
125 
126  // TODO: Currently, the rounds of outlier rejection are done
127  // within FittedPSF, which means that we don't have the opportunity
128  // to select other candidates that might be ok in that
129  // cell. I should pull out some of that functionality, so I
130  // can utilize the SpatialCells better.
131  _fit->calculate(pos, psf, nu, flags);
132 
133  // Mark the flagged candidates as BAD.
134  const int nCand = cand.size();
135  for(int i=0; i<nCand; ++i) if (flags[i]) cand[i]->setBad();
136  }
137 
139  {
141  shapelet::Position pos(x,y);
142  _fit->interpolate(pos,b);
143  return Shapelet::ConstPtr(new Shapelet(b));
144  }
145 
146  double interpolateSingleElement(double x, double y, int i)
147  {
148  shapelet::Position pos(x,y);
149  return _fit->interpolateSingleElement(pos,i);
150  }
151 
152  private :
153  boost::shared_ptr<FittedPsf> _fit;
155  };
156 
158  pImpl(new ShapeletInterpolationImpl(policy))
159  {}
160 
162  { delete pImpl; pImpl=0; }
163 
165  pImpl(new ShapeletInterpolationImpl(*rhs.pImpl))
166  {}
167 
169  {
170  if (this != &rhs) {
171  delete pImpl;
173  }
174  return *this;
175  }
176 
178  { return pImpl->getOrder(); }
179 
181  { return pImpl->getFitOrder(); }
182 
184  { return pImpl->getSigma(); }
185 
187  { return pImpl->getSize(); }
188 
190  { return pImpl->getFitSize(); }
191 
193  { pImpl->setSigma(sigma); }
194 
196  SpatialCellSet::Ptr cellSet,
197  const Exposure& exposure)
198  { pImpl->calculate(cellSet, exposure); }
199 
201  { return interpolate(pos.getX(),pos.getY()); }
203  { return pImpl->interpolate(x, y); }
204 
206  const PointD& pos, int i) const
207  { return interpolateSingleElement(pos.getX(),pos.getY(),i); }
209  double x, double y, int i) const
210  { return pImpl->interpolateSingleElement(x, y, i); }
211 
212 }}}
213 
int y
void calculate(SpatialCellSet::Ptr cellSet, const Exposure &exposure)
int getFitOrder() const
get the order of the fit
int getInt(const std::string &name) const
Definition: Policy.h:603
void setSigma(double sigma)
set a new value of sigma
lsst::afw::math::SpatialCellCandidate SpatialCellCandidate
int getFitSize() const
the number of fit coefficients
A class to contain the data, WCS, and other information needed to describe an image of the sky...
Definition: Exposure.h:48
a container for holding hierarchical configuration data in memory.
Definition: Policy.h:169
void processCandidate(SpatialCellCandidate *cand)
double interpolateSingleElement(double x, double y, int i)
Shapelet::ConstPtr interpolate(const PointD &pos) const
Perform the interpolation.
boost::shared_ptr< const Shapelet > ConstPtr
Definition: Shapelet.h:95
ShapeletInterpolation & operator=(const ShapeletInterpolation &rhs)
op= does a shallow copy
afw::table::Key< double > sigma
Definition: GaussianPsf.cc:43
A module for determining which objects are good PSF stars.
A collection of SpatialCells covering an entire image.
Definition: SpatialCell.h:378
Defines the ShapeletInterpolation class.
Shapelet::ConstPtr getShapelet() const
Get the shapelet decomposition.
void calculate(SpatialCellSet::Ptr cellSet, const Exposure &exposure)
Calculate the interpolation parameters from a SpatialCellSet.
double interpolateSingleElement(const PointD &pos, int i) const
Perform the interpolation for only one shapelet coefficient.
double x
LoadCandidatesVisitor(std::vector< ShapeletPsfCandidate * > &cand, std::vector< Position > &pos, std::vector< BVec > &psf, std::vector< double > &nu, std::vector< long > &flags)
ShapeletInterpolation(const Policy &policy)
Basic constructor just loads parameters from a policy file.
std::vector< ShapeletPsfCandidate * > & _cand
double getDouble(const std::string &name) const
Definition: Policy.h:617
double getCandidateRating() const
Define &quot;goodness&quot; of candidate for SpatialCell.
double getSigma() const
get the scale size of the shapelet
int getOrder() const
get the order of the shapelet
afw::table::Key< double > b
Shapelet::ConstPtr interpolate(double x, double y)
boost::shared_ptr< SpatialCellSet > Ptr
Definition: SpatialCell.h:380
~ShapeletInterpolation()
Destructor needs to delete pImpl.
int getSize() const
the size of the shapelet vector
#define Assert(x)
Definition: dbg.h:73