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 | Protected Attributes | List of all members
lsst::gauss2d::fit::GaussianComponent Class Reference

A Component consisting of a 2D Gaussian. More...

#include <gaussiancomponent.h>

Inheritance diagram for lsst::gauss2d::fit::GaussianComponent:
lsst::gauss2d::fit::GaussianParametricEllipseHolder lsst::gauss2d::fit::EllipticalComponent lsst::gauss2d::fit::Component lsst::gauss2d::fit::ParametricModel lsst::gauss2d::fit::Parametric lsst::gauss2d::Object

Public Member Functions

 GaussianComponent (std::shared_ptr< GaussianParametricEllipse > ellipse=nullptr, std::shared_ptr< CentroidParameters > centroid=nullptr, std::shared_ptr< IntegralModel > integralmodel=nullptr)
 Construct a GaussianComponent from ellipse, centroid and integral parameters.
 
void add_extra_param_map (const Channel &channel, ExtraParamMap &map_extra, const GradParamMap &map_grad, ParameterMap &offsets) const override
 Add extra Parameter indices to a map.
 
void add_extra_param_factors (const Channel &channel, ExtraParamFactors &factors) const override
 Add extra Parameter gradient factors to an existing vector.
 
void add_grad_param_map (const Channel &channel, GradParamMap &map, ParameterMap &offsets) const override
 Add Parameter gradient indices to an existing map.
 
void add_grad_param_factors (const Channel &channel, GradParamFactors &factor) const override
 Add Parameter gradient factors to an existing map.
 
std::unique_ptr< const lsst::gauss2d::Gaussiansget_gaussians (const Channel &channel) const override
 Return the vector of Gaussian sub-components controlled by this model.
 
size_t get_n_gaussians (const Channel &channel) const override
 Return the number of Gaussian sub-components controlled by this model.
 
ParamRefsget_parameters (ParamRefs &params, ParamFilter *filter=nullptr) const override
 Add Parameter refs matching the filter to a vector, in order.
 
ParamCRefsget_parameters_const (ParamCRefs &params, ParamFilter *filter=nullptr) const override
 Same as get_parameters(), but for const refs.
 
void set_extra_param_factors (const Channel &channel, ExtraParamFactors &factors, size_t index) const override
 Set extra Parameter gradient factors in an existing map.
 
void set_grad_param_factors (const Channel &channel, GradParamFactors &factors, size_t index) const override
 Set Parameter gradient factors in an existing map.
 
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.
 
const CentroidParametersget_centroid () const
 Get the centroid Parameter container.
 
const ParametricEllipseget_ellipse () const
 Get the ellipse Parameter container.
 
const IntegralModelget_integralmodel () const override
 
ParamRefs get_parameters_new (ParamFilter *filter=nullptr) const
 Same as get_parameters(), but returning a new vector.
 
ParamCRefs get_parameters_const_new (ParamFilter *filter=nullptr) const
 Same as get_parameters_const(), but returning a new vector.
 

Static Public Member Functions

static std::vector< std::shared_ptr< Component > > make_uniq_default_gaussians (const std::vector< double > &sizes={2.}, bool fixed=true)
 Construct a vector of default-initialized GaussianComponent instances.
 
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 = "."
 

Protected Attributes

std::shared_ptr< ParametricEllipse_ellipse
 
std::shared_ptr< CentroidParameters_centroid
 
std::shared_ptr< IntegralModel_integralmodel
 

Detailed Description

A Component consisting of a 2D Gaussian.

Definition at line 30 of file gaussiancomponent.h.

Constructor & Destructor Documentation

◆ GaussianComponent()

lsst::gauss2d::fit::GaussianComponent::GaussianComponent ( std::shared_ptr< GaussianParametricEllipse > ellipse = nullptr,
std::shared_ptr< CentroidParameters > centroid = nullptr,
std::shared_ptr< IntegralModel > integralmodel = nullptr )
explicit

Construct a GaussianComponent from ellipse, centroid and integral parameters.

Parameters
ellipseThe GaussianParametricEllipse value; default-initialized if null.
centroidThe CentroidParameters value; default-initialized if null.
integralmodelThe IntegralModel value; default-initialized if null.

Definition at line 20 of file gaussiancomponent.cc.

24 EllipticalComponent(_ellipsedata, centroid, integralmodel) {}
EllipticalComponent(std::shared_ptr< ParametricEllipse > ellipse, std::shared_ptr< CentroidParameters > centroid=nullptr, std::shared_ptr< IntegralModel > integralmodel=nullptr)
Construct an EllipticalComponent from Parameter containers.
std::shared_ptr< GaussianParametricEllipse > _ellipsedata
GaussianParametricEllipseHolder(std::shared_ptr< GaussianParametricEllipse > ellipse=nullptr)
T move(T... args)

Member Function Documentation

◆ add_extra_param_factors()

void lsst::gauss2d::fit::GaussianComponent::add_extra_param_factors ( const Channel & channel,
ExtraParamFactors & factors ) const
overridevirtual

Add extra Parameter gradient factors to an existing vector.

Parameters
channelThe Channel to add factors for.
factorsThe ExtraParamFactors to add to.

Implements lsst::gauss2d::fit::ParametricModel.

Definition at line 82 of file gaussiancomponent.cc.

82 {
83 factors.push_back({0, 0, 0});
84}

◆ add_extra_param_map()

void lsst::gauss2d::fit::GaussianComponent::add_extra_param_map ( const Channel & channel,
ExtraParamMap & map_extra,
const GradParamMap & map_grad,
ParameterMap & offsets ) const
overridevirtual

Add extra Parameter indices to a map.

Parameters
channelThe Channel to add indices for.
map_extraThe ExtraParamMap to add to.
map_gradThe completed GradParamMap.
offsetsA map of index offsets for Parameters that have already been added.

Implements lsst::gauss2d::fit::ParametricModel.

Definition at line 55 of file gaussiancomponent.cc.

56 {
57 auto factors_int = _integralmodel->get_integral_derivative_factors(channel);
58 const size_t n_factors = factors_int.size();
59 if (!(n_factors <= N_PARAMS_EXTRA_INTEGRAL_MAX)) {
60 throw std::runtime_error(_integralmodel->str() + ".get_integral_derivative_factors(" + channel.str()
61 + ").size()=" + std::to_string(n_factors)
62 + "!<=" + std::to_string(N_PARAMS_EXTRA_INTEGRAL_MAX));
63 }
64 size_t idx = 0;
65 size_t offset = 0;
66
67 for (const auto& factor : factors_int) {
68 const auto& param = factor.first.get();
69 if (!param.get_fixed()) {
70 auto found = offsets.find(param);
71 if (found == offsets.end()) {
72 throw std::runtime_error("param=" + param.str() + " not found in offsets;"
73 " was add_grad_param_map called first?");
74 }
75 offset = (*found).second;
76 idx = map_grad.size() - 1;
77 }
78 }
79 map_extra.push_back({idx, offset});
80}
std::shared_ptr< IntegralModel > _integralmodel
T to_string(T... args)

◆ add_grad_param_factors()

void lsst::gauss2d::fit::GaussianComponent::add_grad_param_factors ( const Channel & channel,
GradParamFactors & factors ) const
overridevirtual

Add Parameter gradient factors to an existing map.

Parameters
channelThe Channel to add factors for.
factorsThe GradParamFactors to add to.

Implements lsst::gauss2d::fit::ParametricModel.

Definition at line 118 of file gaussiancomponent.cc.

118 {
119 factors.push_back({1, 1, 1, 1, 1, 1});
120}

◆ add_grad_param_map()

void lsst::gauss2d::fit::GaussianComponent::add_grad_param_map ( const Channel & channel,
GradParamMap & map,
ParameterMap & offsets ) const
overridevirtual

Add Parameter gradient indices to an existing map.

Parameters
channelThe Channel to add indices for.
mapThe map to add to.
offsetsA map of index offsets for Parameters that have already been added.

Implements lsst::gauss2d::fit::ParametricModel.

Definition at line 86 of file gaussiancomponent.cc.

87 {
88 auto params = nonconsecutive_unique(this->_get_parameters_grad(channel));
89 map.push_back({0, 0, 0, 0, 0, 0});
90 auto& values = map.back();
91
92 size_t size_map = offsets.size();
93 size_t index_param_map;
94 for (size_t idx_param = 0; idx_param < N_PARAMS_GAUSS2D; ++idx_param) {
95 const size_t& order_param = IDX_ORDER[idx_param];
96 // The parameters must be in the same order as returned by get_parameters(_const)
97 const auto& param = params.at(idx_param).get();
98 if (!param.get_fixed()) {
99 if (offsets.find(param) == offsets.end()) {
100 index_param_map = ++size_map;
101 offsets[param] = index_param_map;
102 } else {
103 index_param_map = offsets[param];
104 }
105 values[order_param] = index_param_map;
106 }
107 }
108 const size_t n_params = params.size();
109 // Add offset for any extra integral parameters
110 for (size_t idx_param = N_PARAMS_GAUSS2D; idx_param < n_params; ++idx_param) {
111 const auto& param = params.at(idx_param).get();
112 if (!param.get_fixed() && (offsets.find(param) == offsets.end())) {
113 offsets[param] = ++size_map;
114 }
115 }
116}
std::vector< T > nonconsecutive_unique(const std::vector< T > &vec)
Definition util.h:92
const size_t N_PARAMS_GAUSS2D
Definition evaluate.h:61

◆ get_centroid()

const CentroidParameters & lsst::gauss2d::fit::EllipticalComponent::get_centroid ( ) const
inherited

Get the centroid Parameter container.

Definition at line 23 of file ellipticalcomponent.cc.

23{ return *_centroid; }
std::shared_ptr< CentroidParameters > _centroid

◆ get_ellipse()

const ParametricEllipse & lsst::gauss2d::fit::EllipticalComponent::get_ellipse ( ) const
inherited

Get the ellipse Parameter container.

Definition at line 24 of file ellipticalcomponent.cc.

24{ return *_ellipse; }
std::shared_ptr< ParametricEllipse > _ellipse

◆ get_gaussians()

std::unique_ptr< const lsst::gauss2d::Gaussians > lsst::gauss2d::fit::GaussianComponent::get_gaussians ( const Channel & channel) const
overridevirtual

Return the vector of Gaussian sub-components controlled by this model.

Parameters
channelThe Channel to return Gaussians for.
Returns
The Gaussians controlled by this model.

Implements lsst::gauss2d::fit::ParametricModel.

Definition at line 122 of file gaussiancomponent.cc.

123 {
124 lsst::gauss2d::Gaussians::Data gaussians = {std::make_shared<Gaussian>(
125 std::make_shared<Centroid>(this->_centroid), std::make_shared<Ellipse>(this->_ellipsedata),
126 std::make_shared<GaussianModelIntegral>(channel, this->_integralmodel))};
127 return std::make_unique<const lsst::gauss2d::Gaussians>(gaussians);
128}

◆ get_integralmodel()

const IntegralModel & lsst::gauss2d::fit::EllipticalComponent::get_integralmodel ( ) const
overridevirtualinherited

Implements lsst::gauss2d::fit::Component.

Definition at line 25 of file ellipticalcomponent.cc.

25{ return *_integralmodel; }

◆ get_n_gaussians()

size_t lsst::gauss2d::fit::GaussianComponent::get_n_gaussians ( const Channel & channel) const
overridevirtual

Return the number of Gaussian sub-components controlled by this model.

Implements lsst::gauss2d::fit::ParametricModel.

Definition at line 130 of file gaussiancomponent.cc.

130{ return 1; };

◆ get_parameters()

ParamRefs & lsst::gauss2d::fit::GaussianComponent::get_parameters ( ParamRefs & params,
ParamFilter * filter = nullptr ) const
overridevirtual

Add Parameter refs matching the filter to a vector, in order.

Parameters
paramsThe vector to add to.
filterThe filter to apply to this Object's parameters.
Returns
A ref to params (for method chaining)

Reimplemented from lsst::gauss2d::fit::EllipticalComponent.

Definition at line 132 of file gaussiancomponent.cc.

132 {
134 return params;
135}
ParamRefs & get_parameters(ParamRefs &params, ParamFilter *filter=nullptr) const override
Add Parameter refs matching the filter to a vector, in order.

◆ get_parameters_const()

ParamCRefs & lsst::gauss2d::fit::GaussianComponent::get_parameters_const ( ParamCRefs & params,
ParamFilter * filter = nullptr ) const
overridevirtual

Same as get_parameters(), but for const refs.

Reimplemented from lsst::gauss2d::fit::EllipticalComponent.

Definition at line 137 of file gaussiancomponent.cc.

137 {
139 return params;
140}
ParamCRefs & get_parameters_const(ParamCRefs &params, ParamFilter *filter=nullptr) const override
Same as get_parameters(), but for const refs.

◆ get_parameters_const_new()

ParamCRefs lsst::gauss2d::fit::Parametric::get_parameters_const_new ( ParamFilter * filter = nullptr) const
inlineinherited

Same as get_parameters_const(), but returning a new vector.

Definition at line 33 of file parametric.h.

33 {
34 ParamCRefs params{};
35 get_parameters_const(params, filter);
36 return params;
37 }
virtual ParamCRefs & get_parameters_const(ParamCRefs &params, ParamFilter *filter=nullptr) const =0
Same as get_parameters(), but for const refs.
std::vector< ParamBaseCRef > ParamCRefs
Definition param_defs.h:11

◆ get_parameters_new()

ParamRefs lsst::gauss2d::fit::Parametric::get_parameters_new ( ParamFilter * filter = nullptr) const
inlineinherited

Same as get_parameters(), but returning a new vector.

Definition at line 27 of file parametric.h.

27 {
28 ParamRefs params{};
29 get_parameters(params, filter);
30 return params;
31 }
virtual ParamRefs & get_parameters(ParamRefs &params, ParamFilter *filter=nullptr) const =0
Add Parameter refs matching the filter to a vector, in order.
std::vector< ParamBaseRef > ParamRefs
Definition param_defs.h:13

◆ make_uniq_default_gaussians()

static std::vector< std::shared_ptr< Component > > lsst::gauss2d::fit::GaussianComponent::make_uniq_default_gaussians ( const std::vector< double > & sizes = {2.},
bool fixed = true )
inlinestatic

Construct a vector of default-initialized GaussianComponent instances.

Parameters
sizesVector of initial values for both sigma_x and sigma_y.
fixedWhether all Parameter members should be fixed initially.
Returns
A vector of GaussianComponent instances.
Note
This can be used to initialize a trivial PsfModel as a noralized, zero-size single Gaussian.

Definition at line 65 of file gaussiancomponent.h.

66 {2.}, bool fixed = true) {
68 for (const double size : sizes) {
70 = {{Channel::NONE(),
71 std::make_shared<IntegralParameterD>(1., nullptr, nullptr, nullptr, fixed)}};
72 comps.emplace_back(std::make_shared<GaussianComponent>(
73 std::make_shared<GaussianParametricEllipse>(
74 std::make_shared<SigmaXParameterD>(size, nullptr, nullptr, nullptr, fixed),
75 std::make_shared<SigmaYParameterD>(size, nullptr, nullptr, nullptr, fixed),
76 std::make_shared<RhoParameterD>(0, nullptr, nullptr, nullptr, fixed)),
77 std::make_shared<CentroidParameters>(
78 std::make_shared<CentroidXParameterD>(0, nullptr, nullptr, nullptr, fixed),
79 std::make_shared<CentroidYParameterD>(0, nullptr, nullptr, nullptr, fixed)),
80 std::make_shared<LinearIntegralModel>(&data)));
81 }
82 return comps;
83 }
char * data
Definition BaseRecord.cc:61
static const Channel & NONE()
Definition channel.cc:111
std::vector< ChannelIntegralParameterD > Data
T emplace_back(T... args)
T fixed(T... args)

◆ 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

◆ repr()

std::string lsst::gauss2d::fit::GaussianComponent::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.

Reimplemented from lsst::gauss2d::fit::EllipticalComponent.

Definition at line 184 of file gaussiancomponent.cc.

184 {
185 return type_name_str<GaussianComponent>(false, namespace_separator) + "("
186 + EllipticalComponent::repr(name_keywords, namespace_separator) + ")";
187}
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.

◆ set_extra_param_factors()

void lsst::gauss2d::fit::GaussianComponent::set_extra_param_factors ( const Channel & channel,
ExtraParamFactors & factors,
size_t index ) const
overridevirtual

Set extra Parameter gradient factors in an existing map.

Parameters
channelThe Channel to set factors for.
factorsThe ExtraParamFactors to set factors for.
indexThe index to begin setting factors at.

Implements lsst::gauss2d::fit::ParametricModel.

Definition at line 142 of file gaussiancomponent.cc.

143 {
144 auto factors_int = _integralmodel->get_integral_derivative_factors(channel);
145 const size_t n_factors = factors_int.size();
146 if (!(n_factors <= 1)) {
147 throw std::runtime_error(this->str() + ".set_extra_param_factors(" + channel.str()
148 + ", index=" + std::to_string(index) + " has " + std::to_string(n_factors)
149 + " parameter factors" + "; only a maximum of one is supported.");
150 }
151 auto& row = factors[index];
152
153 if (n_factors > 0) {
154 row[0] = factors_int[0].second[0] / factors_int[0].first.get().get_transform_derivative();
155 } else {
156 row[0] = 0;
157 }
158 row[1] = 0;
159 row[2] = 0;
160}
std::string str() const override
Return a brief, human-readable string representation of this.
int row
Definition CR.cc:145

◆ set_grad_param_factors()

void lsst::gauss2d::fit::GaussianComponent::set_grad_param_factors ( const Channel & channel,
GradParamFactors & factors,
size_t index ) const
overridevirtual

Set Parameter gradient factors in an existing map.

Parameters
channelThe Channel to set factors for.
factorsThe GradParamFactors to set factors for.
indexThe index to begin setting factors at.

Implements lsst::gauss2d::fit::ParametricModel.

Definition at line 162 of file gaussiancomponent.cc.

163 {
164 auto params = this->_get_parameters_grad(channel);
165 auto& values = factors.at(index);
166
167 for (size_t idx_param = 0; idx_param < N_PARAMS_GAUSS2D; ++idx_param) {
168 const size_t& order_param = IDX_ORDER[idx_param];
169 // The parameters must be in the same order as returned by get_parameters(_const)
170 const auto& param = params[idx_param].get();
171 if (param.get_fixed()) {
172 values[order_param] = 0;
173 } else {
174 auto deriv = param.get_transform_derivative();
175 if (deriv == 0) {
176 throw std::runtime_error("Param[idx=" + std::to_string(idx_param) + "]=" + param.str()
177 + " get_transform_derivative=0 (will result in divide by 0)");
178 }
179 values[order_param] = 1.0 / deriv;
180 }
181 }
182}

◆ str()

std::string lsst::gauss2d::fit::GaussianComponent::str ( ) const
overridevirtual

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

Reimplemented from lsst::gauss2d::fit::EllipticalComponent.

Definition at line 189 of file gaussiancomponent.cc.

189 {
190 return type_name_str<GaussianComponent>(true) + "(" + EllipticalComponent::str() + ")";
191}
std::string str() const override
Return a brief, human-readable string representation of this.

Member Data Documentation

◆ _centroid

std::shared_ptr<CentroidParameters> lsst::gauss2d::fit::EllipticalComponent::_centroid
protectedinherited

Definition at line 42 of file ellipticalcomponent.h.

◆ _ellipse

std::shared_ptr<ParametricEllipse> lsst::gauss2d::fit::EllipticalComponent::_ellipse
protectedinherited

Definition at line 41 of file ellipticalcomponent.h.

◆ _integralmodel

std::shared_ptr<IntegralModel> lsst::gauss2d::fit::EllipticalComponent::_integralmodel
protectedinherited

Definition at line 43 of file ellipticalcomponent.h.

◆ 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: