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

Add option to set a fixed dithering amount #220

Merged
merged 11 commits into from
Dec 19, 2024
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ jobs:

conda config --set always_yes yes

conda install -q mamba==1.5.1

mamba install -q --file requirements.txt
mamba install -q \
conda install -q --file requirements.txt
conda install -q \
flake8 \
pytest \
fitsio \
Expand Down
20 changes: 16 additions & 4 deletions descwl_shear_sims/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def make_sim(
draw_bright=True,
psf_dim=51,
dither=False,
dither_size=0.5,
rotate=False,
bands=["i"],
epochs_per_band=1,
Expand Down Expand Up @@ -106,6 +107,12 @@ def make_sim(
Dimensions of psf image. Default 51
dither: bool, optional
Whether to dither the images at the pixel level, default False
dither_size: float, optional
The amplitude of dithering in unit of a fraction of a pixel
for testing pixel interpolation.
All SE WCS will be given random dithers with this amplitude in both image
x and y direction.
Value must be between 0 and 1. default 0.5.
rotate: bool, optional
Whether to randomly rotate the image exposures randomly [not the
rotation of intrinsic galaxies], default False
Expand Down Expand Up @@ -217,7 +224,6 @@ def make_sim(
coadd_scale=coadd_scale,
coadd_dim=coadd_dim,
se_scale=pixel_scale,
dither=dither,
beckermr marked this conversation as resolved.
Show resolved Hide resolved
rotate=rotate,
)

Expand Down Expand Up @@ -275,6 +281,7 @@ def make_sim(
bright_mags=lists["bright_mags"],
coadd_bbox_cen_gs_skypos=coadd_bbox_cen_gs_skypos,
dither=dither,
dither_size=dither_size,
rotate=rotate,
mask_threshold=mask_threshold,
cosmic_rays=cosmic_rays,
Expand Down Expand Up @@ -355,6 +362,7 @@ def make_exp(
bright_mags=None,
coadd_bbox_cen_gs_skypos=None,
dither=False,
dither_size=None,
rotate=False,
mask_threshold=None,
cosmic_rays=False,
Expand Down Expand Up @@ -392,6 +400,11 @@ def make_exp(
Dimensions of psf image that will be drawn when psf func is called
dither: bool
If set to True, dither randomly by a pixel width
dither_size: float, optional
The amplitude of dithering in unit of a fraction of a pixel
for testing pixel interpolation.
All se WCS will be dithered by this amount in both x and y directions.
Value must be between 0 and 1. default None.
rotate: bool
If set to True, rotate the image exposure randomly, note, this is not
the rotation of intrinsic galaxies in ring test
Expand Down Expand Up @@ -471,6 +484,7 @@ def make_exp(
image_origin=se_origin,
world_origin=coadd_bbox_cen_gs_skypos,
dither=dither,
dither_size=dither_size,
rotate=rotate,
rng=rng,
)
Expand Down Expand Up @@ -847,7 +861,7 @@ def get_sim_config(config=None):


def get_se_dim(
*, coadd_dim, coadd_scale=None, se_scale=None, dither=False, rotate=False
*, coadd_dim, coadd_scale=None, se_scale=None, rotate=False
):
"""
get single epoch (se) dimensions given coadd dim.
Expand All @@ -860,8 +874,6 @@ def get_se_dim(
pixel scale of coadd
se_scale: float, optional
pixel scale of single exposure
dither: bool, optional
Whether there is dithering or not
rotate: bool, optional
Whether there are random rotations of image exposure or not

Expand Down
3 changes: 1 addition & 2 deletions descwl_shear_sims/tests/test_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ def test_sim_exp_mag(rotate, show=False):
# use fixed single epoch dim so we can look in the same spot for the object
se_dim = get_se_dim(
coadd_dim=coadd_dim,
dither=False,
rotate=True,
)

Expand Down Expand Up @@ -204,7 +203,7 @@ def test_sim_psf_type(psf_type):
)

if psf_type == "ps":
se_dim = get_se_dim(coadd_dim=coadd_dim, dither=dither, rotate=rotate)
se_dim = get_se_dim(coadd_dim=coadd_dim, rotate=rotate)
psf = make_ps_psf(rng=rng, dim=se_dim)
else:
psf = make_fixed_psf(psf_type=psf_type)
Expand Down
8 changes: 6 additions & 2 deletions descwl_shear_sims/wcs/sewcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def make_se_wcs(
image_origin: galsim.PositionD,
world_origin: galsim.CelestialCoord = WORLD_ORIGIN,
dither: bool = False,
dither_size: float = None,
rotate: bool = False,
theta: float | None = None,
rng=None,
Expand All @@ -29,6 +30,8 @@ def make_se_wcs(
Origin on the sky
dither: bool, optional
whether to do dither or not, default: False
dither_size: float, optional
dither range in unit of a fraction of a pixel, default: None
rotate: bool
whether to do rotation or not, default: False
theta: float
Expand All @@ -44,9 +47,10 @@ def make_se_wcs(
if dither:
# do a small offset of the origin
assert rng is not None
dither_range = 0.5
off = rng.uniform(low=-dither_range, high=dither_range, size=2)

off = rng.uniform(low=-dither_size, high=dither_size, size=2)
offset = galsim.PositionD(x=off[0], y=off[1])

image_origin = image_origin + offset

if rotate:
Expand Down
Loading