Skip to content

Commit

Permalink
Merge pull request #972 from aphearin/neg_one_corr_cam
Browse files Browse the repository at this point in the history
Fixed bug in treatment of noisy_percentile=-1 edge case.
  • Loading branch information
aphearin authored Jan 7, 2020
2 parents 62724e7 + 33946dd commit b8198cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion halotools/empirical_models/abunmatch/noisy_percentile.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ def noisy_percentile(percentile, correlation_coeff, seed=None, random_percentile
Correlation strengths between zero and unity span the intermediary cases.
"""
if np.all(np.abs(correlation_coeff) == 1):
if np.all(correlation_coeff == 1):
return percentile
elif np.all(correlation_coeff == -1):
return percentile[::-1]

percentile = np.atleast_1d(percentile)
correlation_coeff = np.atleast_1d(correlation_coeff)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ def test_noisy_percentile3():
u2 = noisy_percentile(u, r_desired, random_percentile=uran)
r_achieved = spearmanr(u, u2)[0]
assert np.allclose(r_desired, r_achieved, atol=0.02)


def test_negative_unity_noisy_percentile():
"""Regression test for #939.
"""
r_desired = -1
u2 = noisy_percentile(u, r_desired, seed=fixed_seed)
assert np.allclose(u2, u[::-1])

0 comments on commit b8198cf

Please sign in to comment.