30 : _size_x(
std::move(size_x)),
31 _size_y(
std::move(size_y)),
33 _sersicindex(
std::move(sersicindex)),
35 if ((_size_x ==
nullptr) || (_size_y ==
nullptr) || (_rho ==
nullptr) || (_sersicindex ==
nullptr)) {
38 if (!(_index < _sersicindex->get_order())) {
44 double get_sizeratio()
const {
return _sersicindex->get_sizeratio(_index); }
48 double get_rho()
const override {
return _rho->get_value(); }
54 void set(
double sigma_x,
double sigma_y,
double rho)
override {
57 void set_h(
double hwhm_x,
double hwhm_y,
double rho)
override {
70 std::string repr(
bool name_keywords, std::string_view namespace_separator)
const override {
71 return type_name_str<SersicEllipseData>(
false, namespace_separator) +
"("
72 + (name_keywords ?
"size_x=" :
"") + _size_x->repr(name_keywords, namespace_separator) +
", "
73 + (name_keywords ?
"size_y=" :
"") + _size_y->repr(name_keywords, namespace_separator) +
", "
74 + (name_keywords ?
"rho=" :
"") + _rho->repr(name_keywords, namespace_separator) +
")";
78 return type_name_str<SersicEllipseData>(
true) +
"(size_x=" + _size_x->str()
79 +
", size_y=" + _size_y->str() +
", rho=" + _rho->str() + +
")";
87 unsigned short _index;
96 _sersicindex(
std::move(sersicindex)),
99 if (!(_index < _sersicindex->get_order())) {
116 const Channel& channel)
const override {
134 std::string repr(
bool name_keywords, std::string_view namespace_separator)
const override {
135 return type_name_str<SersicModelIntegral>(
false, namespace_separator) +
")"
136 + (name_keywords ?
"channel=" :
"") +
_channel.
repr(name_keywords, namespace_separator) +
", "
137 + (name_keywords ?
"integralmodel=" :
"")
139 + (name_keywords ?
"sersicindex=" :
"")
140 + _sersicindex->repr(name_keywords, namespace_separator) +
", "
145 return type_name_str<SersicModelIntegral>(
true) +
"(channel=" +
_channel.
str()
146 +
", integralmodel=" +
_integralmodel->str() +
", sersicindex=" + _sersicindex->str()
152 unsigned short _index;
166 : _ellipsedata(
std::move(ellipsedata)),
167 _centroid(
std::move(centroid)),
168 _integralmodel(
std::move(integralmodel)) {}
175 std::make_shared<Centroid>(this->_centroid), std::make_shared<Ellipse>(this->_ellipsedata),
176 std::make_shared<GaussianModelIntegral>(channel, this->_integralmodel))};
177 return std::make_unique<const lsst::gauss2d::Gaussians>(gaussians);
186void SersicMixComponentIndexParameterD::_set_ratios(
double sersicindex) {
187 _integralsizes = _interpolator->get_integralsizes(sersicindex);
188 _integralsizes_derivs = _interpolator->get_integralsizes_derivs(sersicindex);
196 return _integralsizes[index].integral;
204 return _integralsizes_derivs[index].integral;
208 unsigned short order) {
217 return _integralsizes[index].sigma;
225 return _integralsizes_derivs[index].sigma;
229 =
std::string(parameters::type_name<SersicMixComponentIndexParameterD>()) +
".limits_maximal";
231static const auto limits_sersic = std::make_shared<const parameters::Limits<double>>(
233 std::string(parameters::type_name<SersicMixComponentIndexParameterD>()) +
".limits_maximal");
236 return *limits_sersic;
245 _interpolator(
std::move(interpolator == nullptr
247 SERSICMIX_ORDER_DEFAULT)
255 return _interpolator->get_interptype();
276 _sersicindex(sersicindex != nullptr ?
std::move(sersicindex)
279 auto& gaussians = _gaussians[channel];
280 gaussians.reserve(_sersicindex->get_order());
281 for (
size_t index = 0; index < _sersicindex->get_order(); ++index) {
282 auto ell = std::make_shared<SersicEllipseData>(
284 _ellipsedata->get_rho_param_ptr(), _sersicindex, index);
286 = std::make_shared<SersicModelIntegral>(channel,
_integralmodel, _sersicindex, index);
287 gaussians.emplace_back(
288 std::make_unique<SersicMixGaussianComponent>(ell, this->
_centroid, integral));
297 if (_sersicindex->get_free()) {
298 auto found = offsets.find(*_sersicindex);
299 if (found == offsets.end()) {
301 +
" not found in offsets; was add_grad_param_map called?");
303 const auto& offset = (*found).second;
304 const size_t order = _sersicindex->get_order();
305 const size_t size_map_grad = map_grad.
size();
306 if (!(size_map_grad >=
order)) {
310 for (
size_t idx_g = 0; idx_g < _sersicindex->get_order(); ++idx_g) {
314 for (
size_t idx_g = 0; idx_g < _sersicindex->get_order(); ++idx_g) {
321 for (
size_t idx_g = 0; idx_g < _sersicindex->get_order(); ++idx_g) {
340 size_t size_map = offsets.size();
341 size_t index_param_map;
343 const size_t& order_param = IDX_ORDER[idx_param];
345 const auto& param = params.
at(idx_param).get();
346 if (!param.get_fixed()) {
347 if (offsets.find(param) == offsets.end()) {
348 index_param_map = ++size_map;
349 offsets[param] = index_param_map;
351 index_param_map = offsets[param];
353 values[order_param] = index_param_map;
356 if (_sersicindex->get_free() && (offsets.find(*_sersicindex) == offsets.end())) {
359 for (
size_t idx_g = 0; idx_g < _sersicindex->get_order(); ++idx_g) {
375 for (
size_t idx_g = 0; idx_g < _sersicindex->get_order(); ++idx_g) {
382 const Channel& channel)
const {
385 const auto&
components = _gaussians.at(channel);
388 in.push_back(component->get_gaussians(channel)->get_data());
390 return std::make_unique<lsst::gauss2d::Gaussians>(in);
394 return _gaussians.at(channel).size();
412 return *(this->_sersicindex);
416 return this->_sersicindex;
420 size_t index)
const {
421 if (_sersicindex->get_free()) {
423 double dx = 1. / _sersicindex->get_transform_derivative();
424 const double dintegral = dx * integralmodel.get_integral(channel);
425 const double dreff_x = dx *
_ellipse->get_size_x_param().get_size();
426 const double dreff_y = dx *
_ellipse->get_size_y_param().get_size();
427 for (
size_t idx_g = 0; idx_g < _sersicindex->get_order(); ++idx_g) {
428 const double dsizeratio = _sersicindex->get_sizeratio_deriv(idx_g);
429 auto& values = factors.
at(index + idx_g);
430 values[0] = dintegral * _sersicindex->get_integralratio_deriv(idx_g);
431 values[1] = dreff_x * dsizeratio;
432 values[2] = dreff_y * dsizeratio;
435 for (
size_t idx_g = 0; idx_g < _sersicindex->get_order(); ++idx_g) {
436 auto& values = factors[index + idx_g];
445 size_t index)
const {
454 const size_t& order_param = IDX_ORDER[idx_param];
456 const auto& param = params.
at(idx_param).get();
457 if (param.get_fixed()) {
458 values_base[order_param] = 0;
460 const auto deriv = param.get_transform_derivative();
463 +
" get_transform_derivative=0 (will result in divide by 0)");
464 values_base[order_param] /= deriv;
468 const auto& subcomps = _gaussians.at(channel);
469 for (
size_t idx_g = 0; idx_g < _sersicindex->get_order(); ++idx_g) {
470 const auto& subcomp = subcomps[idx_g];
471 auto& values = factors[index + idx_g];
472 values[0] = values_base[0];
473 values[1] = values_base[1];
474 values[2] = values_base[2] * subcomp->get_integralmodel().get_integralratio();
475 const double sizeratio = subcomp->get_ellipse().get_sizeratio();
476 values[3] = values_base[3] * sizeratio;
477 values[4] = values_base[4] * sizeratio;
478 values[5] = values_base[5];
485 return type_name_str<SersicMixComponent>(
false, namespace_separator) +
"("
487 + (name_keywords ?
"sersicindex=" :
"") + _sersicindex->repr(name_keywords, namespace_separator)
493 +
", sersicindex=" + _sersicindex->str() +
")";
table::Key< table::Array< int > > components
Interface for an object storing Ellipse data.
An observational channel, usually representing some range of wavelengths of light.
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.
A Component with an elliptically-symmetric intensity profile.
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.
std::shared_ptr< CentroidParameters > _centroid
ParamCRefs & get_parameters_const(ParamCRefs ¶ms, ParamFilter *filter=nullptr) const override
Same as get_parameters(), but for const refs.
std::shared_ptr< IntegralModel > _integralmodel
ParamRefs & get_parameters(ParamRefs ¶ms, ParamFilter *filter=nullptr) const override
Add Parameter refs matching the filter to a vector, in order.
std::shared_ptr< ParametricEllipse > _ellipse
const IntegralModel & get_integralmodel() const override
A single-channel GaussianIntegral referencing a Parametric IntegralModel.
const std::shared_ptr< const IntegralModel > _integralmodel
A Parametric model for the integral of a 2D distribution.
A Parametric ellipse with two scale sizes.
void set_rho(double rho) override
Set the correlation parameter (rho)
double get_sizeratio() const
void set_sigma_x(double sigma_x) override
Set the x-axis dispersion (sigma)
std::string str() const override
Return a brief, human-readable string representation of this.
std::array< double, 3 > get_xyr() const override
Get sigma_x, sigma_y, rho.
double get_sigma_y() const override
Get sigma_y.
SersicEllipseData(const std::shared_ptr< const ReffXParameterD > size_x, const std::shared_ptr< const ReffYParameterD > size_y, const std::shared_ptr< const RhoParameterD > rho, const std::shared_ptr< const SersicMixComponentIndexParameterD > sersicindex, unsigned short index)
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_sigma_x() const override
Get sigma_x.
void set_xyr(const std::array< double, 3 > &xyr) override
Set sigma_x, sigma_y, rho from an array.
std::string repr(bool name_keywords, std::string_view namespace_separator) const override
Return a full, callable string representation of this.
void set_sigma_y(double sigma_y) override
Set the y-axis dispersion (sigma)
double get_size_y() const override
Get the size_y value.
double get_size_x() const override
Get the size_x value.
void set(double sigma_x, double sigma_y, double rho) override
Set sigma_x, sigma_y, rho.
double get_rho() const override
Get rho.
void set_hxyr(const std::array< double, 3 > &hxyr) override
Set hwhm_x, hwhm_y, rho from an array.
std::unique_ptr< const lsst::gauss2d::Gaussians > get_gaussians(const Channel &channel) const
const SersicEllipseData & get_ellipse() const
const SersicModelIntegral & get_integralmodel() const
SersicMixGaussianComponent(std::shared_ptr< SersicEllipseData > ellipsedata=nullptr, std::shared_ptr< CentroidParameters > centroid=nullptr, std::shared_ptr< SersicModelIntegral > integralmodel=nullptr)
void set_extra_param_factors(const Channel &channel, ExtraParamFactors &factors, size_t index) const override
Set extra Parameter gradient factors in an existing map.
std::string str() const override
Return a brief, human-readable string representation of this.
std::unique_ptr< const lsst::gauss2d::Gaussians > get_gaussians(const Channel &channel) const override
Return the vector of Gaussian sub-components controlled by this model.
double get_sersicindex() const
void set_grad_param_factors(const Channel &channel, GradParamFactors &factors, size_t index) const override
Set Parameter gradient factors in an existing map.
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 set_sersicindex(double value)
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.
ParamRefs & get_parameters(ParamRefs ¶ms, ParamFilter *filter=nullptr) const override
Add Parameter refs matching the filter to a vector, in order.
SersicMixComponentIndexParameterD & get_sersicindex_param() const
std::shared_ptr< SersicMixComponentIndexParameterD > get_sersicindex_param_ptr()
SersicMixComponent(std::shared_ptr< SersicParametricEllipse > ellipse=nullptr, std::shared_ptr< CentroidParameters > centroid=nullptr, std::shared_ptr< IntegralModel > integralmodel=nullptr, std::shared_ptr< SersicMixComponentIndexParameterD > sersicindex=nullptr)
void add_extra_param_factors(const Channel &channel, ExtraParamFactors &factors) const override
Add extra Parameter gradient factors to an existing vector.
ParamCRefs & get_parameters_const(ParamCRefs ¶ms, ParamFilter *filter=nullptr) const override
Same as get_parameters(), but for const refs.
static const size_t N_PARAMS
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.
size_t get_n_gaussians(const Channel &channel) const override
Return the number of Gaussian sub-components controlled by this model.
A SersicIndexParameter for a Gaussian mixture Component.
InterpType get_interptype() const
unsigned short get_order() const
double get_sizeratio(unsigned short index) const
Return the size ratio for a given Gaussian sub-component index.
double get_integralratio_deriv(unsigned short index) const
Return the integral ratio derivative for a given Gaussian sub-component index.
SersicMixComponentIndexParameterD(double value=_get_default(), std::shared_ptr< const parameters::Limits< double > > limits=nullptr, std::shared_ptr< const parameters::Transform< double > > transform=nullptr, std::shared_ptr< const parameters::Unit > unit=nullptr, bool fixed=false, std::string label="", std::shared_ptr< const SersicMixInterpolator > interpolator=nullptr)
See docs for Parameter.
const parameters::Limits< double > & get_limits_maximal() const override
Return limits representing the maximum/minimum untransformed value.
double get_integralratio(unsigned short index) const
Return the integral ratio for a given Gaussian sub-component index.
void set_value_transformed(double value_transformed) override
static std::shared_ptr< const SersicMixInterpolator > get_interpolator_default(unsigned short order=SERSICMIX_ORDER_DEFAULT)
void set_value(double value) override
double get_sizeratio_deriv(unsigned short index) const
Return the size ratio derivative for a given Gaussian sub-component index.
std::string str() const override
Return a brief, human-readable string representation of this.
void set_value(double value) override
double get_value() const override
ParamCRefs & get_parameters_const(ParamCRefs ¶ms, ParamFilter *filter=nullptr) const override
Same as get_parameters(), but for const refs.
std::vector< std::reference_wrapper< const Channel > > get_channels() const override
Get the set of channels this instance is applicable for.
ParamRefs & get_parameters(ParamRefs ¶ms, ParamFilter *filter=nullptr) const override
Add Parameter refs matching the filter to a vector, in order.
double get_integral(const Channel &channel) const override
Get the value of the integral in a single Channel.
SersicModelIntegral(const Channel &channel, const std::shared_ptr< const IntegralModel > integralmodel, const std::shared_ptr< const SersicMixComponentIndexParameterD > sersicindex, unsigned short index)
std::vector< std::pair< ParamBaseCRef, ExtraParamFactorValues > > get_integral_derivative_factors(const Channel &channel) const override
Return the partial derivative of the model w.r.t.
double get_integralratio() const
std::string repr(bool name_keywords, std::string_view namespace_separator) const override
Return a full, callable string representation of this.
A workaround class to store a SersicParametricEllipse.
std::shared_ptr< SersicParametricEllipse > _ellipsedata
Range-based limits for parameter values.
virtual void set_value(T value)=0
Set the untransformed value for this parameter instance.
virtual void set_value_transformed(T value_transformed)=0
Set the transformed value for this parameter instance.
T get_value() const override
Return the untransformed value of this parameter instance.
void set_limits(std::shared_ptr< const Limits< T > > limits) override
Set the limits for this parameter instance.
std::string str() const override
Return a brief, human-readable string representation of this.
void insert_param(g2f::ParamBase ¶m, t ¶ms, ParamFilter *filter=nullptr)
Add a Parameter to a vector thereof, if it meets conditions.
const std::shared_ptr< const SersicMixInterpolator > get_sersic_mix_interpolator_default(unsigned short order=SERSICMIX_ORDER_DEFAULT)
const size_t N_PARAMS_GAUSS2D
Options for filtering Parameter instances.
std::optional< std::reference_wrapper< const Channel > > channel