diff --git a/SConstruct b/SConstruct index 372a100..bffac73 100644 --- a/SConstruct +++ b/SConstruct @@ -541,7 +541,7 @@ if doExtraChecks: # default is to NOT do this; user must specify with "--extra "-Wextra", "-pedantic"]) # which dialect/version of C++ are we using? -if useModernCpp: +if useModernCpp: # command-line option "--modern-cpp" cflags_opt.append("-std=c++17") cflags_db.append("-std=c++17") else: @@ -601,6 +601,9 @@ env = Environment( CC=CC_COMPILER, CXX=CPP_COMPILER, CPPPATH=include_path, LIBS= env_debug = Environment( CC=CC_COMPILER, CXX=CPP_COMPILER, CPPPATH=include_path, LIBS=lib_list, LIBPATH=lib_path, CCFLAGS=cflags_db, LINKFLAGS=link_flags, CPPDEFINES=defines_db, ENV = {'PATH' : os.environ['PATH']} ) +# env_multi = Environment( CC=CC_COMPILER, CXX=CPP_COMPILER, CPPPATH=include_path, LIBS=lib_list, +# LIBPATH=lib_path, CCFLAGS=cflags_db, LINKFLAGS=link_flags, +# CPPDEFINES=defines_opt ) lib_list_nofits = copy.copy(lib_list) if "nlopt" in lib_list_nofits: lib_list_nofits.remove("nlopt") @@ -768,6 +771,25 @@ if useLogging: mcmc_base_objs = mcmc_base_objs + base_objs + image_io_objs + cdream_objs mcmc_base_sources = [name + ".cpp" for name in mcmc_base_objs] +# Main set of files for multimfit +multimfit_obj_string = """print_results print_results_multi bootstrap_errors +estimate_memory multimfit_main model_object_multimage read_simple_params +paramvector_processing param_holder imageparams_file_parser store_psf_oversampling +utilities_multimfit""" +multimfit_base_objs = [ CORE_SUBDIR + name for name in multimfit_obj_string.split() ] +multimfit_base_objs = base_objs + image_io_objs + multimfit_base_objs +multimfit_base_sources = [name + ".cpp" for name in multimfit_base_objs] + +# Main set of files for makemultimages +makemultimages_obj_string = """makemultimages_main model_object_multimage +read_simple_params paramvector_processing param_holder imageparams_file_parser +store_psf_oversampling""" +makemultimages_base_objs = [ CORE_SUBDIR + name for name in makemultimages_obj_string.split() ] +if useLogging: + makemultimages_base_objs.append("loguru/loguru") +makemultimages_base_objs = base_objs + image_io_objs + makemultimages_base_objs +makemultimages_base_sources = [name + ".cpp" for name in makemultimages_base_objs] + # imfit: put all the object and source-code lists together imfit_objs = imfit_base_objs + modelobject_objs + functionobject_objs + solver_objs @@ -781,6 +803,16 @@ makeimage_sources = makeimage_base_sources + modelobject_sources + functionobjec mcmc_objs = mcmc_base_objs + modelobject_objs + functionobject_objs mcmc_sources = mcmc_base_sources + modelobject_sources + functionobject_sources +# makemultimages: put all the object and source-code lists together +# makemultimages_objs = makemultimages_base_objs + modelobject_objs + functionobject_objs +# makemultimages_sources = makemultimages_base_sources + modelobject_sources + functionobject_sources +makemultimages_objs = makemultimages_base_objs + modelobject_objs + functionobject_objs +makemultimages_sources = makemultimages_base_sources + modelobject_sources + functionobject_sources + +# multimfit: put all the object and source-code lists together +multimfit_objs = multimfit_base_objs + modelobject_objs + functionobject_objs + solver_objs +multimfit_sources = multimfit_base_sources + modelobject_sources + functionobject_sources + solver_sources + # import environment variables if we're doing scan-build static analysis if scanBuild: @@ -804,6 +836,12 @@ mcmc_dbg_objlist = [ env_debug.Object(obj + ".do", src) for (obj,src) in zip(mcm env_debug.Program("imfit-mcmc_db", mcmc_dbg_objlist) env.Program("imfit-mcmc", mcmc_sources) +multi_objlist = [ env.Object(obj, src) for (obj,src) in zip(makemultimages_objs, makemultimages_sources) ] +env.Program("makemultimages", multi_objlist) + +# multimfit_objlist = [ env_multi.Object(obj, src) for (obj,src) in zip(multimfit_objs, multimfit_sources) ] +# env_multi.Program("multimfit", multimfit_objlist) + # Run tests # Unit tests: diff --git a/core/add_functions.cpp b/core/add_functions.cpp index c738d7d..b7c0892 100644 --- a/core/add_functions.cpp +++ b/core/add_functions.cpp @@ -8,7 +8,7 @@ * */ -// Copyright 2010--2023 by Peter Erwin. +// Copyright 2010--2024 by Peter Erwin. // // This file is part of Imfit. // @@ -389,12 +389,14 @@ void PopulateFactoryMap( map& input_factory_map ) int AddFunctions( ModelObject *theModel, const vector &functionNameList, vector &functionLabelList, vector &functionSetIndices, const bool subsamplingFlag, const int verboseLevel, - vector< map > &extraParams ) + vector< map > &extraParams, + const vector &globalFuncFlags ) { int nFunctions = functionNameList.size(); int status; string currentName; bool extraParamsMayExist = false; + bool globalFuncFlagsExist = false; FunctionObject *thisFunctionObj; map factory_map; @@ -402,6 +404,8 @@ int AddFunctions( ModelObject *theModel, const vector &functionNameList, if (extraParams.size() > 0) extraParamsMayExist = true; + if (globalFuncFlags.size() > 0) + globalFuncFlagsExist = true; for (int i = 0; i < nFunctions; i++) { currentName = functionNameList[i]; @@ -431,7 +435,10 @@ int AddFunctions( ModelObject *theModel, const vector &functionNameList, } } } - status = theModel->AddFunction(thisFunctionObj); + if (globalFuncFlagsExist) + status = theModel->AddFunction(thisFunctionObj, globalFuncFlags[i]); + else + status = theModel->AddFunction(thisFunctionObj); if (status < 0) { fprintf(stderr, "Error attempting to add function \"%s\" (#%d in list)", thisFunctionObj->GetShortName().c_str(), i + 1); diff --git a/core/add_functions.h b/core/add_functions.h index 1a98e43..b9b212a 100644 --- a/core/add_functions.h +++ b/core/add_functions.h @@ -13,7 +13,8 @@ using namespace std; -static vector< map > EMPTY_MAP_VECTOR; +// static vector< map > EMPTY_MAP_VECTOR; +static vector EMPTY_BOOL_VECTOR; // NOTE: (some of) the following functions are used in PyImfit @@ -22,7 +23,8 @@ static vector< map > EMPTY_MAP_VECTOR; int AddFunctions( ModelObject *theModel, const vector &functionNameList, vector &functionLabelList, vector &functionSetIndices, const bool subamplingFlag, const int verboseFlag=0, - vector< map > &extraParams=EMPTY_MAP_VECTOR ); + vector< map > &extraParams=EMPTY_MAP_VECTOR, + const vector &globalFuncFlags=EMPTY_BOOL_VECTOR ); //! Prints out names of available image functions (FunctionObject classes) to stdout void PrintAvailableFunctions( ); diff --git a/core/definitions.h b/core/definitions.h index cc47d21..5aace98 100644 --- a/core/definitions.h +++ b/core/definitions.h @@ -98,4 +98,6 @@ const std::string Y0_string("Y0"); #define PARAM_FORMAT_WITH_FIXED "%s%s\t\t%7g\t\tfixed" #define UNITS_FORMAT "\t%s%s" +static vector< map > EMPTY_MAP_VECTOR; + #endif /* _DEFINITIONS_H_ */ diff --git a/core/definitions_multimage.h b/core/definitions_multimage.h new file mode 100644 index 0000000..f541799 --- /dev/null +++ b/core/definitions_multimage.h @@ -0,0 +1,116 @@ +/** @file + \brief Generally useful definitions & constants for multimfit, etc. + + */ + +#ifndef _DEFINITIONS_MULTIMAGE_H_ +#define _DEFINITIONS_MULTIMAGE_H_ + +#include +#include +#include + +#include "definitions.h" +#include "param_struct.h" + +using namespace std; + +const int N_IMAGE_DESCRIPTION_PARAMS = 3; // pixScale, rotation, intensityScale +const int N_IMAGE_PARAMS = 5; // pixScale, rotation, intensityScale, X0_0, Y0_0 + +#define DEFAULT_MAKEMULTIMAGE_OUTPUT_FILENAME "modelimage_multi" + +#define DEFAULT_BESTFIT_ROOTNAME "bestfit_parameters_multimfit" + + + + +class ImageInfo +{ + + public: + // Constructor: + ImageInfo( ) + { + dataImage_present = false; + dataImageFileName = ""; + weight = 1.0; + gain = expTime = 1.0; + readNoise = 0.0; + originalSky = 0.0; + nCombined = 1; + maskImage_present = false; + maskImageFileName = ""; + maskFormat = MASK_ZERO_IS_GOOD; + errorImage_present = false; + errorImageFileName = ""; + errorType = WEIGHTS_ARE_SIGMAS; + psfImage_present = false; + psfImageFileName = ""; + + nOversampledFileNames = 0; + psfOversampledImage_present = false; + nOversamplingScales = 0; + //psfOversampledFileName = ""; + //psfOversamplingScale = 0; + oversampleRegionSet = false; + nOversampleRegions = 0; + + nColumns = nRows = 0; + x0 = y0 = 0.0; + + pixelScale = intensityScale = 1.0; + rotation = 0.0; + + bzero(&pixelScale_limitInfo, sizeof(mp_par)); + bzero(&rotation_limitInfo, sizeof(mp_par)); + bzero(&intensityScale_limitInfo, sizeof(mp_par)); + bzero(&x0_limitInfo, sizeof(mp_par)); + bzero(&y0_limitInfo, sizeof(mp_par)); + + perImageFunctionsExist = false; + } + + string dataImageFileName; + string maskImageFileName; + int maskFormat; + string errorImageFileName; + int errorType; + string psfImageFileName; + double weight, gain, readNoise, originalSky, expTime; + int nCombined; + double x0, y0; + int nColumns, nRows; + double pixelScale, intensityScale, rotation; + + bool dataImage_present, maskImage_present, errorImage_present; + bool psfImage_present; + + vector psfOversampledFileNames; + int nOversampledFileNames; + bool psfOversampledImage_present; + vector psfOversamplingScales; + int nOversamplingScales; + bool oversampleRegionSet; + int nOversampleRegions; + vector psfOversampleRegions; + + // stuff for per-image functions, if any + bool perImageFunctionsExist; + vector perImageFuncNames; + vector perImageFuncLabels; + vector perImageFuncSetIndices; + vector perImageParamVals; + bool perImageParamLimitsExist; + vector perImageParamLimits; + + + mp_par pixelScale_limitInfo; + mp_par rotation_limitInfo; + mp_par intensityScale_limitInfo; + mp_par x0_limitInfo; + mp_par y0_limitInfo; +}; + + +#endif /* _DEFINITIONS_MULTIMAGE_H_ */ diff --git a/core/model_object.cpp b/core/model_object.cpp index 5515661..747780e 100644 --- a/core/model_object.cpp +++ b/core/model_object.cpp @@ -276,7 +276,7 @@ void ModelObject::SetOMPChunkSize( int chunkSize ) /* ---------------- PUBLIC METHOD: AddFunction ------------------------- */ /// Adds a FunctionObject subclass to the model -int ModelObject::AddFunction( FunctionObject *newFunctionObj_ptr ) +int ModelObject::AddFunction( FunctionObject *newFunctionObj_ptr, bool isGlobalFunc ) { int nNewParams, result; @@ -285,6 +285,11 @@ int ModelObject::AddFunction( FunctionObject *newFunctionObj_ptr ) nNewParams = newFunctionObj_ptr->GetNParams(); paramSizes.push_back(nNewParams); nFunctionParams += nNewParams; + // multimfit-related + // FIXME: this is just a stub right now (assuming all functions are global) + globalFunctionFlags.push_back(isGlobalFunc); + if (isGlobalFunc) + nGlobalFunctions += 1; // handle optional case of PointSource function if (newFunctionObj_ptr->IsPointSource()) { @@ -303,6 +308,35 @@ int ModelObject::AddFunction( FunctionObject *newFunctionObj_ptr ) } +/* ---------------- PUBLIC METHOD: FinalModelSetup -------------------- */ +/// Do any final setup involving determination of parameter numbers (including +/// accounting for global vs per-image functions in multimfit mode) +// +// We assume that the following has already occurred: +// 1. all functions have been added via repeated calls to AddFunction() +// 2. DefineFunctionSets(functionSetIndices) has been called; +// 3. PopulateParameterNames() has been called +int ModelObject::FinalModelSetup( ) +{ + // The only thing we really do is count up the number of per-image parameters, + // *if* there are any per-image functions + if (nFunctions > nGlobalFunctions) + { + // OK, there are some local, per-image functions + // 1. Count up the function parameters; 2 Add 2 for each new function set + for (int i = nGlobalFunctions; i < nFunctions; i++) { + nPerImageParams += functionObjects[i]->GetNParams(); + if (fsetStartFlags[i]) { + nPerImageParams += 2; + nPerImageFunctionSets += 1; + } + } + } + + return 0; +} + + /* ---------------- PUBLIC METHOD: SetupPsfInterpolation -------------- */ /// Specify that PSF interpolation (by PointSource functions) will be used; /// causes an internal PsfInterpolator object of the appropriate subclass @@ -1046,6 +1080,24 @@ int ModelObject::FinalSetupForFitting( ) +// Tells individual FunctionObject instances about image-description parameters +// (pixel scale, overall rotation, intensity scaling). +// For use by multimfit, etc. +/* ---------------- PUBLIC METHOD: SetImageParameters ------------------ */ + +void ModelObject::SetImageParameters( double imageDescriptionParams[] ) +{ + double pixScale = imageDescriptionParams[0]; + double rotation = imageDescriptionParams[1]; + double intensityScale = imageDescriptionParams[2]; + + for (int i = 0; i < nFunctions; i++) { + if (globalFunctionFlags[i]) + functionObjects[i]->SetImageParameters(pixScale, rotation, intensityScale); + } +} + + /* ---------------- PUBLIC METHOD: CreateModelImage -------------------- */ void ModelObject::CreateModelImage( double params[] ) @@ -2339,6 +2391,22 @@ double * ModelObject::GetDataVector( ) } +/* ---------------- PUBLIC METHOD: AddDataFilename --------------------- */ + +void ModelObject::AddDataFilename( string filename ) +{ + dataFilename = filename; +} + + +/* ---------------- PUBLIC METHOD: GetDataFilename --------------------- */ +/// Returns the name of the input data file (e.g., FITS image) +string ModelObject::GetDataFilename( ) +{ + return dataFilename; +} + + /* ---------------- PUBLIC METHOD: FindTotalFluxes --------------------- */ /// Estimate total fluxes for individual components (and entire model) by integrating /// over a very large image, with each component/function centered in the image. @@ -2498,6 +2566,13 @@ bool ModelObject::CheckWeightVector( ) } +void ModelObject::GetDataImageDimensions( int *nColumns, int *nRows ) +{ + *nColumns = nDataColumns; + *nRows = nDataRows; +} + + // Extra stuff diff --git a/core/model_object.h b/core/model_object.h index 57eea0e..7b81eac 100644 --- a/core/model_object.h +++ b/core/model_object.h @@ -54,7 +54,7 @@ class ModelObject // Adds a new FunctionObject pointer to the internal vector // (Overridden by ModelObjectMultImage) - virtual int AddFunction( FunctionObject *newFunctionObj_ptr ); + virtual int AddFunction( FunctionObject *newFunctionObj_ptr, bool isGlobalFunc=true ); // 2D only int SetupPsfInterpolation( int interpolationType=kInterpolator_bicubic ); @@ -125,6 +125,9 @@ class ModelObject virtual void ApplyMask( ); + // [x] used in multimfit-related programs + virtual void SetImageParameters( double imageDescriptionParams[] ); + // common, but specialized by ModelObject1D virtual void CreateModelImage( double params[] ); @@ -196,6 +199,9 @@ class ModelObject // common, but specialized by ModelObject1D virtual int FinalSetupForFitting( ); + // [x] overridden in ModelObjectMultImage + virtual int FinalModelSetup( ); + string& GetParameterName( int i ); int GetNFunctions( ); @@ -213,7 +219,7 @@ class ModelObject bool HasOversampledPSF( ); bool HasMask( ); - // 2D only + // 2D only (overridden in ModelObjectMultImage) virtual double * GetModelImageVector( ); // 2D only @@ -228,6 +234,12 @@ class ModelObject // 2D only double * GetDataVector( ); + // [x] NEW FOR MODEL_OBJECT (used in multimfit_main.cpp) + void AddDataFilename( string filename ); + + // [x] NEW FOR MODEL_OBJECT; overriden in model_object_multimage (used in model_object_multimage; print_results_multi.cpp) + string GetDataFilename( ); + // 2D only double FindTotalFluxes(double params[], int xSize, int ySize, double individualFluxes[] ); @@ -247,6 +259,9 @@ class ModelObject virtual int UseBootstrap( ); virtual int MakeBootstrapSample( ); + + // [x] 2D only (used in model_object_multimage.cpp) + void GetDataImageDimensions( int *nColumns, int *nRows ); protected: @@ -285,7 +300,13 @@ class ModelObject bool extraCashTermsVectorAllocated; bool localPsfPixels_allocated; bool zeroPointSet; - int nFunctions, nFunctionSets, nFunctionParams, nParamsTot; + int nFunctions, nFunctionSets; + int nFunctionParams; // all function parameters (*excluding* X0,Y0) + // nParamsTot = *all* parameters, including X0,Y0 for each function set + // (for ModelObjectMultImage subclass, this includes parameters for per-image + // functions and image-description parameters). This is always the size of + // the parameter vector. + int nParamsTot; double *dataVector; double *weightVector, *standardWeightVector; double *maskVector; @@ -302,6 +323,7 @@ class ModelObject vector parameterLabels; vector parameterInfoVect; int imageOffset_X0, imageOffset_Y0; + string dataFilename; PsfInterpolator *psfInterpolator; bool psfInterpolator_allocated; @@ -315,7 +337,13 @@ class ModelObject int nOversampledRegions; vectoroversampledRegionsVect; - + // multimfit-related + // specifies which functions are part of main/global model (true) and which are + // local to just this image (false) + vector globalFunctionFlags; + int nGlobalFunctions; // always <= nFunctions + int nPerImageFunctionSets; + int nPerImageParams; // parameters (including X0,Y0) for per-image functions only }; #endif // _MODEL_OBJ_H_ diff --git a/function_objects/func_bpbar3d.cpp b/function_objects/func_bpbar3d.cpp index ff6f856..5e924b7 100644 --- a/function_objects/func_bpbar3d.cpp +++ b/function_objects/func_bpbar3d.cpp @@ -21,7 +21,7 @@ * [v0.1] 5 Aug 2023: Created. */ -// Copyright 2023 by Peter Erwin. +// Copyright 2023-2024 by Peter Erwin. // // This file is part of Imfit. // @@ -129,6 +129,32 @@ BPBar3D::BPBar3D( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void CoreSersic::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, ell, n, I_b, r_e, r_c, alpha, gamma + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = pixelScaling * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = inputFunctionParams[4 + offsetIndex]; + adjustedFunctionParams[5 + offsetIndex] = intensityScale * inputFunctionParams[5 + offsetIndex]; + adjustedFunctionParams[6 + offsetIndex] = pixelScaling * inputFunctionParams[6 + offsetIndex]; + adjustedFunctionParams[7 + offsetIndex] = pixelScaling * inputFunctionParams[7 + offsetIndex]; + adjustedFunctionParams[8 + offsetIndex] = pixelScaling * inputFunctionParams[8 + offsetIndex]; + adjustedFunctionParams[9 + offsetIndex] = inputFunctionParams[9 + offsetIndex]; + adjustedFunctionParams[10 + offsetIndex] = inputFunctionParams[10 + offsetIndex]; + adjustedFunctionParams[11 + offsetIndex] = intensityScale * inputFunctionParams[11 + offsetIndex]; + adjustedFunctionParams[12 + offsetIndex] = pixelScaling * inputFunctionParams[12 + offsetIndex]; + adjustedFunctionParams[13 + offsetIndex] = pixelScaling * inputFunctionParams[13 + offsetIndex]; + adjustedFunctionParams[14 + offsetIndex] = pixelScaling * inputFunctionParams[14 + offsetIndex]; + adjustedFunctionParams[15 + offsetIndex] = pixelScaling * inputFunctionParams[15 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void BPBar3D::Setup( double params[], int offsetIndex, double xc, double yc ) @@ -136,22 +162,22 @@ void BPBar3D::Setup( double params[], int offsetIndex, double xc, double yc ) double ell_outer, ell_bp; x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; inclination = params[1 + offsetIndex]; barPA = params[2 + offsetIndex]; - z_0 = params[3 + offsetIndex]; + z_0 = params[3 + offsetIndex] * pixelScaling; ell_outer = params[4 + offsetIndex]; - J_0_outer = params[5 + offsetIndex ]; - h1 = params[6 + offsetIndex ]; - h2 = params[7 + offsetIndex ]; - r_b = params[8 + offsetIndex ]; + J_0_outer = params[5 + offsetIndex ] * intensityScale; + h1 = params[6 + offsetIndex ] * pixelScaling; + h2 = params[7 + offsetIndex ] * pixelScaling; + r_b = params[8 + offsetIndex ] * pixelScaling; alpha = params[9 + offsetIndex ]; ell_bp = params[10 + offsetIndex ]; - J_0_bp = params[11 + offsetIndex ]; - r_bp_max = params[12 + offsetIndex ]; - z_bp_max = params[13 + offsetIndex ]; - h_bp = params[14 + offsetIndex ]; - sigma_bp = params[15 + offsetIndex ]; + J_0_bp = params[11 + offsetIndex ] * intensityScale; + r_bp_max = params[12 + offsetIndex ] * pixelScaling; + z_bp_max = params[13 + offsetIndex ] * pixelScaling; + h_bp = params[14 + offsetIndex ] * pixelScaling; + sigma_bp = params[15 + offsetIndex ] * pixelScaling; // pre-compute useful things for this round of invoking the function // convert PA to +x-axis reference diff --git a/function_objects/func_bpbar3d.h b/function_objects/func_bpbar3d.h index b4f86ea..baa2a30 100644 --- a/function_objects/func_bpbar3d.h +++ b/function_objects/func_bpbar3d.h @@ -1,5 +1,4 @@ /* Class interface definition for func_brokenexpbar3d.cpp - * VERSION 0.1 * * A class derived from FunctionObject (function_object.h), * which produces the integrated intensity of a 3D "broken-exponential bar" with @@ -21,6 +20,8 @@ * */ +#ifndef _FUNC_BPBAR3D_ +#define _FUNC_BPBAR3D_ // CLASS BPBar3D: @@ -42,6 +43,8 @@ class BPBar3D : public FunctionObject // Constructor BPBar3D( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now @@ -58,3 +61,5 @@ class BPBar3D : public FunctionObject double integrationLimit; gsl_function F; }; + +#endif /* _FUNC_BPBAR3D_ */ diff --git a/function_objects/func_broken-exp.cpp b/function_objects/func_broken-exp.cpp index 8410982..faaacbc 100644 --- a/function_objects/func_broken-exp.cpp +++ b/function_objects/func_broken-exp.cpp @@ -81,19 +81,36 @@ BrokenExponential::BrokenExponential( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void BrokenExponential::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, ell, I_0, h1, h2, r_b, alpha + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = intensityScale * inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = pixelScaling * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = pixelScaling * inputFunctionParams[4 + offsetIndex]; + adjustedFunctionParams[5 + offsetIndex] = pixelScaling * inputFunctionParams[5 + offsetIndex]; + adjustedFunctionParams[6 + offsetIndex] = (1.0/pixelScaling) * inputFunctionParams[6 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void BrokenExponential::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; ell = params[1 + offsetIndex]; - I_0 = params[2 + offsetIndex ]; - h1 = params[3 + offsetIndex ]; - h2 = params[4 + offsetIndex ]; - r_b = params[5 + offsetIndex ]; - alpha = params[6 + offsetIndex ]; + I_0 = params[2 + offsetIndex ] * intensityScale; + h1 = params[3 + offsetIndex ] * pixelScaling; + h2 = params[4 + offsetIndex ] * pixelScaling; + r_b = params[5 + offsetIndex ] * pixelScaling; + alpha = params[6 + offsetIndex ] / pixelScaling; // pre-compute useful things for this round of invoking the function q = 1.0 - ell; diff --git a/function_objects/func_broken-exp.h b/function_objects/func_broken-exp.h index b9afe07..80a546d 100644 --- a/function_objects/func_broken-exp.h +++ b/function_objects/func_broken-exp.h @@ -38,6 +38,8 @@ class BrokenExponential : public FunctionObject // Constructors: BrokenExponential( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_broken-exp2d.cpp b/function_objects/func_broken-exp2d.cpp index 4516463..5865e33 100644 --- a/function_objects/func_broken-exp2d.cpp +++ b/function_objects/func_broken-exp2d.cpp @@ -86,19 +86,36 @@ BrokenExponential2D::BrokenExponential2D( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void BrokenExponential2D::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, I_0, h1, h2, r_b, alpha, h_z + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = intensityScale * inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = pixelScaling * inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = pixelScaling * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = pixelScaling * inputFunctionParams[4 + offsetIndex]; + adjustedFunctionParams[5 + offsetIndex] = (1.0/pixelScaling) * inputFunctionParams[5 + offsetIndex]; + adjustedFunctionParams[6 + offsetIndex] = pixelScaling * inputFunctionParams[6 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void BrokenExponential2D::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; - I_0 = params[1 + offsetIndex ]; - h1 = params[2 + offsetIndex ]; - h2 = params[3 + offsetIndex ]; - r_b = params[4 + offsetIndex ]; - alpha = params[5 + offsetIndex ]; - h_z = params[6 + offsetIndex ]; + PA = params[0 + offsetIndex] - imageRotation; + I_0 = params[1 + offsetIndex ] * intensityScale; + h1 = params[2 + offsetIndex ] * pixelScaling; + h2 = params[3 + offsetIndex ] * pixelScaling; + r_b = params[4 + offsetIndex ] * pixelScaling; + alpha = params[5 + offsetIndex ] / pixelScaling; + h_z = params[6 + offsetIndex ] * pixelScaling; // pre-compute useful things for this round of invoking the function // convert PA to +x-axis reference diff --git a/function_objects/func_broken-exp2d.h b/function_objects/func_broken-exp2d.h index 4b837d8..89f057d 100644 --- a/function_objects/func_broken-exp2d.h +++ b/function_objects/func_broken-exp2d.h @@ -39,6 +39,8 @@ class BrokenExponential2D : public FunctionObject // No destructor for now // class method for returning official short name of class + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); static void GetClassShortName( string& classname ) { classname = className; }; diff --git a/function_objects/func_brokenexpdisk3d.cpp b/function_objects/func_brokenexpdisk3d.cpp index e75d6a9..cda887c 100644 --- a/function_objects/func_brokenexpdisk3d.cpp +++ b/function_objects/func_brokenexpdisk3d.cpp @@ -105,21 +105,40 @@ BrokenExponentialDisk3D::BrokenExponentialDisk3D( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void BrokenExponentialDisk3D::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, inc, J_0, h1, h2, r_b, alpha, n, z_0 + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = intensityScale * inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = pixelScaling * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = pixelScaling * inputFunctionParams[4 + offsetIndex]; + adjustedFunctionParams[5 + offsetIndex] = pixelScaling * inputFunctionParams[5 + offsetIndex]; + adjustedFunctionParams[6 + offsetIndex] = (1.0/pixelScaling) * inputFunctionParams[6 + offsetIndex]; + adjustedFunctionParams[7 + offsetIndex] = inputFunctionParams[7 + offsetIndex]; + adjustedFunctionParams[8 + offsetIndex] = pixelScaling * inputFunctionParams[8 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void BrokenExponentialDisk3D::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; inclination = params[1 + offsetIndex]; - J_0 = params[2 + offsetIndex ]; - h1 = params[3 + offsetIndex ]; - h2 = params[4 + offsetIndex ]; - r_b = params[5 + offsetIndex ]; - alpha = params[6 + offsetIndex ]; + J_0 = params[2 + offsetIndex ] * intensityScale; + h1 = params[3 + offsetIndex ] * pixelScaling; + h2 = params[4 + offsetIndex ] * pixelScaling; + r_b = params[5 + offsetIndex ] * pixelScaling; + alpha = params[6 + offsetIndex ] / pixelScaling; n = params[7 + offsetIndex ]; - z_0 = params[8 + offsetIndex ]; + z_0 = params[8 + offsetIndex ] * pixelScaling; // pre-compute useful things for this round of invoking the function // convert PA to +x-axis reference diff --git a/function_objects/func_brokenexpdisk3d.h b/function_objects/func_brokenexpdisk3d.h index 51bac08..c801fbb 100644 --- a/function_objects/func_brokenexpdisk3d.h +++ b/function_objects/func_brokenexpdisk3d.h @@ -41,6 +41,8 @@ class BrokenExponentialDisk3D : public FunctionObject // Constructor BrokenExponentialDisk3D( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_core-sersic.cpp b/function_objects/func_core-sersic.cpp index a2d021b..fb8a17e 100644 --- a/function_objects/func_core-sersic.cpp +++ b/function_objects/func_core-sersic.cpp @@ -21,7 +21,7 @@ * [v0.1]: 21 Sept 2012: Created (as modification of func_sersic.cpp. */ -// Copyright 2012--2022 by Peter Erwin. +// Copyright 2012--2024 by Peter Erwin. // // This file is part of Imfit. // @@ -90,18 +90,36 @@ CoreSersic::CoreSersic( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void CoreSersic::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, ell, n, I_b, r_e, r_c, alpha, gamma + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = intensityScale * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = pixelScaling * inputFunctionParams[4 + offsetIndex]; + adjustedFunctionParams[5 + offsetIndex] = pixelScaling * inputFunctionParams[5 + offsetIndex]; + adjustedFunctionParams[6 + offsetIndex] = inputFunctionParams[6 + offsetIndex]; + adjustedFunctionParams[7 + offsetIndex] = inputFunctionParams[7 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void CoreSersic::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; ell = params[1 + offsetIndex]; n = params[2 + offsetIndex ]; - I_b = params[3 + offsetIndex ]; - r_e = params[4 + offsetIndex ]; - r_b = params[5 + offsetIndex ]; + I_b = params[3 + offsetIndex ] * intensityScale; + r_e = params[4 + offsetIndex ] * pixelScaling; + r_b = params[5 + offsetIndex ] * pixelScaling; alpha = params[6 + offsetIndex ]; gamma = params[7 + offsetIndex ]; diff --git a/function_objects/func_core-sersic.h b/function_objects/func_core-sersic.h index 6b2cd73..766a50e 100644 --- a/function_objects/func_core-sersic.h +++ b/function_objects/func_core-sersic.h @@ -11,9 +11,9 @@ * PA = params[2 + offsetIndex]; -- PA of component, rel. to +x axis * ell = params[3 + offsetIndex]; -- ellipticity * n = params[4 + offsetIndex ]; -- Sersic index - * I_b = params[5 + offsetIndex ]; -- break-radius surf. brightness (counts/pixel) - * r_e = params[6 + offsetIndex ]; -- half-light radius (pixels) - * r_b = params[7 + offsetIndex ]; -- break radius (pixels) + * I_b = params[5 + offsetIndex ]; -- break-radius surf. brightness (mag/arcsec^2) + * r_e = params[6 + offsetIndex ]; -- half-light radius + * r_b = params[7 + offsetIndex ]; -- break radius * alpha = params[8 + offsetIndex ]; -- sharpness of break * gamma = params[9 + offsetIndex ]; -- inner power-law slope * @@ -37,6 +37,8 @@ class CoreSersic : public FunctionObject // Constructors: CoreSersic( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_edge-on-disk.cpp b/function_objects/func_edge-on-disk.cpp index 389faee..84e9936 100644 --- a/function_objects/func_edge-on-disk.cpp +++ b/function_objects/func_edge-on-disk.cpp @@ -116,17 +116,32 @@ EdgeOnDisk::EdgeOnDisk( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void EdgeOnDisk::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, L_0, h, n, z_0 + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = intensityScale * inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = pixelScaling * inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = pixelScaling * inputFunctionParams[4 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void EdgeOnDisk::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; - L_0 = params[1 + offsetIndex ]; - h = params[2 + offsetIndex ]; + PA = params[0 + offsetIndex] - imageRotation; + L_0 = params[1 + offsetIndex ] * intensityScale; + h = params[2 + offsetIndex ] * pixelScaling; n = params[3 + offsetIndex ]; - z_0 = params[4 + offsetIndex ]; + z_0 = params[4 + offsetIndex ] * pixelScaling; // pre-compute useful things for this round of invoking the function // convert PA to +x-axis reference diff --git a/function_objects/func_edge-on-disk.h b/function_objects/func_edge-on-disk.h index 9ea3111..db5657e 100644 --- a/function_objects/func_edge-on-disk.h +++ b/function_objects/func_edge-on-disk.h @@ -40,6 +40,8 @@ class EdgeOnDisk : public FunctionObject // Constructors: EdgeOnDisk( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_edge-on-ring.cpp b/function_objects/func_edge-on-ring.cpp index 1f9aa02..a76c58b 100644 --- a/function_objects/func_edge-on-ring.cpp +++ b/function_objects/func_edge-on-ring.cpp @@ -85,18 +85,33 @@ EdgeOnRing::EdgeOnRing( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void EdgeOnRing::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, A, r1, sigma_r, sigma_z + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = intensityScale * inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = pixelScaling * inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = pixelScaling * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = pixelScaling * inputFunctionParams[4 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void EdgeOnRing::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; - A = params[1 + offsetIndex ]; - r1 = params[2 + offsetIndex ]; + PA = params[0 + offsetIndex] - imageRotation; + A = params[1 + offsetIndex ] * intensityScale; + r1 = params[2 + offsetIndex ] * pixelScaling; r2 = -r1; - sigma_r = params[3 + offsetIndex ]; - sigma_z = params[4 + offsetIndex ]; + sigma_r = params[3 + offsetIndex ] * pixelScaling; + sigma_z = params[4 + offsetIndex ] * pixelScaling; // pre-compute useful things for this round of invoking the function // convert PA to +x-axis reference diff --git a/function_objects/func_edge-on-ring.h b/function_objects/func_edge-on-ring.h index 4f6202e..f40054f 100644 --- a/function_objects/func_edge-on-ring.h +++ b/function_objects/func_edge-on-ring.h @@ -34,6 +34,8 @@ class EdgeOnRing : public FunctionObject // Constructors: EdgeOnRing( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_edge-on-ring2side.cpp b/function_objects/func_edge-on-ring2side.cpp index 4bd21d6..87ec87a 100644 --- a/function_objects/func_edge-on-ring2side.cpp +++ b/function_objects/func_edge-on-ring2side.cpp @@ -83,19 +83,35 @@ EdgeOnRing2Side::EdgeOnRing2Side( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void EdgeOnRing2Side::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, A, r1, sigma_r_inner, sigma_r_outer, sigma_z + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = intensityScale * inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = pixelScaling * inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = pixelScaling * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = pixelScaling * inputFunctionParams[4 + offsetIndex]; + adjustedFunctionParams[5 + offsetIndex] = pixelScaling * inputFunctionParams[5 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void EdgeOnRing2Side::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; - A = params[1 + offsetIndex ]; - r1 = -params[2 + offsetIndex ]; // left-side radius of ring (negative value) + PA = params[0 + offsetIndex] - imageRotation; + A = params[1 + offsetIndex ] * intensityScale; + r1 = -params[2 + offsetIndex ] * pixelScaling; // left-side radius of ring (negative value) r2 = -r1; // right-side radius of ring (positive value) - sigma_r_inner = params[3 + offsetIndex ]; - sigma_r_outer = params[4 + offsetIndex ]; - sigma_z = params[5 + offsetIndex ]; + sigma_r_inner = params[3 + offsetIndex ] * pixelScaling; + sigma_r_outer = params[4 + offsetIndex ] * pixelScaling; + sigma_z = params[5 + offsetIndex ] * pixelScaling; // pre-compute useful things for this round of invoking the function // convert PA to +x-axis reference diff --git a/function_objects/func_edge-on-ring2side.h b/function_objects/func_edge-on-ring2side.h index 79098b0..2f43791 100644 --- a/function_objects/func_edge-on-ring2side.h +++ b/function_objects/func_edge-on-ring2side.h @@ -35,6 +35,8 @@ class EdgeOnRing2Side : public FunctionObject // Constructors: EdgeOnRing2Side( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_exp.cpp b/function_objects/func_exp.cpp index 021f595..05c62c7 100644 --- a/function_objects/func_exp.cpp +++ b/function_objects/func_exp.cpp @@ -85,16 +85,30 @@ Exponential::Exponential( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void Exponential::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, ell, I_0, h + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = intensityScale * inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = pixelScaling * inputFunctionParams[3 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void Exponential::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; ell = params[1 + offsetIndex]; - I_0 = params[2 + offsetIndex ]; - h = params[3 + offsetIndex ]; + I_0 = params[2 + offsetIndex] * intensityScale; + h = params[3 + offsetIndex] * pixelScaling; // pre-compute useful things for this round of invoking the function q = 1.0 - ell; // convert PA to +x-axis reference diff --git a/function_objects/func_exp.h b/function_objects/func_exp.h index b310355..bf68386 100644 --- a/function_objects/func_exp.h +++ b/function_objects/func_exp.h @@ -16,6 +16,9 @@ */ +#ifndef _UTILITIES_FUNC_EXPONENTIAL_ +#define _UTILITIES_FUNC_EXPONENTIAL_ + // CLASS Exponential: #include "function_object.h" @@ -34,6 +37,8 @@ class Exponential : public FunctionObject // Constructors: Exponential( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); bool CanCalculateTotalFlux( ); @@ -53,3 +58,5 @@ class Exponential : public FunctionObject double q, PA_rad, cosPA, sinPA; // other useful quantities }; +#endif /* _UTILITIES_FUNC_EXPONENTIAL_ */ + diff --git a/function_objects/func_expdisk3d.cpp b/function_objects/func_expdisk3d.cpp index c93a2f0..8cf2254 100644 --- a/function_objects/func_expdisk3d.cpp +++ b/function_objects/func_expdisk3d.cpp @@ -128,18 +128,34 @@ ExponentialDisk3D::ExponentialDisk3D( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void ExponentialDisk3D::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, inc, j_0, h, n, z_0 + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = intensityScale * inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = pixelScaling * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = inputFunctionParams[4 + offsetIndex]; + adjustedFunctionParams[5 + offsetIndex] = pixelScaling * inputFunctionParams[5 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void ExponentialDisk3D::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; inclination = params[1 + offsetIndex]; - J_0 = params[2 + offsetIndex ]; - h = params[3 + offsetIndex ]; + J_0 = params[2 + offsetIndex ] * intensityScale; + h = params[3 + offsetIndex ] * pixelScaling; n = params[4 + offsetIndex ]; - z_0 = params[5 + offsetIndex ]; + z_0 = params[5 + offsetIndex ] * pixelScaling; // pre-compute useful things for this round of invoking the function // convert PA to +x-axis reference diff --git a/function_objects/func_expdisk3d.h b/function_objects/func_expdisk3d.h index edcaa7a..150960b 100644 --- a/function_objects/func_expdisk3d.h +++ b/function_objects/func_expdisk3d.h @@ -29,6 +29,8 @@ class ExponentialDisk3D : public FunctionObject // Constructor ExponentialDisk3D( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_ferrersbar2d.cpp b/function_objects/func_ferrersbar2d.cpp index 560a357..2c2fed0 100644 --- a/function_objects/func_ferrersbar2d.cpp +++ b/function_objects/func_ferrersbar2d.cpp @@ -89,16 +89,29 @@ FerrersBar2D::FerrersBar2D( ) /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ +void FerrersBar2D::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, ell, c0, n, I_0, a_bar + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = intensityScale * inputFunctionParams[4 + offsetIndex]; + adjustedFunctionParams[5 + offsetIndex] = pixelScaling * inputFunctionParams[5 + offsetIndex]; +} + + void FerrersBar2D::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; ell = params[1 + offsetIndex]; c0 = params[2 + offsetIndex ]; n = params[3 + offsetIndex ]; - I_0 = params[4 + offsetIndex ]; - a_bar = params[5 + offsetIndex ]; + I_0 = params[4 + offsetIndex ] * intensityScale; + a_bar = params[5 + offsetIndex ] * pixelScaling; // pre-compute useful things for this round of invoking the function q = 1.0 - ell; diff --git a/function_objects/func_ferrersbar2d.h b/function_objects/func_ferrersbar2d.h index 09367f6..ecc4ad1 100644 --- a/function_objects/func_ferrersbar2d.h +++ b/function_objects/func_ferrersbar2d.h @@ -38,6 +38,8 @@ class FerrersBar2D : public FunctionObject // Constructor FerrersBar2D( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_ferrersbar3d.cpp b/function_objects/func_ferrersbar3d.cpp index cf7723e..a08dd69 100644 --- a/function_objects/func_ferrersbar3d.cpp +++ b/function_objects/func_ferrersbar3d.cpp @@ -102,17 +102,35 @@ FerrersBar3D::FerrersBar3D( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void FerrersBar3D::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, inc, barPA, J_0, R_bar, q, q_z, n + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = intensityScale * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = pixelScaling * inputFunctionParams[4 + offsetIndex]; + adjustedFunctionParams[5 + offsetIndex] = inputFunctionParams[5 + offsetIndex]; + adjustedFunctionParams[6 + offsetIndex] = inputFunctionParams[6 + offsetIndex]; + adjustedFunctionParams[7 + offsetIndex] = inputFunctionParams[7 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void FerrersBar3D::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; inclination = params[1 + offsetIndex]; barPA = params[2 + offsetIndex]; - J_0 = params[3 + offsetIndex ]; - R_bar = params[4 + offsetIndex ]; + J_0 = params[3 + offsetIndex ] * intensityScale; + R_bar = params[4 + offsetIndex ] * pixelScaling; q = params[5 + offsetIndex ]; q_z = params[6 + offsetIndex ]; n = params[7 + offsetIndex ]; diff --git a/function_objects/func_ferrersbar3d.h b/function_objects/func_ferrersbar3d.h index 283462e..0103eac 100644 --- a/function_objects/func_ferrersbar3d.h +++ b/function_objects/func_ferrersbar3d.h @@ -41,6 +41,8 @@ class FerrersBar3D : public FunctionObject // Constructor FerrersBar3D( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_flatbar.cpp b/function_objects/func_flatbar.cpp index 8bffd65..29eb603 100644 --- a/function_objects/func_flatbar.cpp +++ b/function_objects/func_flatbar.cpp @@ -87,20 +87,38 @@ FlatBar::FlatBar( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void FlatBar::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, ell, deltaPA_max, I_0, h1, h2, r_b, alpha + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = intensityScale * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = pixelScaling * inputFunctionParams[4 + offsetIndex]; + adjustedFunctionParams[5 + offsetIndex] = pixelScaling * inputFunctionParams[5 + offsetIndex]; + adjustedFunctionParams[6 + offsetIndex] = pixelScaling * inputFunctionParams[6 + offsetIndex]; + adjustedFunctionParams[7 + offsetIndex] = (1.0/pixelScaling) * inputFunctionParams[7 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void FlatBar::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; ell = params[1 + offsetIndex]; deltaPA_max = params[2 + offsetIndex]; - I_0 = params[3 + offsetIndex ]; - h1 = params[4 + offsetIndex ]; - h2 = params[5 + offsetIndex ]; - r_b = params[6 + offsetIndex ]; - alpha = params[7 + offsetIndex ]; + I_0 = params[3 + offsetIndex ] * pixelScaling; + h1 = params[4 + offsetIndex ] * pixelScaling; + h2 = params[5 + offsetIndex ] * pixelScaling; + r_b = params[6 + offsetIndex ] * pixelScaling; + alpha = params[7 + offsetIndex ] / pixelScaling; // pre-compute useful things for this round of invoking the function q = 1.0 - ell; diff --git a/function_objects/func_flatbar.h b/function_objects/func_flatbar.h index 4066558..31be264 100644 --- a/function_objects/func_flatbar.h +++ b/function_objects/func_flatbar.h @@ -40,6 +40,8 @@ class FlatBar : public FunctionObject // Constructors: FlatBar( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_flatsky.cpp b/function_objects/func_flatsky.cpp index 10d9210..8210f90 100644 --- a/function_objects/func_flatsky.cpp +++ b/function_objects/func_flatsky.cpp @@ -69,13 +69,24 @@ FlatSky::FlatSky( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void FlatSky::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // I_0 + adjustedFunctionParams[0 + offsetIndex] = intensityScale * inputFunctionParams[0 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void FlatSky::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - I_sky = params[0 + offsetIndex ]; + I_sky = params[0 + offsetIndex] * intensityScale; } diff --git a/function_objects/func_flatsky.h b/function_objects/func_flatsky.h index 9130406..9ee4bf5 100644 --- a/function_objects/func_flatsky.h +++ b/function_objects/func_flatsky.h @@ -6,6 +6,9 @@ */ +#ifndef _FUNC_FLATSKY_H_ +#define _FUNC_FLATSKY_H_ + // CLASS FlatSky: #include "function_object.h" @@ -22,6 +25,8 @@ class FlatSky : public FunctionObject // Constructors: FlatSky( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now @@ -33,3 +38,6 @@ class FlatSky : public FunctionObject private: double x0, y0, I_sky; }; + + +#endif /* _FUNC_FLATSKY_H_ */ diff --git a/function_objects/func_gaussian-ring-az.cpp b/function_objects/func_gaussian-ring-az.cpp index 4a8765b..cb1aa4a 100644 --- a/function_objects/func_gaussian-ring-az.cpp +++ b/function_objects/func_gaussian-ring-az.cpp @@ -82,18 +82,34 @@ GaussianRingAz::GaussianRingAz( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void GaussianRingAz::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, ell, A_maj, A_min_rel, R_ring, sigma_r + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = intensityScale * inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = pixelScaling * inputFunctionParams[4 + offsetIndex]; + adjustedFunctionParams[5 + offsetIndex] = pixelScaling * inputFunctionParams[5 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void GaussianRingAz::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; ell = params[1 + offsetIndex]; - A_maj = params[2 + offsetIndex ]; - A_min_rel = params[3 + offsetIndex ]; - R_ring = params[4 + offsetIndex ]; // major-axis radius of ring - sigma_r = params[5 + offsetIndex ]; + A_maj = params[2 + offsetIndex] * intensityScale; + A_min_rel = params[3 + offsetIndex]; + R_ring = params[4 + offsetIndex] * pixelScaling; // major-axis radius of ring + sigma_r = params[5 + offsetIndex] * pixelScaling; // pre-compute useful things for this round of invoking the function A_min = A_min_rel * A_maj; diff --git a/function_objects/func_gaussian-ring-az.h b/function_objects/func_gaussian-ring-az.h index 5e0098e..b113138 100644 --- a/function_objects/func_gaussian-ring-az.h +++ b/function_objects/func_gaussian-ring-az.h @@ -39,6 +39,8 @@ class GaussianRingAz : public FunctionObject // Constructors: GaussianRingAz( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_gaussian-ring.cpp b/function_objects/func_gaussian-ring.cpp index 3e4b99e..e3d47f8 100644 --- a/function_objects/func_gaussian-ring.cpp +++ b/function_objects/func_gaussian-ring.cpp @@ -82,17 +82,32 @@ GaussianRing::GaussianRing( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void GaussianRing::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, ell, A, R_ring, sigma_r + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = intensityScale * inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = pixelScaling * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = pixelScaling * inputFunctionParams[4 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void GaussianRing::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; ell = params[1 + offsetIndex]; - A = params[2 + offsetIndex ]; - R_ring = params[3 + offsetIndex ]; // major-axis radius of ring - sigma_r = params[4 + offsetIndex ]; + A = params[2 + offsetIndex] * intensityScale; + R_ring = params[3 + offsetIndex] * pixelScaling; // major-axis radius of ring + sigma_r = params[4 + offsetIndex] * pixelScaling; // pre-compute useful things for this round of invoking the function q = 1.0 - ell; diff --git a/function_objects/func_gaussian-ring.h b/function_objects/func_gaussian-ring.h index 08a04cf..712cd3a 100644 --- a/function_objects/func_gaussian-ring.h +++ b/function_objects/func_gaussian-ring.h @@ -32,6 +32,8 @@ class GaussianRing : public FunctionObject // Constructors: GaussianRing( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_gaussian-ring2side.cpp b/function_objects/func_gaussian-ring2side.cpp index b6a6237..af8b591 100644 --- a/function_objects/func_gaussian-ring2side.cpp +++ b/function_objects/func_gaussian-ring2side.cpp @@ -83,18 +83,34 @@ GaussianRing2Side::GaussianRing2Side( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void GaussianRing2Side::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, ell, A, R_ring, sigma_r_inner, sigma_r_outer + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = intensityScale * inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = pixelScaling * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = pixelScaling * inputFunctionParams[4 + offsetIndex]; + adjustedFunctionParams[5 + offsetIndex] = pixelScaling * inputFunctionParams[5 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void GaussianRing2Side::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; ell = params[1 + offsetIndex]; - A = params[2 + offsetIndex ]; - R_ring = params[3 + offsetIndex ]; // major-axis radius of ring - sigma_r_inner = params[4 + offsetIndex ]; - sigma_r_outer = params[5 + offsetIndex ]; + A = params[2 + offsetIndex] * intensityScale; + R_ring = params[3 + offsetIndex] * pixelScaling; // major-axis radius of ring + sigma_r_inner = params[4 + offsetIndex] * pixelScaling; + sigma_r_outer = params[5 + offsetIndex] * pixelScaling; // pre-compute useful things for this round of invoking the function q = 1.0 - ell; diff --git a/function_objects/func_gaussian-ring2side.h b/function_objects/func_gaussian-ring2side.h index f8c11e4..40bb7a6 100644 --- a/function_objects/func_gaussian-ring2side.h +++ b/function_objects/func_gaussian-ring2side.h @@ -35,6 +35,8 @@ class GaussianRing2Side : public FunctionObject // Constructors: GaussianRing2Side( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_gaussian.cpp b/function_objects/func_gaussian.cpp index 23af49c..1acc901 100644 --- a/function_objects/func_gaussian.cpp +++ b/function_objects/func_gaussian.cpp @@ -85,16 +85,30 @@ Gaussian::Gaussian( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void Gaussian::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, ell, I_0, sigma + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = intensityScale * inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = pixelScaling * inputFunctionParams[3 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void Gaussian::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; ell = params[1 + offsetIndex]; - I_0 = params[2 + offsetIndex]; - sigma = params[3 + offsetIndex]; + I_0 = params[2 + offsetIndex] * intensityScale; + sigma = params[3 + offsetIndex] * pixelScaling; // pre-compute useful things for this round of invoking the function q = 1.0 - ell; diff --git a/function_objects/func_gaussian.h b/function_objects/func_gaussian.h index 7788ede..f4375ea 100644 --- a/function_objects/func_gaussian.h +++ b/function_objects/func_gaussian.h @@ -7,6 +7,9 @@ */ +#ifndef _FUNC_GAUSSIAN_H_ +#define _FUNC_GAUSSIAN_H_ + // CLASS Gaussian: #include "function_object.h" @@ -14,7 +17,7 @@ -/// Class for image function with elliptical isophotes and %Gaussian profile +/// Class for image function with elliptical isophotes and Gaussian profile class Gaussian : public FunctionObject { // the following static constant will be defined/initialized in the .cpp file @@ -24,6 +27,8 @@ class Gaussian : public FunctionObject // Constructors: Gaussian( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); bool CanCalculateTotalFlux( ); @@ -44,3 +49,6 @@ class Gaussian : public FunctionObject double twosigma_squared; double q, PA_rad, cosPA, sinPA; // other useful (shape-related) quantities }; + + +#endif /* _FUNC_GAUSSIAN_H_ */ diff --git a/function_objects/func_gaussianring3d.cpp b/function_objects/func_gaussianring3d.cpp index ed70bac..e24caf6 100644 --- a/function_objects/func_gaussianring3d.cpp +++ b/function_objects/func_gaussianring3d.cpp @@ -105,6 +105,24 @@ GaussianRing3D::GaussianRing3D( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void GaussianRing3D::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, inc, ringPA, ell, J_0, a_ring, sigma, h_z + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = intensityScale * inputFunctionParams[4 + offsetIndex]; + adjustedFunctionParams[5 + offsetIndex] = pixelScaling * inputFunctionParams[5 + offsetIndex]; + adjustedFunctionParams[6 + offsetIndex] = pixelScaling * inputFunctionParams[6 + offsetIndex]; + adjustedFunctionParams[7 + offsetIndex] = pixelScaling * inputFunctionParams[7 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void GaussianRing3D::Setup( double params[], int offsetIndex, double xc, double yc ) @@ -113,14 +131,14 @@ void GaussianRing3D::Setup( double params[], int offsetIndex, double xc, double x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; inclination = params[1 + offsetIndex]; ringPA = params[2 + offsetIndex]; ell = params[3 + offsetIndex]; - J_0 = params[4 + offsetIndex ]; - a_ring = params[5 + offsetIndex ]; - sigma = params[6 + offsetIndex ]; - h_z = params[7 + offsetIndex ]; + J_0 = params[4 + offsetIndex ] * intensityScale; + a_ring = params[5 + offsetIndex ] * pixelScaling; + sigma = params[6 + offsetIndex ] * pixelScaling; + h_z = params[7 + offsetIndex ] * pixelScaling; // pre-compute useful things for this round of invoking the function q = 1.0 - ell; diff --git a/function_objects/func_gaussianring3d.h b/function_objects/func_gaussianring3d.h index a8317a0..3763428 100644 --- a/function_objects/func_gaussianring3d.h +++ b/function_objects/func_gaussianring3d.h @@ -43,6 +43,8 @@ class GaussianRing3D : public FunctionObject // Constructor GaussianRing3D( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_gen-exp.cpp b/function_objects/func_gen-exp.cpp index 9a319c0..b2215de 100644 --- a/function_objects/func_gen-exp.cpp +++ b/function_objects/func_gen-exp.cpp @@ -83,17 +83,32 @@ GenExponential::GenExponential( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void GenExponential::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, ell, c0, I_0, h + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = intensityScale * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = pixelScaling * inputFunctionParams[4 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void GenExponential::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; ell = params[1 + offsetIndex]; - c0 = params[2 + offsetIndex ]; - I_0 = params[3 + offsetIndex ]; - h = params[4 + offsetIndex ]; + c0 = params[2 + offsetIndex]; + I_0 = params[3 + offsetIndex] * intensityScale; + h = params[4 + offsetIndex] * pixelScaling; // pre-compute useful things for this round of invoking the function q = 1.0 - ell; // convert PA to +x-axis reference diff --git a/function_objects/func_gen-exp.h b/function_objects/func_gen-exp.h index f1318b2..c1b4b7f 100644 --- a/function_objects/func_gen-exp.h +++ b/function_objects/func_gen-exp.h @@ -17,6 +17,9 @@ */ +#ifndef _FUNC_GENEXPONENTIAL_H_ +#define _FUNC_GENEXPONENTIAL_H_ + // CLASS GenExponential: #include "function_object.h" @@ -33,6 +36,8 @@ class GenExponential : public FunctionObject // Constructors: GenExponential( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now @@ -50,3 +55,6 @@ class GenExponential : public FunctionObject double q, PA_rad, cosPA, sinPA; // other useful quantities (basic geometry) double ellExp, invEllExp; // more useful quantities }; + + +#endif /* _FUNC_GENEXPONENTIAL_H_ */ diff --git a/function_objects/func_gen-sersic.cpp b/function_objects/func_gen-sersic.cpp index fc80c24..ba41141 100644 --- a/function_objects/func_gen-sersic.cpp +++ b/function_objects/func_gen-sersic.cpp @@ -86,18 +86,34 @@ GenSersic::GenSersic( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void GenSersic::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, ell, n, c0, I_e, r_e + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = intensityScale * inputFunctionParams[4 + offsetIndex]; + adjustedFunctionParams[5 + offsetIndex] = pixelScaling * inputFunctionParams[5 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void GenSersic::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; ell = params[1 + offsetIndex]; c0 = params[2 + offsetIndex ]; n = params[3 + offsetIndex ]; - I_e = params[4 + offsetIndex ]; - r_e = params[5 + offsetIndex ]; + I_e = params[4 + offsetIndex ] * intensityScale; + r_e = params[5 + offsetIndex ] * pixelScaling; // pre-compute useful things for this round of invoking the function q = 1.0 - ell; diff --git a/function_objects/func_gen-sersic.h b/function_objects/func_gen-sersic.h index dde195f..645364f 100644 --- a/function_objects/func_gen-sersic.h +++ b/function_objects/func_gen-sersic.h @@ -18,6 +18,9 @@ */ +#ifndef _FUNC_GENSERSIC_H_ +#define _FUNC_GENSERSIC_H_ + // CLASS GenSersic: #include "function_object.h" @@ -34,6 +37,8 @@ class GenSersic : public FunctionObject // Constructors: GenSersic( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now @@ -54,3 +59,6 @@ class GenSersic : public FunctionObject double q, PA_rad, cosPA, sinPA; // other useful quantities (basic geometry) double ellExp, invEllExp; // more useful quantities }; + + +#endif /* _FUNC_GENSERSIC_H_ */ diff --git a/function_objects/func_king.cpp b/function_objects/func_king.cpp index 5dea4c5..0fea5f0 100644 --- a/function_objects/func_king.cpp +++ b/function_objects/func_king.cpp @@ -82,17 +82,33 @@ ModifiedKing::ModifiedKing( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void ModifiedKing::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, ell, I_0, r_c, r_t, alpha + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = intensityScale * inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = pixelScaling * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = pixelScaling * inputFunctionParams[4 + offsetIndex]; + adjustedFunctionParams[5 + offsetIndex] = inputFunctionParams[5 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void ModifiedKing::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; ell = params[1 + offsetIndex]; - I_0 = params[2 + offsetIndex ]; - r_c = params[3 + offsetIndex ]; - r_t = params[4 + offsetIndex ]; + I_0 = params[2 + offsetIndex ] * intensityScale; + r_c = params[3 + offsetIndex ] * pixelScaling; + r_t = params[4 + offsetIndex ] * pixelScaling; alpha = params[5 + offsetIndex ]; // alpha = 2 for standard King model // pre-compute useful things for this round of invoking the function diff --git a/function_objects/func_king.h b/function_objects/func_king.h index bdd8d2a..ddc4e9f 100644 --- a/function_objects/func_king.h +++ b/function_objects/func_king.h @@ -37,6 +37,8 @@ class ModifiedKing : public FunctionObject // Constructors: ModifiedKing( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_king2.cpp b/function_objects/func_king2.cpp index 5d3b4c7..48dc015 100644 --- a/function_objects/func_king2.cpp +++ b/function_objects/func_king2.cpp @@ -86,16 +86,32 @@ ModifiedKing2::ModifiedKing2( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void ModifiedKing2::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, ell, I_0, r_c, c, alpha + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = intensityScale * inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = pixelScaling * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = inputFunctionParams[4 + offsetIndex]; + adjustedFunctionParams[5 + offsetIndex] = inputFunctionParams[5 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void ModifiedKing2::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; ell = params[1 + offsetIndex]; - I_0 = params[2 + offsetIndex ]; - r_c = params[3 + offsetIndex ]; + I_0 = params[2 + offsetIndex ] * intensityScale; + r_c = params[3 + offsetIndex ] * pixelScaling; c = params[4 + offsetIndex ]; alpha = params[5 + offsetIndex ]; // alpha = 2 for standard King model diff --git a/function_objects/func_king2.h b/function_objects/func_king2.h index b282fda..9a7418c 100644 --- a/function_objects/func_king2.h +++ b/function_objects/func_king2.h @@ -40,6 +40,8 @@ class ModifiedKing2 : public FunctionObject // Constructors: ModifiedKing2( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_moffat.cpp b/function_objects/func_moffat.cpp index 37b0f56..0717104 100644 --- a/function_objects/func_moffat.cpp +++ b/function_objects/func_moffat.cpp @@ -91,16 +91,31 @@ Moffat::Moffat( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void Moffat::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, ell, I_0, fwhm, beta + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = intensityScale * inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = pixelScaling * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = inputFunctionParams[4 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void Moffat::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; ell = params[1 + offsetIndex]; - I_0 = params[2 + offsetIndex]; - fwhm = params[3 + offsetIndex]; + I_0 = params[2 + offsetIndex] * intensityScale; + fwhm = params[3 + offsetIndex] * pixelScaling; beta = params[4 + offsetIndex]; // pre-compute useful things for this round of invoking the function diff --git a/function_objects/func_moffat.h b/function_objects/func_moffat.h index d4dffe8..8929189 100644 --- a/function_objects/func_moffat.h +++ b/function_objects/func_moffat.h @@ -31,6 +31,8 @@ class Moffat : public FunctionObject // Constructors: Moffat( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_nuker.cpp b/function_objects/func_nuker.cpp index 6bf4e08..b0c2afb 100644 --- a/function_objects/func_nuker.cpp +++ b/function_objects/func_nuker.cpp @@ -21,7 +21,7 @@ * [v0.1]: 20 April 2023: Created (as modification of func_sersic.cpp. */ -// Copyright 2023 by Peter Erwin. +// Copyright 2023-2024 by Peter Erwin. // // This file is part of Imfit. // @@ -90,16 +90,33 @@ NukerLaw::NukerLaw( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void NukerLaw::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, ell, n, I_b, r_e, r_c, alpha, gamma + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = intensityScale * inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = pixelScaling * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = inputFunctionParams[4 + offsetIndex]; + adjustedFunctionParams[5 + offsetIndex] = inputFunctionParams[5 + offsetIndex]; + adjustedFunctionParams[6 + offsetIndex] = inputFunctionParams[6 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void NukerLaw::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; ell = params[1 + offsetIndex]; - I_b = params[2 + offsetIndex ]; - r_b = params[3 + offsetIndex ]; + I_b = params[2 + offsetIndex ] * intensityScale; + r_b = params[3 + offsetIndex ] * pixelScaling; alpha = params[4 + offsetIndex ]; beta = params[5 + offsetIndex ]; gamma = params[6 + offsetIndex ]; diff --git a/function_objects/func_nuker.h b/function_objects/func_nuker.h index 114150b..3950cb6 100644 --- a/function_objects/func_nuker.h +++ b/function_objects/func_nuker.h @@ -34,6 +34,8 @@ class NukerLaw : public FunctionObject // Constructors: NukerLaw( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_peanut_dattathri.cpp b/function_objects/func_peanut_dattathri.cpp index bf4de21..2db1505 100644 --- a/function_objects/func_peanut_dattathri.cpp +++ b/function_objects/func_peanut_dattathri.cpp @@ -98,22 +98,44 @@ DattathriPeanut3D::DattathriPeanut3D( ) +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void DattathriPeanut3D::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, ell, n, I_b, r_e, r_c, alpha, gamma + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = intensityScale * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = pixelScaling * inputFunctionParams[4 + offsetIndex]; + adjustedFunctionParams[5 + offsetIndex] = inputFunctionParams[5 + offsetIndex]; + adjustedFunctionParams[6 + offsetIndex] = inputFunctionParams[6 + offsetIndex]; + adjustedFunctionParams[7 + offsetIndex] = pixelScaling * inputFunctionParams[7 + offsetIndex]; + adjustedFunctionParams[8 + offsetIndex] = pixelScaling * inputFunctionParams[8 + offsetIndex]; + adjustedFunctionParams[9 + offsetIndex] = pixelScaling * inputFunctionParams[9 + offsetIndex]; + adjustedFunctionParams[10 + offsetIndex] = inputFunctionParams[10 + offsetIndex]; + adjustedFunctionParams[11 + offsetIndex] = inputFunctionParams[11 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void DattathriPeanut3D::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; inc = params[1 + offsetIndex]; psi_bar = params[2 + offsetIndex]; - J0_bar = params[3 + offsetIndex]; - R_bar_x = params[4 + offsetIndex]; + J0_bar = params[3 + offsetIndex] * intensityScale; + R_bar_x = params[4 + offsetIndex] * pixelScaling; q = params[5 + offsetIndex]; q_z = params[6 + offsetIndex]; - R_peanut = params[7 + offsetIndex]; - A_peanut = params[8 + offsetIndex]; - sigma_peanut = params[9 + offsetIndex]; + R_peanut = params[7 + offsetIndex] * pixelScaling; + A_peanut = params[8 + offsetIndex] * pixelScaling; + sigma_peanut = params[9 + offsetIndex] * pixelScaling; c_bar_par = params[10 + offsetIndex]; c_bar_perp = params[11 + offsetIndex]; diff --git a/function_objects/func_peanut_dattathri.h b/function_objects/func_peanut_dattathri.h index fc60567..305a870 100644 --- a/function_objects/func_peanut_dattathri.h +++ b/function_objects/func_peanut_dattathri.h @@ -26,6 +26,8 @@ class DattathriPeanut3D : public FunctionObject // Constructor DattathriPeanut3D( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now diff --git a/function_objects/func_pointsource-rot.cpp b/function_objects/func_pointsource-rot.cpp index 93931bf..4ab7646 100644 --- a/function_objects/func_pointsource-rot.cpp +++ b/function_objects/func_pointsource-rot.cpp @@ -1,7 +1,7 @@ /* FILE: func_pointsource_rot.cpp -------------------------------------- */ /* - * This is the base class for the various function object classes. - * It really shouldn't be instantiated by itself. + * Function object for an interpolated point source, based on user-supplied + * PSF image, allowing for arbitrary rotation. * * BASIC IDEA: * Setup() is called as the first part of invoking the function; @@ -22,7 +22,7 @@ * 11 Aug 2021: Created (as modification of func_pointsource.cpp). */ -// Copyright 2021--2023 by Peter Erwin. +// Copyright 2021--2024 by Peter Erwin. // // This file is part of Imfit. // @@ -186,14 +186,26 @@ int PointSourceRot::SetExtraParams( map& inputMap ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void PointSourceRot::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, I_tot + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation;; + adjustedFunctionParams[1 + offsetIndex] = intensityScale * inputFunctionParams[1 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void PointSourceRot::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; - I_tot = params[1 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; + I_tot = params[1 + offsetIndex] * intensityScale; // convert PA to +x-axis reference PA_rad = (PA + 90.0) * DEG2RAD; diff --git a/function_objects/func_pointsource-rot.h b/function_objects/func_pointsource-rot.h index 3df826c..4f15e2c 100644 --- a/function_objects/func_pointsource-rot.h +++ b/function_objects/func_pointsource-rot.h @@ -37,6 +37,8 @@ class PointSourceRot : public FunctionObject bool HasExtraParams( ); int SetExtraParams( map& inputMap ); + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); bool CanCalculateTotalFlux( ); diff --git a/function_objects/func_pointsource.cpp b/function_objects/func_pointsource.cpp index 64d4a78..5003960 100644 --- a/function_objects/func_pointsource.cpp +++ b/function_objects/func_pointsource.cpp @@ -1,7 +1,7 @@ /* FILE: func_pointsource.cpp ------------------------------------------ */ /* - * This is the base class for the various function object classes. - * It really shouldn't be instantiated by itself. + * Function object for an interpolated point source, based on user-supplied + * PSF image. * * BASIC IDEA: * Setup() is called as the first part of invoking the function; @@ -22,7 +22,7 @@ * 2 Oct 2017: Created (as modification of func_gaussian.cpp). */ -// Copyright 2017--2023 by Peter Erwin. +// Copyright 2017--2024 by Peter Erwin. // // This file is part of Imfit. // @@ -190,13 +190,24 @@ int PointSource::SetExtraParams( map& inputMap ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void PointSource::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // I_tot + adjustedFunctionParams[0 + offsetIndex] = intensityScale * inputFunctionParams[0 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void PointSource::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - I_tot = params[0 + offsetIndex]; + I_tot = params[0 + offsetIndex] * intensityScale; } diff --git a/function_objects/func_pointsource.h b/function_objects/func_pointsource.h index 62e549a..a2428a4 100644 --- a/function_objects/func_pointsource.h +++ b/function_objects/func_pointsource.h @@ -35,6 +35,8 @@ class PointSource : public FunctionObject bool HasExtraParams( ); int SetExtraParams( map& inputMap ); + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); bool CanCalculateTotalFlux( ); diff --git a/function_objects/func_sersic.cpp b/function_objects/func_sersic.cpp index f886512..4131c7e 100644 --- a/function_objects/func_sersic.cpp +++ b/function_objects/func_sersic.cpp @@ -89,17 +89,32 @@ Sersic::Sersic( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void Sersic::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // PA, ell, n, I_e, r_e + adjustedFunctionParams[0 + offsetIndex] = inputFunctionParams[0 + offsetIndex] - imageRotation; + adjustedFunctionParams[1 + offsetIndex] = inputFunctionParams[1 + offsetIndex]; + adjustedFunctionParams[2 + offsetIndex] = inputFunctionParams[2 + offsetIndex]; + adjustedFunctionParams[3 + offsetIndex] = intensityScale * inputFunctionParams[3 + offsetIndex]; + adjustedFunctionParams[4 + offsetIndex] = pixelScaling * inputFunctionParams[4 + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void Sersic::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - PA = params[0 + offsetIndex]; + PA = params[0 + offsetIndex] - imageRotation; ell = params[1 + offsetIndex]; - n = params[2 + offsetIndex ]; - I_e = params[3 + offsetIndex ]; - r_e = params[4 + offsetIndex ]; + n = params[2 + offsetIndex]; + I_e = params[3 + offsetIndex] * intensityScale; + r_e = params[4 + offsetIndex] * pixelScaling; // pre-compute useful things for this round of invoking the function q = 1.0 - ell; diff --git a/function_objects/func_sersic.h b/function_objects/func_sersic.h index ddbae1b..b3dfb5a 100644 --- a/function_objects/func_sersic.h +++ b/function_objects/func_sersic.h @@ -17,6 +17,9 @@ */ +#ifndef _FUNC_SERSIC_H_ +#define _FUNC_SERSIC_H_ + // CLASS Sersic: #include "function_object.h" @@ -32,6 +35,8 @@ class Sersic : public FunctionObject // Constructors: Sersic( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); bool CanCalculateTotalFlux( ); @@ -52,3 +57,6 @@ class Sersic : public FunctionObject double bn, invn; double q, PA_rad, cosPA, sinPA; // other useful (shape-related) quantities }; + + +#endif /* _FUNC_SERSIC_H_ */ diff --git a/function_objects/func_tilted-sky-plane.cpp b/function_objects/func_tilted-sky-plane.cpp index 7193b9a..9b59d81 100644 --- a/function_objects/func_tilted-sky-plane.cpp +++ b/function_objects/func_tilted-sky-plane.cpp @@ -7,7 +7,7 @@ * */ -// Copyright 2020--2022 by Peter Erwin. +// Copyright 2020--2024 by Peter Erwin. // // This file is part of Imfit. // @@ -68,13 +68,26 @@ TiltedSkyPlane::TiltedSkyPlane( ) } +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Rescale/adjust input function parameters using current set of image-description +/// parameters +void TiltedSkyPlane::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + // I_0 + adjustedFunctionParams[0 + offsetIndex] = intensityScale * inputFunctionParams[0 + offsetIndex]; + // FIXME: figure out correct size rescaling via pixScaling for m_x and m_y (units of pixel^-1) +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ void TiltedSkyPlane::Setup( double params[], int offsetIndex, double xc, double yc ) { x0 = xc; y0 = yc; - I_0 = params[0 + offsetIndex ]; + I_0 = params[0 + offsetIndex ] * intensityScale; + // FIXME: figure out correct size rescaling via pixScaling for m_x and m_y (units of pixel^-1) m_x = params[1 + offsetIndex ]; // slope in x-direction m_y = params[2 + offsetIndex ]; // slope in y-direction } diff --git a/function_objects/func_tilted-sky-plane.h b/function_objects/func_tilted-sky-plane.h index 455766c..77ccb5e 100644 --- a/function_objects/func_tilted-sky-plane.h +++ b/function_objects/func_tilted-sky-plane.h @@ -6,6 +6,9 @@ */ +#ifndef _FUNC_TILTEDSKY_H_ +#define _FUNC_TILTEDSKY_H_ + // CLASS TiltedSkyPlane: #include "function_object.h" @@ -22,6 +25,8 @@ class TiltedSkyPlane : public FunctionObject // Constructors: TiltedSkyPlane( ); // redefined method/member function: + void AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ); void Setup( double params[], int offsetIndex, double xc, double yc ); double GetValue( double x, double y ); // No destructor for now @@ -33,3 +38,6 @@ class TiltedSkyPlane : public FunctionObject private: double x0, y0, I_0, m_x, m_y; }; + + +#endif /* _FUNC_TILTEDSKY_H_ */ diff --git a/function_objects/function_object.cpp b/function_objects/function_object.cpp index 9ac46cf..022e055 100644 --- a/function_objects/function_object.cpp +++ b/function_objects/function_object.cpp @@ -64,6 +64,12 @@ FunctionObject::FunctionObject( ) // These will get redefined by derived class's constructor functionName = "Base (undefined) function"; shortFunctionName = "BaseFunction"; + extraParamsSet = false; + + // MULTIMFIT default values + pixelScaling = 1.0; + intensityScale = 1.0; + imageRotation = 0.0; } @@ -91,6 +97,29 @@ void FunctionObject::SetLabel( string &userLabel ) } +/* ---------------- PUBLIC METHOD: SetImageParameters ------------------ */ +/// Tell FunctionObject instance about updated image-description parameters +/// (for use with multimfit). +/// Note that pixScale = pixel size of image relative to reference image pixels; +/// internally, we will multiply input size parameters by 1/pixScale +void FunctionObject::SetImageParameters( double pixScale, double imageRot, double intensScale ) +{ + pixelScaling = 1.0 / pixScale; + imageRotation = imageRot; + intensityScale = intensScale; +} + + +/* ---------------- PUBLIC METHOD: AdjustParametersForImage ------------ */ +/// Convert input functionparameters using current set of image-description parameters +void FunctionObject::AdjustParametersForImage( const double inputFunctionParams[], + double adjustedFunctionParams[], int offsetIndex ) +{ + for (int i = 0; i < nParams; i++) + adjustedFunctionParams[i + offsetIndex] = inputFunctionParams[i + offsetIndex]; +} + + /* ---------------- PUBLIC METHOD: Setup ------------------------------- */ /// Base method for 2D functions: pass current parameters into the function object, /// storing them for when GetValue() is called, and pre-compute useful quantities. diff --git a/function_objects/function_object.h b/function_objects/function_object.h index dfaab1e..f3db432 100644 --- a/function_objects/function_object.h +++ b/function_objects/function_object.h @@ -56,6 +56,14 @@ class FunctionObject // probably no need to modify this (for 1D functions): virtual void SetZeroPoint( double zeroPoint ); + // NEW MULTIMFIT STUFF + // probably no need to modify this: + virtual void SetImageParameters( double pixScale, double imageRot, double intensScale ); + + virtual void AdjustParametersForImage( const double inputFunctionsParams[], + double adjustedFunctionParams[], int offsetIndex ); + + // probably no need to modify this virtual void SetLabel( string & userLabel ); @@ -124,6 +132,12 @@ class FunctionObject map inputExtraParams; string functionName, shortFunctionName, label; double ZP; + + // NEW MULTIMFIT STUFF + double pixelScaling; // multiply input size parameters by this + double intensityScale; // multiply input intensity parameters by this + double imageRotation; // treat image +y axis as rotated CCW relative to + // reference image by this many degrees // class member (constant char-vector string) which will hold name of // individual class in derived classes diff --git a/todo_and_bugs-to-fix.txt b/todo_and_bugs-to-fix.txt index 518935e..6224106 100644 --- a/todo_and_bugs-to-fix.txt +++ b/todo_and_bugs-to-fix.txt @@ -1,6 +1,37 @@ *** CURRENT WORK +[ ] Add multimfit code into main repo + [x] Update model_object.cpp + + [X] Update function_object.h/cpp + -- SetImageParameters and AdjustParametersForImage + -- extra image-parameters-related data members + [ ] Update all image functions! + -- individual AdjustParametersForImage method overrides + [x] Update standard functions + [ ] LATER: update extra functions + + [X] Check that imfit & makeimage still work + + [ ] Update add_functions.cpp + [ ] May need to update defintion or calls to AddFunctions() in PyImfit + -- we added optional final parameter globalFuncFlags + + [ ] Check that imfit & makeimage still work + + [ ] Continue trying to compile makemultimages + + [ ] Copy in tests and test files from multimfit + + +[ ] Copy extra functions from imfit_hg to imfit + -- i.e., those functions that aren't in the repos + + +[ ] Investigate ModelObject::GetImageOffsets -- two different versions of this function! + + ** BUGS TO FIX: