Skip to content

Commit

Permalink
Fixes for not recognizing PSF image when trying to use PointSource-ty…
Browse files Browse the repository at this point in the history
…pe functions, including

keeping track of whether functions in models require PSFs.
Changed Imfit "nproc" parameter to "maxThreads".
Attempting to use version 1.9 of Imfit for libimfit.a.
Updated to version 0.12.0.
  • Loading branch information
perwin committed Feb 1, 2023
1 parent b694bb0 commit 2f0f81d
Show file tree
Hide file tree
Showing 23 changed files with 3,573 additions and 3,026 deletions.
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
author = 'Peter Erwin'

# The short X.Y version
version = '0.11'
version = '0.12'
# The full version, including alpha/beta/rc tags
release = '0.11.2'
release = '0.12.0'


# -- General configuration ---------------------------------------------------
Expand Down
14 changes: 8 additions & 6 deletions howto_new_distribution.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ Working by default in ~/coding/pyimfit on Mac.

[opt]1. Generate updated libimfit.a for macOS, IF NECESSARY
A. [mac] cd imfit
B. [mac] scons --clang-openmp libimfit.a
C. [mac] cp libimfit.a ../prebuilt/macos
B. [mac] git pull origin master [if necessary]
C. [mac] scons --clang-openmp libimfit.a
D. [mac] cp libimfit.a ../prebuilt/macos
# copy updated Imfit C++ header files
D. [mac] cd .. ; ./update_from_imfit.sh
E. [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
E. [vm] cp libimfit.a /vagrant/transfer
F. [mac] cp ~/vagrant/ubuntu64-16_dev/transfer/libimfit.a ./prebuilt/linux64
B. [vm] git pull origin master [if necessary]
C. [vm] scons libimfit.a
D. [vm] cp libimfit.a /vagrant/transfer
E. [mac] cp ~/vagrant/ubuntu64-16_dev/transfer/libimfit.a ./prebuilt/linux64

3. Do new "develop" install and run tests on macOS
[mac] $ pip3 install -e ./
Expand Down
2 changes: 1 addition & 1 deletion imfit
Submodule imfit updated 150 files
10 changes: 10 additions & 0 deletions libimfit/include/count_cpu_cores.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Code for determining the number of *physical* CPU cores on a computer;
// useful for determining how many threads to use for OpenMP and (especially)
// FFTW.

#ifndef _COUNT_CPU_CORES_H_
#define _COUNT_CPU_CORES_H_

int GetPhysicalCoreCount( );

#endif // _COUNT_CPU_CORES_H_
32 changes: 25 additions & 7 deletions libimfit/include/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
#ifndef _DEFINITIONS_H_
#define _DEFINITIONS_H_

#include <string>
#include <vector>
#include <map>
#include <signal.h> // for sig_atomic_t

using namespace std;

#ifndef NO_SIGNALS
// volatile sig_atomic_t stopSignal_flag;
extern volatile sig_atomic_t stopSignal_flag;
#endif


const int MAXLINE = 1024;
const int MAX_FILENAME_LENGTH = 512;
Expand All @@ -23,7 +35,7 @@ const double MEMORY_WARNING_LIMT = 1073741824.0; /* 1 gigabyte */
// imfit-related
#define DEFAULT_IMFIT_CONFIG_FILE "imfit_config.dat"
#define DEFAULT_OUTPUT_PARAMETER_FILE "bestfit_parameters_imfit.dat"

#define USER_INTERRUPT_OUTPUT_PARAMETER_FILE "current_parameters_imfit.dat"

// makeimage-related
#define DEFAULT_MAKEIMAGE_OUTPUT_FILENAME "modelimage.fits"
Expand Down Expand Up @@ -68,16 +80,22 @@ const int MASK_ZERO_IS_BAD = 20; /// alternate input mask format (good



/* STRING DEFINITIONS FOR PARAMETER NAMES */
const std::string X0_string("X0");
const std::string Y0_string("Y0");



/* Output string formats for printing parameter values */
#define XY_FORMAT "%s%s\t\t%.4f\n"
#define XY_FORMAT_WITH_ERRS "%s%s\t\t%.4f # +/- %.4f\n"
#define XY_FORMAT_WITH_LIMITS "%s%s\t\t%.4f\t\t%g,%g\n"
#define XY_FORMAT_WITH_FIXED "%s%s\t\t%.4f\t\tfixed\n"
#define PARAM_FORMAT "%s%s\t\t%7g\n"
#define PARAM_FORMAT_WITH_ERRS "%s%s\t\t%7g # +/- %.5g\n"
#define PARAM_FORMAT_WITH_LIMITS "%s%s\t\t%7g\t\t%g,%g\n"
#define PARAM_FORMAT_WITH_FIXED "%s%s\t\t%7g\t\tfixed\n"


// the following do *not* have "\n" at the end
#define PARAM_FORMAT "%s%s\t\t%7g"
#define PARAM_FORMAT_WITH_ERRS "%s%s\t\t%7g # +/- %.5g"
#define PARAM_FORMAT_WITH_LIMITS "%s%s\t\t%7g\t\t%g,%g"
#define PARAM_FORMAT_WITH_FIXED "%s%s\t\t%7g\t\tfixed"
#define UNITS_FORMAT "\t%s%s"

#endif /* _DEFINITIONS_H_ */
16 changes: 13 additions & 3 deletions libimfit/include/function_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class FunctionObject
// override in derived classes only if said class is a "background" object
// which should *not* be used in total flux calculations
/// Returns true if class can calculate total flux internally
virtual bool IsBackground( ) { return(false); }
virtual bool IsBackground( ) { return isBackground; }
// override in derived classes only if said class *can* calcluate total flux
/// Returns true if class can calculate total flux internally
virtual bool CanCalculateTotalFlux( ) { return(false); }
Expand All @@ -95,6 +95,13 @@ class FunctionObject
// probably no need to modify this:
virtual void GetParameterNames( vector<string> &paramNameList );

bool HasParameterUnits( ) { return parameterUnitsExist; };

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

virtual void GetExtraParamsDescription( vector<string> &outputLines );

// probably no need to modify this:
virtual int GetNParams( );

Expand All @@ -110,8 +117,11 @@ class FunctionObject
protected:
int nParams; ///< number of input parameters that image-function uses
bool doSubsampling;
bool extraParamsSet;
vector<string> parameterLabels;
bool isBackground = false;
bool parameterUnitsExist = false;
bool extraParamsSet = false;
vector<string> parameterLabels, parameterUnits;
map<string, string> inputExtraParams;
string functionName, shortFunctionName, label;
double ZP;

Expand Down
1 change: 1 addition & 0 deletions libimfit/include/model_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class ModelObject

virtual string GetParamHeader( );


// common, but Specialized by ModelObject1D
virtual int PrintModelParamsToStrings( vector<string> &stringVector, double params[],
double errs[], const char *prefix="", bool printLimits=false );
Expand Down
1 change: 1 addition & 0 deletions libimfit/include/mpfit.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ typedef int (*mp_func)(int m, /* Number of functions (elts of fvec) */
#define MP_FTOL (6) /* ftol is too small; no further improvement*/
#define MP_XTOL (7) /* xtol is too small; no further improvement*/
#define MP_GTOL (8) /* gtol is too small; no further improvement*/
#define MP_SIGINT (100) /* PE: user typed Ctrl-C */

/* Double precision numeric constants */
#define MP_MACHEP0 2.2204460e-16
Expand Down
3 changes: 2 additions & 1 deletion libimfit/include/oversampled_region.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class OversampledRegion
int nRegionColumns, nRegionRows, nRegionVals;
int x1_region, y1_region;
int nMainImageColumns, nMainImageRows, nMainPSFColumns, nMainPSFRows;
int nModelColumns, nModelRows, nModelVals;
int nModelColumns, nModelRows;
long nModelVals;
bool doConvolution, setupComplete, modelVectorAllocated;
double *modelVector;
string debugImageName;
Expand Down
18 changes: 18 additions & 0 deletions libimfit/include/psf_interpolators.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,22 @@ class PsfInterpolator_lanczos2 : public PsfInterpolator
double *psfDataArray;
};


// Derived class using Lanczos3 kernel
class PsfInterpolator_lanczos3 : public PsfInterpolator
{
public:
PsfInterpolator_lanczos3( double *inputImage, int nCols_image, int nRows_image );

~PsfInterpolator_lanczos3( );

double GetValue( double x, double y );

private:
// new data members
double *xArray;
double *yArray;
double *psfDataArray;
};

#endif // _PSF_INTERPOLATORS_H_
6 changes: 5 additions & 1 deletion make_upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if [[ $# -lt 1 ]]; then
fi

# Make sdist (.tar.gz) and macOS binary wheels
python3.11 setup.py sdist bdist_wheel
python3.10 setup.py sdist bdist_wheel
python3.9 setup.py sdist bdist_wheel
python3.8 setup.py bdist_wheel
Expand All @@ -19,6 +20,7 @@ python3.6 setup.py bdist_wheel
# Copy shared libs into wheel using delocate
VERSION_NUM=$1
cd dist
delocate-wheel -w fixed_wheels -v pyimfit-${VERSION_NUM}-cp311-cp311-macosx_10_9_universal2.whl
delocate-wheel -w fixed_wheels -v pyimfit-${VERSION_NUM}-cp310-cp310-macosx_10_9_universal2.whl
delocate-wheel -w fixed_wheels -v pyimfit-${VERSION_NUM}-cp39-cp39-macosx_10_9_x86_64.whl
delocate-wheel -w fixed_wheels -v pyimfit-${VERSION_NUM}-cp38-cp38-macosx_10_9_x86_64.whl
Expand All @@ -35,7 +37,8 @@ then
python3 -m twine upload --repository testpypi dist/fixed_wheels/pyimfit-${VERSION_NUM}-cp37-cp37m-macosx_10_9_x86_64.whl
python3 -m twine upload --repository testpypi dist/fixed_wheels/pyimfit-${VERSION_NUM}-cp38-cp38-macosx_10_9_x86_64.whl
python3 -m twine upload --repository testpypi dist/fixed_wheels/pyimfit-${VERSION_NUM}-cp39-cp39-macosx_10_9_x86_64.whl
python3 -m twine upload --repository testpypi dist/fixed_wheels/pyimfit-${VERSION_NUM}-cp310-cp310-macosx_10_9_x86_64.whl
python3 -m twine upload --repository testpypi dist/fixed_wheels/pyimfit-${VERSION_NUM}-cp310-cp310-macosx_10_9_universal2.whl
python3 -m twine upload --repository testpypi dist/fixed_wheels/pyimfit-${VERSION_NUM}-cp311-cp311-macosx_10_9_universal2.whl
echo ""
else
echo " Doing standard upload to PyPI"
Expand All @@ -45,6 +48,7 @@ else
python3 -m twine upload dist/fixed_wheels/pyimfit-${VERSION_NUM}-cp38-cp38-macosx_10_9_x86_64.whl
python3 -m twine upload dist/fixed_wheels/pyimfit-${VERSION_NUM}-cp39-cp39-macosx_10_9_x86_64.whl
python3 -m twine upload dist/fixed_wheels/pyimfit-${VERSION_NUM}-cp310-cp310-macosx_10_9_universal2.whl
python3 -m twine upload dist/fixed_wheels/pyimfit-${VERSION_NUM}-cp311-cp311-macosx_10_9_universal2.whl
echo ""
fi

34 changes: 34 additions & 0 deletions new_notes_and_todo_for_python-wrapper_code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,40 @@ PLAN:
Imfit.fit and Imfit.doFit


[ ] Rewrite SimpleModelDescription from scratch
-- this class is currently a mess
-- should just be a light wrapper around ModelDescription, with as little as possible
separate/unique code

[ ] Fix bug in trying to use PointSource-type (PSF interpolation) functios
[X] I. Modify ModelObjectWrapper.__init__() to accept optional PSF & normalization flag

If PSF and flag are non-None, ModelObjectWrapper.__init__() should call setPSF()
*before* calling ModelObjectWrapper._addFunctions()

[X] II. Move code from ModelObjectWrapper.setPSF() into ModelObjectWrapper.__init__();
delete ModelObjectWrapper.setPSF()

[X] III. Modify Imfit._setupModel() so that it initializes ModelObjectWrapper with
new interface, including PSF.
np.asarray(self._psf), self._normalizePSF

[X] IV. Modify Imfit._setupModel() to remove call to self._modelObjectWrapper.setPSF()

[X] Run pytest test_imfit.py to see if test passes

[ ] Modify ModelDescription to include reporting if it contains PointSource-type functions
-- attribute hasPointSources [bool]
[ ] Add tests to test_descriptions.py
[ ] Write code to pass tests

[ ] Add error-checking to catch and report if we try to instantiate Imfit object when
model has PointSource and we didn't supply one (raise TypeError)
[ ] Write test (in test_imfit.py) to check this

[ ] Write code in Imfit.__init__ to make test pass


[ ] Modify various methods in Imfit class to check whether _modelObjectWrapper has been
instantiated or not.

Expand Down
26 changes: 26 additions & 0 deletions notes_on_bugs_and_improvements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
* Problems with missing symbols when importing pyimfit into Python session:

In trying to use the updated version of PyImfit (v0.12, based on Imfit v1.9),
I encountered the following when trying to import pyimfit into a Python
session:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/erwin/coding/pyimfit/pyimfit/__init__.py", line 4, in <module>
from .pyimfit_lib import convolve_image, make_imfit_function, ModelObjectWrapper # type: ignore
ImportError: dlopen(/Users/erwin/coding/pyimfit/pyimfit/pyimfit_lib.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace (__Z20GetPhysicalCoreCountv)

The missing symbol is a mangled form of GetPhysicalCoreCount, which is in the new (in v1.9)
count_cpu_cores.cpp code in Imfit. Since convolver.cpp uses that function, it needs to be
in the library (libimfit.a) file.

The problem turned out to be that the compiled object code for that file -- count_cpu_cores.o --
was *not* in the list of object files to be incorporated into libimfit.a inside SConstruct.
Modifying the base_for_lib_objstring string in SConstruct to add "count_cpu_cores" fixed the problem.

(Note that the SConstruct file in the current Imfit repo already had that modification, but
the Github version and the version inside the pyimfit directory did *not*; this has been
fixed.)



* Problem with attribute access:

Problem encountered in writing unit tests for read_function_set()
Expand Down
Binary file modified prebuilt/linux64/libimfit.a
Binary file not shown.
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.11.2"
__version__ = "0.12.0"

0 comments on commit 2f0f81d

Please sign in to comment.