25#ifndef LSST_GAUSS2D_ELLIPSE_H
26#define LSST_GAUSS2D_ELLIPSE_H
66 explicit Covariance(
double sigma_x_sq = 0,
double sigma_y_sq = 0,
double cov_xy = 0);
71 static void check(
double sigma_x_sq,
double sigma_y_sq,
double cov_xy);
99 void set(
double sigma_x_sq = 0,
double sigma_y_sq = 0,
double cov_xy = 0);
119 double _sigma_x_sq = 0;
120 double _sigma_y_sq = 0;
137 static void check(
double size_x,
double size_y,
double rho, std::string_view error_suffix =
"") {
138 if (!(size_x >= 0) || !(size_y >= 0) || !(rho >= -1 && rho <= 1)) {
141 +
"; sigma_x,y >= 0 and 1 >= rho >= -1 required."
146 static void check_size(
double size, std::string_view error_suffix =
"") {
153 static void check_rho(
double rho, std::string_view error_suffix =
"") {
154 if (!(rho >= -1 && rho <= 1)) {
189 virtual void set(
double sigma_x,
double sigma_y,
double rho);
195 virtual void set_h(
double hwhm_x,
double hwhm_y,
double rho);
211 virtual std::string repr(
bool name_keywords =
false, std::string_view namespace_separator
243 : _sigma_x(sigma_x == nullptr ?
std::make_shared<double>(0) :
std::move(sigma_x)),
244 _sigma_y(sigma_y == nullptr ?
std::make_shared<double>(0) :
std::move(sigma_y)),
245 _rho(rho == nullptr ?
std::make_shared<double>(0) :
std::move(rho)) {};
247 explicit EllipseValues(
double sigma_x = 0,
double sigma_y = 0,
double rho = 0)
248 : _sigma_x(
std::make_shared<double>(sigma_x)),
249 _sigma_y(
std::make_shared<double>(sigma_y)),
250 _rho(
std::make_shared<double>(rho)) {};
254 double get_rho()
const override;
257 void set(
double sigma_x,
double sigma_y,
double rho)
override;
258 void set_h(
double hwhm_x,
double hwhm_y,
double rho)
override;
261 void set_rho(
double rho)
override;
293 explicit Ellipse(
double sigma_x = 0,
double sigma_y = 0,
double rho = 0);
299 double get_rho()
const override;
315 void set_rho(
double rho)
override;
347 explicit EllipseMajor(
double r_major,
double axrat,
double angle,
bool degrees =
false);
352 static void check(
double r_major,
double axrat,
double angle) {
353 if (!(r_major >= 0) || !(axrat >= 0 && axrat <= 1)) {
356 +
"; r_major >= 0, 1 >= axrat >= 0 required.");
360 double get_area()
const {
return M_PI * _r_major * _r_major * _axrat; }
376 void set(
double r_major,
double axrat,
double angle);
391 double _r_major = 0.;
394 bool _degrees =
false;
table::Key< double > angle
A representation of a 2D Gaussian with x and y standard deviations and a covariance value.
bool operator!=(const Covariance &other) const
std::shared_ptr< Covariance > make_convolution(const Covariance &cov) const
Return the convolution of this with another covariance.
double get_cov_xy() const
Get the covariance.
double get_sigma_x_sq() const
Get the square of sigma_x.
std::string repr(bool name_keywords=false, std::string_view namespace_separator=Object::CC_NAMESPACE_SEPARATOR) const override
Return a full, callable string representation of this.
void set_sigma_y_sq(double sigma_y_sq)
Set the square of sigma_y.
void set_sigma_x_sq(double sigma_x_sq)
Set the square of sigma_x.
void set_xyc(const std::array< double, 3 > &xyc)
Set sigma_x_sq, sigma_y_sq and cov_xy from an array ref.
std::array< double, 3 > get_xyc() const
Get the array of sigma_x^2, sigma_y^2, covariance.
std::string str() const override
Return a brief, human-readable string representation of this.
double get_sigma_y_sq() const
Get the square of sigma_y.
void convolve(const Covariance &cov)
Convolve with another covariance, adding the values of each parameter to this.
std::unique_ptr< Covariance > make_convolution_uniq(const Covariance &cov) const
Same as make_convolution(), but returning a unique_ptr.
static void check(double sigma_x_sq, double sigma_y_sq, double cov_xy)
Check whether the supplied values are valid, throwing if not.
void set_cov_xy(double cov_xy)
Set the off-diagonal (covariance) term.
Covariance(double sigma_x_sq=0, double sigma_y_sq=0, double cov_xy=0)
Construct a new Covariance object.
friend std::ostream & operator<<(std::ostream &out, const Covariance &obj)
bool operator==(const Covariance &other) const
Interface for an object storing Ellipse data.
virtual double get_sigma_x_sq() const
Get the square of sigma_x.
static void check_rho(double rho, std::string_view error_suffix="")
Check whether a rho value is valid.
virtual double get_rho() const =0
Get rho.
virtual void set_rho(double rho)=0
Set the correlation parameter (rho)
static void check_size(double size, std::string_view error_suffix="")
Check whether an x- or x-yaxis size value is valid.
virtual void set_hwhm_y(double hwhm_y)
Set the y-axis half-width at half-max (FWHM/2)
virtual ~EllipseData()=default
virtual void set_h(double hwhm_x, double hwhm_y, double rho)
Set hwhm_x, hwhm_y, rho (half-width at half-max)
virtual void convolve(const Ellipse &ell)
Convolve this ellipse with another.
virtual void set_hwhm_x(double hwhm_x)
Set the x-axis half-width at half-max (FWHM/2)
virtual double get_sigma_xy() const
Return sigma_x*sigma_y.
virtual double get_sigma_y_sq() const
Get the square of sigma_y.
virtual void set_xyr(const std::array< double, 3 > &xyr)
Set sigma_x, sigma_y, rho from an array.
bool operator==(const EllipseData &other) const
virtual void set_sigma_y(double sigma_y)=0
Set the y-axis dispersion (sigma)
virtual std::array< double, 3 > get_hxyr() const
Get hwhm_x, hwhm_y, rho.
bool operator!=(const EllipseData &other) const
virtual double get_cov_xy() const
Return the covariance, equal to sigma_x*sigma_y*rho.
static void check(double size_x, double size_y, double rho, std::string_view error_suffix="")
Check whether Ellipse parameter values are valid, throwing if not.
virtual double get_radius_trace() const
Return the trace radius, equal to sqrt(sigma_x^2 + sigma_y^2)
virtual void set_hxyr(const std::array< double, 3 > &hxyr)
Set hwhm_x, hwhm_y, rho from an array.
virtual std::string repr(bool name_keywords=false, std::string_view namespace_separator=Object::CC_NAMESPACE_SEPARATOR) const override=0
Return a full, callable string representation of this.
virtual double get_hwhm_y() const
Get the y-axis half-width at half-maximum.
virtual double get_area() const
Return the area of this ellipse, equal to pi*sigma_major*sigma_minor.
virtual std::string str() const override=0
Return a brief, human-readable string representation of this.
virtual std::array< double, 3 > get_xyr() const
Get sigma_x, sigma_y, rho.
virtual double get_sigma_y() const =0
Get sigma_y.
virtual double get_hwhm_x() const
Get the x-axis half-width at half-maximum.
friend std::ostream & operator<<(std::ostream &out, const EllipseData &obj)
virtual void set_sigma_x(double sigma_x)=0
Set the x-axis dispersion (sigma)
virtual double get_sigma_x() const =0
Get sigma_x.
An Ellipse with sigma_x, sigma_y, and rho values.
std::shared_ptr< Ellipse > make_convolution(const Ellipse &ell) const
Return the convolution of this with another ellipse.
double get_rho() const override
Get rho.
std::unique_ptr< Ellipse > make_convolution_uniq(const Ellipse &ell) const
Same as make_convolution(), but returning a unique_ptr.
bool operator!=(const Ellipse &other) const
bool operator==(const Ellipse &other) const
void set_rho(double rho) override
Set the correlation parameter (rho)
void set_sigma_y(double sigma_y) override
Set the y-axis dispersion (sigma)
Ellipse(std::shared_ptr< EllipseData > data)
void set_sigma_x(double sigma_x) override
Set the x-axis dispersion (sigma)
const EllipseData & get_data() const
Return a const ref to this ellipse's data.
double get_sigma_x() const override
Get sigma_x.
std::string repr(bool name_keywords=false, std::string_view namespace_separator=Object::CC_NAMESPACE_SEPARATOR) const override
Return a full, callable string representation of this.
std::string str() const override
Return a brief, human-readable string representation of this.
double get_sigma_y() const override
Get sigma_y.
An Ellipse with r_major, axrat and angle values.
bool operator!=(const EllipseMajor &other) const
void set_degrees(bool degrees)
double get_axrat() const
Get the axis ratio.
double get_r_major() const
Get the major axis length.
double get_angle_radians() const
Get the position angle in radians.
bool is_degrees() const
Return if the units are degrees (true) or radians (false)
static void check(double r_major, double axrat, double angle)
Check whether the supplied values are valid, throwing if not.
void set_angle(double angle)
double get_area() const
Return the area of this ellipse, equal to pi*sigma_major*sigma_minor.
void set_rqa(const std::array< double, 3 > &rqa)
bool operator==(const EllipseMajor &other) const
void set_r_major(double r_major)
std::string repr(bool name_keywords=false, std::string_view namespace_separator=Object::CC_NAMESPACE_SEPARATOR) const override
Return a full, callable string representation of this.
void set_axrat(double axrat)
std::array< double, 3 > get_rqa() const
Get the array of r_major, axrat, angle.
double get_angle() const
Get the position angle in the configured units.
double get_angle_degrees() const
Get the position angle in degrees.
std::string str() const override
Return a brief, human-readable string representation of this.
EllipseMajor(double r_major, double axrat, double angle, bool degrees=false)
Construct a new EllipseMajor object with default float values.
An EllipseData storing sigma_x, sigma_y, rho values as shared_ptrs.
EllipseValues(std::shared_ptr< double > sigma_x, std::shared_ptr< double > sigma_y, std::shared_ptr< double > rho=nullptr)
Construct a new EllipseValues object.
void set_rho(double rho) override
Set the correlation parameter (rho)
void set_h(double hwhm_x, double hwhm_y, double rho) override
Set hwhm_x, hwhm_y, rho (half-width at half-max)
double get_rho() const override
Get rho.
std::string str() const override
Return a brief, human-readable string representation of this.
EllipseValues(double sigma_x=0, double sigma_y=0, double rho=0)
Construct a new EllipseValues object, creating new pointers for every value.
std::array< double, 3 > get_xyr() const override
Get sigma_x, sigma_y, rho.
std::string repr(bool name_keywords=false, std::string_view namespace_separator=Object::CC_NAMESPACE_SEPARATOR) const override
Return a full, callable string representation of this.
void set_sigma_x(double sigma_x) override
Set the x-axis dispersion (sigma)
double get_sigma_y() const override
Get sigma_y.
void set_sigma_y(double sigma_y) override
Set the y-axis dispersion (sigma)
double get_sigma_x() const override
Get sigma_x.
A generic object from the gauss2d library.
static constexpr std::string_view CC_NAMESPACE_SEPARATOR
The C++ namespace separator.
daf::base::PropertySet * set
const double M_SIGMA_HWHM
const double M_HWHM_SIGMA
std::string to_string_float(const T value, const int precision=6, const bool scientific=true)