Skip to content

Commit 13e7188

Browse files
committed
repr -> serialize for pickoling SBProfile and subclasses.
(#723-better-repr)
1 parent cacd32e commit 13e7188

33 files changed

+398
-397
lines changed

galsim/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ def __hash__(self): return hash(repr(self))
14751475
# convenient way to get the SBProfile to be the correct type in this case.
14761476
# So, getstate just returns the repr string. And setstate builds the right kind of object
14771477
# by essentially doing `self = eval(repr)`.
1478-
_galsim.SBProfile.__getstate__ = lambda self: self.__repr__()
1478+
_galsim.SBProfile.__getstate__ = lambda self: self.serialize()
14791479
def SBProfile_setstate(self, state):
14801480
import galsim
14811481
# In case the repr uses these:

include/galsim/SBAddImpl.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ namespace galsim {
4141
double maxK() const { return _maxMaxK; }
4242
double stepK() const { return _minStepK; }
4343

44-
void getXRange(double& xmin, double& xmax, std::vector<double>& splits) const
45-
{
46-
xmin = integ::MOCK_INF; xmax = -integ::MOCK_INF;
44+
void getXRange(double& xmin, double& xmax, std::vector<double>& splits) const
45+
{
46+
xmin = integ::MOCK_INF; xmax = -integ::MOCK_INF;
4747
for (ConstIter pptr = _plist.begin(); pptr!=_plist.end(); ++pptr) {
4848
double xmin_1, xmax_1;
4949
pptr->getXRange(xmin_1,xmax_1,splits);
@@ -52,9 +52,9 @@ namespace galsim {
5252
}
5353
}
5454

55-
void getYRange(double& ymin, double& ymax, std::vector<double>& splits) const
55+
void getYRange(double& ymin, double& ymax, std::vector<double>& splits) const
5656
{
57-
ymin = integ::MOCK_INF; ymax = -integ::MOCK_INF;
57+
ymin = integ::MOCK_INF; ymax = -integ::MOCK_INF;
5858
for (ConstIter pptr = _plist.begin(); pptr!=_plist.end(); ++pptr) {
5959
double ymin_1, ymax_1;
6060
pptr->getYRange(ymin_1,ymax_1,splits);
@@ -63,9 +63,9 @@ namespace galsim {
6363
}
6464
}
6565

66-
void getYRangeX(double x, double& ymin, double& ymax, std::vector<double>& splits) const
66+
void getYRangeX(double x, double& ymin, double& ymax, std::vector<double>& splits) const
6767
{
68-
ymin = integ::MOCK_INF; ymax = -integ::MOCK_INF;
68+
ymin = integ::MOCK_INF; ymax = -integ::MOCK_INF;
6969
for (ConstIter pptr = _plist.begin(); pptr!=_plist.end(); ++pptr) {
7070
double ymin_1, ymax_1;
7171
pptr->getYRangeX(x,ymin_1,ymax_1,splits);
@@ -79,7 +79,7 @@ namespace galsim {
7979
bool isAnalyticX() const { return _allAnalyticX; }
8080
bool isAnalyticK() const { return _allAnalyticK; }
8181

82-
Position<double> centroid() const
82+
Position<double> centroid() const
8383
{ return Position<double>(_sumfx / _sumflux, _sumfy / _sumflux); }
8484

8585
double getFlux() const { return _sumflux; }
@@ -134,12 +134,12 @@ namespace galsim {
134134
typedef std::list<SBProfile>::iterator Iter;
135135
typedef std::list<SBProfile>::const_iterator ConstIter;
136136

137-
std::string repr() const;
137+
std::string serialize() const;
138138

139139
private:
140140

141141
/// @brief The plist content is a pointer to a fresh copy of the summands.
142-
std::list<SBProfile> _plist;
142+
std::list<SBProfile> _plist;
143143
double _sumflux; ///< Keeps track of the cumulated flux of all summands.
144144
double _sumfx; ///< Keeps track of the cumulated `fx` of all summands.
145145
double _sumfy; ///< Keeps track of the cumulated `fy` of all summands.
@@ -156,11 +156,11 @@ namespace galsim {
156156
/// @brief Keeps track of whether any summands have hard edges.
157157
bool _anyHardEdges;
158158

159-
/// @brief Keeps track of the cumulated `isAnalyticX()` property of all summands.
160-
bool _allAnalyticX;
159+
/// @brief Keeps track of the cumulated `isAnalyticX()` property of all summands.
160+
bool _allAnalyticX;
161161

162162
/// @brief Keeps track of the cumulated `isAnalyticK()` properties of all summands.
163-
bool _allAnalyticK;
163+
bool _allAnalyticK;
164164

165165
void initialize(); ///< Sets all private book-keeping variables to starting state.
166166

@@ -172,4 +172,3 @@ namespace galsim {
172172
}
173173

174174
#endif
175-

include/galsim/SBAiryImpl.h

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ namespace galsim {
2929
/**
3030
* @brief A private class that caches the photon shooting objects for a given
3131
* obscuration value, so they don't have to be set up again each time.
32-
*
32+
*
3333
* This is helpful if people use only 1 or a small number of obscuration values.
3434
*/
3535
class AiryInfo
3636
{
3737
public:
38-
/**
38+
/**
3939
* @brief Constructor
4040
*/
4141
AiryInfo() {}
4242

4343
/// @brief Destructor: deletes photon-shooting classes if necessary
4444
virtual ~AiryInfo() {}
4545

46-
/**
46+
/**
4747
* @brief Returns the real space value of the Airy function,
4848
* normalized to unit flux (see private attributes).
4949
* @param[in] r should be given in units of lam_over_D (i.e. r_true*D)
@@ -55,7 +55,7 @@ namespace galsim {
5555

5656
/**
5757
* @brief Returns the k-space value of the Airy function.
58-
* @param[in] ksq_over_pisq should be given in units of lam_over_D
58+
* @param[in] ksq_over_pisq should be given in units of lam_over_D
5959
* (i.e. k_true^2 / (pi^2 * D^2))
6060
*
6161
* This is used to calculate the real kValue, but it comes back unnormalized.
@@ -78,12 +78,12 @@ namespace galsim {
7878
boost::shared_ptr<PhotonArray> shoot(int N, UniformDeviate ud) const;
7979

8080
protected:
81-
double _stepk; ///< Sampling in k space necessary to avoid folding
81+
double _stepk; ///< Sampling in k space necessary to avoid folding
8282

8383
virtual void checkSampler() const = 0;
8484

8585
///< Class that can sample radial distribution
86-
mutable boost::shared_ptr<OneDimensionalDeviate> _sampler;
86+
mutable boost::shared_ptr<OneDimensionalDeviate> _sampler;
8787

8888
private:
8989
AiryInfo(const AiryInfo& rhs); ///< Hides the copy constructor.
@@ -95,7 +95,7 @@ namespace galsim {
9595
class AiryInfoObs : public AiryInfo
9696
{
9797
public:
98-
AiryInfoObs(double obscuration, const GSParamsPtr& _gsparams);
98+
AiryInfoObs(double obscuration, const GSParamsPtr& _gsparams);
9999
~AiryInfoObs() {}
100100

101101
double xValue(double r) const;
@@ -110,15 +110,15 @@ namespace galsim {
110110
* Input radius is in units of lambda/D. Output normalized
111111
* to integrate to unity over input units.
112112
*/
113-
class RadialFunction : public FluxDensity
113+
class RadialFunction : public FluxDensity
114114
{
115115
public:
116116
/**
117117
* @brief Constructor
118118
* @param[in] obscuration Fractional linear size of central obscuration of pupil.
119119
* @param[in] obssq Pre-computed obscuration^2 supplied as input for speed.
120120
*/
121-
RadialFunction(double obscuration, double obssq, const GSParamsPtr& gsparams) :
121+
RadialFunction(double obscuration, double obssq, const GSParamsPtr& gsparams) :
122122
_obscuration(obscuration), _obssq(obssq),
123123
_norm(M_PI / (1.-_obssq)), _gsparams(gsparams) {}
124124

@@ -143,16 +143,16 @@ namespace galsim {
143143
const GSParamsPtr _gsparams;
144144

145145
/// Circle chord length at `h < r`.
146-
double chord(double r, double h, double rsq, double hsq) const;
146+
double chord(double r, double h, double rsq, double hsq) const;
147147

148148
/// @brief Area inside intersection of 2 circles radii `r` & `s`, seperated by `t`.
149149
double circle_intersection(
150-
double r, double s, double rsq, double ssq, double tsq) const;
151-
double circle_intersection(double r, double rsq, double tsq) const;
150+
double r, double s, double rsq, double ssq, double tsq) const;
151+
double circle_intersection(double r, double rsq, double tsq) const;
152152

153153
/// @brief Area of two intersecting identical annuli.
154154
double annuli_intersect(
155-
double r1, double r2, double r1sq, double r2sq, double tsq) const;
155+
double r1, double r2, double r1sq, double r2sq, double tsq) const;
156156

157157
void checkSampler() const; ///< Check if `OneDimensionalDeviate` is configured.
158158
};
@@ -168,7 +168,7 @@ namespace galsim {
168168
double kValue(double ksq_over_pisq) const;
169169

170170
private:
171-
class RadialFunction : public FluxDensity
171+
class RadialFunction : public FluxDensity
172172
{
173173
public:
174174
RadialFunction(const GSParamsPtr& gsparams) : _gsparams(gsparams) {}
@@ -186,7 +186,7 @@ namespace galsim {
186186
void checkSampler() const; ///< Check if `OneDimensionalDeviate` is configured.
187187
};
188188

189-
class SBAiry::SBAiryImpl : public SBProfileImpl
189+
class SBAiry::SBAiryImpl : public SBProfileImpl
190190
{
191191
public:
192192
SBAiryImpl(double lam_over_D, double obs, double flux,
@@ -197,15 +197,15 @@ namespace galsim {
197197
double xValue(const Position<double>& p) const;
198198
std::complex<double> kValue(const Position<double>& k) const;
199199

200-
bool isAxisymmetric() const { return true; }
200+
bool isAxisymmetric() const { return true; }
201201
bool hasHardEdges() const { return false; }
202202
bool isAnalyticX() const { return true; }
203203
bool isAnalyticK() const { return true; }
204204

205205
double maxK() const;
206206
double stepK() const;
207207

208-
Position<double> centroid() const
208+
Position<double> centroid() const
209209
{ return Position<double>(0., 0.); }
210210

211211
double getFlux() const { return _flux; }
@@ -235,13 +235,13 @@ namespace galsim {
235235
double kx0, double dkx, double dkxy,
236236
double ky0, double dky, double dkyx) const;
237237

238-
std::string repr() const;
238+
std::string serialize() const;
239239

240240
private:
241-
241+
242242
double _lam_over_D; ///< inverse of _D (see below), harmonise inputs with other GSObjects
243-
/**
244-
* `_D` = (telescope diam) / (lambda * focal length) if arg is focal plane position,
243+
/**
244+
* `_D` = (telescope diam) / (lambda * focal length) if arg is focal plane position,
245245
* else `_D` = (telescope diam) / lambda if arg is in radians of field angle.
246246
*/
247247
double _D;
@@ -259,14 +259,13 @@ namespace galsim {
259259
SBAiryImpl(const SBAiryImpl& rhs);
260260
void operator=(const SBAiryImpl& rhs);
261261

262-
/// Info object that stores things that are common to all Airy functions with this
262+
/// Info object that stores things that are common to all Airy functions with this
263263
/// obscuration value.
264-
const boost::shared_ptr<AiryInfo> _info;
264+
const boost::shared_ptr<AiryInfo> _info;
265265

266266
/// One static map of all `AiryInfo` structures for whole program.
267267
static LRUCache< std::pair< double, GSParamsPtr >, AiryInfo > cache;
268268
};
269269
}
270270

271271
#endif
272-

include/galsim/SBBoxImpl.h

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
namespace galsim {
2727

28-
class SBBox::SBBoxImpl : public SBProfileImpl
28+
class SBBox::SBBoxImpl : public SBProfileImpl
2929
{
3030
public:
3131
SBBoxImpl(double width, double height, double flux, const GSParamsPtr& gsparams);
@@ -34,21 +34,21 @@ namespace galsim {
3434
double xValue(const Position<double>& p) const;
3535
std::complex<double> kValue(const Position<double>& k) const;
3636

37-
bool isAxisymmetric() const { return false; }
37+
bool isAxisymmetric() const { return false; }
3838
bool hasHardEdges() const { return true; }
3939
bool isAnalyticX() const { return true; }
4040
bool isAnalyticK() const { return true; }
4141

4242
double maxK() const;
4343
double stepK() const;
4444

45-
void getXRange(double& xmin, double& xmax, std::vector<double>& ) const
45+
void getXRange(double& xmin, double& xmax, std::vector<double>& ) const
4646
{ xmin = -_wo2; xmax = _wo2; }
4747

48-
void getYRange(double& ymin, double& ymax, std::vector<double>& ) const
48+
void getYRange(double& ymin, double& ymax, std::vector<double>& ) const
4949
{ ymin = -_ho2; ymax = _ho2; }
5050

51-
Position<double> centroid() const
51+
Position<double> centroid() const
5252
{ return Position<double>(0., 0.); }
5353

5454
double getFlux() const { return _flux; }
@@ -74,7 +74,7 @@ namespace galsim {
7474
double kx0, double dkx, double dkxy,
7575
double ky0, double dky, double dkyx) const;
7676

77-
std::string repr() const;
77+
std::string serialize() const;
7878

7979
private:
8080
double _width;
@@ -91,7 +91,7 @@ namespace galsim {
9191
void operator=(const SBBoxImpl& rhs);
9292
};
9393

94-
class SBTopHat::SBTopHatImpl : public SBProfileImpl
94+
class SBTopHat::SBTopHatImpl : public SBProfileImpl
9595
{
9696
public:
9797
SBTopHatImpl(double radius, double flux, const GSParamsPtr& gsparams);
@@ -100,28 +100,28 @@ namespace galsim {
100100
double xValue(const Position<double>& p) const;
101101
std::complex<double> kValue(const Position<double>& k) const;
102102

103-
bool isAxisymmetric() const { return true; }
103+
bool isAxisymmetric() const { return true; }
104104
bool hasHardEdges() const { return true; }
105105
bool isAnalyticX() const { return true; }
106106
bool isAnalyticK() const { return true; }
107107

108108
double maxK() const;
109109
double stepK() const;
110110

111-
void getXRange(double& xmin, double& xmax, std::vector<double>& ) const
111+
void getXRange(double& xmin, double& xmax, std::vector<double>& ) const
112112
{ xmin = -_r0; xmax = _r0; }
113113

114-
void getYRange(double& ymin, double& ymax, std::vector<double>& ) const
114+
void getYRange(double& ymin, double& ymax, std::vector<double>& ) const
115115
{ ymin = -_r0; ymax = _r0; }
116116

117117
void getYRangeX(
118118
double x, double& ymin, double& ymax, std::vector<double>& ) const
119-
{
119+
{
120120
ymax = sqrt(_r0*_r0 - x*x);
121121
ymin = -ymax;
122122
}
123123

124-
Position<double> centroid() const
124+
Position<double> centroid() const
125125
{ return Position<double>(0., 0.); }
126126

127127
double getFlux() const { return _flux; }
@@ -146,7 +146,7 @@ namespace galsim {
146146
double kx0, double dkx, double dkxy,
147147
double ky0, double dky, double dkyx) const;
148148

149-
std::string repr() const;
149+
std::string serialize() const;
150150

151151
private:
152152
double _r0;
@@ -164,5 +164,4 @@ namespace galsim {
164164

165165
}
166166

167-
#endif
168-
167+
#endif

0 commit comments

Comments
 (0)