diff --git a/CHANGES.md b/CHANGES.md index 29456b82..db90465b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,19 @@ +## v2.2.1 + +### New Features + + - Added new guesser BDFPSFFluxGuesser, makes a flux guess + based on the PSF flux + +### Performance + - Added O(N) phase shift computation for pre-psf moments + +### Misc + + - ignore NumbaExperimentalFeatureWarning being spewed by + numba. We can ignore these, as the features are of order + ten years old from the time of writing + ## v2.2.0 ### new features diff --git a/ngmix/__init__.py b/ngmix/__init__.py index 1a4f59e9..1770b9ea 100644 --- a/ngmix/__init__.py +++ b/ngmix/__init__.py @@ -1,5 +1,10 @@ # flake8: noqa +from numba.core.errors import NumbaExperimentalFeatureWarning +import warnings + +warnings.simplefilter('ignore', category=NumbaExperimentalFeatureWarning) + from ._version import __version__ from . import util diff --git a/ngmix/_version.py b/ngmix/_version.py index 8acd0c49..411d8388 100644 --- a/ngmix/_version.py +++ b/ngmix/_version.py @@ -1 +1 @@ -__version__ = '2.2.0' # noqa +__version__ = '2.2.1' # noqa diff --git a/ngmix/guessers.py b/ngmix/guessers.py index 92174b9e..85ac9652 100644 --- a/ngmix/guessers.py +++ b/ngmix/guessers.py @@ -322,6 +322,60 @@ def __call__(self, nrand=1, obs=None): return guess +class BDFPSFFluxGuesser(TPSFFluxGuesser): + """ + Make BDF guesses from the input T, the psf flux and the prior + + parameters + ---------- + T: float + Center for T guesses + prior: + cen, g drawn from this prior + """ + + def __init__(self, T, prior): + self.T = T + self.prior = prior + self._id_last = None + self._psf_fluxes = None + self.rng = self.prior.cen_prior.rng + + def __call__(self, obs, nrand=1): + """ + center, shape are just distributed around zero + + obs: Observation + The observation(s) used for psf fluxes + nrand: int, optional + Number of samples to draw. Default 1 + """ + rng = self.prior.cen_prior.rng + + fluxes = self._get_psf_fluxes(obs=obs) + + guess = self.prior.sample(nrand) + + nband = fluxes.size + + r = rng.uniform(low=-0.1, high=0.1, size=nrand) + guess[:, 4] = self.T * (1.0 + r) + + # fracdev prior + guess[:, 5] = rng.uniform(low=0.4, high=0.6, size=nrand) + + for band in range(nband): + r = rng.uniform(low=-0.1, high=0.1, size=nrand) + guess[:, 6 + band] = fluxes[band] * (1.0 + r) + + _fix_guess(guess, self.prior) + + if nrand == 1: + guess = guess[0, :] + + return guess + + class BDFGuesser(object): """ Make BDF guesses from the input T, flux and prior @@ -368,8 +422,7 @@ def __call__(self, nrand=1, obs=None): r = rng.uniform(low=-0.1, high=0.1, size=nrand) guess[:, 6 + band] = fluxes[band] * (1.0 + r) - if self.prior is not None: - _fix_guess(guess, self.prior) + _fix_guess(guess, self.prior) if nrand == 1: guess = guess[0, :] diff --git a/ngmix/tests/test_guessers.py b/ngmix/tests/test_guessers.py index 68c917d7..91712a59 100644 --- a/ngmix/tests/test_guessers.py +++ b/ngmix/tests/test_guessers.py @@ -94,7 +94,7 @@ def test_noprior_guessers_smoke(guesser_type, nband, with_prior): @pytest.mark.parametrize( 'guesser_type', - ['TFluxAndPrior', 'TPSFFluxAndPrior', 'BD', 'BDF', 'Prior'], + ['TFluxAndPrior', 'TPSFFluxAndPrior', 'BD', 'BDF', 'BDFPSFlux', 'Prior'], ) @pytest.mark.parametrize('nband', [None, 1, 2]) def test_prior_guessers_smoke(guesser_type, nband): @@ -113,7 +113,7 @@ def test_prior_guessers_smoke(guesser_type, nband): # this always gets coverage assert guesser_type in [ - 'TFluxAndPrior', 'TPSFFluxAndPrior', 'BD', 'BDF', 'Prior', + 'TFluxAndPrior', 'TPSFFluxAndPrior', 'BD', 'BDF', 'BDFPSFlux', 'Prior', ] T_center = 0.001 @@ -150,7 +150,7 @@ def test_prior_guessers_smoke(guesser_type, nband): T=T_center, flux=flux_center, prior=prior, ) npars = 7 + nband_use - elif guesser_type == 'BDF': + elif guesser_type in ('BDF', 'BDFPSFlux'): prior = ngmix.joint_prior.PriorBDFSep( cen_prior=ngmix.priors.CenPrior(0.0, 0.0, 0.1, 0.1, rng=rng), g_prior=ngmix.priors.GPriorBA(0.3, rng=rng), @@ -158,9 +158,14 @@ def test_prior_guessers_smoke(guesser_type, nband): T_prior=ngmix.priors.FlatPrior(-1.0, 1.e5, rng=rng), F_prior=[ngmix.priors.FlatPrior(-1.0, 1.e5, rng=rng)]*nband_use, ) - guesser = guessers.BDFGuesser( - T=T_center, flux=flux_center, prior=prior, - ) + if guesser_type == 'BDF': + guesser = guessers.BDFGuesser( + T=T_center, flux=flux_center, prior=prior, + ) + else: + guesser = guessers.BDFPSFFluxGuesser( + T=T_center, prior=prior, + ) npars = 6 + nband_use guess = guesser(obs=data['obs'])