Skip to content

Commit

Permalink
Sort out validate_parameters() confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinmacaulay committed Nov 29, 2024
1 parent d8ef242 commit 3779ecf
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/echosms/dcmmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def validate_parameters(self, params):
See [here][echosms.ScatterModelBase.validate_parameters] for calling details.
"""

p = as_dict(params)
super()._present_and_in(p, ['boundary_type'], self.boundary_types)
super()._present_and_positive(p, ['medium_rho', 'medium_c', 'a', 'b', 'f'])
Expand Down
7 changes: 4 additions & 3 deletions src/echosms/dwbamodel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""The distorted-wave Born approximation model."""

from .scattermodelbase import ScatterModelBase
from .utils import wavenumber
from .utils import wavenumber, as_dict
from math import log10, cos, acos, pi, isclose
from cmath import exp
from scipy.spatial.transform import Rotation as R
Expand Down Expand Up @@ -30,13 +30,14 @@ def __init__(self):
self.h_range = [0.95, 1.05]
self.no_expand_parameters = ['a', 'rv_pos', 'rv_tan']

def validate_parameters(self, p):
def validate_parameters(self, params):
"""Validate the model parameters.
See [here][echosms.ScatterModelBase.validate_parameters] for calling details.
"""
return
p = as_dict(params)
super()._present_and_positive(p, ['medium_rho', 'medium_c', 'target_rho', 'target_c', 'f'])

g = p['target_rho'] / p['medium_rho']
h = p['target_c'] / p['medium_c']

Expand Down
3 changes: 1 addition & 2 deletions src/echosms/esmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ def __init__(self):

def validate_parameters(self, params):
"""Validate the model parameters.
See [here][echosms.ScatterModelBase.validate_parameters] for calling details.
"""

p = as_dict(params)
super()._present_and_in(p, ['boundary_type'], self.boundary_types)
super()._present_and_positive(p, ['medium_rho', 'medium_c', 'a', 'f',
Expand Down
1 change: 0 additions & 1 deletion src/echosms/kamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def validate_parameters(self, params):
See [here][echosms.ScatterModelBase.validate_parameters] for calling details.
"""

p = as_dict(params)
super()._present_and_in(p, ['boundary_type'], self.boundary_types)
super()._present_and_positive(p, ['medium_c', 'f'])
Expand Down
2 changes: 1 addition & 1 deletion src/echosms/krmmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class KRMModel(ScatterModelBase):
----
The KRM model is not yet functional.
"""

def __init__(self):
super().__init__()
self.long_name = 'Kirchhoff ray mode'
Expand All @@ -29,7 +30,6 @@ def validate_parameters(self, params):
See [here][echosms.ScatterModelBase.validate_parameters] for calling details.
"""

p = as_dict(params)
super()._present_and_in(p, ['boundary_type'], self.boundary_types)
super()._present_and_positive(p, ['medium_c', 'f'])
Expand Down
1 change: 0 additions & 1 deletion src/echosms/psmsmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def validate_parameters(self, params):
See [here][echosms.ScatterModelBase.validate_parameters] for calling details.
"""

p = as_dict(params)
super()._present_and_in(p, ['boundary_type'], self.boundary_types)
super()._present_and_positive(p, ['medium_c', 'medium_rho', 'a', 'b', 'f'])
Expand Down
1 change: 0 additions & 1 deletion src/echosms/ptdwbamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def validate_parameters(self, params):
See [here][echosms.ScatterModelBase.validate_parameters] for calling details.
"""

p = as_dict(params)

def calculate_ts_single(self, volume, theta, phi, f, voxel_size, rho, c,
Expand Down
6 changes: 3 additions & 3 deletions src/echosms/scattermodelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ def __ts_helper(self, *args):
return self.calculate_ts_single(**p, validate_parameters=False)

@abc.abstractmethod
def validate_parameters(self, p):
def validate_parameters(self, p: dict | pd.DataFrame | xr.DataArray):
"""Validate the model parameters.
Parameters
----------
p : dict
Dict containing the model parameters.
p :
The model parameters.
Raises
------
Expand Down
1 change: 0 additions & 1 deletion src/echosms/sdwbamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def validate_parameters(self, params):
See [here][echosms.ScatterModelBase.validate_parameters] for calling details.
"""

p = as_dict(params)

def calculate_ts_single(self, theta, phi, f, target_rho, target_c, validate_parameters=True):
Expand Down
3 changes: 2 additions & 1 deletion src/echosms/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ def as_dict(params: dict | pd.DataFrame | xr.DataArray) -> dict:
if isinstance(params, xr.DataArray):
return dict(zip(params.coords, params.indexes.values())) | p
elif isinstance(params, pd.DataFrame):
return params.to_dict(orient='list') | p
# params.attrs = {} # otherwise to_dict() exposes a bug in pandas?
return params.to_dict(orient='series') | p

raise TypeError('Only dict, DataFrame, or DataArray are accepted.')

Expand Down

0 comments on commit 3779ecf

Please sign in to comment.