Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of correlated noise #151

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
40 changes: 37 additions & 3 deletions descwl_shear_sims/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def make_sim(
star_bleeds=False,
sky_n_sigma=None,
draw_method='auto',
g2_noise=0.01,
g1_noise=0.01,
corr_noise=False,
):
"""
Make simulation data
Expand Down Expand Up @@ -105,6 +108,12 @@ def make_sim(
draw_method: string
Draw method for galsim objects, default 'auto'. Set to
'phot' to get poisson noise. Note this is much slower.
corr_noise: bool
If True, make correlated noise
g1_noise: float
g1 for shear correlated noise
g2_noise: float
g2 for shear correlated noise
"""

coadd_wcs, coadd_bbox = make_coadd_dm_wcs(coadd_dim)
Expand Down Expand Up @@ -159,6 +168,9 @@ def make_sim(
star_bleeds=star_bleeds,
sky_n_sigma=sky_n_sigma,
draw_method=draw_method,
corr_noise=corr_noise,
g1_noise=g1_noise,
g2_noise=g2_noise,
)
if galaxy_catalog.gal_type == 'wldeblend':
rescale_wldeblend_exp(
Expand Down Expand Up @@ -221,6 +233,9 @@ def make_exp(
star_bleeds=False,
sky_n_sigma=None,
draw_method='auto',
corr_noise=False,
g1_noise=0.01,
g2_noise=0.01,
):
"""
Make an SEObs
Expand Down Expand Up @@ -275,6 +290,12 @@ def make_exp(
draw_method: string
Draw method for galsim objects, default 'auto'. Set to
'phot' to get poisson noise. Note this is much slower.
corr_noise: bool
If True, make correlated noise
g1_noise: float
g1 for shear correlated noise
g2_noise: float
g2 for shear correlated noise
"""

shear = galsim.Shear(g1=g1, g2=g2)
Expand Down Expand Up @@ -321,9 +342,22 @@ def make_exp(
rng,
)

image.array[:, :] += rng.normal(scale=noise, size=dims)
if sky_n_sigma is not None:
image.array[:, :] += sky_n_sigma * noise
# Make correlated noise
if corr_noise:
galsim_seed = rng.randint(low=1, high=2**29, size=1)
galsim_rng = galsim.BaseDeviate(seed=galsim_seed)
corr_noise = galsim.UncorrelatedNoise(
variance=noise**2.,
rng=galsim_rng,
scale=SCALE,
)
# Shear correlation in the noise
corr_noise = corr_noise.shear(g1=g1_noise, g2=g2_noise)
image.addNoise(corr_noise)
else:
image.array[:, :] += rng.normal(scale=noise, size=dims)
if sky_n_sigma is not None:
image.array[:, :] += sky_n_sigma * noise

bmask = get_bmask(
image=image,
Expand Down
75 changes: 75 additions & 0 deletions shear_meas_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import pytest


def pytest_addoption(parser):
parser.addoption(
"--save",
action="store_true",
default=False,
help="--save: Wether to save the results in a separate file"
)
parser.addoption(
"--save_dir",
action="store",
default='.',
type=str,
help="--save_dir: Directory where to store the output"
)
parser.addoption(
"--g1_noise",
action="store",
default=0.,
type=float,
help="--g1_noise: g1 shear to apply on the noise"
)
parser.addoption(
"--g2_noise",
action="store",
default=0.,
type=float,
help="--g2_noise: g2 shear to apply on the noise"
)
parser.addoption(
"--gal_mag",
action="store",
default=None,
type=float,
help="--gal_mag: magnitude of the galaxies drawn"
)
parser.addoption(
"--n_jobs",
action="store",
default=2,
type=int,
help="--n_jobs: Number of cores to use"
)


@pytest.fixture()
def save(request):
return request.config.getoption("--save")


@pytest.fixture()
def save_dir(request):
return request.config.getoption("--save_dir")


@pytest.fixture()
def g1_noise(request):
return request.config.getoption("--g1_noise")


@pytest.fixture()
def g2_noise(request):
return request.config.getoption("--g2_noise")


@pytest.fixture()
def gal_mag(request):
return request.config.getoption("--gal_mag")


@pytest.fixture()
def n_jobs(request):
return request.config.getoption("--n_jobs")
Loading