Skip to content

Commit

Permalink
Merge branch 'master' into refactor/deprecation-and-affine-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
waltsims authored Feb 20, 2025
2 parents d6ea904 + 8ca3f30 commit 98d6a15
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion kwave/ksource.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def p0(self):
@p0.setter
def p0(self, val):
# check size and contents
if len(val) == 0 or np.sum(val != 0) == 0:
if len(val) == 0:
# if the initial pressure is empty, remove field
self._p0 = None
else:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies = [
"h5py==3.12.1",
"scipy==1.15.1",
"opencv-python==4.11.0.86",
"deepdiff==8.1.1",
"deepdiff==8.2.0",
"numpy>=1.22.2,<2.3.0",
"matplotlib==3.10.0",
"beartype==0.19.0",
Expand All @@ -42,7 +42,7 @@ Bug-tracker = "/~https://github.com/waltsims/k-wave-python/issues"

[project.optional-dependencies]
test = ["pytest",
"coverage==7.6.10",
"coverage==7.6.11",
"phantominator",
"testfixtures==8.3.0",
"requests==2.32.3"]
Expand Down
42 changes: 42 additions & 0 deletions tests/test_ksource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import unittest
import numpy as np
from kwave.ksource import kSource


class TestKSource(unittest.TestCase):
def setUp(self):
self.source = kSource()

def test_p0_setter_empty_array(self):
"""Test that p0 is set to None when given an empty array"""
self.source.p0 = np.array([])
self.assertIsNone(self.source.p0)

def test_p0_setter_non_empty_array(self):
"""Test that p0 is set correctly for non-empty array"""
test_array = np.array([1.0, 2.0, 3.0])
self.source.p0 = test_array
np.testing.assert_array_equal(self.source.p0, test_array)

def test_p0_setter_zero_array(self):
"""Test that p0 is set correctly for array of zeros (should not be set to None)"""
test_array = np.zeros(5)
self.source.p0 = test_array
np.testing.assert_array_equal(self.source.p0, test_array)

def test_is_p0_empty(self):
"""Test the is_p0_empty method"""
# Test with None
self.assertTrue(self.source.is_p0_empty())

# Test with empty array
self.source.p0 = np.array([])
self.assertTrue(self.source.is_p0_empty())

# Test with non-empty array
self.source.p0 = np.array([1.0, 2.0])
self.assertFalse(self.source.is_p0_empty())

# Test with zero array
self.source.p0 = np.zeros(5)
self.assertTrue(self.source.is_p0_empty())

0 comments on commit 98d6a15

Please sign in to comment.