Skip to content

Commit

Permalink
Various changes to accomodate use of function labels in v1.8 of Imfit.
Browse files Browse the repository at this point in the history
  • Loading branch information
perwin committed Oct 10, 2020
1 parent ba553e6 commit 108f4c0
Show file tree
Hide file tree
Showing 19 changed files with 2,342 additions and 2,468 deletions.
8 changes: 6 additions & 2 deletions howto_new_distribution.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ Working by default in ~/coding/pyimfit on Mac.
A. [mac] cd imfit
B. [mac] scons --clang-openmp libimfit.a
C. [mac] cp libimfit.a ../prebuilt/macos
# copy updated Imfit C++ header files
D. [mac] cd .. ; ./update_from_imfit.sh

[opt]2. Generate updated libimfit.a for Linux [VM: ubuntu64-16_dev], IF NECESSARY
A. [vm] cd /home/vagrant/build/pyimfit/imfit
B. [vm] scons libimfit.a
C. [vm] cp libimfit.a ../prebuilt/linux64
D. [vm] cp libimfit.a /vagrant/transfer
E. [mac] cp ~/vagrant/ubuntu64-16_dev/transfer/libimfit.a ./prebuilt/linux64
# copy updated Imfit C++ header files
D. [mac] cd .. ; ./update_from_imfit.sh
E. [vm] cp libimfit.a /vagrant/transfer
F. [mac] cp ~/vagrant/ubuntu64-16_dev/transfer/libimfit.a ./prebuilt/linux64

3. Do new "develop" install and run tests on macOS
[mac] $ python3 setup.py develop
Expand Down
6 changes: 4 additions & 2 deletions libimfit/include/add_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ using namespace std;
static vector< map<string, string> > EMPTY_MAP_VECTOR;


// NOTE: (some of) the following functions are used in PyImfit

//! Main function which adds a list of FunctionObject instances to an instance of ModelObject
int AddFunctions( ModelObject *theModel, const vector<string> &functionNameList,
vector<int> &functionBlockIndices, const bool subamplingFlag,
const int verboseFlag=0,
vector<string> &functionLabelList, vector<int> &functionSetIndices,
const bool subamplingFlag, const int verboseFlag=0,
vector< map<string, string> > &extraParams=EMPTY_MAP_VECTOR );

//! Prints out names of available image functions (FunctionObject classes) to stdout
Expand Down
3 changes: 3 additions & 0 deletions libimfit/include/bootstrap_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ int BootstrapErrors( const double *bestfitParams, vector<mp_par> parameterLimits
const int nIterations, const int nFreeParams, const int whichStatistic,
FILE *outputFile_ptr, unsigned long rngSeed=0 );


// NOTE: The following function is used in PyImfit

/*! \brief Alternate interface: returns array of best-fit parameters in outputParamArray,
which is 1D contiguous array (not array of pointers to arrays); doesn't
print any output at all or save anything to a file.
Expand Down
3 changes: 3 additions & 0 deletions libimfit/include/convolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ void PrintComplexImage_RealPart( fftw_complex *image_cmplx, int nColumns, int nR
void PrintComplexImage_Absolute( fftw_complex *image_cmplx, int nColumns, int nRows );



// NOTE: The following class is used in PyImfit

/// Class for handling PSF convolution (stores PSF, performs convolutions
/// with input model images)
class Convolver
Expand Down
4 changes: 3 additions & 1 deletion libimfit/include/dispatch_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "param_struct.h" // for mp_par structure
#include "solver_results.h"

// NOTE: The following functions is used in PyImfit

// Possible return values from DispatchToSolver
// All:
Expand Down Expand Up @@ -74,7 +75,8 @@
int DispatchToSolver( int solverID, int nParametersTot, int nFreeParameters, int nPixelsTot,
double *parameters, vector<mp_par> parameterInfo, ModelObject *modelObj,
double fracTolerance, bool paramLimitsExist, int verboseLevel,
SolverResults *solverResults, string& solverName, unsigned long rngSeed=0 );
SolverResults *solverResults, string& solverName,
unsigned long rngSeed=0, bool useLHS=false );


#endif /* _DISPATCH_SOLVER_H_ */
12 changes: 9 additions & 3 deletions libimfit/include/function_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ class FunctionObject
/// Sets internal oversamplingScale to specified value (for use in oversampled regions)
virtual void SetOversamplingScale( int oversampleScale ) { ; };

// probably no need to modify this:
// probably no need to modify this (unless function uses subcomponent functions):
virtual void SetSubsampling( bool subsampleFlag );

// probably no need to modify this:
// probably no need to modify this (for 1D functions):
virtual void SetZeroPoint( double zeroPoint );

// probably no need to modify this
virtual void SetLabel( string & userLabel );

// derived classes will almost certainly modify this, which
// is used for pre-calculations and convolutions, if any:
virtual void Setup( double params[], int offsetIndex, double xc, double yc );
Expand Down Expand Up @@ -86,6 +89,9 @@ class FunctionObject
// no need to modify this:
virtual string& GetShortName( );

// no need to modify this:
virtual string& GetLabel( );

// probably no need to modify this:
virtual void GetParameterNames( vector<string> &paramNameList );

Expand All @@ -106,7 +112,7 @@ class FunctionObject
bool doSubsampling;
bool extraParamsSet;
vector<string> parameterLabels;
string functionName, shortFunctionName;
string functionName, shortFunctionName, label;
double ZP;

// class member (constant char-vector string) which will hold name of
Expand Down
17 changes: 12 additions & 5 deletions libimfit/include/model_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
using namespace std;


// NOTE: (parts of) the following class are used in PyImfit


// assume that all methods are "common" to both 2D (base) and 1D (derived) versions,
// unless otherwise stated

Expand All @@ -50,13 +53,14 @@ class ModelObject


// Adds a new FunctionObject pointer to the internal vector
// (Overridden by ModelObjectMultImage)
virtual int AddFunction( FunctionObject *newFunctionObj_ptr );

// 2D only
int SetupPsfInterpolation( int interpolationType=kInterpolator_bicubic );

// common, but Specialized by ModelObject1D
virtual void DefineFunctionBlocks( vector<int>& functionStartIndices );
virtual void DefineFunctionSets( vector<int>& functionStartIndices );


// 1D only
Expand Down Expand Up @@ -111,7 +115,7 @@ class ModelObject
int AddPSFVector( long nPixels_psf, int nColumns_psf, int nRows_psf,
double *psfPixels, bool normalizePSF=true );

// 2D only [this will eventually replace AddOversampledPSFVector]
// 2D only
int AddOversampledPsfInfo( PsfOversamplingInfo *oversampledPsfInfo );

// 1D only
Expand Down Expand Up @@ -142,6 +146,7 @@ class ModelObject

virtual int WhichFitStatistic( bool verbose=false );

// Specialized by ModelObjectMultImages
virtual double GetFitStatistic( double params[] );

virtual double ChiSquared( double params[] );
Expand All @@ -157,6 +162,8 @@ class ModelObject

void GetFunctionNames( vector<string>& functionNames );

void GetFunctionLabels( vector<string>& functionLabels );

void GetImageOffsets( double params[] );

virtual string GetParamHeader( );
Expand Down Expand Up @@ -266,7 +273,7 @@ class ModelObject
bool modelVectorAllocated, weightVectorAllocated, maskVectorAllocated;
bool standardWeightVectorAllocated;
bool residualVectorAllocated, outputModelVectorAllocated;
bool fblockStartFlags_allocated;
bool fsetStartFlags_allocated;
bool modelImageSetupDone;
bool modelImageComputed;
bool weightValsSet, maskExists, doBootstrap, bootstrapIndicesAllocated;
Expand All @@ -277,7 +284,7 @@ class ModelObject
bool extraCashTermsVectorAllocated;
bool localPsfPixels_allocated;
bool zeroPointSet;
int nFunctions, nFunctionBlocks, nFunctionParams, nParamsTot;
int nFunctions, nFunctionSets, nFunctionParams, nParamsTot;
double *dataVector;
double *weightVector, *standardWeightVector;
double *maskVector;
Expand All @@ -288,7 +295,7 @@ class ModelObject
double *extraCashTermsVector;
double *localPsfPixels;
long *bootstrapIndices;
bool *fblockStartFlags;
bool *fsetStartFlags;
vector<FunctionObject *> functionObjects;
vector<int> paramSizes;
vector<string> parameterLabels;
Expand Down
3 changes: 3 additions & 0 deletions libimfit/include/mpfit.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ struct mp_config_struct {

};


// NOTE: (parts of) the following struct are used in PyImfit

/* Definition of results structure, for when fit completes */
struct mp_result_struct {
double bestnorm; /* Final chi^2 */
Expand Down
2 changes: 2 additions & 0 deletions libimfit/include/param_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#define _PARAM_STRUCT_H_


// NOTE: (parts of) the following struct is used in PyImfit

/* Definition of a parameter constraint structure */
// This is a structure which holds metadata about a particular parameter:
// its name, whether or not it is fixed, any limits on its allowed values,
Expand Down
2 changes: 2 additions & 0 deletions libimfit/include/psf_oversampling_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using namespace std;


// NOTE: the following class is used in PyImfit

class PsfOversamplingInfo
{
public:
Expand Down
1 change: 1 addition & 0 deletions libimfit/include/statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ double StandardDeviation( double *vector, int nVals );

std::tuple<double, double> ConfidenceInterval( double *vector, int nVals );

// NOTE: the following two functions are used in PyImfit
double AIC_corrected( double logLikelihood, int nParams, long nData, int chiSquareUsed );

double BIC( double logLikelihood, int nParams, long nData, int chiSquareUsed );
Expand Down
18 changes: 15 additions & 3 deletions new_notes_and_todo_for_python-wrapper_code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PLAN:
** New Update: Update code to use Imfit v1.8

[ ] Build and text new Mac Python version
[ ] Update imfit submodule
[x] Update imfit submodule
[x] Update submodule
$ cd ~/coding/pyimfit
$ git submodule update --remote --merge
Expand All @@ -21,8 +21,20 @@ PLAN:
A. [mac] cd imfit
B. [mac] scons --clang-openmp libimfit.a
C. [mac] cp libimfit.a ../prebuilt/macos

[ ] Build and test pyimfit on Mac
# copy updated Imfit C++ header files
D. [mac] cd .. ; ./update_from_imfit.sh

[..] Build and test pyimfit on Mac
[..] Changed AddFunctions() in v1.8
-- now includes functionLabelList input parameter
[ ] Update imfit_lib.pxd to handle changed AddFunctions
[ ] Update pyimfit_lib.pyx to handle changed AddFunctions

[ ] Update Python code to handle changed AddFunctions
-- e.g., pass in labels when initializing FunctionDescription objects?
[x] Update code in descriptions.py
[ ] Update code that reads in config files to check for and add
function labels

[ ] Build and test pyimfit on Linux VM

Expand Down
2 changes: 1 addition & 1 deletion pyimfit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
imageFunctionList = get_function_list()
imageFunctionDict = get_function_dict()

__version__ = "0.9.0"
__version__ = "0.10.0"
14 changes: 11 additions & 3 deletions pyimfit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def parse_config( lines: List[str] ) -> ModelDescription:
model = ModelDescription()

block_start = 0
functionBlock_id = 0 # number of current function block ("function set")
functionBlock_id = 0 # number of current function set
for i in range(block_start, len(lines)):
if lines[i].startswith(x0_str):
if block_start == 0:
Expand Down Expand Up @@ -220,15 +220,23 @@ def read_function( lines: List[str] ) -> FunctionDescription:
func : :class:`~imfit.`FunctionDescription`
Contains extracted information about function and its parameters
"""
# First line contains the function name.

def GetFunctionLabel( theLine ):
labelText = ""
if theLine.find("LABEL:") > 0:
labelText = theLine.split("LABEL:")[1].strip()
return labelText

# First line contains the function name, and optionally the label
pieces = lines[0].split()
test_function_str = pieces[0]
if test_function_str != function_str:
raise ValueError('Function definition must begin with FUNCTION.')
if len(pieces) <= 1:
raise ValueError('No function name was supplied.')
name = pieces[1].strip()
func = FunctionDescription(name)
label = GetFunctionLabel(lines[0])
func = FunctionDescription(name, label)
# Read the function parameters.
for i in range(1, len(lines)):
func.addParameter(read_parameter(lines[i]))
Expand Down

0 comments on commit 108f4c0

Please sign in to comment.