Skip to content

Commit 960a3e7

Browse files
authored
Removes qzshift from user-facing code (#28)
1 parent 6bdce54 commit 960a3e7

File tree

4 files changed

+38
-50
lines changed

4 files changed

+38
-50
lines changed

RAT/inputs.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def make_input(project: RAT.Project, controls: Union[RAT.controls.Calculate, RAT
3939
parameter_field = {'parameters': 'param',
4040
'bulk_in': 'bulkIn',
4141
'bulk_out': 'bulkOut',
42-
'qz_shifts': 'qzshift',
4342
'scalefactors': 'scalefactor',
4443
'domain_ratios': 'domainRatio',
4544
'background_parameters': 'backgroundParam',
@@ -48,7 +47,6 @@ def make_input(project: RAT.Project, controls: Union[RAT.controls.Calculate, RAT
4847
checks_field = {'parameters': 'fitParam',
4948
'bulk_in': 'fitBulkIn',
5049
'bulk_out': 'fitBulkOut',
51-
'qz_shifts': 'fitQzshift',
5250
'scalefactors': 'fitScalefactor',
5351
'domain_ratios': 'fitDomainRatio',
5452
'background_parameters': 'fitBackgroundParam',
@@ -71,6 +69,11 @@ def make_input(project: RAT.Project, controls: Union[RAT.controls.Calculate, RAT
7169
setattr(priors, parameter_field[class_list], [[element.name, element.prior_type, element.mu, element.sigma]
7270
for element in getattr(project, class_list)])
7371

72+
# Use dummy values for qzshifts
73+
checks.fitQzshift = []
74+
limits.qzshift = []
75+
priors.qzshift = []
76+
7477
priors.priorNames = [param.name for class_list in RAT.project.parameter_class_lists
7578
for param in getattr(project, class_list)]
7679
priors.priorValues = [[prior_id[param.prior_type], param.mu, param.sigma]
@@ -115,7 +118,7 @@ def make_problem(project: RAT.Project) -> ProblemDefinition:
115118
problem.params = [param.value for param in project.parameters]
116119
problem.bulkIn = [param.value for param in project.bulk_in]
117120
problem.bulkOut = [param.value for param in project.bulk_out]
118-
problem.qzshifts = [param.value for param in project.qz_shifts]
121+
problem.qzshifts = []
119122
problem.scalefactors = [param.value for param in project.scalefactors]
120123
problem.domainRatio = [param.value for param in project.domain_ratios]
121124
problem.backgroundParams = [param.value for param in project.background_parameters]
@@ -216,7 +219,7 @@ def make_cells(project: RAT.Project) -> Cells:
216219
cells.f7 = [param.name for param in project.parameters]
217220
cells.f8 = [param.name for param in project.background_parameters]
218221
cells.f9 = [param.name for param in project.scalefactors]
219-
cells.f10 = [param.name for param in project.qz_shifts]
222+
cells.f10 = [] # Placeholder for qzshifts
220223
cells.f11 = [param.name for param in project.bulk_in]
221224
cells.f12 = [param.name for param in project.bulk_out]
222225
cells.f13 = [param.name for param in project.resolution_parameters]

RAT/project.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
model_in_classlist = {'parameters': 'Parameter',
1919
'bulk_in': 'Parameter',
2020
'bulk_out': 'Parameter',
21-
'qz_shifts': 'Parameter',
2221
'scalefactors': 'Parameter',
2322
'domain_ratios': 'Parameter',
2423
'background_parameters': 'Parameter',
@@ -73,7 +72,7 @@
7372
}
7473

7574
# Note that the order of these parameters is hard-coded into RAT
76-
parameter_class_lists = ['parameters', 'background_parameters', 'scalefactors', 'qz_shifts', 'bulk_in', 'bulk_out',
75+
parameter_class_lists = ['parameters', 'background_parameters', 'scalefactors', 'bulk_in', 'bulk_out',
7776
'resolution_parameters', 'domain_ratios']
7877
class_lists = [*parameter_class_lists, 'backgrounds', 'resolutions', 'custom_files', 'data', 'layers',
7978
'domain_contrasts', 'contrasts']
@@ -100,9 +99,6 @@ class Project(BaseModel, validate_assignment=True, extra='forbid', arbitrary_typ
10099
fit=False, prior_type=Priors.Uniform, mu=0.0,
101100
sigma=np.inf))
102101

103-
qz_shifts: ClassList = ClassList(RAT.models.Parameter(name='Qz shift 1', min=-1e-4, value=0.0, max=1e-4, fit=False,
104-
prior_type=Priors.Uniform, mu=0.0, sigma=np.inf))
105-
106102
scalefactors: ClassList = ClassList(RAT.models.Parameter(name='Scalefactor 1', min=0.02, value=0.23, max=0.25,
107103
fit=False, prior_type=Priors.Uniform, mu=0.0,
108104
sigma=np.inf))
@@ -137,7 +133,7 @@ class Project(BaseModel, validate_assignment=True, extra='forbid', arbitrary_typ
137133
_contrast_model_field: str
138134
_protected_parameters: dict
139135

140-
@field_validator('parameters', 'bulk_in', 'bulk_out', 'qz_shifts', 'scalefactors', 'background_parameters',
136+
@field_validator('parameters', 'bulk_in', 'bulk_out', 'scalefactors', 'background_parameters',
141137
'backgrounds', 'resolution_parameters', 'resolutions', 'custom_files', 'data', 'layers',
142138
'domain_contrasts', 'contrasts')
143139
@classmethod

tests/test_inputs.py

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ def standard_layers_problem():
7070
problem.params = [3.0, 0.0, 0.0, 0.0]
7171
problem.bulkIn = [0.0]
7272
problem.bulkOut = [6.35e-06]
73-
problem.qzshifts = [0.0]
73+
problem.qzshifts = []
7474
problem.scalefactors = [0.23]
7575
problem.domainRatio = []
7676
problem.backgroundParams = [1e-06]
7777
problem.resolutionParams = [0.03]
7878
problem.contrastBulkIns = [1]
7979
problem.contrastBulkOuts = [1]
80-
problem.contrastQzshifts = [1]
80+
problem.contrastQzshifts = []
8181
problem.contrastScalefactors = [1]
8282
problem.contrastBackgrounds = [1]
8383
problem.contrastBackgroundActions = [1]
@@ -91,10 +91,10 @@ def standard_layers_problem():
9191
problem.numberOfLayers = 1
9292
problem.numberOfDomainContrasts = 0
9393
problem.fitParams = [3.0]
94-
problem.otherParams = [0.0, 0.0, 0.0, 1e-06, 0.23, 0.0, 0.0, 6.35e-06, 0.03]
94+
problem.otherParams = [0.0, 0.0, 0.0, 1e-06, 0.23, 0.0, 6.35e-06, 0.03]
9595
problem.fitLimits = [[1.0, 5.0]]
96-
problem.otherLimits = [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1e-07, 1e-05], [0.02, 0.25], [-0.0001, 0.0001],
97-
[0.0, 0.0], [6.2e-06, 6.35e-06], [0.01, 0.05]]
96+
problem.otherLimits = [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1e-07, 1e-05], [0.02, 0.25], [0.0, 0.0],
97+
[6.2e-06, 6.35e-06], [0.01, 0.05]]
9898

9999
return problem
100100

@@ -110,14 +110,14 @@ def domains_problem():
110110
problem.params = [3.0, 0.0, 0.0, 0.0]
111111
problem.bulkIn = [0.0]
112112
problem.bulkOut = [6.35e-06]
113-
problem.qzshifts = [0.0]
113+
problem.qzshifts = []
114114
problem.scalefactors = [0.23]
115115
problem.domainRatio = [0.5]
116116
problem.backgroundParams = [1e-06]
117117
problem.resolutionParams = [0.03]
118118
problem.contrastBulkIns = [1]
119119
problem.contrastBulkOuts = [1]
120-
problem.contrastQzshifts = [1]
120+
problem.contrastQzshifts = []
121121
problem.contrastScalefactors = [1]
122122
problem.contrastBackgrounds = [1]
123123
problem.contrastBackgroundActions = [1]
@@ -131,10 +131,10 @@ def domains_problem():
131131
problem.numberOfLayers = 1
132132
problem.numberOfDomainContrasts = 2
133133
problem.fitParams = [3.0]
134-
problem.otherParams = [0.0, 0.0, 0.0, 1e-06, 0.23, 0.0, 0.0, 6.35e-06, 0.03, 0.5]
134+
problem.otherParams = [0.0, 0.0, 0.0, 1e-06, 0.23, 0.0, 6.35e-06, 0.03, 0.5]
135135
problem.fitLimits = [[1.0, 5.0]]
136-
problem.otherLimits = [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1e-07, 1e-05], [0.02, 0.25], [-0.0001, 0.0001],
137-
[0.0, 0.0], [6.2e-06, 6.35e-06], [0.01, 0.05], [0.4, 0.6]]
136+
problem.otherLimits = [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1e-07, 1e-05], [0.02, 0.25], [0.0, 0.0],
137+
[6.2e-06, 6.35e-06], [0.01, 0.05], [0.4, 0.6]]
138138

139139
return problem
140140

@@ -150,14 +150,14 @@ def custom_xy_problem():
150150
problem.params = [3.0, 0.0, 0.0, 0.0]
151151
problem.bulkIn = [0.0]
152152
problem.bulkOut = [6.35e-06]
153-
problem.qzshifts = [0.0]
153+
problem.qzshifts = []
154154
problem.scalefactors = [0.23]
155155
problem.domainRatio = []
156156
problem.backgroundParams = [1e-06]
157157
problem.resolutionParams = [0.03]
158158
problem.contrastBulkIns = [1]
159159
problem.contrastBulkOuts = [1]
160-
problem.contrastQzshifts = [1]
160+
problem.contrastQzshifts = []
161161
problem.contrastScalefactors = [1]
162162
problem.contrastBackgrounds = [1]
163163
problem.contrastBackgroundActions = [1]
@@ -171,10 +171,10 @@ def custom_xy_problem():
171171
problem.numberOfLayers = 0
172172
problem.numberOfDomainContrasts = 0
173173
problem.fitParams = [3.0]
174-
problem.otherParams = [0.0, 0.0, 0.0, 1e-06, 0.23, 0.0, 0.0, 6.35e-06, 0.03]
174+
problem.otherParams = [0.0, 0.0, 0.0, 1e-06, 0.23, 0.0, 6.35e-06, 0.03]
175175
problem.fitLimits = [[1.0, 5.0]]
176-
problem.otherLimits = [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1e-07, 1e-05], [0.02, 0.25], [-0.0001, 0.0001],
177-
[0.0, 0.0], [6.2e-06, 6.35e-06], [0.01, 0.05]]
176+
problem.otherLimits = [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1e-07, 1e-05], [0.02, 0.25], [0.0, 0.0],
177+
[6.2e-06, 6.35e-06], [0.01, 0.05]]
178178

179179
return problem
180180

@@ -192,7 +192,7 @@ def standard_layers_cells():
192192
cells.f7 = ['Substrate Roughness', 'Test Thickness', 'Test SLD', 'Test Roughness']
193193
cells.f8 = ['Background Param 1']
194194
cells.f9 = ['Scalefactor 1']
195-
cells.f10 = ['Qz shift 1']
195+
cells.f10 = []
196196
cells.f11 = ['SLD Air']
197197
cells.f12 = ['SLD D2O']
198198
cells.f13 = ['Resolution Param 1']
@@ -220,7 +220,7 @@ def domains_cells():
220220
cells.f7 = ['Substrate Roughness', 'Test Thickness', 'Test SLD', 'Test Roughness']
221221
cells.f8 = ['Background Param 1']
222222
cells.f9 = ['Scalefactor 1']
223-
cells.f10 = ['Qz shift 1']
223+
cells.f10 = []
224224
cells.f11 = ['SLD Air']
225225
cells.f12 = ['SLD D2O']
226226
cells.f13 = ['Resolution Param 1']
@@ -248,7 +248,7 @@ def custom_xy_cells():
248248
cells.f7 = ['Substrate Roughness', 'Test Thickness', 'Test SLD', 'Test Roughness']
249249
cells.f8 = ['Background Param 1']
250250
cells.f9 = ['Scalefactor 1']
251-
cells.f10 = ['Qz shift 1']
251+
cells.f10 = []
252252
cells.f11 = ['SLD Air']
253253
cells.f12 = ['SLD D2O']
254254
cells.f13 = ['Resolution Param 1']
@@ -269,7 +269,7 @@ def non_polarised_limits():
269269
limits = Limits()
270270
limits.param = [[1.0, 5.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]
271271
limits.backgroundParam = [[1e-7, 1e-5]]
272-
limits.qzshift = [[-1e-4, 1e-4]]
272+
limits.qzshift = []
273273
limits.scalefactor = [[0.02, 0.25]]
274274
limits.bulkIn = [[0.0, 0.0]]
275275
limits.bulkOut = [[6.2e-6, 6.35e-6]]
@@ -285,7 +285,7 @@ def domains_limits():
285285
limits = Limits()
286286
limits.param = [[1.0, 5.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]
287287
limits.backgroundParam = [[1e-7, 1e-5]]
288-
limits.qzshift = [[-1e-4, 1e-4]]
288+
limits.qzshift = []
289289
limits.scalefactor = [[0.02, 0.25]]
290290
limits.bulkIn = [[0.0, 0.0]]
291291
limits.bulkOut = [[6.2e-6, 6.35e-6]]
@@ -304,16 +304,16 @@ def non_polarised_priors():
304304
['Test SLD', RAT.utils.enums.Priors.Uniform, 0.0, np.inf],
305305
['Test Roughness', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
306306
priors.backgroundParam = [['Background Param 1', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
307-
priors.qzshift = [['Qz shift 1', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
307+
priors.qzshift = []
308308
priors.scalefactor = [['Scalefactor 1', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
309309
priors.bulkIn = [['SLD Air', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
310310
priors.bulkOut = [['SLD D2O', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
311311
priors.resolutionParam = [['Resolution Param 1', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
312312
priors.domainRatio = []
313313
priors.priorNames = ['Substrate Roughness', 'Test Thickness', 'Test SLD', 'Test Roughness', 'Background Param 1',
314-
'Scalefactor 1', 'Qz shift 1', 'SLD Air', 'SLD D2O', 'Resolution Param 1']
314+
'Scalefactor 1', 'SLD Air', 'SLD D2O', 'Resolution Param 1']
315315
priors.priorValues = [[1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf],
316-
[1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf]]
316+
[1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf]]
317317

318318
return priors
319319

@@ -327,17 +327,16 @@ def domains_priors():
327327
['Test SLD', RAT.utils.enums.Priors.Uniform, 0.0, np.inf],
328328
['Test Roughness', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
329329
priors.backgroundParam = [['Background Param 1', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
330-
priors.qzshift = [['Qz shift 1', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
330+
priors.qzshift = []
331331
priors.scalefactor = [['Scalefactor 1', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
332332
priors.bulkIn = [['SLD Air', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
333333
priors.bulkOut = [['SLD D2O', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
334334
priors.resolutionParam = [['Resolution Param 1', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
335335
priors.domainRatio = [['Domain Ratio 1', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
336336
priors.priorNames = ['Substrate Roughness', 'Test Thickness', 'Test SLD', 'Test Roughness', 'Background Param 1',
337-
'Scalefactor 1', 'Qz shift 1', 'SLD Air', 'SLD D2O', 'Resolution Param 1', 'Domain Ratio 1']
337+
'Scalefactor 1', 'SLD Air', 'SLD D2O', 'Resolution Param 1', 'Domain Ratio 1']
338338
priors.priorValues = [[1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf],
339-
[1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf],
340-
[1, 0.0, np.inf]]
339+
[1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf]]
341340

342341
return priors
343342

@@ -376,7 +375,7 @@ def standard_layers_controls():
376375
controls.boundHandling = BoundHandling.Fold
377376
controls.checks.fitParam = [1, 0, 0, 0]
378377
controls.checks.fitBackgroundParam = [0]
379-
controls.checks.fitQzshift = [0]
378+
controls.checks.fitQzshift = []
380379
controls.checks.fitScalefactor = [0]
381380
controls.checks.fitBulkIn = [0]
382381
controls.checks.fitBulkOut = [0]
@@ -419,7 +418,7 @@ def custom_xy_controls():
419418
controls.boundHandling = BoundHandling.Fold
420419
controls.checks.fitParam = [1, 0, 0, 0]
421420
controls.checks.fitBackgroundParam = [0]
422-
controls.checks.fitQzshift = [0]
421+
controls.checks.fitQzshift = []
423422
controls.checks.fitScalefactor = [0]
424423
controls.checks.fitBulkIn = [0]
425424
controls.checks.fitBulkOut = [0]
@@ -435,7 +434,7 @@ def test_checks():
435434
checks = Checks()
436435
checks.fitParam = [1, 0, 0, 0]
437436
checks.fitBackgroundParam = [0]
438-
checks.fitQzshift = [0]
437+
checks.fitQzshift = []
439438
checks.fitScalefactor = [0]
440439
checks.fitBulkIn = [0]
441440
checks.fitBulkOut = [0]
@@ -535,7 +534,6 @@ def check_problem_equal(actual_problem, expected_problem) -> None:
535534
for scalar_field in scalar_fields:
536535
assert getattr(actual_problem, scalar_field) == getattr(expected_problem, scalar_field)
537536
for array_field in array_fields:
538-
print(array_field)
539537
assert (getattr(actual_problem, array_field) == getattr(expected_problem, array_field)).all()
540538

541539
# Need to account for "NaN" entries in contrastCustomFiles field

tests/test_project.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ def default_project_repr():
6060
'+-------+---------+---------+----------+----------+-------+------------+-----+-------+\n'
6161
'| 0 | SLD D2O | 6.2e-06 | 6.35e-06 | 6.35e-06 | False | uniform | 0.0 | inf |\n'
6262
'+-------+---------+---------+----------+----------+-------+------------+-----+-------+\n\n'
63-
'Qz Shifts: -----------------------------------------------------------------------------------------\n\n'
64-
'+-------+------------+---------+-------+--------+-------+------------+-----+-------+\n'
65-
'| index | name | min | value | max | fit | prior type | mu | sigma |\n'
66-
'+-------+------------+---------+-------+--------+-------+------------+-----+-------+\n'
67-
'| 0 | Qz shift 1 | -0.0001 | 0.0 | 0.0001 | False | uniform | 0.0 | inf |\n'
68-
'+-------+------------+---------+-------+--------+-------+------------+-----+-------+\n\n'
6963
'Scalefactors: --------------------------------------------------------------------------------------\n\n'
7064
'+-------+---------------+------+-------+------+-------+------------+-----+-------+\n'
7165
'| index | name | min | value | max | fit | prior type | mu | sigma |\n'
@@ -116,7 +110,6 @@ def test_project_script():
116110
" Parameter(name='Test Roughness', min=0.0, value=0.0, max=0.0, fit=False, prior_type='uniform', mu=0.0, sigma=inf)]),\n"
117111
" background_parameters=RAT.ClassList([Parameter(name='Background Param 1', min=1e-07, value=1e-06, max=1e-05, fit=False, prior_type='uniform', mu=0.0, sigma=inf)]),\n"
118112
" scalefactors=RAT.ClassList([Parameter(name='Scalefactor 1', min=0.02, value=0.23, max=0.25, fit=False, prior_type='uniform', mu=0.0, sigma=inf)]),\n"
119-
" qz_shifts=RAT.ClassList([Parameter(name='Qz shift 1', min=-0.0001, value=0.0, max=0.0001, fit=False, prior_type='uniform', mu=0.0, sigma=inf)]),\n"
120113
" bulk_in=RAT.ClassList([Parameter(name='SLD Air', min=0.0, value=0.0, max=0.0, fit=False, prior_type='uniform', mu=0.0, sigma=inf)]),\n"
121114
" bulk_out=RAT.ClassList([Parameter(name='SLD D2O', min=6.2e-06, value=6.35e-06, max=6.35e-06, fit=False, prior_type='uniform', mu=0.0, sigma=inf)]),\n"
122115
" resolution_parameters=RAT.ClassList([Parameter(name='Resolution Param 1', min=0.01, value=0.03, max=0.05, fit=False, prior_type='uniform', mu=0.0, sigma=inf)]),\n"
@@ -603,7 +596,6 @@ def test_get_all_names(test_project) -> None:
603596
'Test Roughness'],
604597
'bulk_in': ['SLD Air'],
605598
'bulk_out': ['SLD D2O'],
606-
'qz_shifts': ['Qz shift 1'],
607599
'scalefactors': ['Scalefactor 1'],
608600
'domain_ratios': [],
609601
'background_parameters': ['Background Param 1'],
@@ -623,7 +615,6 @@ def test_get_all_protected_parameters(test_project) -> None:
623615
assert test_project.get_all_protected_parameters() == {'parameters': ['Substrate Roughness'],
624616
'bulk_in': [],
625617
'bulk_out': [],
626-
'qz_shifts': [],
627618
'scalefactors': [],
628619
'domain_ratios': [],
629620
'background_parameters': [],

0 commit comments

Comments
 (0)