Skip to content

Commit

Permalink
Merge branch 'master' of github.com:dstndstn/tractor
Browse files Browse the repository at this point in the history
  • Loading branch information
dstndstn committed Dec 11, 2017
2 parents 7ef3846 + 8dd3190 commit bda7444
Show file tree
Hide file tree
Showing 11 changed files with 3,546 additions and 224 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ install:
# - which fitsverify

script:
- gcc --version
- python --version
- python setup.py install
- python setup.py build_ext --inplace
Expand Down
29 changes: 15 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from distutils.core import setup, Extension
from distutils.command.build_ext import *
from distutils.dist import Distribution

# import sys
# py3 = (sys.version_info[0] >= 3)
import os

# from http://stackoverflow.com/questions/12491328/python-distutils-not-include-the-swig-generated-module
from distutils.command.build import build
Expand Down Expand Up @@ -58,21 +56,26 @@ class CustomBuild(build):
#extra_compile_args=['-O0','-g'],
#extra_link_args=['-O0', '-g'],

module_fourier = Extension('tractor._mp_fourier',
sources = ['tractor/mp_fourier.i'],
include_dirs = numpy_inc,
extra_objects = [],
undef_macros=['NDEBUG'],
)

module_em = Extension('tractor._emfit',
sources = ['tractor/emfit.i' ],
include_dirs = numpy_inc,
extra_objects = [],
undef_macros=['NDEBUG'],
)
#extra_compile_args=['-O0','-g'],
#extra_link_args=['-O0', '-g'],

kwargs = {}
if os.environ.get('CC') == 'icc':
kwargs.update(extra_compile_args=['-g', '-xhost', '-axMIC-AVX512'],
extra_link_args=['-g', '-lsvml'])
else:
kwargs.update(extra_compile_args=['-g', '-std=c99'],
extra_link_args=['-g'])

module_fourier = Extension('tractor._mp_fourier',
sources = ['tractor/mp_fourier.i'],
include_dirs = numpy_inc,
undef_macros=['NDEBUG'],
**kwargs)

class MyDistribution(Distribution):
display_options = Distribution.display_options + [
Expand Down Expand Up @@ -100,8 +103,6 @@ class MyDistribution(Distribution):
author_email="[email protected]",
packages=['tractor', 'wise'],
ext_modules = mods,
# py_modules = pymods,
# data_files=[('lib/python/wise', ['wise/wise-psf-avg.fits'])],
package_data={'wise':['wise-psf-avg.fits', 'allsky-atlas.fits']},
package_dir={'wise':'wise', 'tractor':'tractor'},
url="http://theTractor.org/",
Expand Down
5 changes: 2 additions & 3 deletions tractor/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ mix.py _mix$(PYTHON_SO_EXT): mix.i approx3.c gauss_masked.c setup-mix.py
_emfit$(PYTHON_SO_EXT): emfit.i emfit2.c setup-emfit.py
$(PYTHON) setup-emfit.py build_ext --inplace


NUMPY_INC := $(shell $(PYTHON) -c "from __future__ import print_function; from numpy.distutils.misc_util import get_numpy_include_dirs as d; print(' '.join('-I'+x for x in d()))")

PYMOD_LIB ?= -L$(shell $(PYTHON_CONFIG) --prefix)/lib $(shell $(PYTHON_CONFIG) --libs)
Expand Down Expand Up @@ -58,8 +57,8 @@ BLAS_LIB ?= -lblas
GLOG_LIB ?= $(shell pkg-config --libs libglog) #-lglog
GLOG_INC ?= $(shell pkg-config --cflags libglog)

GFLAGS_LIB ?= $(shell pkg-config --libs libgflags)
GFLAGS_INC ?= $(shell pkg-config --cflags libgflags)
GFLAGS_LIB ?= $(shell pkg-config --libs gflags)
GFLAGS_INC ?= $(shell pkg-config --cflags gflags)

CERES_LIB_DIR ?= /usr/local/lib

Expand Down
2 changes: 1 addition & 1 deletion tractor/ceres.i
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static PyObject* real_ceres_forced_phot(PyObject* blocks,
Nblocks = PyList_Size(blocks);
//printf("N blocks: %i\n", (int)Nblocks);
assert(PyArray_Check(np_fluxes));
assert(PyArray_TYPE(np_fluxes) == NPY_DOUBLE);
assert(PyArray_TYPE((PyArrayObject*)np_fluxes) == NPY_DOUBLE);
int Nfluxes = (int)PyArray_Size(np_fluxes);
double* realfluxes = (double*)PyArray_DATA((PyArrayObject*)np_fluxes);
T* mod0data;
Expand Down
35 changes: 5 additions & 30 deletions tractor/galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
from tractor.patch import Patch, add_patches, ModelMask
from tractor.basics import SingleProfileSource, BasicSource

#from .cache import Cache

debug_ps = None


Expand Down Expand Up @@ -466,34 +464,19 @@ def run_mog(amix=None, mm=None):

if fftmix is not None:
#print('fftmix; mux,muy=', mux,muy)
Fsum = fftmix.getFourierTransform(v, w)
Fsum = fftmix.getFourierTransform(v, w, zero_mean=True)
# print('inverse Fourier-transforming into result size:', pH,pW)
G = np.fft.irfft2(Fsum * P, s=(pH, pW))

# FIXME -- we could try to be sneaky and Lanczos-interp
# after cutting G down to nearly its final size... tricky
# tho

# Lanczos-3 interpolation in ~ the same way we do for
# Lanczos-3 interpolation in ~the same way we do for
# pixelized PSFs.
from astrometry.util.miscutils import lanczos_filter
from scipy.ndimage.filters import correlate1d
#L = 3
L = fft_lanczos_order
Lx = lanczos_filter(L, np.arange(-L, L + 1) + mux)
Ly = lanczos_filter(L, np.arange(-L, L + 1) + muy)
# Normalize the Lanczos interpolants (preserve flux)
Lx /= Lx.sum()
Ly /= Ly.sum()
#print('Lx centroid', np.sum(Lx * (np.arange(-L,L+1))))
#print('Ly centroid', np.sum(Ly * (np.arange(-L,L+1))))

#print('kernels:', Lx, Ly)

cx = correlate1d(G, Lx, axis=1, mode='constant')
G = correlate1d(cx, Ly, axis=0, mode='constant')
del cx

from tractor.psf import lanczos_shift_image
G = G.astype(np.float32)
lanczos_shift_image(G, mux, muy, inplace=True)
else:
G = np.zeros((pH, pW), np.float32)

Expand All @@ -507,10 +490,6 @@ def run_mog(amix=None, mm=None):
shG = np.zeros((mh, mw), G.dtype)
shG[yo, xo] = G[yi, xi]

# print('shift:', (sx,sy), 'mm', (mw,mh), 'g', (gw,gh))
# print('yi,xi,', yi,xi)
# print('yo,xo,', yo,xo)

if debug_ps is not None:
_fourier_galaxy_debug_plots(G, shG, xi, yi, xo, yo, P, Fsum,
pW, pH, psf)
Expand Down Expand Up @@ -545,10 +524,6 @@ def run_mog(amix=None, mm=None):

return Patch(ix0, iy0, G)


fft_lanczos_order = 3


def _fourier_galaxy_debug_plots(G, shG, xi, yi, xo, yo, P, Fsum,
pW, pH, psf):
import pylab as plt
Expand Down
12 changes: 7 additions & 5 deletions tractor/mixture_profiles.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pylab as plt
import matplotlib.cm as cm
import numpy as np
#import scipy.spatial.distance as scp

try:
from tractor import mp_fourier
Expand Down Expand Up @@ -147,7 +146,7 @@ def convolve(self, other):
newk = nextnewk
return MixtureOfGaussians(newamp, newmean, newvar)

def getFourierTransform(self, v, w, use_mp_fourier=True):
def getFourierTransform(self, v, w, use_mp_fourier=True, zero_mean=False):
'''
v: FFT frequencies in the x direction
w: FFT frequencies in the y direction
Expand All @@ -160,10 +159,13 @@ def getFourierTransform(self, v, w, use_mp_fourier=True):
v = np.fft.rfftfreq(W)
w = np.fft.fftfreq(H)
If zero_mean is *True*, ignore the *mean* of this mixture of Gaussians.
'''
if mp_fourier and use_mp_fourier:
f = mp_fourier.mixture_profile_fourier_transform(
self.amp, self.mean, self.var, v, w)
if mp_fourier and use_mp_fourier and zero_mean:
f = np.zeros((len(w), len(v)), np.float64)
mp_fourier.gaussian_fourier_transform_zero_mean(
self.amp, self.var, v, w, f)
return f

Fsum = None
Expand Down
Loading

0 comments on commit bda7444

Please sign in to comment.