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, previous_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.
previous_values (list [str]) – The list of allowed values for the fields given in field_list after the previous validation.
- 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, previous_values, allowed_field)#
Ensure the contents of the
modelfor a contrast or domain contrast exist in the required project fields.- 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.
previous_values (list [str]) – The list of allowed values for the model of the contrast_attribute after the previous validation.
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(_Project__context)#
Set up the Class to protect against disallowed modification.
We initialise the class handle in the ClassLists for empty data fields, set protected parameters, get names of all defined parameters, determine the contents of the “model” field in contrasts, and wrap ClassList routines to control revalidation.
- Parameters:
_Project__context (Any)
- Return type:
None
- save(filepath='./project.json')#
Save a project to a JSON file.
- Parameters:
filepath (str or Path) – The path to where the project file will be written.
- 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.
- to_dict()#
Generate a dictionary representation of the model.
- Returns:
model_dict – A dict containing the model information.
- Return type:
dict
- 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”).