Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes qzshift from user-facing code #28

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions RAT/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def make_input(project: RAT.Project, controls: Union[RAT.controls.Calculate, RAT
parameter_field = {'parameters': 'param',
'bulk_in': 'bulkIn',
'bulk_out': 'bulkOut',
'qz_shifts': 'qzshift',
'scalefactors': 'scalefactor',
'domain_ratios': 'domainRatio',
'background_parameters': 'backgroundParam',
Expand All @@ -48,7 +47,6 @@ def make_input(project: RAT.Project, controls: Union[RAT.controls.Calculate, RAT
checks_field = {'parameters': 'fitParam',
'bulk_in': 'fitBulkIn',
'bulk_out': 'fitBulkOut',
'qz_shifts': 'fitQzshift',
'scalefactors': 'fitScalefactor',
'domain_ratios': 'fitDomainRatio',
'background_parameters': 'fitBackgroundParam',
Expand All @@ -71,6 +69,11 @@ def make_input(project: RAT.Project, controls: Union[RAT.controls.Calculate, RAT
setattr(priors, parameter_field[class_list], [[element.name, element.prior_type, element.mu, element.sigma]
for element in getattr(project, class_list)])

# Use dummy values for qzshifts
checks.fitQzshift = []
limits.qzshift = []
priors.qzshift = []

priors.priorNames = [param.name for class_list in RAT.project.parameter_class_lists
for param in getattr(project, class_list)]
priors.priorValues = [[prior_id[param.prior_type], param.mu, param.sigma]
Expand Down Expand Up @@ -115,7 +118,7 @@ def make_problem(project: RAT.Project) -> ProblemDefinition:
problem.params = [param.value for param in project.parameters]
problem.bulkIn = [param.value for param in project.bulk_in]
problem.bulkOut = [param.value for param in project.bulk_out]
problem.qzshifts = [param.value for param in project.qz_shifts]
problem.qzshifts = []
problem.scalefactors = [param.value for param in project.scalefactors]
problem.domainRatio = [param.value for param in project.domain_ratios]
problem.backgroundParams = [param.value for param in project.background_parameters]
Expand Down Expand Up @@ -216,7 +219,7 @@ def make_cells(project: RAT.Project) -> Cells:
cells.f7 = [param.name for param in project.parameters]
cells.f8 = [param.name for param in project.background_parameters]
cells.f9 = [param.name for param in project.scalefactors]
cells.f10 = [param.name for param in project.qz_shifts]
cells.f10 = [] # Placeholder for qzshifts
cells.f11 = [param.name for param in project.bulk_in]
cells.f12 = [param.name for param in project.bulk_out]
cells.f13 = [param.name for param in project.resolution_parameters]
Expand Down
8 changes: 2 additions & 6 deletions RAT/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
model_in_classlist = {'parameters': 'Parameter',
'bulk_in': 'Parameter',
'bulk_out': 'Parameter',
'qz_shifts': 'Parameter',
'scalefactors': 'Parameter',
'domain_ratios': 'Parameter',
'background_parameters': 'Parameter',
Expand Down Expand Up @@ -73,7 +72,7 @@
}

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

qz_shifts: ClassList = ClassList(RAT.models.Parameter(name='Qz shift 1', min=-1e-4, value=0.0, max=1e-4, fit=False,
prior_type=Priors.Uniform, mu=0.0, sigma=np.inf))

scalefactors: ClassList = ClassList(RAT.models.Parameter(name='Scalefactor 1', min=0.02, value=0.23, max=0.25,
fit=False, prior_type=Priors.Uniform, mu=0.0,
sigma=np.inf))
Expand Down Expand Up @@ -137,7 +133,7 @@ class Project(BaseModel, validate_assignment=True, extra='forbid', arbitrary_typ
_contrast_model_field: str
_protected_parameters: dict

@field_validator('parameters', 'bulk_in', 'bulk_out', 'qz_shifts', 'scalefactors', 'background_parameters',
@field_validator('parameters', 'bulk_in', 'bulk_out', 'scalefactors', 'background_parameters',
'backgrounds', 'resolution_parameters', 'resolutions', 'custom_files', 'data', 'layers',
'domain_contrasts', 'contrasts')
@classmethod
Expand Down
60 changes: 29 additions & 31 deletions tests/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ def standard_layers_problem():
problem.params = [3.0, 0.0, 0.0, 0.0]
problem.bulkIn = [0.0]
problem.bulkOut = [6.35e-06]
problem.qzshifts = [0.0]
problem.qzshifts = []
problem.scalefactors = [0.23]
problem.domainRatio = []
problem.backgroundParams = [1e-06]
problem.resolutionParams = [0.03]
problem.contrastBulkIns = [1]
problem.contrastBulkOuts = [1]
problem.contrastQzshifts = [1]
problem.contrastQzshifts = []
problem.contrastScalefactors = [1]
problem.contrastBackgrounds = [1]
problem.contrastBackgroundActions = [1]
Expand All @@ -91,10 +91,10 @@ def standard_layers_problem():
problem.numberOfLayers = 1
problem.numberOfDomainContrasts = 0
problem.fitParams = [3.0]
problem.otherParams = [0.0, 0.0, 0.0, 1e-06, 0.23, 0.0, 0.0, 6.35e-06, 0.03]
problem.otherParams = [0.0, 0.0, 0.0, 1e-06, 0.23, 0.0, 6.35e-06, 0.03]
problem.fitLimits = [[1.0, 5.0]]
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],
[0.0, 0.0], [6.2e-06, 6.35e-06], [0.01, 0.05]]
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],
[6.2e-06, 6.35e-06], [0.01, 0.05]]

return problem

Expand All @@ -110,14 +110,14 @@ def domains_problem():
problem.params = [3.0, 0.0, 0.0, 0.0]
problem.bulkIn = [0.0]
problem.bulkOut = [6.35e-06]
problem.qzshifts = [0.0]
problem.qzshifts = []
problem.scalefactors = [0.23]
problem.domainRatio = [0.5]
problem.backgroundParams = [1e-06]
problem.resolutionParams = [0.03]
problem.contrastBulkIns = [1]
problem.contrastBulkOuts = [1]
problem.contrastQzshifts = [1]
problem.contrastQzshifts = []
problem.contrastScalefactors = [1]
problem.contrastBackgrounds = [1]
problem.contrastBackgroundActions = [1]
Expand All @@ -131,10 +131,10 @@ def domains_problem():
problem.numberOfLayers = 1
problem.numberOfDomainContrasts = 2
problem.fitParams = [3.0]
problem.otherParams = [0.0, 0.0, 0.0, 1e-06, 0.23, 0.0, 0.0, 6.35e-06, 0.03, 0.5]
problem.otherParams = [0.0, 0.0, 0.0, 1e-06, 0.23, 0.0, 6.35e-06, 0.03, 0.5]
problem.fitLimits = [[1.0, 5.0]]
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],
[0.0, 0.0], [6.2e-06, 6.35e-06], [0.01, 0.05], [0.4, 0.6]]
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],
[6.2e-06, 6.35e-06], [0.01, 0.05], [0.4, 0.6]]

return problem

Expand All @@ -150,14 +150,14 @@ def custom_xy_problem():
problem.params = [3.0, 0.0, 0.0, 0.0]
problem.bulkIn = [0.0]
problem.bulkOut = [6.35e-06]
problem.qzshifts = [0.0]
problem.qzshifts = []
problem.scalefactors = [0.23]
problem.domainRatio = []
problem.backgroundParams = [1e-06]
problem.resolutionParams = [0.03]
problem.contrastBulkIns = [1]
problem.contrastBulkOuts = [1]
problem.contrastQzshifts = [1]
problem.contrastQzshifts = []
problem.contrastScalefactors = [1]
problem.contrastBackgrounds = [1]
problem.contrastBackgroundActions = [1]
Expand All @@ -171,10 +171,10 @@ def custom_xy_problem():
problem.numberOfLayers = 0
problem.numberOfDomainContrasts = 0
problem.fitParams = [3.0]
problem.otherParams = [0.0, 0.0, 0.0, 1e-06, 0.23, 0.0, 0.0, 6.35e-06, 0.03]
problem.otherParams = [0.0, 0.0, 0.0, 1e-06, 0.23, 0.0, 6.35e-06, 0.03]
problem.fitLimits = [[1.0, 5.0]]
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],
[0.0, 0.0], [6.2e-06, 6.35e-06], [0.01, 0.05]]
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],
[6.2e-06, 6.35e-06], [0.01, 0.05]]

return problem

Expand All @@ -192,7 +192,7 @@ def standard_layers_cells():
cells.f7 = ['Substrate Roughness', 'Test Thickness', 'Test SLD', 'Test Roughness']
cells.f8 = ['Background Param 1']
cells.f9 = ['Scalefactor 1']
cells.f10 = ['Qz shift 1']
cells.f10 = []
cells.f11 = ['SLD Air']
cells.f12 = ['SLD D2O']
cells.f13 = ['Resolution Param 1']
Expand Down Expand Up @@ -220,7 +220,7 @@ def domains_cells():
cells.f7 = ['Substrate Roughness', 'Test Thickness', 'Test SLD', 'Test Roughness']
cells.f8 = ['Background Param 1']
cells.f9 = ['Scalefactor 1']
cells.f10 = ['Qz shift 1']
cells.f10 = []
cells.f11 = ['SLD Air']
cells.f12 = ['SLD D2O']
cells.f13 = ['Resolution Param 1']
Expand Down Expand Up @@ -248,7 +248,7 @@ def custom_xy_cells():
cells.f7 = ['Substrate Roughness', 'Test Thickness', 'Test SLD', 'Test Roughness']
cells.f8 = ['Background Param 1']
cells.f9 = ['Scalefactor 1']
cells.f10 = ['Qz shift 1']
cells.f10 = []
cells.f11 = ['SLD Air']
cells.f12 = ['SLD D2O']
cells.f13 = ['Resolution Param 1']
Expand All @@ -269,7 +269,7 @@ def non_polarised_limits():
limits = Limits()
limits.param = [[1.0, 5.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]
limits.backgroundParam = [[1e-7, 1e-5]]
limits.qzshift = [[-1e-4, 1e-4]]
limits.qzshift = []
limits.scalefactor = [[0.02, 0.25]]
limits.bulkIn = [[0.0, 0.0]]
limits.bulkOut = [[6.2e-6, 6.35e-6]]
Expand All @@ -285,7 +285,7 @@ def domains_limits():
limits = Limits()
limits.param = [[1.0, 5.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]
limits.backgroundParam = [[1e-7, 1e-5]]
limits.qzshift = [[-1e-4, 1e-4]]
limits.qzshift = []
limits.scalefactor = [[0.02, 0.25]]
limits.bulkIn = [[0.0, 0.0]]
limits.bulkOut = [[6.2e-6, 6.35e-6]]
Expand All @@ -304,16 +304,16 @@ def non_polarised_priors():
['Test SLD', RAT.utils.enums.Priors.Uniform, 0.0, np.inf],
['Test Roughness', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
priors.backgroundParam = [['Background Param 1', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
priors.qzshift = [['Qz shift 1', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
priors.qzshift = []
priors.scalefactor = [['Scalefactor 1', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
priors.bulkIn = [['SLD Air', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
priors.bulkOut = [['SLD D2O', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
priors.resolutionParam = [['Resolution Param 1', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
priors.domainRatio = []
priors.priorNames = ['Substrate Roughness', 'Test Thickness', 'Test SLD', 'Test Roughness', 'Background Param 1',
'Scalefactor 1', 'Qz shift 1', 'SLD Air', 'SLD D2O', 'Resolution Param 1']
'Scalefactor 1', 'SLD Air', 'SLD D2O', 'Resolution Param 1']
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],
[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]]
[1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf], [1, 0.0, np.inf]]

return priors

Expand All @@ -327,17 +327,16 @@ def domains_priors():
['Test SLD', RAT.utils.enums.Priors.Uniform, 0.0, np.inf],
['Test Roughness', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
priors.backgroundParam = [['Background Param 1', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
priors.qzshift = [['Qz shift 1', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
priors.qzshift = []
priors.scalefactor = [['Scalefactor 1', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
priors.bulkIn = [['SLD Air', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
priors.bulkOut = [['SLD D2O', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
priors.resolutionParam = [['Resolution Param 1', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
priors.domainRatio = [['Domain Ratio 1', RAT.utils.enums.Priors.Uniform, 0.0, np.inf]]
priors.priorNames = ['Substrate Roughness', 'Test Thickness', 'Test SLD', 'Test Roughness', 'Background Param 1',
'Scalefactor 1', 'Qz shift 1', 'SLD Air', 'SLD D2O', 'Resolution Param 1', 'Domain Ratio 1']
'Scalefactor 1', 'SLD Air', 'SLD D2O', 'Resolution Param 1', 'Domain Ratio 1']
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],
[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],
[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], [1, 0.0, np.inf]]

return priors

Expand Down Expand Up @@ -376,7 +375,7 @@ def standard_layers_controls():
controls.boundHandling = BoundHandling.Fold
controls.checks.fitParam = [1, 0, 0, 0]
controls.checks.fitBackgroundParam = [0]
controls.checks.fitQzshift = [0]
controls.checks.fitQzshift = []
controls.checks.fitScalefactor = [0]
controls.checks.fitBulkIn = [0]
controls.checks.fitBulkOut = [0]
Expand Down Expand Up @@ -419,7 +418,7 @@ def custom_xy_controls():
controls.boundHandling = BoundHandling.Fold
controls.checks.fitParam = [1, 0, 0, 0]
controls.checks.fitBackgroundParam = [0]
controls.checks.fitQzshift = [0]
controls.checks.fitQzshift = []
controls.checks.fitScalefactor = [0]
controls.checks.fitBulkIn = [0]
controls.checks.fitBulkOut = [0]
Expand All @@ -435,7 +434,7 @@ def test_checks():
checks = Checks()
checks.fitParam = [1, 0, 0, 0]
checks.fitBackgroundParam = [0]
checks.fitQzshift = [0]
checks.fitQzshift = []
checks.fitScalefactor = [0]
checks.fitBulkIn = [0]
checks.fitBulkOut = [0]
Expand Down Expand Up @@ -535,7 +534,6 @@ def check_problem_equal(actual_problem, expected_problem) -> None:
for scalar_field in scalar_fields:
assert getattr(actual_problem, scalar_field) == getattr(expected_problem, scalar_field)
for array_field in array_fields:
print(array_field)
assert (getattr(actual_problem, array_field) == getattr(expected_problem, array_field)).all()

# Need to account for "NaN" entries in contrastCustomFiles field
Expand Down
9 changes: 0 additions & 9 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ def default_project_repr():
'+-------+---------+---------+----------+----------+-------+------------+-----+-------+\n'
'| 0 | SLD D2O | 6.2e-06 | 6.35e-06 | 6.35e-06 | False | uniform | 0.0 | inf |\n'
'+-------+---------+---------+----------+----------+-------+------------+-----+-------+\n\n'
'Qz Shifts: -----------------------------------------------------------------------------------------\n\n'
'+-------+------------+---------+-------+--------+-------+------------+-----+-------+\n'
'| index | name | min | value | max | fit | prior type | mu | sigma |\n'
'+-------+------------+---------+-------+--------+-------+------------+-----+-------+\n'
'| 0 | Qz shift 1 | -0.0001 | 0.0 | 0.0001 | False | uniform | 0.0 | inf |\n'
'+-------+------------+---------+-------+--------+-------+------------+-----+-------+\n\n'
'Scalefactors: --------------------------------------------------------------------------------------\n\n'
'+-------+---------------+------+-------+------+-------+------------+-----+-------+\n'
'| index | name | min | value | max | fit | prior type | mu | sigma |\n'
Expand Down Expand Up @@ -116,7 +110,6 @@ def test_project_script():
" Parameter(name='Test Roughness', min=0.0, value=0.0, max=0.0, fit=False, prior_type='uniform', mu=0.0, sigma=inf)]),\n"
" 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"
" 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"
" 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"
" 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"
" 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"
" 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"
Expand Down Expand Up @@ -603,7 +596,6 @@ def test_get_all_names(test_project) -> None:
'Test Roughness'],
'bulk_in': ['SLD Air'],
'bulk_out': ['SLD D2O'],
'qz_shifts': ['Qz shift 1'],
'scalefactors': ['Scalefactor 1'],
'domain_ratios': [],
'background_parameters': ['Background Param 1'],
Expand All @@ -623,7 +615,6 @@ def test_get_all_protected_parameters(test_project) -> None:
assert test_project.get_all_protected_parameters() == {'parameters': ['Substrate Roughness'],
'bulk_in': [],
'bulk_out': [],
'qz_shifts': [],
'scalefactors': [],
'domain_ratios': [],
'background_parameters': [],
Expand Down
Loading