Skip to content

Commit

Permalink
Merge branch 'main' into dep_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremykubica committed Sep 27, 2023
2 parents 859c23b + 17fd2b5 commit 8241902
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 65 deletions.
6 changes: 0 additions & 6 deletions src/kbmod/fake_data_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ def add_fake_object(img, x, y, flux, psf=None):
for j in range(dim):
sci.add_pixel_interp(initial_x + i, initial_y + j, flux * psf.get_value(i, j))

# The python/C++ interface requires us to explicitly re-set the science
# image in a LayeredImage.
if sci is not img:
img.set_science(sci)


class FakeDataSet:
"""This class creates fake data sets for testing and demo notebooks."""
Expand Down Expand Up @@ -147,7 +142,6 @@ def insert_object(self, trj):
# explicitly because of how pybind handles references.
current = self.stack.get_single_image(i)
add_fake_object(current, px, py, trj.flux, current.get_psf())
self.stack.set_single_image(i, current)

# Save the trajectory into the internal list.
self.trajectories.append(trj)
Expand Down
4 changes: 2 additions & 2 deletions src/kbmod/run_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ def do_gpu_search(self, search, img_info, suggested_angle, post_process):
if self.config["x_pixel_bounds"] and len(self.config["x_pixel_bounds"]) == 2:
search.set_start_bounds_x(self.config["x_pixel_bounds"][0], self.config["x_pixel_bounds"][1])
elif self.config["x_pixel_buffer"] and self.config["x_pixel_buffer"] > 0:
width = search.get_ImageStack().get_width()
width = search.get_imagestack().get_width()
search.set_start_bounds_x(-self.config["x_pixel_buffer"], width + self.config["x_pixel_buffer"])

if self.config["y_pixel_bounds"] and len(self.config["y_pixel_bounds"]) == 2:
search.set_start_bounds_y(self.config["y_pixel_bounds"][0], self.config["y_pixel_bounds"][1])
elif self.config["y_pixel_buffer"] and self.config["y_pixel_buffer"] > 0:
height = search.get_ImageStack().get_height()
height = search.get_imagestack().get_height()
search.set_start_bounds_y(-self.config["y_pixel_buffer"], height + self.config["y_pixel_buffer"])

# If we are using barycentric corrections, compute the parameters and
Expand Down
4 changes: 3 additions & 1 deletion src/kbmod/search/image_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ namespace search {
.def(py::init<std::vector<std::string>, std::vector<pf>>())
.def(py::init<std::vector<li>>())
.def("get_images", &is::get_images, pydocs::DOC_ImageStack_get_images)
.def("get_single_image", &is::get_single_image, pydocs::DOC_ImageStack_get_single_image)
.def("get_single_image", &is::get_single_image,
py::return_value_policy::reference_internal,
pydocs::DOC_ImageStack_get_single_image)
.def("set_single_image", &is::set_single_image, pydocs::DOC_ImageStack_set_single_image)
.def("get_times", &is::get_times, pydocs::DOC_ImageStack_get_times)
.def("set_times", &is::set_times, pydocs::DOC_ImageStack_set_times )
Expand Down
16 changes: 12 additions & 4 deletions src/kbmod/search/layered_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,22 @@ namespace search {
.def(py::init<std::string, int, int, double, float, float, pf &>())
.def(py::init<std::string, int, int, double, float, float, pf &, int>())
.def("set_psf", &li::set_psf, pydocs::DOC_LayeredImage_set_psf)
.def("get_psf", &li::get_psf, pydocs::DOC_LayeredImage_get_psf)
.def("get_psf", &li::get_psf,
py::return_value_policy::reference_internal,
pydocs::DOC_LayeredImage_get_psf)
.def("apply_mask_flags", &li::apply_mask_flags, pydocs::DOC_LayeredImage_apply_mask_flags)
.def("apply_mask_threshold", &li::apply_mask_threshold, pydocs::DOC_LayeredImage_apply_mask_threshold)
.def("sub_template", &li::subtract_template, pydocs::DOC_LayeredImage_sub_template)
.def("save_layers", &li::save_layers, pydocs::DOC_LayeredImage_save_layers)
.def("get_science", &li::get_science, pydocs::DOC_LayeredImage_get_science)
.def("get_mask", &li::get_mask, pydocs::DOC_LayeredImage_get_mask)
.def("get_variance", &li::get_variance, pydocs::DOC_LayeredImage_get_variance)
.def("get_science", &li::get_science,
py::return_value_policy::reference_internal,
pydocs::DOC_LayeredImage_get_science)
.def("get_mask", &li::get_mask,
py::return_value_policy::reference_internal,
pydocs::DOC_LayeredImage_get_mask)
.def("get_variance", &li::get_variance,
py::return_value_policy::reference_internal,
pydocs::DOC_LayeredImage_get_variance)
.def("set_science", &li::set_science, pydocs::DOC_LayeredImage_set_science)
.def("set_mask", &li::set_mask, pydocs::DOC_LayeredImage_set_mask)
.def("set_variance", &li::set_variance, pydocs::DOC_LayeredImage_set_variance)
Expand Down
4 changes: 3 additions & 1 deletion src/kbmod/search/stack_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,9 @@ namespace search {
.def("set_debug", &ks::set_debug, pydocs::DOC_StackSearch_set_debug)
.def("filter_min_obs", &ks::filter_results, pydocs::DOC_StackSearch_filter_min_obs)
.def("get_num_images", &ks::num_images, pydocs::DOC_StackSearch_get_num_images)
.def("get_imagestack", &ks::get_imagestack, pydocs::DOC_StackSearch_get_imagestack)
.def("get_imagestack", &ks::get_imagestack,
py::return_value_policy::reference_internal,
pydocs::DOC_StackSearch_get_imagestack)
// Science Stamp Functions
.def("get_stamps", &ks::get_stamps, pydocs::DOC_StackSearch_get_stamps)
.def("get_median_stamp", &ks::get_median_stamp, pydocs::DOC_StackSearch_get_median_stamp)
Expand Down
3 changes: 0 additions & 3 deletions tests/test_image_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def setUp(self):
# Include one masked pixel per time step at (10, 10 + i).
mask = self.images[i].get_mask()
mask.set_pixel(10, 10 + i, 1)
self.images[i].set_mask(mask)

self.im_stack = ImageStack(self.images)

Expand Down Expand Up @@ -133,8 +132,6 @@ def test_create_global_mask_reset(self):
img = self.im_stack.get_single_image(i)
mask = img.get_mask()
mask.set_pixel(10, 10 + i, 0)
img.set_mask(mask)
self.im_stack.set_single_image(i, img)

# Reapply the mask and check that nothing is masked.
# Note the science pixels will still be masked from the previous application.
Expand Down
30 changes: 9 additions & 21 deletions tests/test_layered_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ def test_apply_mask(self):
mask.set_pixel(10, 11, 1)
mask.set_pixel(10, 12, 2)
mask.set_pixel(10, 13, 3)
self.image.set_mask(mask)

# Apply the mask flags to only (10, 11) and (10, 13)
self.image.apply_mask_flags(1, [])
Expand All @@ -187,7 +186,6 @@ def test_apply_mask_exceptions(self):
mask.set_pixel(10, 11, 1)
mask.set_pixel(10, 12, 2)
mask.set_pixel(10, 13, 3)
self.image.set_mask(mask)

# Apply the mask flags to only (10, 11).
self.image.apply_mask_flags(1, [1])
Expand All @@ -205,7 +203,6 @@ def test_grow_mask(self):
mask.set_pixel(10, 11, 1)
mask.set_pixel(10, 12, 1)
mask.set_pixel(10, 13, 1)
self.image.set_mask(mask)
self.image.apply_mask_flags(1, [])
self.image.grow_mask(1)

Expand All @@ -224,7 +221,6 @@ def test_grow_mask_mult(self):
mask = self.image.get_mask()
mask.set_pixel(10, 11, 1)
mask.set_pixel(10, 12, 1)
self.image.set_mask(mask)
self.image.apply_mask_flags(1, [])
self.image.grow_mask(3)

Expand All @@ -250,8 +246,6 @@ def test_psi_and_phi_image(self):
sci.set_pixel(x, y, float(x))
var.set_pixel(x, y, float(y + 1))
var.set_pixel(3, 1, KB_NO_DATA)
img.set_science(sci)
img.set_variance(var)

# Generate and check psi and phi images.
psi = img.generate_psi_image()
Expand All @@ -272,26 +266,21 @@ def test_psi_and_phi_image(self):
self.assertAlmostEqual(phi.get_pixel(x, y), 1.0 / float(y + 1))

def test_subtract_template(self):
old_science = self.image.get_science()

# Mask out a few points and reset (needed because of how pybind handles
# pass by reference).
old_science.set_pixel(5, 6, KB_NO_DATA)
old_science.set_pixel(10, 7, KB_NO_DATA)
old_science.set_pixel(10, 21, KB_NO_DATA)
self.image.set_science(old_science)
sci = self.image.get_science()
sci.set_pixel(10, 7, KB_NO_DATA)
sci.set_pixel(10, 21, KB_NO_DATA)
old_sci = RawImage(sci) # Make a copy.

template = RawImage(self.image.get_width(), self.image.get_height())
template.set_all(0.0)
for h in range(old_science.get_height()):
for h in range(sci.get_height()):
template.set_pixel(10, h, 0.01 * h)
self.image.sub_template(template)

new_science = self.image.get_science()
for x in range(old_science.get_width()):
for y in range(old_science.get_height()):
val1 = old_science.get_pixel(x, y)
val2 = new_science.get_pixel(x, y)
for x in range(sci.get_width()):
for y in range(sci.get_height()):
val1 = old_sci.get_pixel(x, y)
val2 = sci.get_pixel(x, y)
if x == 10 and y != 7 and y != 21:
self.assertAlmostEqual(val2, val1 - 0.01 * y, delta=1e-6)
else:
Expand All @@ -316,7 +305,6 @@ def test_read_write_files(self):
mask1 = im1.get_mask()
mask1.set_pixel(3, 5, 1.0)
mask1.set_pixel(5, 3, 1.0)
im1.set_mask(mask1)

# Save the test data.
im1.save_layers(dir_name + "/")
Expand Down
20 changes: 0 additions & 20 deletions tests/test_masking.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ def test_threshold_masker(self):
sci.set_pixel(2 + i, 8, 501.0)
sci.set_pixel(1 + i, 9, 499.0)

# We need to reset the images because of how pybind handles pass by reference.
img.set_science(sci)
self.stack.set_single_image(i, img)

# With a threshold of 500 one pixel per image should be masked.
mask = ThresholdMask(500)
self.stack = mask.apply_mask(self.stack)
Expand All @@ -85,10 +81,6 @@ def test_per_image_dictionary_mask(self):
for x in range(self.dim_x):
msk.set_pixel(x, 3, 2**x)

# We need to reset the images because of how pybind handles pass by reference.
img.set_mask(msk)
self.stack.set_single_image(i, img)

# Mask with two keys.
mask = DictionaryMasker(self.mask_bits_dict, ["BAD", "EDGE"])
self.stack = mask.apply_mask(self.stack)
Expand Down Expand Up @@ -121,10 +113,6 @@ def test_mask_grow(self):
for x in range(self.dim_x):
msk.set_pixel(2 + i, 8, 1)

# We need to reset the images because of how pybind handles pass by reference.
img.set_mask(msk)
self.stack.set_single_image(i, img)

# Apply the bit vector based mask and check that one pixel per image is masked.
self.stack = BitVectorMasker(1, []).apply_mask(self.stack)
for i in range(self.img_count):
Expand Down Expand Up @@ -156,10 +144,6 @@ def test_global_mask(self):
if i == 0:
msk.set_pixel(5, 5, 4)

# We need to reset the images because of how pybind handles pass by reference.
img.set_mask(msk)
self.stack.set_single_image(i, img)

mask = GlobalDictionaryMasker(self.mask_bits_dict, ["CR", "INTRP"], 2)
self.stack = mask.apply_mask(self.stack)
for i in range(self.img_count):
Expand Down Expand Up @@ -228,10 +212,6 @@ def test_apply_masks(self):
msk.set_pixel(6, 5, 8)
bad_pixels.append((i, 6, 5))

# We need to reset the images because of how pybind handles pass by reference.
img.set_science(sci)
img.set_mask(msk)
self.stack.set_single_image(i, img)
bad_set = set(bad_pixels)

# Do the actual masking.
Expand Down
6 changes: 0 additions & 6 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def setUp(self):
if i % 2 == 0:
mask = im.get_mask()
mask.set_pixel(self.masked_x, self.masked_y, 1)
im.set_mask(mask)
im.apply_mask_flags(1, [])

self.imlist.append(im)
Expand Down Expand Up @@ -103,7 +102,6 @@ def test_psiphi(self):

mask = image2.get_mask()
mask.set_pixel(4, 9, 1)
image2.set_mask(mask)
image2.apply_mask_flags(1, [])

# Create a stack from the two objects.
Expand Down Expand Up @@ -477,7 +475,6 @@ def test_coadd_cpu_simple(self):
sci = im.get_science()
for x in range(3):
sci.set_pixel(x, 1, i + 1)
im.set_science(sci)

# Mask out the row's first pixel twice and second pixel once.
mask = im.get_mask()
Expand All @@ -486,7 +483,6 @@ def test_coadd_cpu_simple(self):
mask.set_pixel(1, 1, 1)
if i == 1:
mask.set_pixel(0, 1, 1)
im.set_mask(mask)
im.apply_mask_flags(1, [])

imlist.append(im)
Expand Down Expand Up @@ -539,7 +535,6 @@ def test_coadd_gpu_simple(self):
sci = im.get_science()
for x in range(3):
sci.set_pixel(x, 1, i + 1)
im.set_science(sci)

# Mask out the row's first pixel twice and second pixel once.
mask = im.get_mask()
Expand All @@ -548,7 +543,6 @@ def test_coadd_gpu_simple(self):
mask.set_pixel(1, 1, 1)
if i == 1:
mask.set_pixel(0, 1, 1)
im.set_mask(mask)
im.apply_mask_flags(1, [])

imlist.append(im)
Expand Down
1 change: 0 additions & 1 deletion tests/test_stamp_parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def setUp(self):
if i % 2 == 0:
mask = im.get_mask()
mask.set_pixel(self.masked_x, self.masked_y, 1)
im.set_mask(mask)
im.apply_mask_flags(1, [])

self.imlist.append(im)
Expand Down

0 comments on commit 8241902

Please sign in to comment.