Skip to content

Commit ec09804

Browse files
authored
Merge pull request #230 from esheldon/bdf-guesser
add guesser for BDF with psf flux
2 parents ad8e8ac + 1a28c5f commit ec09804

File tree

5 files changed

+88
-9
lines changed

5 files changed

+88
-9
lines changed

CHANGES.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
## v2.2.1
2+
3+
### New Features
4+
5+
- Added new guesser BDFPSFFluxGuesser, makes a flux guess
6+
based on the PSF flux
7+
8+
### Performance
9+
- Added O(N) phase shift computation for pre-psf moments
10+
11+
### Misc
12+
13+
- ignore NumbaExperimentalFeatureWarning being spewed by
14+
numba. We can ignore these, as the features are of order
15+
ten years old from the time of writing
16+
117
## v2.2.0
218

319
### new features

ngmix/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# flake8: noqa
22

3+
from numba.core.errors import NumbaExperimentalFeatureWarning
4+
import warnings
5+
6+
warnings.simplefilter('ignore', category=NumbaExperimentalFeatureWarning)
7+
38
from ._version import __version__
49

510
from . import util

ngmix/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.2.0' # noqa
1+
__version__ = '2.2.1' # noqa

ngmix/guessers.py

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,60 @@ def __call__(self, nrand=1, obs=None):
322322
return guess
323323

324324

325+
class BDFPSFFluxGuesser(TPSFFluxGuesser):
326+
"""
327+
Make BDF guesses from the input T, the psf flux and the prior
328+
329+
parameters
330+
----------
331+
T: float
332+
Center for T guesses
333+
prior:
334+
cen, g drawn from this prior
335+
"""
336+
337+
def __init__(self, T, prior):
338+
self.T = T
339+
self.prior = prior
340+
self._id_last = None
341+
self._psf_fluxes = None
342+
self.rng = self.prior.cen_prior.rng
343+
344+
def __call__(self, obs, nrand=1):
345+
"""
346+
center, shape are just distributed around zero
347+
348+
obs: Observation
349+
The observation(s) used for psf fluxes
350+
nrand: int, optional
351+
Number of samples to draw. Default 1
352+
"""
353+
rng = self.prior.cen_prior.rng
354+
355+
fluxes = self._get_psf_fluxes(obs=obs)
356+
357+
guess = self.prior.sample(nrand)
358+
359+
nband = fluxes.size
360+
361+
r = rng.uniform(low=-0.1, high=0.1, size=nrand)
362+
guess[:, 4] = self.T * (1.0 + r)
363+
364+
# fracdev prior
365+
guess[:, 5] = rng.uniform(low=0.4, high=0.6, size=nrand)
366+
367+
for band in range(nband):
368+
r = rng.uniform(low=-0.1, high=0.1, size=nrand)
369+
guess[:, 6 + band] = fluxes[band] * (1.0 + r)
370+
371+
_fix_guess(guess, self.prior)
372+
373+
if nrand == 1:
374+
guess = guess[0, :]
375+
376+
return guess
377+
378+
325379
class BDFGuesser(object):
326380
"""
327381
Make BDF guesses from the input T, flux and prior
@@ -368,8 +422,7 @@ def __call__(self, nrand=1, obs=None):
368422
r = rng.uniform(low=-0.1, high=0.1, size=nrand)
369423
guess[:, 6 + band] = fluxes[band] * (1.0 + r)
370424

371-
if self.prior is not None:
372-
_fix_guess(guess, self.prior)
425+
_fix_guess(guess, self.prior)
373426

374427
if nrand == 1:
375428
guess = guess[0, :]

ngmix/tests/test_guessers.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_noprior_guessers_smoke(guesser_type, nband, with_prior):
9494

9595
@pytest.mark.parametrize(
9696
'guesser_type',
97-
['TFluxAndPrior', 'TPSFFluxAndPrior', 'BD', 'BDF', 'Prior'],
97+
['TFluxAndPrior', 'TPSFFluxAndPrior', 'BD', 'BDF', 'BDFPSFlux', 'Prior'],
9898
)
9999
@pytest.mark.parametrize('nband', [None, 1, 2])
100100
def test_prior_guessers_smoke(guesser_type, nband):
@@ -113,7 +113,7 @@ def test_prior_guessers_smoke(guesser_type, nband):
113113

114114
# this always gets coverage
115115
assert guesser_type in [
116-
'TFluxAndPrior', 'TPSFFluxAndPrior', 'BD', 'BDF', 'Prior',
116+
'TFluxAndPrior', 'TPSFFluxAndPrior', 'BD', 'BDF', 'BDFPSFlux', 'Prior',
117117
]
118118

119119
T_center = 0.001
@@ -150,17 +150,22 @@ def test_prior_guessers_smoke(guesser_type, nband):
150150
T=T_center, flux=flux_center, prior=prior,
151151
)
152152
npars = 7 + nband_use
153-
elif guesser_type == 'BDF':
153+
elif guesser_type in ('BDF', 'BDFPSFlux'):
154154
prior = ngmix.joint_prior.PriorBDFSep(
155155
cen_prior=ngmix.priors.CenPrior(0.0, 0.0, 0.1, 0.1, rng=rng),
156156
g_prior=ngmix.priors.GPriorBA(0.3, rng=rng),
157157
fracdev_prior=ngmix.priors.Normal(0.5, 0.1, rng=rng),
158158
T_prior=ngmix.priors.FlatPrior(-1.0, 1.e5, rng=rng),
159159
F_prior=[ngmix.priors.FlatPrior(-1.0, 1.e5, rng=rng)]*nband_use,
160160
)
161-
guesser = guessers.BDFGuesser(
162-
T=T_center, flux=flux_center, prior=prior,
163-
)
161+
if guesser_type == 'BDF':
162+
guesser = guessers.BDFGuesser(
163+
T=T_center, flux=flux_center, prior=prior,
164+
)
165+
else:
166+
guesser = guessers.BDFPSFFluxGuesser(
167+
T=T_center, prior=prior,
168+
)
164169
npars = 6 + nband_use
165170

166171
guess = guesser(obs=data['obs'])

0 commit comments

Comments
 (0)