Skip to content

Commit

Permalink
Remove center option to drawStar and model.draw, which we don't need …
Browse files Browse the repository at this point in the history
…anymore
  • Loading branch information
rmjarvis committed Jun 28, 2024
1 parent ef0b1e3 commit 6a16d17
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 29 deletions.
8 changes: 2 additions & 6 deletions piff/convolvepsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,11 @@ def interpolateStar(self, star):
star = comp.interpolateStar(star)
return star

def _drawStar(self, star, center=None):
def _drawStar(self, star):
params = star.fit.get_params(self._num)
prof, method = self._getRawProfile(star)
prof = prof.shift(star.fit.center) * star.fit.flux
if center is None:
center = star.image_pos
else:
center = galsim.PositionD(*center)
image = prof.drawImage(image=star.image.copy(), method=method, center=center)
image = prof.drawImage(image=star.image.copy(), method=method, center=star.image_pos)
return Star(star.data.withNew(image=image), star.fit)

def _getRawProfile(self, star, skip=None):
Expand Down
10 changes: 2 additions & 8 deletions piff/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,14 @@ def fit(self, star, convert_func=None):
"""
raise NotImplementedError("Derived classes must define the fit function")

def draw(self, star, copy_image=True, center=None):
def draw(self, star, copy_image=True):
"""Draw the model on the given image.
:param star: A Star instance with the fitted parameters to use for drawing and a
data field that acts as a template image for the drawn model.
:param copy_image: If False, will use the same image object.
If True, will copy the image and then overwrite it.
[default: True]
:param center: An optional tuple (x,y) location for where to center the drawn profile
in the image. [default: None, which draws at the star's location.]
:returns: a new Star instance with the data field having an image of the drawn model.
"""
Expand All @@ -153,11 +151,7 @@ def draw(self, star, copy_image=True, center=None):
image = star.image.copy()
else:
image = star.image
if center is None:
center = star.image_pos
else:
center = galsim.PositionD(*center)
prof.drawImage(image, method=self._method, center=center)
prof.drawImage(image, method=self._method, center=star.image_pos)
return Star(star.data.withNew(image=image), star.fit)

def write(self, fits, extname):
Expand Down
8 changes: 3 additions & 5 deletions piff/psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def drawStarList(self, stars, copy_image=True):
stars = self.interpolateStarList(stars)
return [self._drawStar(star) for star in stars]

def drawStar(self, star, copy_image=True, center=None):
def drawStar(self, star, copy_image=True):
"""Generate PSF image for a given star.
.. note::
Expand All @@ -689,8 +689,6 @@ def drawStar(self, star, copy_image=True, center=None):
:param copy_image: If False, will use the same image object.
If True, will copy the image and then overwrite it.
[default: True]
:param center: An optional tuple (x,y) location for where to center the drawn profile
in the image. [default: None, which draws at the star's location.]
:returns: Star instance with its image filled with rendered PSF
"""
Expand All @@ -702,9 +700,9 @@ def drawStar(self, star, copy_image=True, center=None):
if star.fit is None or star.fit.get_params(self._num) is None:
star = self.interpolateStar(star)
# Render the image
return self._drawStar(star, center=center)
return self._drawStar(star)

def _drawStar(self, star, center=None):
def _drawStar(self, star):
# Derived classes may choose to override any of the above functions
# But they have to at least override this one and interpolateStar to implement
# their actual PSF model.
Expand Down
4 changes: 2 additions & 2 deletions piff/simplepsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ def interpolateStar(self, star):
self.model.normalize(star)
return star

def _drawStar(self, star, center=None):
return self.model.draw(star, center=center)
def _drawStar(self, star):
return self.model.draw(star)

def _getRawProfile(self, star):
return self.model.getProfile(star.fit.get_params(self._num)), self.model._method
Expand Down
4 changes: 2 additions & 2 deletions piff/singlechip.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ def interpolateStar(self, star):
chipnum = star['chipnum']
return self.psf_by_chip[chipnum].interpolateStar(star)

def _drawStar(self, star, center=None):
def _drawStar(self, star):
if 'chipnum' not in star.data.properties:
raise ValueError("SingleChip requires the star to have a chipnum property")
chipnum = star['chipnum']
return self.psf_by_chip[chipnum]._drawStar(star, center=center)
return self.psf_by_chip[chipnum]._drawStar(star)

def _getProfile(self, star):
chipnum = star['chipnum']
Expand Down
4 changes: 2 additions & 2 deletions piff/sumpsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ def interpolateStar(self, star):
star = comp.interpolateStar(star)
return star

def _drawStar(self, star, center=None):
def _drawStar(self, star):
# Draw each component
comp_stars = []
for comp in self.components:
comp_star = comp._drawStar(star, center=center)
comp_star = comp._drawStar(star)
comp_stars.append(comp_star)

# Add them up.
Expand Down
4 changes: 0 additions & 4 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,6 @@ def test_single_image():
assert test_star_nocopy.image.array[1,1] == target_star_copy.image.array[1,1]
assert test_star_copy.image.array[1,1] == target_star_copy.image.array[1,1]

test_star_center = psf.model.draw(test_star_copy, copy_image=True, center=(x+1,y+1))
np.testing.assert_almost_equal(test_star_center.image.array[1:,1:],
test_star_copy.image.array[:-1,:-1])

# test that draw works
test_image = psf.draw(x=target['x'], y=target['y'], stamp_size=config['input']['stamp_size'],
flux=target.fit.flux, offset=target.fit.center)
Expand Down

0 comments on commit 6a16d17

Please sign in to comment.