CARTA Backend
The backend component of CARTA
Loading...
Searching...
No Matches
carta::ImageFitter Class Reference

A class for fitting multiple Gaussian components to an image and generating model and residual images. More...

#include <ImageFitter.h>

Collaboration diagram for carta::ImageFitter:
[legend]

Public Member Functions

 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.
 

Private Member Functions

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 Private Member Functions

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.
 

Private Attributes

FitData _fit_data
 Fitting-related data.
 
double _image_std
 Standard deviation of the image data.
 
double _beam_size
 Beam size of the image.
 
string _unit
 Unit of the image.
 
size_t _num_components
 Number of Gaussian components.
 
gsl_vector * _fit_values
 Fitting parameter values.
 
gsl_vector * _fit_errors
 Fitting parameter errors.
 
std::vector< double > _integrated_flux_values
 Integrated flux values of components.
 
std::vector< double > _integrated_flux_errors
 Integrated flux errors of components.
 
gsl_multifit_nlinear_fdf _fdf
 Object for the fitting model.
 
FitStatus _fit_status
 Status of the fitting result.
 
bool _create_model_data
 Whether to create a model image.
 
bool _create_residual_data
 Whether to create a residual image.
 
std::vector< float > _model_data
 Model image data.
 
std::vector< float > _residual_data
 Residual image data.
 
const size_t _max_iter = 200
 Maximum number of fitting iterations.
 
GeneratorProgressCallback _progress_callback
 Callback function for updating fitting progress.
 

Detailed Description

A class for fitting multiple Gaussian components to an image and generating model and residual images.

Constructor & Destructor Documentation

◆ ImageFitter()

ImageFitter::ImageFitter ( )

Constructor for the ImageFitter class.

Here is the call graph for this function:

Member Function Documentation

◆ CalculateErrors()

void ImageFitter::CalculateErrors ( )
private

Calculate parameter errors after fitting.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CalculateImageData()

void ImageFitter::CalculateImageData ( const gsl_vector *  residual)
private

Calculate the model and residual image data after fitting.

Parameters
residualPointer to the residual values
Here is the caller graph for this function:

◆ CalculateNanNumAndStd()

void ImageFitter::CalculateNanNumAndStd ( )
private

Calculate the number of NaN values and standard deviation of the image data.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
iterThe current iteration number
paramsFitting parameters
wThe workspace for the fitting
Here is the caller graph for this function:

◆ ErrorHandler()

void ImageFitter::ErrorHandler ( const char *  reason,
const char *  file,
int  line,
int  gsl_errno 
)
staticprivate

Customize GSL errors.

Parameters
reasonThe error reason
fileThe source file where the error occurred
lineThe line number where the error occurred
gsl_errnoThe GSL error number
Here is the caller graph for this function:

◆ 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
widthThe width of the image
heightThe height of the image
imagePointer to the image data
beam_sizeBeam size of the image
unitUnit of the image
initial_valuesInitial fitting parameters
fixed_paramsWhether the fitting parameters are fixed
background_offsetBackground offset of the image
solverThe type of solver to use.
create_model_imageWhether to create a model image
create_residual_imageWhether to create a residual image
fitting_responseThe fitting response message
progress_callbackCallback function for updating fitting progress
offset_xX-axis offset from the fitting region to the entire image
offset_yY-axis offset from the fitting region to the entire image
Returns
Whether the fitting is successful
Here is the call graph for this function:

◆ 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_paramsFitting parameters
fit_dataFitting-related data
fThe residual of the image data
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFilename()

std::string ImageFitter::GetFilename ( const std::string &  filename,
std::string  suffix 
)
private

Generate filenames by adding a suffix.

Parameters
filenameName of the fitting image file
suffixThe suffix to add
Returns
The modified filename
Here is the caller graph for this function:

◆ 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
paramsTuple containing Gaussian parameters
Returns
A Gaussian component sub-message
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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_vectorThe vector containing fitting parameters
indexThe index of the Gaussian component
fit_values_indexesIndexes of the Gaussian parameters in the fittig parameters
initial_valuesInitial fitting parameter
offset_xX-axis offset from the fitting region to the entire image
offset_yY-axis offset from the fitting region to the entire image
Returns
A tuple of Gaussian parameters
Here is the caller graph for this function:

◆ 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
imagePointer to the casacore ImageInterface object
image_regionThe fitting region
file_idID of the fitting image file
filenameName of the fitting image file
model_imageThe generated model image
residual_imageThe generated residual image
fitting_responseThe fitting response message
Returns
Whether the images are successfully generated
Here is the call graph for this function:

◆ 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
filenameName of the fitting image file
suffixThe 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
imageThe casacore ImageInterface object of the entire image
image_regionThe fitting region
image_dataThe image data for the generated casacore ImageInterface object
Returns
A casacore ImageInterface object
Here is the caller graph for this function:

◆ GetLog()

std::string ImageFitter::GetLog ( )
private

Retrieve a log message describing the fitting status.

Returns
The log message
Here is the caller graph for this function:

◆ GetMedianAbsDeviation()

double ImageFitter::GetMedianAbsDeviation ( const size_t  n,
double  x[] 
)
staticprivate

Calculate the Median Absolute Deviation (MAD) of an array of data.

Parameters
nThe number of data points in the array.
xAn array containing the data points.
Returns
The calculated MAD.
Here is the caller graph for this function:

◆ 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_valuesInitial fitting parameters
background_offsetBackground offset of the image
fixed_paramsWhether the fitting parameters are fixed
Here is the caller graph for this function:

◆ SolveSystem()

int ImageFitter::SolveSystem ( CARTA::FittingSolverType  solver)
private

Main function for the multiple Gaussian image fitting.

Parameters
solverThe type of solver to use
Returns
The status of the fitting
Here is the call graph for this function:
Here is the caller graph for this function:

◆ StopFitting()

void ImageFitter::StopFitting ( )

Stop the ongoing fitting process.

Member Data Documentation

◆ _beam_size

double carta::ImageFitter::_beam_size
private

Beam size of the image.

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

Fitting-related data.

◆ _fit_errors

gsl_vector* carta::ImageFitter::_fit_errors
private

Fitting parameter errors.

◆ _fit_status

FitStatus carta::ImageFitter::_fit_status
private

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

Model image data.

◆ _num_components

size_t carta::ImageFitter::_num_components
private

Number of Gaussian components.

◆ _progress_callback

GeneratorProgressCallback carta::ImageFitter::_progress_callback
private

Callback function for updating fitting progress.

◆ _residual_data

std::vector<float> carta::ImageFitter::_residual_data
private

Residual image data.

◆ _unit

string carta::ImageFitter::_unit
private

Unit of the image.


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