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
Ellipse.h
Go to the documentation of this file.
1 #ifndef MeasAlgoShapeletEllipse_H
2 #define MeasAlgoShapeletEllipse_H
3 
4 #include <complex>
5 #include <vector>
6 #include <ostream>
10 
11 namespace lsst {
12 namespace meas {
13 namespace algorithms {
14 namespace shapelet {
15 
16  class Ellipse
17  {
18 
19  public :
20 
21  Ellipse() :
22  _cen(0.), _gamma(0.), _mu(0.),
23  _isFixedCen(false), _isFixedGamma(false), _isFixedMu(false),
24  _shouldDoTimings(false) {}
25 
26  Ellipse(std::complex<double> cen, std::complex<double> gamma,
27  std::complex<double> mu) :
28  _cen(cen), _gamma(gamma), _mu(mu),
29  _isFixedCen(false), _isFixedGamma(false), _isFixedMu(false),
30  _shouldDoTimings(false) {}
31 
32  Ellipse(double vals[]) :
33  _cen(vals[0],vals[1]), _gamma(vals[2],vals[3]), _mu(vals[4]),
34  _isFixedCen(false), _isFixedGamma(false), _isFixedMu(false),
35  _shouldDoTimings(false) {}
36 
37  // Copy constructor and op= do not copy fixed-ness.
38  // They only copy the tranformation itself.
39  Ellipse(const Ellipse& e2) :
40  _cen(e2.getCen()), _gamma(e2.getGamma()),
41  _mu(e2.getMu(),e2.getTheta()),
42  _isFixedCen(false), _isFixedGamma(false), _isFixedMu(false),
43  _shouldDoTimings(false) {}
44 
46  {
47  _cen = e2.getCen();
48  _gamma = e2.getGamma();
49  _mu = std::complex<double>(e2.getMu(),e2.getTheta());
50  return *this;
51  }
52 
53  // Find the ellipse transformation in which the galaxy is observed
54  // to be "round", where round means:
55  // b10 = 0, so galaxy is centroided,
56  // iff _isFixedCen == false
57  // b11 = 0, so shapelet is using optimal sigma,
58  // iff _isFixedMu == false, and not deconvolving by psf.
59  // b20 = 0, so galaxy is round,
60  // iff _isFixedGamma == false
61  // The first one below is for the galaxy as observed, and the
62  // second is for the galaxy before being convolved by the psf.
63  bool measure(
64  const std::vector<PixelList>& pix,
65  int order, int order2, int maxm,
66  double sigma, long& flag, double thresh, DMatrix* cov=0);
67  bool measure(
68  const std::vector<PixelList>& pix,
69  const std::vector<BVec>& psf,
70  int order, int order2, int maxm,
71  double sigma, long& flag, double thresh, DMatrix* cov=0);
72 
73  // Given a measured shapelet vector, find the ellipse transformation
74  // in which this shapelet vector would be observed to be round.
75  bool findRoundFrame(
76  const BVec& b, bool psf, int galOrder2, double thresh,
77  long& flag, DMatrix* cov=0);
78 
79  // Do a really simple and fast measurement to get a good starting point.
80  // Only does centroid and size.
81  void crudeMeasure(const PixelList& pix, double sigma);
82  void crudeMeasure(const std::vector<PixelList>& pix, double sigma);
83 
84  // Even simpler starting point, just doing the centroid.
85  void peakCentroid(const PixelList& pix, double maxr);
86 
87  // Measure the shapelet decomposition in the frame described by
88  // the current Ellipse parameters.
89  // The order parameter is allowed to be less than the order of bret,
90  // in which case the rest of the vector is set to zeros.
91  // order2 is the order for the intermediate steps in the calculation.
92  // Again, the first is for the galaxy as observed (the "native" fit),
93  // and the second is for the galaxy before being convolved by the psf.
94  bool measureShapelet(
95  const std::vector<PixelList>& pix, BVec& bret,
96  int order, int order2, int maxm, DMatrix* bcov=0) const;
97  bool measureShapelet(
98  const std::vector<PixelList>& pix,
99  const std::vector<BVec>& psf, BVec& bret,
100  int order, int order2, int maxm, DMatrix* bcov=0) const;
101 
102  // An alternative measurement that uses the formula:
103  // <psi_pq | psi_st> = delta_ps delta_qt
104  // Since this formulat is only really accurate in the limit of an
105  // infinite field and infinitely small pixels, it is not really useful
106  // for real data. However, it is useful for testing purposes.
107  bool altMeasureShapelet(
108  const std::vector<PixelList>& pix,
109  const std::vector<BVec>& psf, BVec& bret, int order, int order2,
110  double pixScale, DMatrix* bcov=0) const;
111  bool altMeasureShapelet(
112  const std::vector<PixelList>& pix, BVec& bret, int order, int order2,
113  double pixScale, DMatrix* bcov=0) const;
114 
115  // Find the effective Ellipse transformation from combining the
116  // current transformation with a second one, either before or after.
117  void preShiftBy(const std::complex<double>& cen,
118  const std::complex<double>& gamma,
119  const std::complex<double>& mu);
120  void postShiftBy(const std::complex<double>& cen,
121  const std::complex<double>& gamma,
122  const std::complex<double>& mu);
123 
124  // Find the rotation-free transformation that distorts a
125  // circle to the same final shape as the current transformation does.
126  // In otherwords, we move the rotation part from the end of the
127  // transformation to the beginning, since a rotation of a circle
128  // is a null operation.
129  // After doing this method, getTheta() will return 0.
130  void removeRotation();
131 
132  std::complex<double> getCen() const { return _cen; }
133  std::complex<double> getGamma() const { return _gamma; }
134  double getMu() const { return real(_mu); }
135  double getTheta() const { return imag(_mu); }
136 
137  void setCen(const std::complex<double>& cen) { _cen = cen; }
138  void setGamma(const std::complex<double>& gamma) { _gamma = gamma; }
139  void setMu(double mu) { _mu = std::complex<double>(mu,getTheta()); }
140  void setTheta(double theta) { _mu = std::complex<double>(getMu(),theta); }
141 
142  void fixCen() { _isFixedCen = true; }
143  void fixGam() { _isFixedGamma = true; }
144  void fixMu() { _isFixedMu = true; }
145 
146  void unfixCen() { _isFixedCen = false; }
147  void unfixGam() { _isFixedGamma = false; }
148  void unfixMu() { _isFixedMu = false; }
149 
150  bool isFixedCen() const { return _isFixedCen; }
151  bool isFixedGamma() const { return _isFixedGamma; }
152  bool isFixedMu() const { return _isFixedMu; }
153 
154  void doTimings() { _shouldDoTimings = true; }
155 
156  void write(std::ostream& os) const
157  { os << _cen<<" "<<_gamma<<" "<<_mu; }
158 
159  private :
160 
161  bool doMeasure(
162  const std::vector<PixelList>& pix,
163  const std::vector<BVec>* psf, int order, int order2, int maxm,
164  double sigma, long& flag, double thresh, DMatrix* cov=0);
165 
166  bool doMeasureShapelet(
167  const std::vector<PixelList>& pix,
168  const std::vector<BVec>* psf, BVec& bret,
169  int order, int order2, int maxm, DMatrix* bcov=0) const;
170 
172  const std::vector<PixelList>& pix,
173  const std::vector<BVec>* psf, BVec& bret,
174  int order, int order2, double pixScale, DMatrix* bcov=0) const;
175 
176  std::complex<double> _cen;
177  std::complex<double> _gamma;
178  std::complex<double> _mu;
179 
181 
183 
184  };
185 
186  inline std::ostream& operator<<(std::ostream& os, const Ellipse& s)
187  { s.write(os); return os; }
188 
189  // The Miralda-Escude formula for adding two shears.
190  // We transform to distortion first, then use his formula, then
191  // transform back to shear.
192  std::complex<double> addShears(
193  const std::complex<double> g1, const std::complex<double> g2);
194 
195  // Find the net Ellipse parameters from doing (c1,g1,m1) first,
196  // then (c2,g2,m2).
197  // The final transformation is returned as (c3,g3,m3).
198  void CalculateShift(
199  std::complex<double> c1, std::complex<double> g1, std::complex<double> m1,
200  std::complex<double> c2, std::complex<double> g2, std::complex<double> m2,
201  std::complex<double>& c3, std::complex<double>& g3,
202  std::complex<double>& m3);
203 
204 }}}}
205 
206 #endif
bool doMeasure(const std::vector< PixelList > &pix, const std::vector< BVec > *psf, int order, int order2, int maxm, double sigma, long &flag, double thresh, DMatrix *cov=0)
Definition: Ellipse_meas.cc:39
bool doAltMeasureShapelet(const std::vector< PixelList > &pix, const std::vector< BVec > *psf, BVec &bret, int order, int order2, double pixScale, DMatrix *bcov=0) const
Definition: Ellipse.cc:445
Ellipse & operator=(const Ellipse &e2)
Definition: Ellipse.h:45
void postShiftBy(const std::complex< double > &cen, const std::complex< double > &gamma, const std::complex< double > &mu)
Definition: Ellipse.cc:135
bool findRoundFrame(const BVec &b, bool psf, int galOrder2, double thresh, long &flag, DMatrix *cov=0)
Definition: Ellipse_meas.cc:75
std::ostream & operator<<(std::ostream &os, const Position &pos)
Definition: Bounds.h:78
Ellipse(std::complex< double > cen, std::complex< double > gamma, std::complex< double > mu)
Definition: Ellipse.h:26
void crudeMeasure(const PixelList &pix, double sigma)
std::complex< double > addShears(const std::complex< double > g1, const std::complex< double > g2)
afw::table::Key< double > sigma
Definition: GaussianPsf.cc:43
void write(std::ostream &os) const
Definition: Ellipse.h:156
void peakCentroid(const PixelList &pix, double maxr)
void preShiftBy(const std::complex< double > &cen, const std::complex< double > &gamma, const std::complex< double > &mu)
Definition: Ellipse.cc:124
bool doMeasureShapelet(const std::vector< PixelList > &pix, const std::vector< BVec > *psf, BVec &bret, int order, int order2, int maxm, DMatrix *bcov=0) const
Definition: Ellipse.cc:186
std::complex< double > getGamma() const
Definition: Ellipse.h:133
bool altMeasureShapelet(const std::vector< PixelList > &pix, const std::vector< BVec > &psf, BVec &bret, int order, int order2, double pixScale, DMatrix *bcov=0) const
Definition: Ellipse.cc:619
void CalculateShift(std::complex< double > c1, std::complex< double > g1, std::complex< double > m1, std::complex< double > c2, std::complex< double > g2, std::complex< double > m2, std::complex< double > &c3, std::complex< double > &g3, std::complex< double > &m3)
Definition: Ellipse.cc:38
bool measureShapelet(const std::vector< PixelList > &pix, BVec &bret, int order, int order2, int maxm, DMatrix *bcov=0) const
Definition: Ellipse.cc:614
afw::table::Key< double > b
void setCen(const std::complex< double > &cen)
Definition: Ellipse.h:137
bool measure(const std::vector< PixelList > &pix, int order, int order2, int maxm, double sigma, long &flag, double thresh, DMatrix *cov=0)
Definition: Ellipse.cc:180
T real(const T &x)
Definition: Integrate.h:193
std::complex< double > getCen() const
Definition: Ellipse.h:132
void setGamma(const std::complex< double > &gamma)
Definition: Ellipse.h:138