Skip to content

Commit

Permalink
review fixes to docstrings and data backgrounds
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhroom committed Dec 12, 2024
1 parent b336f14 commit 5ae4a97
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion RATapi/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def append_data_background(data: np.array, background: np.array) -> np.array:
if not np.allclose(data[:, 0], background[:, 0]):
raise ValueError("The q-values of the data and background must be equal.")

return np.hstack((data, background[:, 1:]))
return np.hstack((data, np.zeros((data.shape[0], 4 - data.shape[1])), background[:, 1:]))


def make_controls(input_controls: RATapi.Controls) -> Control:
Expand Down
24 changes: 12 additions & 12 deletions RATapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Background(Signal):
type : TypeOptions
The type of background (constant, function or data)
source : str
The source data for the background;
The source of the background;
- if type is 'constant', this should be the name of a background parameter.
- if type is 'data', this should be the name of a dataset defined in `Project.data`.
- if type is 'function', this should be the name of a custom function defined in `Project.custom_files`.
Expand Down Expand Up @@ -132,15 +132,16 @@ class Contrast(RATModel):
The name of the bulk-out parameter which defines the SLD of the interface between the last
layer and the environment.
scalefactor : str
The name of the scalefactor which defines how much the data for this contrast should be scaled.
resolution : str
The name of the instrument resolution for this contrast.
resample : bool
Whether adaptive resampling should be used for interface microslicing.
model : list[str]
If this is a standard layers model, this should be a list of layer names
that make up the slab model for this contrast.
For custom models, this should be a list of custom file names of the custom
model functions.
For custom models, this should be a list containing just the custom file name for the
custom model function.
"""

Expand Down Expand Up @@ -213,11 +214,13 @@ class ContrastWithRatio(RATModel):
resample : bool
Whether adaptive resampling should be used for interface microslicing.
domain_ratio : str
The name of the domain ratio parameter describing how the first domain should be weighted
relative to the second.
model : list[str]
If this is a standard layers model, this should be a list of layer names
that make up the slab model for this contrast.
For custom models, this should be a list of custom file names of the custom
model functions.
If this is a standard layers model, this should be a list of the names of the two domain contrasts
which make up the domain model for this contrast.
For custom models, this should be a list containing just the custom file name for the
custom model function.
"""

Expand Down Expand Up @@ -302,7 +305,7 @@ class Data(RATModel, arbitrary_types_allowed=True):
name : str
The name of this dataset.
data : np.ndarray[np.float64]
The (x,y,z) data for this dataset, given as a Numpy array of three columns.
The (x, y, error) data for this dataset, given as a Numpy array of three columns.
data_range : list[float]
simulation_range : list[float]
Expand Down Expand Up @@ -405,10 +408,7 @@ class DomainContrast(RATModel):
name : str
The name of this domain contrast.
model : list[str]
If this is a standard layers model, this should be a list of layer names
that make up the slab model for this contrast.
For custom models, this should be a list of custom file names of the custom
model functions.
A list of layer names that make up the slab model for this contrast.
"""

Expand Down
11 changes: 10 additions & 1 deletion tests/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,16 @@ def test_append_data_background():
background = np.array([[1, 10, 11], [4, 12, 13], [7, 14, 15]])

result = RATapi.inputs.append_data_background(data, background)
np.testing.assert_allclose(result, np.array([[1, 2, 3, 10, 11], [4, 5, 6, 12, 13], [7, 8, 9, 14, 15]]))
np.testing.assert_allclose(result, np.array([[1, 2, 3, 0, 10, 11], [4, 5, 6, 0, 12, 13], [7, 8, 9, 0, 14, 15]]))


def test_append_data_background_res():
"""Test that background data is correctly added to contrast data when a resolution is in the data."""
data = np.array([[1, 2, 3, 4], [4, 5, 6, 6], [7, 8, 9, 72]])
background = np.array([[1, 10, 11], [4, 12, 13], [7, 14, 15]])

result = RATapi.inputs.append_data_background(data, background)
np.testing.assert_allclose(result, np.array([[1, 2, 3, 4, 10, 11], [4, 5, 6, 6, 12, 13], [7, 8, 9, 72, 14, 15]]))


def test_append_data_background_error():
Expand Down

0 comments on commit 5ae4a97

Please sign in to comment.