Skip to content

Commit 29ba45b

Browse files
committed
updated example data and better name resolution
1 parent 8bc930c commit 29ba45b

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

RATapi/examples/orso_integration/orso_integration.ipynb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
"source": [
9999
"RAT can also load both data and model information from an .ort file. This is done through the `ORSOProject` object, which takes a file path and can also optionally account for absorption.\n",
100100
"\n",
101-
"The example data file we use here [is example data by Artur Glavic, taken on the Amor reflectometer at PSI.](https://github.com/reflectivity/orsopy/blob/main/examples/prist5_10K_m_025.Rqz.ort)"
101+
"The example data file we use here is example data for an unknown film on deposited on silicon."
102102
]
103103
},
104104
{
@@ -110,7 +110,7 @@
110110
"import pathlib\n",
111111
"data_path = pathlib.Path(\"../data\")\n",
112112
"\n",
113-
"orso_data = RATapi.utils.orso.ORSOProject(data_path / \"prist5_10K_m_025.Rqz.ort\")\n",
113+
"orso_data = RATapi.utils.orso.ORSOProject(data_path / \"c_PLP0011859_q.ort\")\n",
114114
"print(orso_data)"
115115
]
116116
},
@@ -136,11 +136,12 @@
136136
"\n",
137137
"project = RATapi.Project(\n",
138138
" name = \"Example Project\",\n",
139+
" geometry = \"substrate/liquid\",\n",
139140
" parameters = sample.parameters,\n",
140141
" bulk_in = [sample.bulk_in],\n",
141142
" bulk_out = [sample.bulk_out],\n",
142-
" scalefactors = [Parameter(name=\"Scalefactor\", min=0, value=1, max=1.5, fit=True)],\n",
143-
" background_parameters = [Parameter(name=\"Background Parameter\", min=0, value=0.025, max=1, fit=True)],\n",
143+
" scalefactors = [Parameter(name=\"Scalefactor\", min=0, value=0.34, max=1.5)],\n",
144+
" background_parameters = [Parameter(name=\"Background Parameter\", min=0, value=2e-6, max=1)],\n",
144145
" backgrounds = [Background(name=\"Background\", type=\"constant\", source=\"Background Parameter\")],\n",
145146
" resolutions = [Resolution(name=\"Data Resolution\", type=\"data\")],\n",
146147
" data = [dataset],\n",

RATapi/utils/orso.py

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,12 @@ def orso_model_to_rat(
148148

149149
parameters = ClassList()
150150
layers = ClassList()
151+
contrast_model = []
151152

152153
for orso_layer in stack[1:-1]:
153-
layer_params, layer = orso_layer_to_rat_layer(orso_layer, absorption)
154+
name = get_material_name(orso_layer.material, model)
155+
contrast_model.append(name)
156+
layer_params, layer = orso_layer_to_rat_layer(orso_layer, name, absorption)
154157
parameters.union(layer_params)
155158
layers.union(layer)
156159

@@ -159,19 +162,21 @@ def orso_model_to_rat(
159162
bulk_out=bulk_out,
160163
parameters=parameters,
161164
layers=layers,
162-
model=[layer.material.formula for layer in stack[1:-1]],
165+
model=contrast_model,
163166
)
164167

165168

166169
def orso_layer_to_rat_layer(
167-
layer: orsopy.fileio.model_language.Layer, absorption: bool = False
170+
layer: orsopy.fileio.model_language.Layer, name: str, absorption: bool = False
168171
) -> tuple[ClassList[Parameter], Layer]:
169172
"""Convert an ``orsopy`` layer to a RAT layer.
170173
171174
Parameters
172175
----------
173176
layer : orsopy.fileio.model_language.Layer
174177
An ``orsopy`` Layer.
178+
name : str
179+
The name of the material in the layer.
175180
absorption : bool, default True
176181
Whether absorption should be accounted for in the layer.
177182
@@ -181,7 +186,6 @@ def orso_layer_to_rat_layer(
181186
The parameters required for the RAT layer and the layer itself.
182187
183188
"""
184-
name = layer.material.formula
185189
thickness = layer.thickness.as_unit("angstrom")
186190
roughness = layer.roughness.as_unit("angstrom")
187191
sld = layer.material.get_sld()
@@ -196,18 +200,49 @@ def orso_layer_to_rat_layer(
196200
if absorption:
197201
params.append(Parameter(name=f"{name} SLD imaginary", min=sld.imag, value=sld.imag, max=sld.imag, fit=False))
198202
layer = AbsorptionLayer(
199-
name=f"{name}",
203+
name=name,
200204
thickness=f"{name} Thickness",
201205
roughness=f"{name} Roughness",
202206
SLD_real=f"{name} SLD",
203207
SLD_imaginary=f"{name} SLD imaginary",
204208
)
205209
else:
206210
layer = Layer(
207-
name=f"{name}",
211+
name=name,
208212
thickness=f"{name} Thickness",
209213
roughness=f"{name} Roughness",
210214
SLD=f"{name} SLD",
211215
)
212216

213217
return params, layer
218+
219+
220+
def get_material_name(
221+
material: orsopy.fileio.model_language.Material, model: orsopy.fileio.model_language.SampleModel
222+
) -> str:
223+
"""Get the name of a material in the model.
224+
225+
Layers with custom property definitions may not have a formula, so this adjusts the name for that.
226+
227+
Parameters
228+
----------
229+
material : Material
230+
The material to get the name of.
231+
model : SampleModel
232+
The sample model from which the material came.
233+
234+
Returns
235+
-------
236+
str
237+
The name of the material.
238+
239+
"""
240+
if material.formula is not None:
241+
return material.formula
242+
else:
243+
matching_materials = [k for k, v in model.materials.items() if v == material]
244+
if matching_materials:
245+
return matching_materials[0]
246+
else:
247+
# orsopy should catch that this is the case before we get here, but just in case...
248+
raise ValueError("ORSO model contains layers with undefined materials!")

0 commit comments

Comments
 (0)