A class for fitting multiple Gaussian components to an image and generating model and residual images.
More...
#include <ImageFitter.h>
|
| ImageFitter () |
| Constructor for the ImageFitter class.
|
|
bool | FitImage (size_t width, size_t height, float *image, double beam_size, string unit, const std::vector< CARTA::GaussianComponent > &initial_values, const std::vector< bool > &fixed_params, double background_offset, CARTA::FittingSolverType solver, bool create_model_image, bool create_residual_image, CARTA::FittingResponse &fitting_response, GeneratorProgressCallback progress_callback, size_t offset_x=0, size_t offset_y=0) |
| Fit Gaussian components to an image and generate fitting results along with model and residual data.
|
|
bool | GetGeneratedImages (std::shared_ptr< casacore::ImageInterface< float > > image, const casacore::ImageRegion &image_region, const std::string &filename, GeneratedImage &model_image, GeneratedImage &residual_image, CARTA::FittingResponse &fitting_response) |
| Generate model and residual images based on the fitting results.
|
|
void | StopFitting () |
| Stop the ongoing fitting process.
|
|
|
void | CalculateNanNumAndStd () |
| Calculate the number of NaN values and standard deviation of the image data.
|
|
void | SetInitialValues (const std::vector< CARTA::GaussianComponent > &initial_values, double background_offset, const std::vector< bool > &fixed_params) |
| Set initial fitting parameters for the fitting.
|
|
int | SolveSystem (CARTA::FittingSolverType solver) |
| Main function for the multiple Gaussian image fitting.
|
|
void | CalculateErrors () |
| Calculate parameter errors after fitting.
|
|
void | CalculateImageData (const gsl_vector *residual) |
| Calculate the model and residual image data after fitting.
|
|
std::string | GetLog () |
| Retrieve a log message describing the fitting status.
|
|
casa::SPIIF | GetImageData (casa::SPIIF image, const casacore::ImageRegion &image_region, std::vector< float > image_data) |
| Generate a casacore ImageInterface object from the provided image data.
|
|
std::string | GetFilename (const std::string &filename, std::string suffix) |
| Generate filenames by adding a suffix.
|
|
std::string | GetGeneratedMomentFilename (const std::string &filename, std::string suffix) |
| Generate filenames by adding a suffix for generated moment images.
|
|
|
static int | FuncF (const gsl_vector *fit_params, void *fit_data, gsl_vector *f) |
| Calculate the residual of the image data with the provided fitting parameters.
|
|
static void | Callback (const size_t iter, void *params, const gsl_multifit_nlinear_workspace *w) |
| Called after each iteration of the fitting.
|
|
static void | ErrorHandler (const char *reason, const char *file, int line, int gsl_errno) |
| Customize GSL errors.
|
|
static std::tuple< double, double, double, double, double, double > | GetGaussianParams (const gsl_vector *value_vector, size_t index, std::vector< int > &fit_values_indexes, std::vector< double > &initial_values, size_t offset_x=0, size_t offset_y=0) |
| Extract Gaussian parameters from a vector.
|
|
static CARTA::GaussianComponent | GetGaussianComponent (std::tuple< double, double, double, double, double, double > params) |
| Create a Gaussian component sub-message from Gaussian parameters.
|
|
static double | GetMedianAbsDeviation (const size_t n, double x[]) |
| Calculate the Median Absolute Deviation (MAD) of an array of data.
|
|
A class for fitting multiple Gaussian components to an image and generating model and residual images.
◆ ImageFitter()
ImageFitter::ImageFitter |
( |
| ) |
|
◆ CalculateErrors()
void ImageFitter::CalculateErrors |
( |
| ) |
|
|
private |
Calculate parameter errors after fitting.
◆ CalculateImageData()
void ImageFitter::CalculateImageData |
( |
const gsl_vector * |
residual | ) |
|
|
private |
Calculate the model and residual image data after fitting.
- Parameters
-
residual | Pointer to the residual values |
◆ CalculateNanNumAndStd()
void ImageFitter::CalculateNanNumAndStd |
( |
| ) |
|
|
private |
Calculate the number of NaN values and standard deviation of the image data.
◆ Callback()
void ImageFitter::Callback |
( |
const size_t |
iter, |
|
|
void * |
params, |
|
|
const gsl_multifit_nlinear_workspace * |
w |
|
) |
| |
|
staticprivate |
Called after each iteration of the fitting.
- Parameters
-
iter | The current iteration number |
params | Fitting parameters |
w | The workspace for the fitting |
◆ ErrorHandler()
void ImageFitter::ErrorHandler |
( |
const char * |
reason, |
|
|
const char * |
file, |
|
|
int |
line, |
|
|
int |
gsl_errno |
|
) |
| |
|
staticprivate |
Customize GSL errors.
- Parameters
-
reason | The error reason |
file | The source file where the error occurred |
line | The line number where the error occurred |
gsl_errno | The GSL error number |
◆ FitImage()
bool ImageFitter::FitImage |
( |
size_t |
width, |
|
|
size_t |
height, |
|
|
float * |
image, |
|
|
double |
beam_size, |
|
|
string |
unit, |
|
|
const std::vector< CARTA::GaussianComponent > & |
initial_values, |
|
|
const std::vector< bool > & |
fixed_params, |
|
|
double |
background_offset, |
|
|
CARTA::FittingSolverType |
solver, |
|
|
bool |
create_model_image, |
|
|
bool |
create_residual_image, |
|
|
CARTA::FittingResponse & |
fitting_response, |
|
|
GeneratorProgressCallback |
progress_callback, |
|
|
size_t |
offset_x = 0 , |
|
|
size_t |
offset_y = 0 |
|
) |
| |
Fit Gaussian components to an image and generate fitting results along with model and residual data.
- Parameters
-
width | The width of the image |
height | The height of the image |
image | Pointer to the image data |
beam_size | Beam size of the image |
unit | Unit of the image |
initial_values | Initial fitting parameters |
fixed_params | Whether the fitting parameters are fixed |
background_offset | Background offset of the image |
solver | The type of solver to use. |
create_model_image | Whether to create a model image |
create_residual_image | Whether to create a residual image |
fitting_response | The fitting response message |
progress_callback | Callback function for updating fitting progress |
offset_x | X-axis offset from the fitting region to the entire image |
offset_y | Y-axis offset from the fitting region to the entire image |
- Returns
- Whether the fitting is successful
◆ FuncF()
int ImageFitter::FuncF |
( |
const gsl_vector * |
fit_params, |
|
|
void * |
fit_data, |
|
|
gsl_vector * |
f |
|
) |
| |
|
staticprivate |
Calculate the residual of the image data with the provided fitting parameters.
- Parameters
-
fit_params | Fitting parameters |
fit_data | Fitting-related data |
f | The residual of the image data |
◆ GetFilename()
std::string ImageFitter::GetFilename |
( |
const std::string & |
filename, |
|
|
std::string |
suffix |
|
) |
| |
|
private |
Generate filenames by adding a suffix.
- Parameters
-
filename | Name of the fitting image file |
suffix | The suffix to add |
- Returns
- The modified filename
◆ GetGaussianComponent()
CARTA::GaussianComponent ImageFitter::GetGaussianComponent |
( |
std::tuple< double, double, double, double, double, double > |
params | ) |
|
|
staticprivate |
Create a Gaussian component sub-message from Gaussian parameters.
- Parameters
-
params | Tuple containing Gaussian parameters |
- Returns
- A Gaussian component sub-message
◆ GetGaussianParams()
std::tuple< double, double, double, double, double, double > ImageFitter::GetGaussianParams |
( |
const gsl_vector * |
value_vector, |
|
|
size_t |
index, |
|
|
std::vector< int > & |
fit_values_indexes, |
|
|
std::vector< double > & |
initial_values, |
|
|
size_t |
offset_x = 0 , |
|
|
size_t |
offset_y = 0 |
|
) |
| |
|
staticprivate |
Extract Gaussian parameters from a vector.
- Parameters
-
value_vector | The vector containing fitting parameters |
index | The index of the Gaussian component |
fit_values_indexes | Indexes of the Gaussian parameters in the fittig parameters |
initial_values | Initial fitting parameter |
offset_x | X-axis offset from the fitting region to the entire image |
offset_y | Y-axis offset from the fitting region to the entire image |
- Returns
- A tuple of Gaussian parameters
◆ GetGeneratedImages()
bool ImageFitter::GetGeneratedImages |
( |
std::shared_ptr< casacore::ImageInterface< float > > |
image, |
|
|
const casacore::ImageRegion & |
image_region, |
|
|
const std::string & |
filename, |
|
|
GeneratedImage & |
model_image, |
|
|
GeneratedImage & |
residual_image, |
|
|
CARTA::FittingResponse & |
fitting_response |
|
) |
| |
Generate model and residual images based on the fitting results.
- Parameters
-
image | Pointer to the casacore ImageInterface object |
image_region | The fitting region |
file_id | ID of the fitting image file |
filename | Name of the fitting image file |
model_image | The generated model image |
residual_image | The generated residual image |
fitting_response | The fitting response message |
- Returns
- Whether the images are successfully generated
◆ GetGeneratedMomentFilename()
std::string carta::ImageFitter::GetGeneratedMomentFilename |
( |
const std::string & |
filename, |
|
|
std::string |
suffix |
|
) |
| |
|
private |
Generate filenames by adding a suffix for generated moment images.
- Parameters
-
filename | Name of the fitting image file |
suffix | The suffix to add |
- Returns
- The modified filename
◆ GetImageData()
casa::SPIIF ImageFitter::GetImageData |
( |
casa::SPIIF |
image, |
|
|
const casacore::ImageRegion & |
image_region, |
|
|
std::vector< float > |
image_data |
|
) |
| |
|
private |
Generate a casacore ImageInterface object from the provided image data.
- Parameters
-
image | The casacore ImageInterface object of the entire image |
image_region | The fitting region |
image_data | The image data for the generated casacore ImageInterface object |
- Returns
- A casacore ImageInterface object
◆ GetLog()
std::string ImageFitter::GetLog |
( |
| ) |
|
|
private |
Retrieve a log message describing the fitting status.
- Returns
- The log message
◆ GetMedianAbsDeviation()
double ImageFitter::GetMedianAbsDeviation |
( |
const size_t |
n, |
|
|
double |
x[] |
|
) |
| |
|
staticprivate |
Calculate the Median Absolute Deviation (MAD) of an array of data.
- Parameters
-
n | The number of data points in the array. |
x | An array containing the data points. |
- Returns
- The calculated MAD.
◆ SetInitialValues()
void ImageFitter::SetInitialValues |
( |
const std::vector< CARTA::GaussianComponent > & |
initial_values, |
|
|
double |
background_offset, |
|
|
const std::vector< bool > & |
fixed_params |
|
) |
| |
|
private |
Set initial fitting parameters for the fitting.
- Parameters
-
initial_values | Initial fitting parameters |
background_offset | Background offset of the image |
fixed_params | Whether the fitting parameters are fixed |
◆ SolveSystem()
int ImageFitter::SolveSystem |
( |
CARTA::FittingSolverType |
solver | ) |
|
|
private |
Main function for the multiple Gaussian image fitting.
- Parameters
-
solver | The type of solver to use |
- Returns
- The status of the fitting
◆ StopFitting()
void ImageFitter::StopFitting |
( |
| ) |
|
Stop the ongoing fitting process.
◆ _beam_size
double carta::ImageFitter::_beam_size |
|
private |
◆ _create_model_data
bool carta::ImageFitter::_create_model_data |
|
private |
Whether to create a model image.
◆ _create_residual_data
bool carta::ImageFitter::_create_residual_data |
|
private |
Whether to create a residual image.
◆ _fdf
gsl_multifit_nlinear_fdf carta::ImageFitter::_fdf |
|
private |
Object for the fitting model.
◆ _fit_data
FitData carta::ImageFitter::_fit_data |
|
private |
◆ _fit_errors
gsl_vector* carta::ImageFitter::_fit_errors |
|
private |
Fitting parameter errors.
◆ _fit_status
Status of the fitting result.
◆ _fit_values
gsl_vector* carta::ImageFitter::_fit_values |
|
private |
Fitting parameter values.
◆ _image_std
double carta::ImageFitter::_image_std |
|
private |
Standard deviation of the image data.
◆ _integrated_flux_errors
std::vector<double> carta::ImageFitter::_integrated_flux_errors |
|
private |
Integrated flux errors of components.
◆ _integrated_flux_values
std::vector<double> carta::ImageFitter::_integrated_flux_values |
|
private |
Integrated flux values of components.
◆ _max_iter
const size_t carta::ImageFitter::_max_iter = 200 |
|
private |
Maximum number of fitting iterations.
◆ _model_data
std::vector<float> carta::ImageFitter::_model_data |
|
private |
◆ _num_components
size_t carta::ImageFitter::_num_components |
|
private |
Number of Gaussian components.
◆ _progress_callback
Callback function for updating fitting progress.
◆ _residual_data
std::vector<float> carta::ImageFitter::_residual_data |
|
private |
◆ _unit
string carta::ImageFitter::_unit |
|
private |
The documentation for this class was generated from the following files: