LSST Applications g0d97872fb5+4fd969bb9d,g1653933729+34a971ddd9,g28da252d5a+072f89fe25,g2bbee38e9b+a99b0ab4cd,g2bc492864f+a99b0ab4cd,g2ca4be77d2+c0e3b27cd8,g2cdde0e794+704103fe75,g3156d2b45e+6e87dc994a,g347aa1857d+a99b0ab4cd,g35bb328faa+34a971ddd9,g3a166c0a6a+a99b0ab4cd,g3e281a1b8c+8ec26ec694,g4005a62e65+ba0306790b,g414038480c+9ed5ed841a,g569e0e2b34+cb4faa46ad,g5a97de2502+520531a62c,g717e5f8c0f+29153700a5,g7ede599f99+367733290c,g80478fca09+17051a22cc,g82479be7b0+f2f1ea0a87,g858d7b2824+29153700a5,g8b782ad322+29153700a5,g8cd86fa7b1+05420e7f7d,g9125e01d80+34a971ddd9,ga5288a1d22+e7f674aaf3,gae0086650b+34a971ddd9,gae74b0b5c6+45ef5cdc51,gb58c049af0+ace264a4f2,gc28159a63d+a99b0ab4cd,gcf0d15dbbd+8051a81198,gda6a2b7d83+8051a81198,gdaeeff99f8+7774323b41,gdf4d240d4a+34a971ddd9,ge2409df99d+cb167bac99,ge33fd446bb+29153700a5,ge79ae78c31+a99b0ab4cd,gf0baf85859+890af219f9,gf5289d68f6+9faa5c5784,w.2024.36
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
lsst::gauss2d::Covariance Class Reference

A representation of a 2D Gaussian with x and y standard deviations and a covariance value. More...

#include <ellipse.h>

Inheritance diagram for lsst::gauss2d::Covariance:
lsst::gauss2d::Object

Public Member Functions

 Covariance (double sigma_x_sq=0, double sigma_y_sq=0, double cov_xy=0)
 Construct a new Covariance object.
 
 Covariance (const Ellipse &ell)
 Construct a covariance using values from an ellipse instance.
 
void convolve (const Covariance &cov)
 Convolve with another covariance, adding the values of each parameter to this.
 
double get_sigma_x_sq () const
 Get the square of sigma_x.
 
double get_sigma_y_sq () const
 Get the square of sigma_y.
 
double get_cov_xy () const
 Get the covariance.
 
std::array< double, 3 > get_xyc () const
 Get the array of sigma_x^2, sigma_y^2, covariance.
 
std::shared_ptr< Covariancemake_convolution (const Covariance &cov) const
 Return the convolution of this with another covariance.
 
std::unique_ptr< Covariancemake_convolution_uniq (const Covariance &cov) const
 Same as make_convolution(), but returning a unique_ptr.
 
void set (const Ellipse &ellipse)
 Set values from an ellipse instance.
 
void set (double sigma_x_sq=0, double sigma_y_sq=0, double cov_xy=0)
 Set all values at once.
 
void set_sigma_x_sq (double sigma_x_sq)
 Set the square of sigma_x.
 
void set_sigma_y_sq (double sigma_y_sq)
 Set the square of sigma_y.
 
void set_cov_xy (double cov_xy)
 Set the off-diagonal (covariance) term.
 
void set_xyc (const std::array< double, 3 > &xyc)
 Set sigma_x_sq, sigma_y_sq and cov_xy from an array ref.
 
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.
 
bool operator== (const Covariance &other) const
 
bool operator!= (const Covariance &other) const
 

Static Public Member Functions

static void check (double sigma_x_sq, double sigma_y_sq, double cov_xy)
 Check whether the supplied values are valid, throwing if not.
 
static std::string_view null_str (const std::string_view &namespace_separator)
 

Static Public Attributes

static constexpr std::string_view CC_NAMESPACE_SEPARATOR = "::"
 The C++ namespace separator.
 
static constexpr std::string_view NULL_STR_GENERAL = "None"
 
static constexpr std::string_view PY_NAMESPACE_SEPARATOR = "."
 

Friends

std::ostreamoperator<< (std::ostream &out, const Covariance &obj)
 

Detailed Description

A representation of a 2D Gaussian with x and y standard deviations and a covariance value.

This ellipse representation is intended for intermediate calculations and does not use an abstract Data class.

Note
The covariance is equal to sigma_x*sigma_y*rho, where -1 < rho < 1. Covariance values implying rho values outside this range are invalid.

Definition at line 57 of file ellipse.h.

Constructor & Destructor Documentation

◆ Covariance() [1/2]

lsst::gauss2d::Covariance::Covariance ( double sigma_x_sq = 0,
double sigma_y_sq = 0,
double cov_xy = 0 )
explicit

Construct a new Covariance object.

Parameters
sigma_x_sqThe value of sigma_x^2
sigma_y_sqThe value of sigma_y^2
cov_xyThe value of the covariance

Definition at line 40 of file ellipse.cc.

40 {
41 set(sigma_x_sq, sigma_y_sq, cov_xy);
42}
daf::base::PropertySet * set
Definition fits.cc:931

◆ Covariance() [2/2]

lsst::gauss2d::Covariance::Covariance ( const Ellipse & ell)
explicit

Construct a covariance using values from an ellipse instance.

Definition at line 44 of file ellipse.cc.

44{ set(ell); }

Member Function Documentation

◆ check()

void lsst::gauss2d::Covariance::check ( double sigma_x_sq,
double sigma_y_sq,
double cov_xy )
static

Check whether the supplied values are valid, throwing if not.

Definition at line 46 of file ellipse.cc.

46 {
47 double offdiag_max = sqrt(sigma_x_sq) * sqrt(sigma_y_sq);
48 // Define implied rho as -1 for negative cov and +1 for positive cov if zero size
49 // This enforces cov_xy == 0 if sigma_x_sq == sigma_y_sq == 0
50 double rho = offdiag_max > 0 ? cov_xy / offdiag_max : (cov_xy > 0) - (cov_xy < 0);
51 if (!(sigma_x_sq >= 0) || !(sigma_y_sq >= 0) || !(rho >= -1 && rho <= 1)) {
52 throw std::invalid_argument("Invalid sigma_x_sq, sigma_y_sq, cov_xy=" + to_string_float(sigma_x_sq)
53 + "," + to_string_float(sigma_y_sq) + "," + to_string_float(cov_xy)
54 + " with implied rho=" + to_string_float(rho)
55 + "; sigma_x,y_sq >= 0 and -1 < rho < 1 required.");
56 }
57}
std::string to_string_float(const T value, const int precision=6, const bool scientific=true)
Definition to_string.h:15

◆ convolve()

void lsst::gauss2d::Covariance::convolve ( const Covariance & cov)

Convolve with another covariance, adding the values of each parameter to this.

Definition at line 59 of file ellipse.cc.

59 {
60 double sigma_x_sq = this->get_sigma_x_sq() + cov.get_sigma_x_sq();
61 double sigma_y_sq = this->get_sigma_y_sq() + cov.get_sigma_y_sq();
62 double cov_xy = this->get_cov_xy() + cov.get_cov_xy();
63 this->set(sigma_x_sq, sigma_y_sq, cov_xy);
64}
double get_cov_xy() const
Get the covariance.
Definition ellipse.h:79
double get_sigma_x_sq() const
Get the square of sigma_x.
Definition ellipse.h:75
double get_sigma_y_sq() const
Get the square of sigma_y.
Definition ellipse.h:77

◆ get_cov_xy()

double lsst::gauss2d::Covariance::get_cov_xy ( ) const
inline

Get the covariance.

Definition at line 79 of file ellipse.h.

79{ return _cov_xy; };

◆ get_sigma_x_sq()

double lsst::gauss2d::Covariance::get_sigma_x_sq ( ) const
inline

Get the square of sigma_x.

Definition at line 75 of file ellipse.h.

75{ return _sigma_x_sq; };

◆ get_sigma_y_sq()

double lsst::gauss2d::Covariance::get_sigma_y_sq ( ) const
inline

Get the square of sigma_y.

Definition at line 77 of file ellipse.h.

77{ return _sigma_y_sq; };

◆ get_xyc()

std::array< double, 3 > lsst::gauss2d::Covariance::get_xyc ( ) const
inline

Get the array of sigma_x^2, sigma_y^2, covariance.

Definition at line 81 of file ellipse.h.

81{ return {_sigma_x_sq, _sigma_y_sq, _cov_xy}; }

◆ make_convolution()

std::shared_ptr< Covariance > lsst::gauss2d::Covariance::make_convolution ( const Covariance & cov) const

Return the convolution of this with another covariance.

Convolution simply sums the values of each respective parameter.

Parameters
covThe covariance to convolve with.
Returns
A new covariance with values set to the convolution.

Definition at line 66 of file ellipse.cc.

66 {
67 std::shared_ptr<Covariance> cov_ret = std::make_shared<Covariance>(
68 this->get_sigma_x_sq(), this->get_sigma_y_sq(), this->get_cov_xy());
69 cov_ret->convolve(cov);
70 return cov_ret;
71}

◆ make_convolution_uniq()

std::unique_ptr< Covariance > lsst::gauss2d::Covariance::make_convolution_uniq ( const Covariance & cov) const

Same as make_convolution(), but returning a unique_ptr.

◆ null_str()

static std::string_view lsst::gauss2d::Object::null_str ( const std::string_view & namespace_separator)
inlinestaticinherited

Definition at line 49 of file object.h.

49 {
50 return namespace_separator == CC_NAMESPACE_SEPARATOR ? "nullptr" : NULL_STR_GENERAL;
51 }
static constexpr std::string_view CC_NAMESPACE_SEPARATOR
The C++ namespace separator.
Definition object.h:45
static constexpr std::string_view NULL_STR_GENERAL
Definition object.h:46

◆ operator!=()

bool lsst::gauss2d::Covariance::operator!= ( const Covariance & other) const

Definition at line 135 of file ellipse.cc.

135{ return !(*this == other); }

◆ operator==()

bool lsst::gauss2d::Covariance::operator== ( const Covariance & other) const

Definition at line 134 of file ellipse.cc.

134{ return get_xyc() == other.get_xyc(); }
std::array< double, 3 > get_xyc() const
Get the array of sigma_x^2, sigma_y^2, covariance.
Definition ellipse.h:81

◆ repr()

std::string lsst::gauss2d::Covariance::repr ( bool name_keywords = false,
std::string_view namespace_separator = Object::CC_NAMESPACE_SEPARATOR ) const
overridevirtual

Return a full, callable string representation of this.

Parameters
name_keywordsWhether to prefix arguments with "{name}=", where name is the arg name in the header (as with keyword arguments in Python).
namespace_separatorThe string to use to delimit namespaces, i.e. :: in C++ and . in Python.
Returns
A callable string representation of this, which should return an an identical object to this.
Note
The representation with name_keywords=false must be callable in C++. The representation with name_keywords=true should be callable in Python, if there are any bindings.

Implements lsst::gauss2d::Object.

Definition at line 122 of file ellipse.cc.

122 {
123 return type_name_str<Covariance>(false, namespace_separator) + "(" + (name_keywords ? "sigma_x_sq=" : "")
124 + to_string_float(_sigma_x_sq) + ", " + (name_keywords ? "sigma_y_sq=" : "")
125 + to_string_float(_sigma_y_sq) + ", " + (name_keywords ? "cov_xy=" : "") + to_string_float(_cov_xy)
126 + ")";
127}

◆ set() [1/2]

void lsst::gauss2d::Covariance::set ( const Ellipse & ellipse)

Set values from an ellipse instance.

Definition at line 73 of file ellipse.cc.

73 {
74 double sigma_x = ellipse.get_sigma_x();
75 double sigma_y = ellipse.get_sigma_y();
76 double rho = ellipse.get_rho();
77 this->_sigma_x_sq = sigma_x * sigma_x;
78 this->_sigma_y_sq = sigma_y * sigma_y;
79 // Must be done like so in case sigma_x/y^2 round to zero, and check after
80 this->set_cov_xy(sigma_x * sigma_y * (_sigma_x_sq > 0) * (_sigma_y_sq > 0) * rho);
81}
void set_cov_xy(double cov_xy)
Set the off-diagonal (covariance) term.
Definition ellipse.cc:105

◆ set() [2/2]

void lsst::gauss2d::Covariance::set ( double sigma_x_sq = 0,
double sigma_y_sq = 0,
double cov_xy = 0 )

Set all values at once.

Definition at line 83 of file ellipse.cc.

83 {
84 set_sigma_x_sq(sigma_x_sq);
85 set_sigma_y_sq(sigma_y_sq);
86 set_cov_xy(cov_xy);
87}
void set_sigma_y_sq(double sigma_y_sq)
Set the square of sigma_y.
Definition ellipse.cc:97
void set_sigma_x_sq(double sigma_x_sq)
Set the square of sigma_x.
Definition ellipse.cc:89

◆ set_cov_xy()

void lsst::gauss2d::Covariance::set_cov_xy ( double cov_xy)

Set the off-diagonal (covariance) term.

Definition at line 105 of file ellipse.cc.

105 {
106 // Take individual sqrt just to be safe and avoid potential overflow
107 double offdiag_max = sqrt(_sigma_x_sq) * sqrt(_sigma_y_sq);
108 // If offdiag_max is zero, we can only accept cov_xy exactly zero
109 double rho = offdiag_max > 0 ? cov_xy / offdiag_max : -!(cov_xy >= 0) + !(cov_xy <= 0);
110 if (!(rho > -1 && rho < 1)) {
111 throw std::invalid_argument(this->str() + "can't set invalid cov_xy=" + to_string_float(cov_xy)
112 + " (>0=" + to_string_float(cov_xy > 0)
113 + ", <0=" + to_string_float(cov_xy < 0)
114 + ", offdiag_max=" + to_string_float(offdiag_max) + " with implied rho="
115 + to_string_float(rho) + "; -1 < rho < 1 required.");
116 }
117 _cov_xy = cov_xy;
118}
std::string str() const override
Return a brief, human-readable string representation of this.
Definition ellipse.cc:129

◆ set_sigma_x_sq()

void lsst::gauss2d::Covariance::set_sigma_x_sq ( double sigma_x_sq)

Set the square of sigma_x.

Definition at line 89 of file ellipse.cc.

89 {
90 if (!(sigma_x_sq >= 0)) {
91 throw std::invalid_argument(this->str() + " can't set invalid sigma_x_sq="
92 + to_string_float(sigma_x_sq) + "; sigma_x_sq >= 0 required.");
93 }
94 _sigma_x_sq = sigma_x_sq;
95}

◆ set_sigma_y_sq()

void lsst::gauss2d::Covariance::set_sigma_y_sq ( double sigma_y_sq)

Set the square of sigma_y.

Definition at line 97 of file ellipse.cc.

97 {
98 if (!(sigma_y_sq >= 0)) {
99 throw std::invalid_argument(this->str() + " can't set invalid sigma_y_sq="
100 + to_string_float(sigma_y_sq) + "; sigma_y_sq >= 0 required.");
101 }
102 _sigma_y_sq = sigma_y_sq;
103}

◆ set_xyc()

void lsst::gauss2d::Covariance::set_xyc ( const std::array< double, 3 > & xyc)

Set sigma_x_sq, sigma_y_sq and cov_xy from an array ref.

Definition at line 120 of file ellipse.cc.

120{ this->set(xyc[0], xyc[1], xyc[2]); }

◆ str()

std::string lsst::gauss2d::Covariance::str ( ) const
overridevirtual

Return a brief, human-readable string representation of this.

Implements lsst::gauss2d::Object.

Definition at line 129 of file ellipse.cc.

129 {
130 return type_name_str<Covariance>(true) + "(sigma_x_sq=" + to_string_float(_sigma_x_sq)
131 + ", sigma_y_sq=" + to_string_float(_sigma_y_sq) + ", cov_xy=" + to_string_float(_cov_xy) + ")";
132}

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
const Covariance & obj )
friend

Definition at line 137 of file ellipse.cc.

137 {
138 out << obj.str();
139 return out;
140}

Member Data Documentation

◆ CC_NAMESPACE_SEPARATOR

constexpr std::string_view lsst::gauss2d::Object::CC_NAMESPACE_SEPARATOR = "::"
staticconstexprinherited

The C++ namespace separator.

Definition at line 45 of file object.h.

◆ NULL_STR_GENERAL

constexpr std::string_view lsst::gauss2d::Object::NULL_STR_GENERAL = "None"
staticconstexprinherited

Definition at line 46 of file object.h.

◆ PY_NAMESPACE_SEPARATOR

constexpr std::string_view lsst::gauss2d::Object::PY_NAMESPACE_SEPARATOR = "."
staticconstexprinherited

Definition at line 47 of file object.h.


The documentation for this class was generated from the following files: