From 5ae4a972fbfb4b1fb5b56d6280e7290fe15897c9 Mon Sep 17 00:00:00 2001 From: alexhroom Date: Thu, 12 Dec 2024 13:30:43 +0000 Subject: [PATCH] review fixes to docstrings and data backgrounds --- RATapi/inputs.py | 2 +- RATapi/models.py | 24 ++++++++++++------------ tests/test_inputs.py | 11 ++++++++++- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/RATapi/inputs.py b/RATapi/inputs.py index 795df36..87fbf60 100644 --- a/RATapi/inputs.py +++ b/RATapi/inputs.py @@ -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: diff --git a/RATapi/models.py b/RATapi/models.py index dfb1c49..8fa028d 100644 --- a/RATapi/models.py +++ b/RATapi/models.py @@ -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`. @@ -132,6 +132,7 @@ 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 @@ -139,8 +140,8 @@ class Contrast(RATModel): 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. """ @@ -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. """ @@ -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] @@ -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. """ diff --git a/tests/test_inputs.py b/tests/test_inputs.py index 1328089..b725ff8 100644 --- a/tests/test_inputs.py +++ b/tests/test_inputs.py @@ -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():