Skip to content

Commit 92c6d67

Browse files
authored
Updates backgrounds and resolutions in line with the MATLAB (RascalSoftware#100)
* refactored backgrounds and resolutions to use source parameter * added model renaming for data and function backgrounds/resolutions * added validators for value warnings and unimplemented behaviour * added data and function background examples and example test * updated check_indices to be nested * data backgrounds add to contrast data * added source/value wiping for type change * created shared parent class for backgrounds and resolutions * review fixes to docstrings and data backgrounds * reordered check_indices list to match packParams * added backgrounds to outputs * updated tests * review fixes to docstrings * ruff format * added warning for fields clearing
1 parent 973ff1d commit 92c6d67

26 files changed

+1918
-460
lines changed

RATapi/examples/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from RATapi.examples.absorption.absorption import absorption
2-
from RATapi.examples.convert_rascal_project import convert_rascal
2+
from RATapi.examples.convert_rascal_project.convert_rascal import convert_rascal
33
from RATapi.examples.domains.domains_custom_layers import domains_custom_layers
44
from RATapi.examples.domains.domains_custom_XY import domains_custom_XY
55
from RATapi.examples.domains.domains_standard_layers import domains_standard_layers
66
from RATapi.examples.non_polarised.DSPC_custom_layers import DSPC_custom_layers
77
from RATapi.examples.non_polarised.DSPC_custom_XY import DSPC_custom_XY
8+
from RATapi.examples.non_polarised.DSPC_data_background import DSPC_data_background
9+
from RATapi.examples.non_polarised.DSPC_function_background import DSPC_function_background
810
from RATapi.examples.non_polarised.DSPC_standard_layers import DSPC_standard_layers
911

1012
__all__ = [
@@ -15,5 +17,7 @@
1517
"DSPC_custom_layers",
1618
"DSPC_custom_XY",
1719
"DSPC_standard_layers",
20+
"DSPC_data_background",
21+
"DSPC_function_background",
1822
"convert_rascal",
1923
]

RATapi/examples/absorption/absorption.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@
140140
"problem.background_parameters.append(name=\"Background parameter 3\", min=1.0e-06, value=9.01e-06, max=9.0e-05, fit=True)\n",
141141
"problem.background_parameters.append(name=\"Background parameter 4\", min=1.0e-06, value=5.61e-06, max=9.0e-05, fit=True)\n",
142142
"\n",
143-
"problem.backgrounds.append(name=\"Background 1\", type=\"constant\", value_1=\"Background parameter 1\")\n",
144-
"problem.backgrounds.append(name=\"Background 2\", type=\"constant\", value_1=\"Background parameter 2\")\n",
145-
"problem.backgrounds.append(name=\"Background 3\", type=\"constant\", value_1=\"Background parameter 3\")\n",
146-
"problem.backgrounds.append(name=\"Background 4\", type=\"constant\", value_1=\"Background parameter 4\")\n",
143+
"problem.backgrounds.append(name=\"Background 1\", type=\"constant\", source=\"Background parameter 1\")\n",
144+
"problem.backgrounds.append(name=\"Background 2\", type=\"constant\", source=\"Background parameter 2\")\n",
145+
"problem.backgrounds.append(name=\"Background 3\", type=\"constant\", source=\"Background parameter 3\")\n",
146+
"problem.backgrounds.append(name=\"Background 4\", type=\"constant\", source=\"Background parameter 4\")\n",
147147
"\n",
148148
"# Make the resolution fittable\n",
149149
"problem.resolution_parameters.set_fields(0, fit=True)\n"

RATapi/examples/absorption/absorption.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ def absorption():
6868
name="Background parameter 4", min=1.0e-06, value=5.61e-06, max=9.0e-05, fit=True
6969
)
7070

71-
problem.backgrounds.append(name="Background 1", type="constant", value_1="Background parameter 1")
72-
problem.backgrounds.append(name="Background 2", type="constant", value_1="Background parameter 2")
73-
problem.backgrounds.append(name="Background 3", type="constant", value_1="Background parameter 3")
74-
problem.backgrounds.append(name="Background 4", type="constant", value_1="Background parameter 4")
71+
problem.backgrounds.append(name="Background 1", type="constant", source="Background parameter 1")
72+
problem.backgrounds.append(name="Background 2", type="constant", source="Background parameter 2")
73+
problem.backgrounds.append(name="Background 3", type="constant", source="Background parameter 3")
74+
problem.backgrounds.append(name="Background 4", type="constant", source="Background parameter 4")
7575

7676
# Make the resolution fittable
7777
problem.resolution_parameters.set_fields(0, fit=True)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
0.011403 1.90034798968076e-06 -9.65035874608547e-07
2+
0.011973 1.81361996101478e-06 -4.67852140773275e-09
3+
0.012572 1.5763144199176e-06 -1.36151693657437e-06
4+
0.013201 2.66861902156408e-06 5.28737972088124e-07
5+
0.013861 1.19184137102607e-06 6.5429177234931e-07
6+
0.014554 1.75409120253422e-06 -4.50039804064594e-07
7+
0.015281 1.51534921649628e-06 3.54060605152339e-07
8+
0.016045 1.76294603973655e-06 2.30273872099416e-07
9+
0.016848 1.66691808740296e-06 1.02729272466451e-06
10+
0.01769 2.2391873415575e-06 2.02710446930881e-07
11+
0.018575 1.47947093349392e-06 9.31566506641381e-07
12+
0.019503 1.58967045467121e-06 6.58308695637623e-09
13+
0.020479 2.05056480300655e-06 -4.18637528083399e-07
14+
0.021502 2.54199126843229e-06 6.96150360898885e-08
15+
0.022578 1.07273638130851e-06 -5.94598550176916e-08
16+
0.023706 2.89987639289405e-06 8.05335897612554e-07
17+
0.024892 1.56081284721073e-06 5.50847432744533e-08
18+
0.026136 2.32386636321661e-06 -5.72991095509919e-07
19+
0.027443 2.52478251612625e-06 -2.38750704688337e-08
20+
0.028815 2.66154668842285e-06 1.05087573637142e-06
21+
0.030256 1.74132051718101e-06 -2.3192582338868e-07
22+
0.031769 2.01215747485553e-06 -4.26893410009117e-07
23+
0.033357 1.91881656322323e-06 8.87192534478923e-07
24+
0.035025 1.69716945696631e-06 1.80981995646851e-07
25+
0.036777 2.13585488200451e-06 -1.90164659296111e-07
26+
0.038615 2.17932170608953e-06 -4.91062265460096e-07
27+
0.040546 1.82384243860966e-06 -1.08387392818395e-06
28+
0.042573 2.06617996409986e-06 2.22697399577916e-07
29+
0.044702 3.33679088859971e-06 -1.53613977488785e-07
30+
0.046937 1.99621696227773e-06 3.55134601922439e-07
31+
0.049284 2.3551514683307e-06 -1.06523727035749e-06
32+
0.051748 1.76873031859355e-06 1.15746760150783e-06
33+
0.054336 1.73606104969994e-06 4.89763150040874e-07
34+
0.057052 1.82710646654775e-06 -1.15330099931726e-06
35+
0.059905 2.28227888686718e-06 9.45647703159621e-07
36+
0.0629 1.59923042799896e-06 -3.70062237263438e-07
37+
0.066045 1.07352660741589e-06 3.41777294345909e-07
38+
0.069348 2.02660800872659e-06 2.75569910736786e-07
39+
0.072815 1.78179239147256e-06 -6.0256088120987e-07
40+
0.076456 2.14000373613308e-06 -2.18911980741668e-06
41+
0.080279 2.04230294359047e-06 5.284442372682e-07
42+
0.084292 2.36455952978407e-06 -1.73629847921614e-07
43+
0.088507 2.45037654782291e-06 -3.78287083788833e-07
44+
0.092932 1.33718085273407e-06 4.35130166728242e-07
45+
0.097579 1.23771058575749e-06 -4.51744576618967e-07
46+
0.10246 2.25121666653143e-06 6.36952833032752e-07
47+
0.10758 2.15319571282475e-06 2.20717968415214e-07
48+
0.11296 1.53041976734067e-06 -6.93055107868105e-07
49+
0.11861 2.61870106321507e-06 7.69463958198665e-07
50+
0.12454 2.01650595727752e-06 4.79607176188218e-07
51+
0.13077 2.06178415911062e-06 1.10173268381594e-06
52+
0.1373 2.13696968977538e-06 -6.14098124528528e-07
53+
0.14417 2.3770829041412e-06 -6.16219383494697e-07
54+
0.15138 2.7622487528669e-06 3.50660742020884e-07
55+
0.15895 1.86901211887215e-06 6.33626529015099e-07
56+
0.16689 1.13465824611353e-06 7.62493241842828e-07
57+
0.17524 2.50673214999504e-06 1.05207422581854e-07
58+
0.184 1.53613195077685e-06 -8.87137577093779e-08
59+
0.1932 2.62184014311179e-06 6.22256875962273e-07
60+
0.20286 1.70525565120706e-06 1.67162600924891e-06
61+
0.213 2.74574086739327e-06 8.07667338780613e-07
62+
0.22365 1.59701095264287e-06 1.67629565660922e-07
63+
0.23484 1.4437004736234e-06 -3.59611249006791e-07
64+
0.24658 2.47846978404969e-06 4.99800504594724e-07
65+
0.25891 1.31847420553136e-06 -2.87283586089481e-07
66+
0.27185 2.34029248136207e-06 2.90756508518823e-07
67+
0.28544 2.21891181128286e-06 7.22598553179947e-07
68+
0.29972 1.92836622666398e-06 8.39418345516717e-07
69+
0.3147 1.82923374769972e-06 5.70510331434857e-07
70+
0.33044 3.02890531703209e-06 1.20234742176368e-06
71+
0.34696 1.8127324822871e-06 1.58096394623758e-06
72+
0.36431 1.90489840127358e-06 -1.41813181395574e-06
73+
0.38252 1.53063379469415e-06 -1.32294734328625e-06
74+
0.40165 1.59326881780842e-06 -6.38112989285387e-07
75+
0.42173 1.7081906242357e-06 -1.49834166690205e-06
76+
0.44282 2.85476268526193e-06 -1.85680046178151e-07
77+
0.46496 1.80479009111448e-06 -1.69120607911057e-07
78+
0.48821 1.6549673183601e-06 3.00340803829798e-07
79+
0.51262 1.77588964903545e-06 3.28929520936145e-07
80+
0.53825 2.35718817504981e-06 -4.48934854489947e-07
81+
0.56516 1.34213437585845e-06 -5.50651590195596e-07
82+
0.59342 2.31356104763158e-06 7.347220470815e-07

RATapi/examples/languages/setup_problem.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ def make_example_problem():
8282
)
8383

8484
# And add the two new constant backgrounds
85-
problem.backgrounds.append(name="Background SMW", type="constant", value_1="Background parameter SMW")
86-
problem.backgrounds.append(name="Background H2O", type="constant", value_1="Background parameter H2O")
85+
problem.backgrounds.append(name="Background SMW", type="constant", source="Background parameter SMW")
86+
problem.backgrounds.append(name="Background H2O", type="constant", source="Background parameter H2O")
8787

8888
# And edit the other one
89-
problem.backgrounds.set_fields(0, name="Background D2O", value_1="Background parameter D2O")
89+
problem.backgrounds.set_fields(0, name="Background D2O", source="Background parameter D2O")
9090

9191
# Finally modify some of the other parameters to be more suitable values for a solid / liquid experiment
9292
problem.scalefactors.set_fields(0, value=1.0, min=0.5, max=2.0, fit=True)

RATapi/examples/non_polarised/DSPC_custom_XY.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ def DSPC_custom_XY():
9090
problem.background_parameters.append(name="Background parameter H2O", min=0.0, value=1.0e-7, max=1.0e-5, fit=True)
9191

9292
# And add the two new constant backgrounds
93-
problem.backgrounds.append(name="Background SMW", type="constant", value_1="Background parameter SMW")
94-
problem.backgrounds.append(name="Background H2O", type="constant", value_1="Background parameter H2O")
93+
problem.backgrounds.append(name="Background SMW", type="constant", source="Background parameter SMW")
94+
problem.backgrounds.append(name="Background H2O", type="constant", source="Background parameter H2O")
9595

9696
# And edit the other one
97-
problem.backgrounds.set_fields(0, name="Background D2O", value_1="Background parameter D2O")
97+
problem.backgrounds.set_fields(0, name="Background D2O", source="Background parameter D2O")
9898

9999
# Finally modify some of the other parameters to be more suitable values for a solid / liquid experiment
100100
problem.scalefactors.set_fields(0, value=1.0, min=0.5, max=2.0, fit=True)

RATapi/examples/non_polarised/DSPC_custom_layers.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,11 +534,11 @@
534534
"problem.background_parameters.append(name=\"Background parameter H2O\", min=1.0e-10, value=1.0e-7, max=1.0e-5, fit=True)\n",
535535
"\n",
536536
"# And add the two new constant backgrounds\n",
537-
"problem.backgrounds.append(name=\"Background SMW\", type=\"constant\", value_1=\"Background parameter SMW\")\n",
538-
"problem.backgrounds.append(name=\"Background H2O\", type=\"constant\", value_1=\"Background parameter H2O\")\n",
537+
"problem.backgrounds.append(name=\"Background SMW\", type=\"constant\", source=\"Background parameter SMW\")\n",
538+
"problem.backgrounds.append(name=\"Background H2O\", type=\"constant\", source=\"Background parameter H2O\")\n",
539539
"\n",
540540
"# And edit the other one\n",
541-
"problem.backgrounds.set_fields(0, name=\"Background D2O\", value_1=\"Background parameter D2O\")\n",
541+
"problem.backgrounds.set_fields(0, name=\"Background D2O\", source=\"Background parameter D2O\")\n",
542542
"\n",
543543
"# Finally modify some of the other parameters to be more suitable values for a solid / liquid experiment\n",
544544
"problem.scalefactors.set_fields(0, value=1.0, min=0.5, max=2.0, fit=True)"

RATapi/examples/non_polarised/DSPC_custom_layers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ def DSPC_custom_layers():
7474
)
7575

7676
# And add the two new constant backgrounds
77-
problem.backgrounds.append(name="Background SMW", type="constant", value_1="Background parameter SMW")
78-
problem.backgrounds.append(name="Background H2O", type="constant", value_1="Background parameter H2O")
77+
problem.backgrounds.append(name="Background SMW", type="constant", source="Background parameter SMW")
78+
problem.backgrounds.append(name="Background H2O", type="constant", source="Background parameter H2O")
7979

8080
# And edit the other one
81-
problem.backgrounds.set_fields(0, name="Background D2O", value_1="Background parameter D2O")
81+
problem.backgrounds.set_fields(0, name="Background D2O", source="Background parameter D2O")
8282

8383
# Finally modify some of the other parameters to be more suitable values for a solid / liquid experiment
8484
problem.scalefactors.set_fields(0, value=1.0, min=0.5, max=2.0, fit=True)

RATapi/examples/non_polarised/DSPC_custom_xy.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@
175175
"problem.background_parameters.append(name=\"Background parameter H2O\", min=0.0, value=1.0e-7, max=1.0e-5, fit=True)\n",
176176
"\n",
177177
"# And add the two new constant backgrounds\n",
178-
"problem.backgrounds.append(name=\"Background SMW\", type=\"constant\", value_1=\"Background parameter SMW\")\n",
179-
"problem.backgrounds.append(name=\"Background H2O\", type=\"constant\", value_1=\"Background parameter H2O\")\n",
178+
"problem.backgrounds.append(name=\"Background SMW\", type=\"constant\", source=\"Background parameter SMW\")\n",
179+
"problem.backgrounds.append(name=\"Background H2O\", type=\"constant\", source=\"Background parameter H2O\")\n",
180180
"\n",
181181
"# And edit the other one\n",
182-
"problem.backgrounds.set_fields(0, name=\"Background D2O\", value_1=\"Background parameter D2O\")\n",
182+
"problem.backgrounds.set_fields(0, name=\"Background D2O\", source=\"Background parameter D2O\")\n",
183183
"\n",
184184
"# Finally modify some of the other parameters to be more suitable values for a solid / liquid experiment\n",
185185
"problem.scalefactors.set_fields(0, value=1.0, min=0.5, max=2.0, fit=True)\n",

0 commit comments

Comments
 (0)