Skip to content

Commit

Permalink
Replacements of NULL with nullptr.
Browse files Browse the repository at this point in the history
Moved compilation of func_edge-on-disk_n4762 and func_edge-on-disk_n4762v2 to
useExtraFuncs part of SConstruct.
  • Loading branch information
perwin committed Jun 23, 2024
1 parent 4944611 commit 0010071
Show file tree
Hide file tree
Showing 70 changed files with 1,078 additions and 152 deletions.
40 changes: 39 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down
13 changes: 10 additions & 3 deletions core/add_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
*/

// Copyright 2010--2023 by Peter Erwin.
// Copyright 2010--2024 by Peter Erwin.
//
// This file is part of Imfit.
//
Expand Down Expand Up @@ -389,19 +389,23 @@ void PopulateFactoryMap( map<string, factory*>& input_factory_map )
int AddFunctions( ModelObject *theModel, const vector<string> &functionNameList,
vector<string> &functionLabelList, vector<int> &functionSetIndices,
const bool subsamplingFlag, const int verboseLevel,
vector< map<string, string> > &extraParams )
vector< map<string, string> > &extraParams,
const vector<bool> &globalFuncFlags )
{
int nFunctions = functionNameList.size();
int status;
string currentName;
bool extraParamsMayExist = false;
bool globalFuncFlagsExist = false;
FunctionObject *thisFunctionObj;
map<string, factory*> factory_map;

PopulateFactoryMap(factory_map);

if (extraParams.size() > 0)
extraParamsMayExist = true;
if (globalFuncFlags.size() > 0)
globalFuncFlagsExist = true;

for (int i = 0; i < nFunctions; i++) {
currentName = functionNameList[i];
Expand Down Expand Up @@ -431,7 +435,10 @@ int AddFunctions( ModelObject *theModel, const vector<string> &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);
Expand Down
6 changes: 4 additions & 2 deletions core/add_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

using namespace std;

static vector< map<string, string> > EMPTY_MAP_VECTOR;
// static vector< map<string, string> > EMPTY_MAP_VECTOR;
static vector<bool> EMPTY_BOOL_VECTOR;


// NOTE: (some of) the following functions are used in PyImfit
Expand All @@ -22,7 +23,8 @@ static vector< map<string, string> > EMPTY_MAP_VECTOR;
int AddFunctions( ModelObject *theModel, const vector<string> &functionNameList,
vector<string> &functionLabelList, vector<int> &functionSetIndices,
const bool subamplingFlag, const int verboseFlag=0,
vector< map<string, string> > &extraParams=EMPTY_MAP_VECTOR );
vector< map<string, string> > &extraParams=EMPTY_MAP_VECTOR,
const vector<bool> &globalFuncFlags=EMPTY_BOOL_VECTOR );

//! Prints out names of available image functions (FunctionObject classes) to stdout
void PrintAvailableFunctions( );
Expand Down
2 changes: 2 additions & 0 deletions core/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> > EMPTY_MAP_VECTOR;

#endif /* _DEFINITIONS_H_ */
116 changes: 116 additions & 0 deletions core/definitions_multimage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/** @file
\brief Generally useful definitions & constants for multimfit, etc.
*/

#ifndef _DEFINITIONS_MULTIMAGE_H_
#define _DEFINITIONS_MULTIMAGE_H_

#include <string>
#include <vector>
#include <strings.h>

#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<string> psfOversampledFileNames;
int nOversampledFileNames;
bool psfOversampledImage_present;
vector<int> psfOversamplingScales;
int nOversamplingScales;
bool oversampleRegionSet;
int nOversampleRegions;
vector<string> psfOversampleRegions;

// stuff for per-image functions, if any
bool perImageFunctionsExist;
vector<string> perImageFuncNames;
vector<string> perImageFuncLabels;
vector<int> perImageFuncSetIndices;
vector<double> perImageParamVals;
bool perImageParamLimitsExist;
vector<mp_par> 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_ */
77 changes: 76 additions & 1 deletion core/model_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()) {
Expand All @@ -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
Expand Down Expand Up @@ -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[] )
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -2498,6 +2566,13 @@ bool ModelObject::CheckWeightVector( )
}


void ModelObject::GetDataImageDimensions( int *nColumns, int *nRows )
{
*nColumns = nDataColumns;
*nRows = nDataRows;
}




// Extra stuff
Expand Down
Loading

0 comments on commit 0010071

Please sign in to comment.