Skip to content

Commit

Permalink
Edits based on Theo's code review.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmjarvis committed Mar 27, 2024
1 parent 8693068 commit 8941647
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions piff/sumpsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, components, outliers=None, chisq_thresh=0.1, max_iter=30):
self.chisq_thresh = chisq_thresh
self.max_iter = max_iter
self.kwargs = {
# If components is a list, mark the number of components here for I/O purposed.
# If components is a list, mark the number of components here for I/O purposes.
# But if it's just a number, leave it alone.
'components': len(components) if isinstance(components, list) else components,
'outliers': 0,
Expand Down Expand Up @@ -88,10 +88,9 @@ def set_num(self, num):
self._num_components += comp.num_components
self._num = self._nums[0]
else:
# else components are not yet built. This will be called again when that's done.
self._num = None

# else components are not yet built. This will be called again when that's done.

@property
def num_components(self):
return self._num_components
Expand Down Expand Up @@ -172,9 +171,7 @@ def single_iteration(self, stars, logger, convert_func):
nremoved = 0 # For this iteration

# Draw the current models for each component
current_models = []
for k, comp in enumerate(self.components):
current_models.append(comp.drawStarList(stars))
current_models = [comp.drawStarList(stars) for comp in self.components]

# Fit each component in order
for k, comp in enumerate(self.components):
Expand All @@ -192,9 +189,10 @@ def single_iteration(self, stars, logger, convert_func):
# Fit this component
new_stars, nremoved1 = comp.single_iteration(modified_stars, logger, convert_func)

# The fit components in new_stars are what we want, but the data parts are
# corrupted by subtracting the other components, which we don't want.
# Just copy over the fits.
# new_stars now has the updated fit components, but the data parts are corrupted by
# subtracting the other components during fitting.
# Update the stars by copying the undisturbed data from the original stars and the
# updated fits from new_stars.
stars = [Star(s1.data, s2.fit) for s1,s2 in zip(stars, new_stars)]
nremoved += nremoved1

Expand Down
2 changes: 1 addition & 1 deletion tests/test_sumpsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def test_easy_sum2():
print('image max diff = ',np.max(np.abs(test_image[b].array - test_star.image[b].array)))
np.testing.assert_allclose(test_image[b].array, test_star.image[b].array, atol=1.e-8)

# Repeat with both components being PixelGrid mdoels.
# Repeat with both components being PixelGrid models.
# Both pretty chunky, so this test doesn't take forever.
config['psf']['components'][0]['model'] = {
'type': 'PixelGrid',
Expand Down

0 comments on commit 8941647

Please sign in to comment.