Skip to content

Commit

Permalink
Merge branch 'main' into prediction_consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremykubica committed Apr 3, 2024
2 parents e5f42e6 + 1c6d0f7 commit 566270a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
14 changes: 14 additions & 0 deletions tests/test_fake_data_creator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import numpy as np
import os
import tempfile
import unittest
Expand All @@ -23,6 +24,19 @@ def test_create_fake_times(self):
for i in range(7):
self.assertAlmostEqual(times2[i], expected[i])

def test_add_fake_object(self):
img = RawImage(20, 10, 0.0, 1.0) # All zero image.
p = PSF(np.full((3, 3), 1.0 / 9.0)) # Equal PSF.
add_fake_object(img, 5.5, 3.5, 100.0, p)

for r in range(10):
for c in range(20):
pix_val = img.get_pixel(r, c)
if abs(c - 5) <= 1 and abs(r - 3) <= 1:
self.assertAlmostEqual(pix_val, 100.0 / 9.0, delta=0.001)
else:
self.assertEqual(pix_val, 0.0)

def test_create(self):
times = create_fake_times(10)
ds = FakeDataSet(256, 128, times)
Expand Down
28 changes: 25 additions & 3 deletions tests/test_raw_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,33 @@ def test_interpolated_add(self):
# Get the original value using (r, c) lookup.
org_val17 = img.get_pixel(1, 7)

# Get the sum of this pixel and its immediate neighbors.
org_sum = np.sum(img.image[0:3, 6:9])

# Interpolated add uses the cartesian coordinates (x, y)
img.interpolated_add(7, 1, 10.0)
self.assertLess(img.get_pixel(1, 7), org_val17 + 10.0)
self.assertGreater(img.get_pixel(1, 7), org_val17 + 2.0)

# Test we have added a total of 10.0 to the pixel and its neighbors.
new_sum = np.sum(img.image[0:3, 6:9])
self.assertAlmostEqual(new_sum - org_sum, 10.0)

# Add values right near the edge of the pixel.
org_val21 = img.get_pixel(2, 1)
org_val31 = img.get_pixel(3, 1)
org_val32 = img.get_pixel(3, 2)
org_val41 = img.get_pixel(4, 1)
img.interpolated_add(1.9, 3.5, 10.0)

# All the value should go to (3, 1) and (3, 2) with more going to (3, 1)
diff31 = img.get_pixel(3, 1) - org_val31
diff32 = img.get_pixel(3, 2) - org_val32
self.assertAlmostEqual(diff31 + diff32, 10.0)
self.assertGreater(diff31, diff32)
self.assertAlmostEqual(org_val21, img.get_pixel(2, 1))
self.assertAlmostEqual(org_val41, img.get_pixel(4, 1))

def test_approx_equal(self):
"""Test RawImage pixel value setters."""
img = RawImage(img=self.array, obs_time=10.0)
Expand Down Expand Up @@ -440,10 +462,10 @@ def test_convolve_psf_orientation_gpu(self):
"""Test convolution on GPU with a non-symmetric PSF"""
self.convolve_psf_orientation_cpu("GPU")

# Stamp as is tested here and as it's used in StackSearch are heaven and earth
# TODO: Add proper tests
# Tests the basic cutout of a stamp from an image. More advanced stamp
# construction is done in stamp_creator.cpp and tested in test_search.py.
def test_make_stamp(self):
"""Test stamp creation."""
"""Tests the basic stamp creation."""
img = RawImage(self.array)
stamp = img.create_stamp(2.5, 2.5, 2, False)
self.assertEqual(stamp.image.shape, (5, 5))
Expand Down

0 comments on commit 566270a

Please sign in to comment.