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

Release/1.0.0b6 #476

Merged
merged 6 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions .github/MAINTAINER.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,48 +52,50 @@ git pull origin dev
# 4. Created a release branch that tracks origin/dev
git checkout -b release/$RELEASE origin/dev

# 5. Bump version in release branch
# 5. Update README with latest pre-release version

# 6. Bump version in release branch
# edit pyproject.toml file to update the version
poetry version $RELEASE
git add pyproject.toml
git commit -m "Version $RELEASE"

# 6. Pushed release branch to remote repository
# 7. Pushed release branch to remote repository
git push --set-upstream origin release/$RELEASE

# 7. Open a "pull request" in GitHub for team to verify the release
# 8. Open a "pull request" in GitHub for team to verify the release

# 8. Checkout into main branch
# 9. Checkout into main branch
git checkout main

# 9. Updated local main branch with remote copy
# 10. Updated local main branch with remote copy
git pull origin main

# 10. Merged release branch into main branch
# 11. Merged release branch into main branch
git merge release/$RELEASE

# 11. Tagged the release point by creating a new tag
# 12. Tagged the release point by creating a new tag
git tag -a $RELEASE -m "Create release tag $RELEASE"

# 12. Pushed main branch to remote repository
# 13. Pushed main branch to remote repository
git push origin main

# 13. Pushed the tags to remote repository
# 14. Pushed the tags to remote repository
git push origin --tags

# 14. Checkout into dev branch
# 15. Checkout into dev branch
git checkout dev

# 15. Merged release branch into dev branch
# 16. Merged release branch into dev branch
git merge release/$RELEASE

# 16. Pushed dev branch to remote repository
# 17. Pushed dev branch to remote repository
git push origin dev

# 17. Removed release branch from the local repository
# 18. Removed release branch from the local repository
git branch -D release/$RELEASE

# 18. Removed release branch from the remote repository
# 19. Removed release branch from the remote repository
git push origin :release/$RELEASE


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ print("Precision: ", precision(matching.tp, matching.t, matching.p))
BTK is pip installable, with the following command:

```bash
pip install blending-toolkit==1.0.0b2
pip install blending-toolkit==1.0.0b6
```

In case of any issues and for details of required packages, please see the more detailed installation instructions [here](https://lsstdesc.org/BlendingToolKit/install.html).
Expand Down
53 changes: 31 additions & 22 deletions btk/draw_blends.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ def _get_center_in_pixels(blend_table: Table, wcs: WCS):
return dx_col, dy_col


def render_single_catsim_galaxy(
entry: Table,
filt: Filter,
survey: Survey,
psf: galsim.GSObject,
slen: int,
apply_shear: bool = False,
):
"""Render an image of a single galsim galaxy from a CATSIM entry."""
gal = get_catsim_galaxy(entry, filt, survey)
gal = gal.rotate(galsim.Angle(entry["btk_rotation"], unit=galsim.degrees))
if apply_shear:
if "g1" in entry.keys() and "g2" in entry.keys():
gal = gal.shear(g1=entry["g1"], g2=entry["g2"])
else:
raise KeyError("g1 and g2 not found in blend list.")
gal_conv = galsim.Convolve(gal, psf)
gal_conv = gal_conv.shift(entry["ra"], entry["dec"])
return gal_conv.drawImage(nx=slen, ny=slen, scale=survey.pixel_scale.to_value("arcsec"))


def get_catsim_galaxy(
entry: Table,
filt: Filter,
Expand Down Expand Up @@ -404,35 +425,36 @@ def render_blend(
blend_catalog.add_column(
Column(np.zeros(len(blend_catalog)), name="not_drawn_" + filt.name)
)
pix_stamp_size = int(self.stamp_size / survey.pixel_scale.to_value("arcsec"))
iso_image = np.zeros((self.max_number, pix_stamp_size, pix_stamp_size))
_blend_image = galsim.Image(np.zeros((pix_stamp_size, pix_stamp_size)))
slen = int(self.stamp_size / survey.pixel_scale.to_value("arcsec"))

iso_image = np.zeros((self.max_number, slen, slen))
blend_image = galsim.Image(np.zeros((slen, slen)))

for ii, entry in enumerate(blend_catalog):
single_image = self.render_single(entry, filt, psf, survey)
if single_image is None:
iso_image[ii] = np.zeros(single_image)
else:
iso_image[ii] = single_image.array
_blend_image += single_image
blend_image += single_image

# add noise.
if self.add_noise in ("galaxy", "all"):
if self.verbose:
print("Galaxy noise added to blend image")
generator = galsim.random.BaseDeviate(seed=seedseq_blend.generate_state(1))
galaxy_noise = galsim.PoissonNoise(rng=generator, sky_level=0.0)
_blend_image.addNoise(galaxy_noise)
blend_image.addNoise(galaxy_noise)
if self.add_noise in ("background", "all"):
if self.verbose:
print("Background noise added to blend image")
generator = galsim.random.BaseDeviate(seed=seedseq_blend.generate_state(1))
background_noise = galsim.PoissonNoise(rng=generator, sky_level=sky_level)
noise_image = galsim.Image(np.zeros((pix_stamp_size, pix_stamp_size)))
noise_image = galsim.Image(np.zeros((slen, slen)))
noise_image.addNoise(background_noise)
_blend_image += noise_image
blend_image += noise_image

blend_image = _blend_image.array
blend_image = blend_image.array
return blend_image, iso_image

@abstractmethod
Expand Down Expand Up @@ -483,20 +505,7 @@ def render_single(self, entry: Catalog, filt: Filter, psf: galsim.GSObject, surv

slen = self._get_pix_stamp_size(survey)
try:
gal = get_catsim_galaxy(entry, filt, survey)
gal = gal.rotate(galsim.Angle(entry["btk_rotation"], unit=galsim.degrees))
if self.apply_shear:
if "g1" in entry.keys() and "g2" in entry.keys():
gal = gal.shear(g1=entry["g1"], g2=entry["g2"])
else:
raise KeyError("g1 and g2 not found in blend list.")
gal_conv = galsim.Convolve(gal, psf)
gal_conv = gal_conv.shift(entry["ra"], entry["dec"])
return gal_conv.drawImage( # pylint: disable=no-value-for-parameter
nx=slen,
ny=slen,
scale=survey.pixel_scale.to_value("arcsec"),
)
return render_single_catsim_galaxy(entry, filt, survey, psf, slen, self.apply_shear)

except SourceNotVisible:
if self.verbose:
Expand Down
Loading
Loading