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

A few small cleanups to the C++ code #756

Merged
merged 2 commits into from
Dec 16, 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
Binary file removed lib/libcfitsio.a
Binary file not shown.
28 changes: 0 additions & 28 deletions src/kbmod/search/image_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,33 +144,6 @@ void ImageStack::clear_from_gpu() {
data_on_gpu = false;
}

RawImage ImageStack::make_global_mask(int flags, int threshold) {
uint64_t npixels = get_npixels();

// Start with an empty global mask.
RawImage global_mask = RawImage(width, height);
global_mask.set_all(0.0);

// For each pixel count the number of images where it is masked.
std::vector<int> counts(npixels, 0);
for (unsigned int img = 0; img < images.size(); ++img) {
auto imgMask = images[img].get_mask().get_image().reshaped();

// Count the number of times a pixel has any of the given flags
for (uint64_t pixel = 0; pixel < npixels; ++pixel) {
if ((flags & static_cast<int>(imgMask[pixel])) != 0) counts[pixel]++;
}
}

// Set all pixels below threshold to 0 and all above to 1
auto global_m = global_mask.get_image().reshaped();
for (uint64_t p = 0; p < npixels; ++p) {
global_m[p] = counts[p] < threshold ? 0.0 : 1.0;
}

return global_mask;
}

#ifdef Py_PYTHON_H
static void image_stack_bindings(py::module& m) {
using is = search::ImageStack;
Expand All @@ -194,7 +167,6 @@ static void image_stack_bindings(py::module& m) {
.def("build_zeroed_times", &is::build_zeroed_times, pydocs::DOC_ImageStack_build_zeroed_times)
.def("sort_by_time", &is::sort_by_time, pydocs::DOC_ImageStack_sort_by_time)
.def("img_count", &is::img_count, pydocs::DOC_ImageStack_img_count)
.def("make_global_mask", &is::make_global_mask, pydocs::DOC_ImageStack_make_global_mask)
.def("convolve_psf", &is::convolve_psf, pydocs::DOC_ImageStack_convolve_psf)
.def("get_width", &is::get_width, pydocs::DOC_ImageStack_get_width)
.def("get_height", &is::get_height, pydocs::DOC_ImageStack_get_height)
Expand Down
3 changes: 0 additions & 3 deletions src/kbmod/search/image_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ class ImageStack {

void convolve_psf();

// Make and return a global mask.
RawImage make_global_mask(int flags, int threshold);

virtual ~ImageStack();

// Functions to handle transfering data to/from GPU.
Expand Down
21 changes: 0 additions & 21 deletions src/kbmod/search/pydocs/image_stack_docs.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,27 +130,6 @@ static const auto DOC_ImageStack_sort_by_time = R"doc(
Raises a ``RuntimeError`` if the input image is the data is currently on GPU.
)doc";

static const auto DOC_ImageStack_make_global_mask = R"doc(
Create a new global mask from a set of flags and a threshold.
The global mask marks a pixel as masked if and only if it is masked
by one of the given flags in at least ``threshold`` individual images.
The returned mask is binary.

Parameters
----------
flags : `int`
A bit mask of mask flags to use when counting.
threshold : `int`
The minimum number of images in which a pixel must be masked to be
part of the global mask.

Returns
-------
global_mask : `RawImage`
A RawImage containing the global mask with 1 for masked pixels
and 0 for unmasked pixels.
)doc";

static const auto DOC_ImageStack_convolve_psf = R"doc(
Convolves each image (science and variance layers) with the PSF
stored in the LayeredImage object.
Expand Down
17 changes: 0 additions & 17 deletions tests/test_image_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,6 @@ def test_times(self):
for i in range(self.num_images):
self.assertEqual(times[i], 2.0 * i)

def test_make_global_mask(self):
# Mask a single point in each image with flag=2.
for i in range(self.num_images):
self.images[i].get_mask().set_pixel(5, 5, 2)

# Apply the global mask for flag=1 and a threshold of the bit set
# in at least one mask. Note this ignores flag=2 for the count.
mask = self.im_stack.make_global_mask(1, 1)

# Check that the correct pixels are masked
for y in range(self.im_stack.get_height()):
for x in range(self.im_stack.get_width()):
if y == 10 and x >= 10 and x <= 10 + (self.num_images - 1):
self.assertEqual(mask.get_pixel(y, x), 1)
else:
self.assertEqual(mask.get_pixel(y, x), 0)

# WOW, this is the first test that caught the fact that interpolated_add
# called add, and that add had flipped i and j by accident. The first one.
# TODO: more clean understandable tests for basic functionality, these big
Expand Down