Skip to content

Commit

Permalink
tractor.sdss: push astrometry imports down to where they are used
Browse files Browse the repository at this point in the history
  • Loading branch information
dstndstn committed Oct 28, 2015
1 parent e89fffd commit 8f0f33b
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 327 deletions.
46 changes: 23 additions & 23 deletions tractor/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Core image modeling and fitting.
'''

from __future__ import print_function
import logging

import numpy as np
Expand Down Expand Up @@ -62,9 +62,9 @@ def __str__(self):
(len(self), self.numberOfParams()))

def printLong(self):
print 'Catalog with %i sources:' % len(self)
print('Catalog with %i sources:' % len(self))
for i,x in enumerate(self):
print ' %i:' % i, x
print(' %i:' % i, x)

def getThawedSources(self):
return self._getActiveSubs()
Expand Down Expand Up @@ -291,8 +291,8 @@ def getDerivs(self):
continue
srcderivs[k].append((deriv, img))
allderivs.extend(srcderivs)
#print 'allderivs:', len(allderivs)
#print 'N params:', self.numberOfParams()
#print('allderivs:', len(allderivs))
#print('N params:', self.numberOfParams())

assert(len(allderivs) == self.numberOfParams())
return allderivs
Expand Down Expand Up @@ -342,9 +342,9 @@ def _checkModelMask(self, patch, mask):

if patch is not None and mask is not None and patch.patch is not None:
nonzero = Patch(patch.x0, patch.y0, patch.patch != 0)
#print 'nonzero type:', nonzero.patch.dtype
#print('nonzero type:', nonzero.patch.dtype)
unmasked = Patch(mask.x0, mask.y0, np.logical_not(mask.patch))
#print 'unmasked type:', unmasked.patch.dtype
#print('unmasked type:', unmasked.patch.dtype)
bad = nonzero.performArithmetic(unmasked, '__iand__', otype=bool)
assert(np.all(bad.patch == False))

Expand All @@ -355,9 +355,9 @@ def _getSourceDerivatives(self, src, img, **kwargs):
if self.expectModelMasks and mask is None:
return [None] * src.numberOfParams()

#print 'getting param derivs for', src
#print('getting param derivs for', src)
derivs = src.getParamDerivatives(img, modelMask=mask, **kwargs)
#print 'done getting param derivs for', src
#print('done getting param derivs for', src)

# HACK -- auto-add?
# if self.expectModelMasks:
Expand Down Expand Up @@ -423,18 +423,18 @@ def getChiImage(self, imgi=-1, img=None, srcs=None, minsb=0.):
mod = self.getModelImage(img, srcs=srcs, minsb=minsb)
chi = (img.getImage() - mod) * img.getInvError()
if not np.all(np.isfinite(chi)):
print 'Chi not finite'
print 'Image finite?', np.all(np.isfinite(img.getImage()))
print 'Mod finite?', np.all(np.isfinite(mod))
print 'InvErr finite?', np.all(np.isfinite(img.getInvError()))
print 'Current thawed parameters:'
print('Chi not finite')
print('Image finite?', np.all(np.isfinite(img.getImage())))
print('Mod finite?', np.all(np.isfinite(mod)))
print('InvErr finite?', np.all(np.isfinite(img.getInvError())))
print('Current thawed parameters:')
self.printThawedParams()
print 'Current sources:'
print('Current sources:')
for src in self.getCatalog():
print ' ', src
print 'Image:', img
print 'sky:', img.getSky()
print 'psf:', img.getPsf()
print(' ', src)
print('Image:', img)
print('sky:', img.getSky())
print('psf:', img.getPsf())
return chi

def getLogLikelihood(self):
Expand All @@ -453,11 +453,11 @@ def getLogProb(self):
lnl = self.getLogLikelihood()
lnp = lnprior + lnl
if np.isnan(lnp):
print 'Tractor.getLogProb() returning NaN.'
print 'Params:'
print('Tractor.getLogProb() returning NaN.')
print('Params:')
self.printThawedParams()
print 'log likelihood:', lnl
print 'log prior:', lnprior
print('log likelihood:', lnl)
print('log prior:', lnprior)
return -np.inf
return lnp

Loading

0 comments on commit 8f0f33b

Please sign in to comment.