dirac-institute/kbmod

Support loading and searching likelihood images

Closed this issue · 1 comments

I am hoping to use the GPU implementation of shift and stack portion of the KBMOD code on a set of custom likelihood images.

Currently, the KBMOD search procedure involves loading images (from fits on disk or constructing a kbmod.search.ImageStack from a list of kbmod.search.LayeredImage by hand), followed by convolution with a point spread function (PSF), followed by a shift-and-stack algorithm that calculates the ratio of two "likelihood images" implemented as a psi and phi array to find a search candidate.

I have a new way to construct a likelihood image that involves more than PSF convolution, and I would like to provide the psi and phi arrays directly to KBMOD before running a search. The operations are: PSF convolution to create psi and phi, threshold based on the ratio of psi and phi and a given threshold value (i.e. single-epoch detection SNR), digitize pixels to 0 and 1 (detected or not), and finally perform sum-pooling (add all of the values in neighboring pixels) to decrease the resolution of the images.

I am playing around with the code, and creating setters for the Psi and Phi images as well as a function to write to the protected variable psiPhiGenerated seems to be working so far.

# src/kbmod/search/bindings.cpp
    py::class_<ks>(m, "stack_search")
...
            .def("set_psi_images", &ks::setPsiImages)
            .def("set_phi_images", &ks::setPhiImages)
            .def("set_psi_phi_generated", &ks::setPsiPhiGenerated)
# src/kbmod/search/KBMOSearch.cpp
void KBMOSearch::setPsiImages(std::vector<RawImage>& imgs) { 
    psiImages.clear();
    for (auto i : imgs) { 
        psiImages.push_back(i);
    }
}

void KBMOSearch::setPhiImages(std::vector<RawImage>& imgs) {
    phiImages.clear();
    for (auto i : imgs) { 
        phiImages.push_back(i);
    }
}

void KBMOSearch::setPsiPhiGenerated(bool generated) {
    psiPhiGenerated = generated;
}
# src/kbmod/search/KBMOSearch.h
class KBMOSearch {
public:
...
    void setPsiImages(std::vector<RawImage>&);
    void setPhiImages(std::vector<RawImage>&);
    void setPsiPhiGenerated(bool generated);

The kbmod.search.search function still relies on an image stack though, so it would be helpful to have a search function that doesn't rely on the image stack if supporting this functionality of searching custom likelihood images directly.

The code right now depends on being able to compute the Psi and Phi components instead of the aggregated likelihood. I think we want to focus on that approach for now instead of redesigning the core search. Feel free to re-open if you think this is urgent.