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

Initial transliteration of RawImage to an Eigen backend. #364

Merged
merged 37 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
fe75f09
Initial transliteration of RawImage to an Eigen backend.
DinoBektesevic Oct 2, 2023
c0d271f
Remove accidentally committed file.
DinoBektesevic Oct 2, 2023
2eeb773
Try to fix the eigen submodule.
DinoBektesevic Oct 2, 2023
c8615bc
Try to remove the submodule and re-add it.
DinoBektesevic Oct 2, 2023
3564ccd
Add Eigen submodule back in.
DinoBektesevic Oct 2, 2023
36884c6
Remove accidentally commited binary.
DinoBektesevic Oct 6, 2023
234cc88
Fix interpolate methods.
DinoBektesevic Oct 6, 2023
03623ee
Address Index constructors comments.
DinoBektesevic Oct 6, 2023
5ed10af
Revert grow_mask to previous implementation
DinoBektesevic Oct 6, 2023
d65457e
Remove create_median_image_eigen2 test func.
DinoBektesevic Oct 6, 2023
9bb6047
Remove create_median_image_eigen2, interpolate and rename interpolate…
DinoBektesevic Oct 6, 2023
c577fee
Remove old getters and setters.
DinoBektesevic Oct 7, 2023
37c9936
Move is_within to RawImage, fix missing call to centered_block.
DinoBektesevic Oct 8, 2023
e94aa4f
Revert image back to private attribute.
DinoBektesevic Oct 10, 2023
f419b02
Flakify.
DinoBektesevic Oct 10, 2023
2a48292
Add check when psf_portion==0 in convolve.
DinoBektesevic Oct 10, 2023
23efd44
Use a nested for loop for apply_mask.
DinoBektesevic Oct 10, 2023
e2f9438
Add 'exclude*' prefix to gitignore.
DinoBektesevic Oct 12, 2023
01c743d
Cleanup Index and Point.
DinoBektesevic Oct 12, 2023
e8d6fe1
Clean up the declarations of namespace py.
DinoBektesevic Oct 12, 2023
d7e644f
Merge raw_image_eigen into codebase, fix tests.
DinoBektesevic Oct 23, 2023
14caac8
Update the new code to fit the eigen transition, fix more tests.
DinoBektesevic Oct 23, 2023
9a14c27
Fix last of the tests, update analysis_utils.
DinoBektesevic Oct 24, 2023
1ab7772
Clang and flakify.
DinoBektesevic Oct 24, 2023
4696483
Fix for loop limits in raw image apply_mask.
DinoBektesevic Oct 25, 2023
331ba8b
Add tests for geom.h. Improve bindings.
DinoBektesevic Oct 29, 2023
40c4a2f
Add documentation.
DinoBektesevic Oct 30, 2023
1bacda6
Use Point vs Index more consistently in the codebase.
DinoBektesevic Oct 30, 2023
f49395a
Clean the mess and confusion in kernels.cu
DinoBektesevic Oct 31, 2023
312e74d
Raise error in set_pixel, inline more accessors, respond to more revi…
DinoBektesevic Oct 31, 2023
b1cf112
Cleanup more of the code comments.
DinoBektesevic Oct 31, 2023
ff716a2
clang-format and blacken.
DinoBektesevic Oct 31, 2023
3462cd5
Add obstime test to workunit.
DinoBektesevic Oct 31, 2023
daf3b09
Increase velocity error tolerance in test_search.
DinoBektesevic Nov 2, 2023
d988c87
Update RawImage documentation.
DinoBektesevic Nov 2, 2023
fd8b0f1
Update src/kbmod/search/pydocs/geom_docs.h
DinoBektesevic Nov 2, 2023
c443edb
Fix comments and clarify docs.
DinoBektesevic Nov 2, 2023
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ docs/source/examples/_notebooks
# emacs work in progress files (lock and autosave)
.#*
\#*#
# Exclude files starting with exclude (local test and development)
exclude*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "lib/pybind11"]
path = lib/pybind11
url = https://github.com/pybind/pybind11.git
[submodule "include/eigen"]
path = include/eigen
url = https://gitlab.com/libeigen/eigen.git
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ find_library(CFITSIO_LIBRARY

add_subdirectory(lib/pybind11)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

include_directories(
include/
include/eigen
)


Expand Down
1 change: 1 addition & 0 deletions include/eigen
Submodule eigen added at 6d829e
20 changes: 17 additions & 3 deletions src/kbmod/analysis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@ def get_all_stamps(self, result_list, search, stamp_radius):
stamp_edge = stamp_radius * 2 + 1
for row in result_list.results:
stamps = kb.StampCreator.get_stamps(search.get_imagestack(), row.trajectory, stamp_radius)
row.all_stamps = np.array([np.array(stamp).reshape(stamp_edge, stamp_edge) for stamp in stamps])
# TODO: a way to avoid a copy here would be to do
# np.array([s.image for s in stamps], dtype=np.single, copy=False)
# but that could cause a problem with reference counting at the m
# moment. The real fix is to make the stamps return Image not
# RawImage, return the Image and avoid a reference to a private
# attribute. This risks collecting RawImage but leaving a dangling
# ref to its private field. That's a fix for another time.
DinoBektesevic marked this conversation as resolved.
Show resolved Hide resolved
row.all_stamps = np.array([stamp.image for stamp in stamps])

def apply_clipped_sigmaG(self, result_list):
"""This function applies a clipped median filter to the results of a KBMOD
Expand Down Expand Up @@ -324,9 +331,16 @@ def apply_stamp_filter(
params,
kb.HAS_GPU and len(trj_slice) > 100,
)
# TODO: a way to avoid a copy here would be to do
# np.array([s.image for s in stamps], dtype=np.single, copy=False)
# but that could cause a problem with reference counting at the m
# moment. The real fix is to make the stamps return Image not
# RawImage and avoid reference to an private attribute and risking
# collecting RawImage but leaving a dangling ref to the attribute.
# That's a fix for another time so I'm leaving it as a copy here
for ind, stamp in enumerate(stamps_slice):
if stamp.get_width() > 1:
result_list.results[ind + start_idx].stamp = np.array(stamp)
if stamp.width > 1:
result_list.results[ind + start_idx].stamp = np.array(stamp.image)
all_valid_inds.append(ind + start_idx)

# Move to the next chunk.
Expand Down
13 changes: 6 additions & 7 deletions src/kbmod/fake_data_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from kbmod.work_unit import WorkUnit


def add_fake_object(img, x, y, flux, psf=None):
def add_fake_object(img, y, x, flux, psf=None):
DinoBektesevic marked this conversation as resolved.
Show resolved Hide resolved
"""Add a fake object to a LayeredImage or RawImage

Parameters
Expand All @@ -39,21 +39,20 @@ def add_fake_object(img, x, y, flux, psf=None):
sci = img

if psf is None:
sci.add_pixel_interp(x, y, flux)
sci.interpolated_add(y, x, flux)
else:
dim = psf.get_dim()
initial_x = x - psf.get_radius()
initial_y = y - psf.get_radius()

for i in range(dim):
for j in range(dim):
sci.add_pixel_interp(initial_x + i, initial_y + j, flux * psf.get_value(i, j))
sci.interpolated_add(float(initial_y + j), float(initial_x + i), flux * psf.get_value(i, j))


class FakeDataSet:
"""This class creates fake data sets for testing and demo notebooks."""

def __init__(self, width, height, num_times, noise_level=2.0, psf_val=0.5, obs_per_day=3, use_seed=False):
def __init__(self, height, width, num_times, noise_level=2.0, psf_val=0.5, obs_per_day=3, use_seed=False):
"""The constructor.

Parameters
Expand Down Expand Up @@ -111,8 +110,8 @@ def make_fake_ImageStack(self):
for i in range(self.num_times):
img = LayeredImage(
("%06i" % i),
self.width,
self.height,
self.width,
self.noise_level,
self.noise_level**2,
self.times[i],
Expand Down Expand Up @@ -143,7 +142,7 @@ def insert_object(self, trj):
# re-set the image. This last step needs to be done
# 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())
add_fake_object(current, py, px, trj.flux, current.get_psf())

# Save the trajectory into the internal list.
self.trajectories.append(trj)
Expand Down
4 changes: 2 additions & 2 deletions src/kbmod/filters/stamp_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def keep_row(self, row: ResultRow):
stamp = row.stamp.reshape([self.width, self.width])
peak_pos = RawImage(stamp).find_peak(True)
return (
abs(peak_pos.x - self.stamp_radius) < self.x_thresh
and abs(peak_pos.y - self.stamp_radius) < self.y_thresh
abs(peak_pos.i - self.stamp_radius) < self.x_thresh
and abs(peak_pos.j - self.stamp_radius) < self.y_thresh
)


Expand Down
15 changes: 10 additions & 5 deletions src/kbmod/search/bindings.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/numpy.h>
#include <pybind11/eigen.h>
#include <pybind11/stl.h>

namespace py = pybind11;

#include "common.h"
#include "geom.h"

#include "psf.cpp"
#include "raw_image.cpp"
Expand All @@ -9,10 +15,6 @@
#include "stack_search.cpp"
#include "stamp_creator.cpp"
#include "filtering.cpp"
#include "common.h"

using pp = search::PixelPos;
using std::to_string;

PYBIND11_MODULE(search, m) {
m.attr("KB_NO_DATA") = pybind11::float_(search::NO_DATA);
Expand All @@ -22,6 +24,9 @@ PYBIND11_MODULE(search, m) {
.value("STAMP_MEAN", search::StampType::STAMP_MEAN)
.value("STAMP_MEDIAN", search::StampType::STAMP_MEDIAN)
.export_values();
indexing::index_bindings(m);
indexing::point_bindings(m);
indexing::anchored_rectangle_bindings(m);
search::psf_bindings(m);
search::raw_image_bindings(m);
search::layered_image_bindings(m);
Expand Down
7 changes: 5 additions & 2 deletions src/kbmod/search/common.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#ifndef COMMON_H_
#define COMMON_H_

#include <assert.h>
#include <string>

#include "pydocs/common_docs.h"

// assert(condition, message if !condition)
#define assertm(exp, msg) assert(((void)msg, exp))

namespace search {
#ifdef HAVE_CUDA
constexpr bool HAVE_GPU = true;
DinoBektesevic marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -143,8 +148,6 @@ struct ImageMoments {
};

#ifdef Py_PYTHON_H
namespace py = pybind11;

static void trajectory_bindings(py::module &m) {
using tj = Trajectory;

Expand Down
Loading