From 30e3fe8e7f254d0391cd9786eba05506c7948704 Mon Sep 17 00:00:00 2001 From: Stephen Nneji Date: Thu, 1 Oct 2026 16:01:04 +0100 Subject: [PATCH 1/3] Add doc for function background --- source/_static/custom.css | 4 -- source/advanced/backgroundFunctions.rst | 60 +++++++++++++++++++++++++ source/advanced/index.rst | 1 + 3 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 source/advanced/backgroundFunctions.rst diff --git a/source/_static/custom.css b/source/_static/custom.css index 4fbc003a..5c623438 100644 --- a/source/_static/custom.css +++ b/source/_static/custom.css @@ -47,10 +47,6 @@ html[data-theme=dark] { margin: 0; } -#rat{ - margin-bottom: 1.5em; -} - .sd-card-header{ font-weight: 550; } \ No newline at end of file diff --git a/source/advanced/backgroundFunctions.rst b/source/advanced/backgroundFunctions.rst new file mode 100644 index 00000000..01a10f89 --- /dev/null +++ b/source/advanced/backgroundFunctions.rst @@ -0,0 +1,60 @@ +==================== +Function Backgrounds +==================== + +RAT supports function backgrounds which use a custom function to describe the background for the experiment. + + +The signature for background functions is shown in the code snippet below. The first argument `xdata` is a vector containing the q points over the simulation range, +which should incorporate the q values of the supplied data and the second argument `params` is a vector containing the background parameters associated with the background +up to 5 can be related to a specific functoin background. The function should return an array with the background value for each of the input simulation points. + +.. tab-set-code:: + .. code-block:: MATLAB + + function background = backgroundFunction(xdata, params) + + background = zeros(numel(xdata), 1); + + end + + .. code-block:: Python + + import numpy as np + + + def background_function(xdata, params): + + background = np.zeros(len(xdata)) + return background + +To define a function background, add the custom function, associated background parameters, then create the background as shown below + +.. tab-set-code:: + .. code-block:: MATLAB + + % Add the function background + % Add the function to custom files, and its parameters to background + % parameters + problem.addCustomFile('Back Fun','backgroundFunction.m','matlab',pwd); + + problem.addBackgroundParam('Fn Ao',5e-7, 8e-6, 5e-5); + problem.addBackgroundParam('Fn k',40, 70, 90); + problem.addBackgroundParam('Fn Const',1e-7, 8e-6, 1e-5); + + % Add the Background + problem.addBackground('Func Background','function','Back Fun','Fn Ao','Fn k','Fn Const'); + + .. code-block:: Python + + problem.custom_files.append(name="Back Fun", filename="background_function.py", language="python") + + problem.background_parameters.append(name="Fn Ao", min=5e-7, value=8e-6, max=5e-5) + problem.background_parameters.append(name="Fn k", min=40, value=70, max=90) + problem.background_parameters.append(name="Fn Const", min=1e-7, value=8e-6, max=1e-5) + + problem.backgrounds.append(name="Func Background", type="function", source="Back Func", value_1="Fn Ao", value_2="Fn k", value_3="Fn Const") + + +An example of using Python and Matlab custom models can be found in examples folder. Look at DSPCScriptWithFunctionBackground.m and +DSPC_function_background.py in Matlab and Python respectively. diff --git a/source/advanced/index.rst b/source/advanced/index.rst index 3f0f3c73..04c280ae 100644 --- a/source/advanced/index.rst +++ b/source/advanced/index.rst @@ -12,6 +12,7 @@ In this section we discuss some advanced features of the toolbox:- resampling parallelisation customLanguages + backgroundFunctions events From 92c172b5c7061e89c3cc38dcd6d53505bcdb901d Mon Sep 17 00:00:00 2001 From: Stephen Nneji Date: Fri, 2 Oct 2026 12:40:13 +0100 Subject: [PATCH 2/3] change matlab version --- .github/workflows/build_docs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml index 9b36cdba..326bed53 100644 --- a/.github/workflows/build_docs.yml +++ b/.github/workflows/build_docs.yml @@ -23,7 +23,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: '3.10' - name: Build docs run: | # create an x11 display because otherwise MATLAB refuses to export live scripts... @@ -48,7 +48,7 @@ jobs: wget https://github.com/jgm/pandoc/releases/download/3.6.2/pandoc-3.6.2-1-amd64.deb sudo apt install -y ./pandoc-3.6.2-1-amd64.deb - pip install matlabengine==24.1.* + pip install matlabengine==9.14.* pip install -r requirements.txt python build_docs.py - name: Checkout gh-pages From d0e715792137e72e05e1491f70888620e61db642 Mon Sep 17 00:00:00 2001 From: Stephen Nneji Date: Mon, 12 Oct 2026 10:07:07 +0100 Subject: [PATCH 3/3] Address review comments --- source/advanced/backgroundFunctions.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/advanced/backgroundFunctions.rst b/source/advanced/backgroundFunctions.rst index 01a10f89..b0367c6e 100644 --- a/source/advanced/backgroundFunctions.rst +++ b/source/advanced/backgroundFunctions.rst @@ -2,12 +2,12 @@ Function Backgrounds ==================== -RAT supports function backgrounds which use a custom function to describe the background for the experiment. +RAT supports function backgrounds, which use a custom function to describe the background for the experiment. The signature for background functions is shown in the code snippet below. The first argument `xdata` is a vector containing the q points over the simulation range, -which should incorporate the q values of the supplied data and the second argument `params` is a vector containing the background parameters associated with the background -up to 5 can be related to a specific functoin background. The function should return an array with the background value for each of the input simulation points. +which should incorporate the q values of the supplied data and the second argument `params` is a vector containing the background parameters associated with the background, +up to 5 can be related to a specific function background. The function should return an array with the background value for each of the input simulation points. .. tab-set-code:: .. code-block:: MATLAB