Skip to content

Commit

Permalink
small changes in Parameters class and new test
Browse files Browse the repository at this point in the history
  • Loading branch information
schuenke committed Jul 18, 2024
1 parent f06dc81 commit 78648cf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/bmctool/parameters/Parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ def __eq__(self, other: object) -> bool:
"""Check if two Parameters instances are equal."""
if not isinstance(other, self.__class__):
return NotImplemented
# Todo: check if cest_pool comparison is correct and add test(s)
if self.__slots__ == other.__slots__:
return (
self.water_pool == other.water_pool
and self.cest_pools == other.cest_pools
and all(
self.cest_pools[ii] == other.cest_pools[ii] for ii in range(len(self.cest_pools)) if self.cest_pools
)
and self.mt_pool == other.mt_pool
and self.system == other.system
and self.options == other.options
Expand All @@ -60,7 +63,7 @@ def num_cest_pools(self) -> int:
@property
def mz_loc(self) -> int:
"""Get the location of the water z-magnetization in the BMC matrix."""
if not self.water_pool:
if not hasattr(self, 'water_pool'):
raise Exception('No water pool defined. mz_loc cannot be determined')

# mz_loc is 2 for water pool and +2 for each CEST pool
Expand All @@ -69,7 +72,7 @@ def mz_loc(self) -> int:
@property
def m_vec(self) -> np.ndarray:
"""Get the initial magnetization vector (fully relaxed)."""
if not self.water_pool:
if not hasattr(self, 'water_pool'):
raise Exception('No water pool defined. m_vec cannot be determined')

num_full_pools = self.num_cest_pools + 1
Expand Down Expand Up @@ -128,9 +131,6 @@ def from_yaml(cls, yaml_file: str | Path) -> Self:
yaml_file
Path to yaml config file.
"""
if not Path(yaml_file).exists():
raise FileNotFoundError(f'File {yaml_file} not found.')

with Path(yaml_file).open() as file:
config = yaml.safe_load(file)

Expand Down
6 changes: 5 additions & 1 deletion src/bmctool/utils/seq/write.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""write.py Auxiliary functions for writing seq files."""
"""Auxiliary functions for writing seq files.
These function are used in the pulseq-cest library to write seq files matching the MATLAB style.
The pulseq-cest library can be found at: https://github.com/kherz/pulseq-cest-library
"""

import math
from datetime import datetime
Expand Down
12 changes: 12 additions & 0 deletions tests/parameters/test_Parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
from bmctool.parameters import Parameters


def test_properties_raise_error(valid_parameters_object):
"""Test that m_vec and mz_loc raise an error if water_pool does not exist."""
p = deepcopy(valid_parameters_object)
del p.water_pool
with pytest.raises(Exception, match='No water pool defined.'):
_ = p.mz_loc

with pytest.raises(Exception, match='No water pool defined.'):
_ = p.m_vec


def test_init_from_valid_dict(valid_config_dict):
"""Test initialization of the Parameters class from a valid dictionary."""
p = Parameters.from_dict(valid_config_dict)
Expand Down Expand Up @@ -199,3 +210,4 @@ def test_equality(
assert a == valid_parameters_object
assert a != b
assert a != c
assert a != 'not a Parameters object'

0 comments on commit 78648cf

Please sign in to comment.