Skip to content

Commit

Permalink
Merge a4cbe92 into 76470ef
Browse files Browse the repository at this point in the history
  • Loading branch information
dstndstn committed Mar 24, 2019
2 parents 76470ef + a4cbe92 commit d35eef5
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 39 deletions.
7 changes: 3 additions & 4 deletions tractor/ducks.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def setParams(self, p):
`numberOfParams()`.
'''
assert(len(p) == self.numberOfParams())
pass

def setAllParams(self, p):
return self.setParams(p)
Expand Down Expand Up @@ -156,9 +155,9 @@ class ImageCalibration(object):
def toFitsHeader(self, hdr, prefix=''):
params = self.getAllParams()
names = self.getParamNames()
for i in range(len(params)):
for i,(name,val) in enumerate(zip(names, params)):
k = prefix + 'P%i' % i
hdr.add_record(dict(name=k, value=params[i], comment=names[i]))
hdr.add_record(dict(name=k, value=val, comment=name))

def toStandardFitsHeader(self, hdr):
pass
Expand Down Expand Up @@ -332,7 +331,7 @@ def getSunTheta(self):
ie, the time of year expressed as an angle in radians.'''
pass

def toYears():
def toYears(self):
pass


Expand Down
6 changes: 5 additions & 1 deletion tractor/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,15 @@ def getName():
def getNamedParams():
return dict(images=0, catalog=1)

def __init__(self, images=[], catalog=[], optimizer=None):
def __init__(self, images=None, catalog=None, optimizer=None):
'''
- `images:` list of Image objects (data)
- `catalog:` list of Source objects
'''
if images is None:
images = []
if catalog is None:
catalog = []
if not isinstance(images, Images):
images = Images(*images)
if not isinstance(catalog, Catalog):
Expand Down
14 changes: 7 additions & 7 deletions tractor/galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def getParamDerivatives(self, img, modelMask=None):
else:
minval = None

patch0 = self.getUnitFluxModelPatch(img, px0, py0, minval=minval,
patch0 = self.getUnitFluxModelPatch(img, px=px0, py=py0, minval=minval,
modelMask=modelMask)
if patch0 is None:
return [None] * self.numberOfParams()
Expand All @@ -179,7 +179,7 @@ def getParamDerivatives(self, img, modelMask=None):
(px, py) = img.getWcs().positionToPixel(pos0, self)
pos0.setParam(i, oldval)
patchx = self.getUnitFluxModelPatch(
img, px, py, minval=minval, modelMask=modelMask)
img, px=px, py=py, minval=minval, modelMask=modelMask)
if patchx is None or patchx.getImage() is None:
derivs.append(None)
continue
Expand Down Expand Up @@ -210,7 +210,7 @@ def getParamDerivatives(self, img, modelMask=None):
for i, gstep in enumerate(gsteps):
oldval = self.shape.setParam(i, oldvals[i] + gstep)
patchx = self.getUnitFluxModelPatch(
img, px0, py0, minval=minval, modelMask=modelMask)
img, px=px0, py=py0, minval=minval, modelMask=modelMask)
self.shape.setParam(i, oldval)
if patchx is None:
print('patchx is None:')
Expand Down Expand Up @@ -249,7 +249,7 @@ def _getAffineProfile(self, img, px, py):
def _getUnitFluxDeps(self, img, px, py):
return None

def _getUnitFluxPatchSize(self, img, minval):
def _getUnitFluxPatchSize(self, img, **kwargs):
return 0

def getUnitFluxModelPatch(self, img, px=None, py=None, minval=0.0,
Expand All @@ -267,7 +267,7 @@ def _realGetUnitFluxModelPatch(self, img, px, py, minval, modelMask=None):
x0, y0 = modelMask.x0, modelMask.y0
else:
# choose the patch size
halfsize = self._getUnitFluxPatchSize(img, px, py, minval)
halfsize = self._getUnitFluxPatchSize(img, px=px, py=py, minval=minval)
# find overlapping pixels to render
(outx, inx) = get_overlapping_region(
int(np.floor(px - halfsize)), int(np.ceil(px + halfsize + 1)),
Expand Down Expand Up @@ -673,7 +673,7 @@ def _getUnitFluxDeps(self, img, px, py):
img.getPsf().hashkey(), self.shape.hashkey())
)

def _getUnitFluxPatchSize(self, img, px, py, minval):
def _getUnitFluxPatchSize(self, img, px=0., py=0., minval=0.):
if hasattr(self, 'halfsize'):
return self.halfsize
pixscale = img.wcs.pixscale_at(px, py)
Expand Down Expand Up @@ -847,7 +847,7 @@ def _getAffineProfile(self, img, px, py):
#print('amp sum', np.sum(smix.amp))
return mix[0] + mix[1]

def _getUnitFluxPatchSize(self, img, px, py, minval):
def _getUnitFluxPatchSize(self, img, px=0., py=0., minval=0.):
if hasattr(self, 'halfsize'):
return self.halfsize
pixscale = img.wcs.pixscale_at(px, py)
Expand Down
2 changes: 1 addition & 1 deletion tractor/psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def getMixtureOfGaussians(self, px=None, py=None):
return self.mog

def applyTo(self, image):
raise
raise RuntimeError('Not implemented')

def scaleBy(self, factor):
# Use not advised, ever
Expand Down
4 changes: 2 additions & 2 deletions tractor/sersic.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def getParamDerivatives(self, img, modelMask=None):

pos0 = self.getPosition()
(px0, py0) = img.getWcs().positionToPixel(pos0, self)
patch0 = self.getUnitFluxModelPatch(img, px0, py0, modelMask=modelMask)
patch0 = self.getUnitFluxModelPatch(img, px=px0, py=py0, modelMask=modelMask)
if patch0 is None:
derivs.append(None)
return derivs
Expand All @@ -362,7 +362,7 @@ def getParamDerivatives(self, img, modelMask=None):
for i, istep in enumerate(isteps):
oldval = self.sersicindex.setParam(i, oldvals[i] + istep)
patchx = self.getUnitFluxModelPatch(
img, px0, py0, modelMask=modelMask)
img, px=px0, py=py0, modelMask=modelMask)
self.sersicindex.setParam(i, oldval)
if patchx is None:
print('patchx is None:')
Expand Down
4 changes: 0 additions & 4 deletions tractor/splinesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ def addTo(self, mod, scale=1.):
S = self.evaluateGrid(np.arange(W), np.arange(H))
mod += (S * scale)

def evaluateGrid(self, x, y):
S = self.spl(x + self.x0, y + self.y0).T
return S

def getParamGrid(self):
arr = np.array(self.vals)
assert(len(arr) == (self.W * self.H))
Expand Down
5 changes: 4 additions & 1 deletion wise/forcedphot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
get_unwise_tractor_image)


def unwise_forcedphot(cat, tiles, bands=[1, 2, 3, 4], roiradecbox=None,
def unwise_forcedphot(cat, tiles, bands=None, roiradecbox=None,
unwise_dir='.',
use_ceres=True, ceres_block=8,
save_fits=False, get_models=False, ps=None,
Expand All @@ -27,6 +27,9 @@ def unwise_forcedphot(cat, tiles, bands=[1, 2, 3, 4], roiradecbox=None,
runs forced photometry, returning a FITS table the same length as *cat*.
'''

if bands is None:
bands = [1,2,3,4]

# # Severely limit sizes of models
for src in cat:
if isinstance(src, PointSource):
Expand Down
39 changes: 20 additions & 19 deletions wise/wise.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
matplotlib.use('Agg')

import os
import tempfile
import pylab as plt
import numpy as np
import sys
Expand Down Expand Up @@ -35,12 +34,15 @@
logger = logging.getLogger('wise')


def read_wise_level1b(basefn, radecroi=None, radecrad=None, filtermap={},
def read_wise_level1b(basefn, radecroi=None, radecrad=None, filtermap=None,
nanomaggies=False, mask_gz=False, unc_gz=False,
sipwcs=False, constantInvvar=False,
roi=None,
zrsigs=[-3, 10],
):
if filtermap is None:
filtermap = {}

intfn = basefn + '-int-1b.fits'
maskfn = basefn + '-msk-1b.fits'

Expand Down Expand Up @@ -230,8 +232,10 @@ def read_wise_level1b(basefn, radecroi=None, radecrad=None, filtermap={},
return tim


def read_wise_level3(basefn, radecroi=None, filtermap={},
def read_wise_level3(basefn, radecroi=None, filtermap=None,
nanomaggies=False):
if filtermap is None:
filtermap = {}
intfn = basefn + '-int-3.fits'
uncfn = basefn + '-unc-3.fits'

Expand All @@ -245,7 +249,6 @@ def read_wise_level3(basefn, radecroi=None, filtermap={},
band = ihdr['BAND']

P = pyfits.open(uncfn)
uhdr = P[0].header
unc = P[0].data
print('Read', unc.shape, 'uncertainty')

Expand Down Expand Up @@ -310,16 +313,16 @@ def read_wise_level3(basefn, radecroi=None, filtermap={},
H, W = data.shape
x0, x1, y0, y1 = 0, W, 0, H

filter = 'w%i' % band
filt = 'w%i' % band
if filtermap:
filter = filtermap.get(filter, filter)
filt = filtermap.get(filt, filt)
zp = ihdr['MAGZP']

if nanomaggies:
photocal = tractor.LinearPhotoCal(tractor.NanoMaggies.zeropointToScale(zp),
band=filter)
band=filt)
else:
photocal = tractor.MagsPhotoCal(filter, zp)
photocal = tractor.MagsPhotoCal(filt, zp)

print('Image median:', np.median(data))
print('unc median:', np.median(unc))
Expand All @@ -343,12 +346,13 @@ def read_wise_level3(basefn, radecroi=None, filtermap={},
read_wise_image = read_wise_level1b


def get_psf_model(band, pixpsf=False, xy=None, positive=True, cache={}):

def get_psf_model(band, pixpsf=False, xy=None, positive=True, cache=None):
if cache is None:
cache = {}
if xy is not None:
x, y = xy
x,y = xy
gx = np.clip((int(x) / 100) * 100 + 50, 50, 950)
gy = np.clip((int(x) / 100) * 100 + 50, 50, 950)
gy = np.clip((int(y) / 100) * 100 + 50, 50, 950)
assert(gx % 100 == 50)
assert(gy % 100 == 50)
xy = (gx, gy)
Expand Down Expand Up @@ -415,7 +419,7 @@ def forcedphot():
for fn in ['04933b137-w1', '04937b137-w1', '04941b137-w1', '04945b137-w1', '04948a112-w1',
'04949b137-w1', '04952a112-w1', '04953b137-w1', '04956a112-w1', '04960a112-w1',
'04964a112-w1', '04968a112-w1', '05204a106-w1']:
basefn = os.path.join(basedir, '04933b137-w1')
basefn = os.path.join(basedir, fn)
tim = read_wise_image(
basefn, radecroi=[rl, rh, dl, dh], nanomaggies=True)
tims.append(tim)
Expand Down Expand Up @@ -743,15 +747,15 @@ def plot_unmatched():
dbo.fResolveStatus('SURVEY_EDGE') |
dbo.fResolveStatus('SURVEY_BEST')
)) != 0
--> sdss-cas-testarea-3.fits
'''

''' Check it out: spatial source density looks fine. No overlap between runs.
'''

rng = ((333.5, 335.5), (-0.5, 1.5))

from astrometry.util.plotutils import PlotSequence
ps = PlotSequence('sdss')

if False:
Expand Down Expand Up @@ -855,7 +859,6 @@ def plot_unmatched():

basedir = os.environ.get('BIGBOSS_DATA', '/project/projectdirs/bigboss')
wisedatadir = os.path.join(basedir, 'data', 'wise')
l1bdir = os.path.join(wisedatadir, 'level1b')

wisecat = fits_table(os.path.join(
wisedatadir, 'catalogs', 'wisecat2.fits'))
Expand Down Expand Up @@ -1187,7 +1190,7 @@ def forced2():

# CAS PhotoObjAll.resolveStatus bits
sprim = 0x100
sbad = 0x800
#sbad = 0x800
sedge = 0x1000
sbest = 0x200

Expand Down Expand Up @@ -1422,8 +1425,6 @@ def forced2():
forcedphot()

from astrometry.util.fits import fits_table
from astrometry.libkd.spherematch import match_radec
import pylab as plt

T1 = fits_table('cs82data/cas-primary-DR8.fits')
print(len(T1), 'SDSS')
Expand Down

0 comments on commit d35eef5

Please sign in to comment.