-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
880 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef GAUSS2DFIT_GSL_H | ||
#define GAUSS2DFIT_GSL_H | ||
|
||
#ifdef GAUSS2D_FIT_HAS_GSL | ||
|
||
#include <unordered_map> | ||
|
||
#include <gsl/gsl_interp.h> | ||
|
||
#include "interpolation.h" | ||
|
||
namespace gauss2d::fit { | ||
|
||
/** | ||
* See GSL docs for 1D interpolation types, or (as of 2.7): | ||
* https://www.gnu.org/software/gsl/doc/html/interp.html#d-interpolation-types | ||
*/ | ||
static const std::unordered_map<InterpType, const gsl_interp_type*> GSLInterpTypes{ | ||
{InterpType::linear, gsl_interp_linear}, | ||
{InterpType::polynomial, gsl_interp_polynomial}, | ||
{InterpType::cspline, gsl_interp_cspline}, | ||
{InterpType::akima, gsl_interp_akima}}; | ||
} // namespace gauss2d::fit | ||
|
||
#endif // GAUSS2D_FIT_HAS_GSL | ||
#endif // GAUSS2DFIT_GSL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#ifndef GAUSS2D_FIT_GSLINTERPOLATOR_H | ||
#define GAUSS2D_FIT_GSLINTERPOLATOR_H | ||
|
||
#ifdef GAUSS2D_FIT_HAS_GSL | ||
|
||
#include "gsl.h" | ||
#include "interpolation.h" | ||
|
||
#include "gauss2d/object.h" | ||
|
||
#include <gsl/gsl_errno.h> | ||
#include <gsl/gsl_spline.h> | ||
|
||
namespace gauss2d::fit { | ||
|
||
/** | ||
* A wrapper for GSL 1D interpolators. | ||
*/ | ||
class GSLInterpolator : public Object { | ||
private: | ||
gsl_interp_accel* _acc; | ||
gsl_spline* _spline; | ||
size_t _n_knots; | ||
std::vector<double> _x; | ||
std::vector<double> _y; | ||
|
||
public: | ||
const InterpType interp_type; | ||
static constexpr InterpType INTERPTYPE_DEFAULT = InterpType::cspline; | ||
|
||
/// Get the interpolant value for a knot of the given index | ||
double get_knot_x(size_t idx) const; | ||
/// Get the interpolated function value for a knot of the given index | ||
double get_knot_y(size_t idx) const; | ||
|
||
/// Get the interpolated function value for a given interpolant value | ||
double eval(double x) const; | ||
/// Get the derivative of the interpolated function value for a given interpolant value | ||
double eval_deriv(double x) const; | ||
/// Get the number of knots | ||
size_t size() const; | ||
|
||
std::string repr(bool name_keywords = false) const override; | ||
std::string str() const override; | ||
|
||
explicit GSLInterpolator(std::vector<double> x, std::vector<double> y, | ||
InterpType interp_type = INTERPTYPE_DEFAULT); | ||
~GSLInterpolator(); | ||
}; | ||
|
||
} // namespace gauss2d::fit | ||
|
||
#endif // GAUSS2D_FIT_HAS_GSL | ||
#endif // GAUSS2D_FIT_GSLINTERPOLATOR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#ifndef GAUSS2D_FIT_GSLSERSICMIXINTERPOLATOR_H | ||
#define GAUSS2D_FIT_GSLSERSICMIXINTERPOLATOR_H | ||
|
||
#ifdef GAUSS2D_FIT_HAS_GSL | ||
|
||
#include <memory> | ||
|
||
#include "gsl.h" | ||
#include "gslinterpolator.h" | ||
#include "sersicmix.h" | ||
|
||
#include <gsl/gsl_errno.h> | ||
#include <gsl/gsl_spline.h> | ||
|
||
namespace gauss2d::fit { | ||
|
||
/** | ||
* A SersicMixInterpolator that uses GSL interpolators between knots. | ||
*/ | ||
class GSLSersicMixInterpolator : public SersicMixInterpolator { | ||
private: | ||
mutable double _final_correction = 1.; | ||
const InterpType _interp_type; | ||
const unsigned short _order; | ||
std::vector<std::pair<std::unique_ptr<GSLInterpolator>, std::unique_ptr<GSLInterpolator>>> _interps; | ||
|
||
public: | ||
bool correct_final_integral = true; | ||
static constexpr InterpType INTERPTYPE_DEFAULT = InterpType::cspline; | ||
/// The knot positions and values. | ||
const std::vector<SersicMixValues>& knots; | ||
|
||
/// Get the multiplicative factor required to adjust the integral for the final order | ||
/// component such that the sum of all integral factors is unity (normalized). | ||
double get_final_correction() const; | ||
|
||
std::vector<IntegralSize> get_integralsizes(double sersicindex) const override; | ||
std::vector<IntegralSize> get_integralsizes_derivs(double sersicindex) const override; | ||
|
||
InterpType get_interptype() const override; | ||
unsigned short get_order() const override; | ||
|
||
const double sersicindex_min; | ||
const double sersicindex_max; | ||
|
||
std::string repr(bool name_keywords = false) const override; | ||
std::string str() const override; | ||
|
||
explicit GSLSersicMixInterpolator(unsigned short order = SERSICMIX_ORDER_DEFAULT, | ||
InterpType interp_type = INTERPTYPE_DEFAULT); | ||
~GSLSersicMixInterpolator(); | ||
}; | ||
|
||
} // namespace gauss2d::fit | ||
|
||
#endif // GAUSS2D_FIT_HAS_GSL | ||
#endif // GAUSS2D_FIT_GSLSERSICMIXINTERPOLATOR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef GAUSS2DFIT_INTERPOLATION_H | ||
#define GAUSS2DFIT_INTERPOLATION_H | ||
|
||
namespace gauss2d::fit { | ||
|
||
enum class InterpType { | ||
linear, ///< Linear interpolation. | ||
polynomial, ///< Polynomial interpolation. | ||
cspline, ///< Cubic spline interpolation. | ||
akima, ///< Akima spline with natural boundary conditions. | ||
}; | ||
|
||
} // namespace gauss2d::fit | ||
|
||
#endif // GAUSS2DFIT_INTERPOLATION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* This file is part of gauss2dfit. | ||
* | ||
* Developed for the LSST Data Management System. | ||
* This product includes software developed by the LSST Project | ||
* (https://www.lsst.org). | ||
* See the COPYRIGHT file at the top-level directory of this distribution | ||
* for details of code ownership. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifdef GAUSS2D_FIT_HAS_GSL | ||
|
||
#include <pybind11/attr.h> | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
|
||
#include "pybind11.h" | ||
|
||
#include "gauss2d/fit/gsl.h" | ||
|
||
namespace py = pybind11; | ||
using namespace pybind11::literals; | ||
|
||
namespace g2f = gauss2d::fit; | ||
|
||
void bind_gsl(py::module &m) { | ||
// Placeholder for now - Python doesn't need to know about gsl_interp_type | ||
} | ||
|
||
#endif // GAUSS2D_FIT_HAS_GSL |
Oops, something went wrong.