Skip to content

Commit

Permalink
Merge pull request #465 from dirac-institute/psf_checks
Browse files Browse the repository at this point in the history
Add some basic checks and tests for PSF
  • Loading branch information
jeremykubica authored Feb 8, 2024
2 parents 545d107 + a2a2a03 commit ed8df11
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/kbmod/search/psf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ PSF::PSF() : kernel(1, 1.0) {
}

PSF::PSF(float stdev) {
if (stdev <= 0.0) {
throw std::runtime_error("PSF stdev must be > 0.0.");
}

width = stdev;
float simple_gauss[MAX_KERNEL_RADIUS];
double psf_coverage = 0.0;
Expand All @@ -28,7 +32,7 @@ PSF::PSF(float stdev) {
i++;
}

radius = i - 1; // This value is good for
radius = i - 1;
dim = 2 * radius + 1;

// Create 2D gaussain by multiplying with itself
Expand Down Expand Up @@ -155,6 +159,7 @@ static void psf_bindings(py::module& m) {
.def(py::init<float>())
.def(py::init<py::array_t<float>>())
.def(py::init<psf&>())
.def("__str__", &psf::print)
.def("set_array", &psf::set_array, pydocs::DOC_PSF_set_array)
.def("get_std", &psf::get_std, pydocs::DOC_PSF_get_std)
.def("get_sum", &psf::get_sum, pydocs::DOC_PSF_get_sum)
Expand Down
18 changes: 11 additions & 7 deletions src/kbmod/search/pydocs/psf_docs.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ static const auto DOC_PSF = R"doc(
Parameters
----------
stdev : `float`, optional
Standard deviation of the Gaussian PSF.
Standard deviation of the Gaussian PSF. Must be > 0.0.
psf : `PSF`, optional
Another PSF object.
arr : `numpy.array`, optional
A realization of the PSF.
Notes
-----
When instantiated with another `psf` object, returns its copy.
When instantiated with an array-like object, that array must be
a square matrix and have an odd number of dimensions. Only one
of the arguments is required.
Notes
-----
When instantiated with another `psf` object, returns its copy.
When instantiated with an array-like object, that array must be
a square matrix and have an odd number of dimensions. Only one
of the arguments is required.
Raises
------
Raises a ``RuntimeError`` when given an invalid stdev.
)doc";

static const auto DOC_PSF_set_array = R"doc(
Expand Down
8 changes: 8 additions & 0 deletions tests/test_psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ def test_make_noop(self):
self.assertEqual(len(kernel0), 1)
self.assertEqual(kernel0[0], 1.0)

def test_make_invalud(self):
# Raise an error if creating a PSF with a negative stdev.
self.assertRaises(RuntimeError, PSF, -1.0)

def test_to_string(self):
result = self.psf_list[0].__str__()
self.assertGreater(len(result), 1)

def test_make_and_copy(self):
psf1 = PSF(1.0)
self.assertEqual(psf1.get_size(), 25)
Expand Down

0 comments on commit ed8df11

Please sign in to comment.