Skip to content

Commit

Permalink
Fix last of the tests, update analysis_utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoBektesevic committed Oct 24, 2023
1 parent 14caac8 commit 9a14c27
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 183 deletions.
18 changes: 16 additions & 2 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.
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.width > 1:
result_list.results[ind + start_idx].stamp = np.array(stamp)
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
12 changes: 8 additions & 4 deletions src/kbmod/search/kernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ namespace search {
}

// Get origin pixel for the trajectories in pixel space.
const int x = x_i + params.x_start_min;
const int y = y_i + params.y_start_min;
// TODO: this is an ugly hack to get things to work,
// beautify before merge, see also later
const int y = x_i + params.x_start_min;
const int x = y_i + params.y_start_min;
const unsigned int n_pixels = width * height;

// Data structures used for filtering.
Expand Down Expand Up @@ -149,8 +151,10 @@ namespace search {
for (int i = 0; i < num_images; ++i) {
// Predict the trajectory's position.
float curr_time = image_data.image_times[i];
int current_x = x + int(curr_trj.vx * curr_time + 0.5);
int current_y = y + int(curr_trj.vy * curr_time + 0.5);
// TODO: the hack again, make sure to properly contextualize
// before merging
int current_y = x + int(curr_trj.vx * curr_time + 0.5);
int current_x = y + int(curr_trj.vy * curr_time + 0.5);

// Test if trajectory goes out of the image, in which case we do not
// look up a pixel value for this time step (allowing trajectories to
Expand Down
8 changes: 8 additions & 0 deletions src/kbmod/search/raw_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,14 @@ RawImage& RawImage::operator=(RawImage&& source) {
.def_property("obstime", &rie::get_obstime, &rie::set_obstime)
.def_property("image", py::overload_cast<>(&rie::get_image, py::const_), &rie::set_image)
.def_property("imref", py::overload_cast<>(&rie::get_image), &rie::set_image)
.def("data", [](rie& cls){
for (int j=0; j<cls.get_height(); j++){
for (int i=0; i<cls.get_width(); i++){
std::cout << cls.get_image()(j, i) << " ";
}
std::cout << std::endl;
}
})
// pixel accessors and setters
.def("get_pixel", &rie::get_pixel)
.def("pixel_has_data", &rie::pixel_has_data)
Expand Down
17 changes: 17 additions & 0 deletions src/kbmod/search/stack_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,23 @@ namespace search {
}


Point StackSearch::get_trajectory_position(const Trajectory& t, int i) const {
float time = stack.get_zeroed_time(i);
return {t.y + time * t.vy, t.x + time * t.vx};
}


std::vector<Point> StackSearch::get_trajectory_positions(Trajectory& t) const {
std::vector<Point> results;
int num_times = stack.img_count();
for (int i = 0; i < num_times; ++i) {
Point pos = get_trajectory_position(t, i);
results.push_back(pos);
}
return results;
}


std::vector<float> StackSearch::create_curves(Trajectory t, const std::vector<RawImage>& imgs) {
/*Create a lightcurve from an image along a trajectory
*
Expand Down
Loading

0 comments on commit 9a14c27

Please sign in to comment.