Project#
- pydantic model RATapi.Project#
Defines the input data for a reflectivity calculation in RAT.
This class combines the data defined in each of the pydantic models included in “models.py” into the full set of inputs required for a reflectivity calculation.
- Fields:
absorption (bool)
background_parameters (RATapi.classlist.ClassList[RATapi.models.Parameter])
backgrounds (RATapi.classlist.ClassList[RATapi.models.Background])
bulk_in (RATapi.classlist.ClassList[RATapi.models.Parameter])
bulk_out (RATapi.classlist.ClassList[RATapi.models.Parameter])
calculation (RATapi.utils.enums.Calculations)
contrasts (RATapi.classlist.ClassList[RATapi.models.Contrast] | RATapi.classlist.ClassList[RATapi.models.ContrastWithRatio])
custom_files (RATapi.classlist.ClassList[RATapi.models.CustomFile])
data (RATapi.classlist.ClassList[RATapi.models.Data])
domain_contrasts (RATapi.classlist.ClassList[RATapi.models.DomainContrast])
domain_ratios (RATapi.classlist.ClassList[RATapi.models.Parameter])
geometry (RATapi.utils.enums.Geometries)
layers (RATapi.classlist.ClassList[RATapi.models.Layer] | RATapi.classlist.ClassList[RATapi.models.AbsorptionLayer])
model (RATapi.utils.enums.LayerModels)
name (str)
parameters (RATapi.classlist.ClassList[RATapi.models.Parameter])
resolution_parameters (RATapi.classlist.ClassList[RATapi.models.Parameter])
resolutions (RATapi.classlist.ClassList[RATapi.models.Resolution])
scalefactors (RATapi.classlist.ClassList[RATapi.models.Parameter])
- field absorption: bool = False#
Whether imaginary SLD (absorption) should be accounted for.
- field background_parameters: ClassList[Parameter] = [Parameter(name='Background Param 1', min=1e-07, value=1e-06, max=1e-05, fit=False, prior_type='uniform', mu=0.0, sigma=inf, show_priors=False)]#
The list of parameters for models of backgrounds.
- field backgrounds: ClassList[Background] = [Background(name='Background 1', type='constant', source='Background Param 1', value_1='', value_2='', value_3='', value_4='', value_5='')]#
The list of models for background noise in the project.
- field bulk_in: ClassList[Parameter] = [Parameter(name='SLD Air', min=0.0, value=0.0, max=0.0, fit=False, prior_type='uniform', mu=0.0, sigma=inf, show_priors=False)]#
The list of parameters for SLD of the entry interfaces of a model.
- field bulk_out: ClassList[Parameter] = [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, show_priors=False)]#
The list of parameters for SLD of the exit interfaces of a model.
- field calculation: Calculations = Calculations.Normal#
What calculation type should be used. Can be ‘normal’ or ‘domains’.
- field contrasts: Annotated[ClassList[Contrast], Tag(tag=no_ratio)] | Annotated[ClassList[ContrastWithRatio], Tag(tag=ratio)] = []#
All groups of components used to define each model in the project.
- field custom_files: ClassList[CustomFile] = []#
Handles for custom files used by the project.
- field domain_contrasts: ClassList[DomainContrast] = []#
The groups of layers required by each domain in a domains model.
- field domain_ratios: ClassList[Parameter] = [Parameter(name='Domain Ratio 1', min=0.4, value=0.5, max=0.6, fit=False, prior_type='uniform', mu=0.0, sigma=inf, show_priors=False)]#
The list of parameters for weighting between domains of a domains model.
- field geometry: Geometries = Geometries.AirSubstrate#
What geometry should be used. Can be ‘air/substrate’ or ‘substrate/liquid’
- field layers: Annotated[ClassList[Layer], Tag(tag=no_abs)] | Annotated[ClassList[AbsorptionLayer], Tag(tag=abs)] = []#
The layers of a standard layer model.
- field model: LayerModels = LayerModels.StandardLayers#
What layer model should be used. Can be ‘standard layers’, ‘custom layers’, or ‘custom xy’.
- field name: str = ''#
The name of the project.
- field resolution_parameters: ClassList[Parameter] = [Parameter(name='Resolution Param 1', min=0.01, value=0.03, max=0.05, fit=False, prior_type='uniform', mu=0.0, sigma=inf, show_priors=False)]#
The list of parameters for models of resolutions.
- field resolutions: ClassList[Resolution] = [Resolution(name='Resolution 1', type='constant', source='Resolution Param 1', value_1='', value_2='', value_3='', value_4='', value_5='')]#
The list of models for instrument resolution in the project.
- field scalefactors: ClassList[Parameter] = [Parameter(name='Scalefactor 1', min=0.02, value=0.23, max=0.25, fit=False, prior_type='uniform', mu=0.0, sigma=inf, show_priors=False)]#
The list of parameters for scale factors to handle systematic error in model data.
- check_allowed_source(attribute)#
Check that the source of a background or resolution is defined in the relevant field for its type.
A constant background or resolution source should be defined in background_parameters or resolution_parameters respectively;
A data background source should be defined in data
A function background source should be defined in custom_files
- Parameters:
attribute (str) – The attribute of Project being validated.
- Raises:
ValueError – Raised if any field in field_list has a value not specified in allowed_constants or allowed_data as appropriate.
- Return type:
None
- check_allowed_values(attribute, field_list, allowed_values)#
Check the values of the given fields in the given model are in the supplied list of allowed values.
- Parameters:
attribute (str) – The attribute of Project being validated.
field_list (list [str]) – The fields of the attribute to be checked for valid values.
allowed_values (list [str]) – The list of allowed values for the fields given in field_list.
- Raises:
ValueError – Raised if any field in field_list has a value not specified in allowed_values.
- Return type:
None
- check_contrast_model_allowed_values(contrast_attribute, allowed_values, allowed_field)#
The contents of the “model” field of “contrasts” and “domain_contrasts” must be defined elsewhere in the project.
- Parameters:
contrast_attribute (str) – The specific contrast attribute of Project being validated (either “contrasts” or “domain_contrasts”).
allowed_values (list [str]) – The list of allowed values for the model of the contrast_attribute.
allowed_field (str) – The name of the field in the project in which the allowed_values are defined.
- Raises:
ValueError – Raised if any model in contrast_attribute has a value not specified in allowed_values.
- Return type:
None
- get_all_names()#
Record the names of all models defined in the project.
- get_all_protected_parameters()#
Record the protected parameters defined in the project.
- get_contrast_model_field()#
Get the field used to define the contents of the “model” field in contrasts.
- Returns:
model_field – The name of the field used to define the contrasts’ model field.
- Return type:
str
- hide_priors()#
Hide priors for all parameters in the model.
- classmethod load(path)#
Load a project from file.
- Parameters:
path (str or Path) – The path to the project file.
- Return type:
- model_post_init(context, /)#
We need to both initialize private attributes and call the user-defined model_post_init method.
- Parameters:
self (BaseModel)
context (Any)
- Return type:
None
- save(path, filename='project')#
Save a project to a JSON file.
- Parameters:
path (str or Path) – The path in which the project will be written.
filename (str) – The name of the generated project file.
- set_prior_visibility(priors_visible)#
Set whether priors are visible or invisible for all parameters.
- Parameters:
priors_visible (bool) – Whether priors should be shown.
- show_priors()#
Show priors for all parameters in the model.
- write_script(obj_name='problem', script='project_script.py')#
Write a python script that can be run to reproduce this project object.
- Parameters:
obj_name (str, optional) – The name given to the project object under construction (default is “problem”).
script (str, optional) – The filepath of the generated script (default is “project_script.py”).