AFL.automation.instrument.VirtualSAS#
Functions
|
Classes
|
|
|
Encode target labels with value between 0 and n_classes-1. |
|
A random forest classifier. |
|
- class AFL.automation.instrument.VirtualSAS.VirtualSAS(overrides=None)[source]#
- defaults = {'boundary_datasets': {}, 'components': [], 'fast_locate': True, 'noise': 0.0, 'reference_data': [], 'rfc_max_depth': None, 'rfc_min_samples_leaf': 1, 'rfc_min_samples_split': 2, 'rfc_n_estimators': 100, 'rfc_random_state': 42, 'sasview_models': {}, 'ternary': False}#
- __init__(overrides=None)[source]#
Generates smoothly interpolated scattering data via a noiseless GPR from an experiments netcdf file. Uses RandomForestClassifier for phase boundary classification.
- load_reference_data()[source]#
Load reference data from config into sasmodels Data1D objects.
Config format: reference_data = [
{‘q’: […], ‘I’: […], ‘dI’: […], ‘dq’: […]}, {‘q’: […], ‘I’: […], ‘dI’: […], ‘dq’: […]},
]
- load_sasview_models()[source]#
Load SASView models from config.
Config format: sasview_models = {
‘phase_A’: {‘model_name’: ‘sphere’, ‘model_kw’: {‘radius’: 50, …}}, ‘phase_B’: {‘model_name’: ‘cylinder’, ‘model_kw’: {‘radius’: 20, …}},
}
- validate_boundary_datasets_config()[source]#
Validate boundary_datasets config structure and dimensionality.
- Returns:
True if valid, raises ValueError otherwise
- Return type:
- Raises:
ValueError – If config structure is invalid
- migrate_boundary_dataset_to_config()[source]#
Convert old boundary_dataset xarray object to new config format.
This is a migration helper for transitioning from the old shapely-based system to the new RFC-based system.
- Returns:
Boundary datasets in new config format
- Return type:
- Raises:
ValueError – If boundary_dataset is None or invalid
- train_classifier(reset=True, drop_phases=None)[source]#
Train RandomForestClassifier on boundary datasets from config.
- Parameters:
- Raises:
ValueError – If boundary_datasets not configured or invalid format
- locate(composition)[source]#
Predict phase membership using trained RandomForestClassifier.
- Parameters:
composition (array-like) – Composition vector. Dimensionality depends on ternary mode: - ternary=True: Must be 3D (will be transformed to 2D for RFC) - ternary=False: Any dimension matching training data
- Returns:
ds – Dataset containing: - ‘phase’: predicted phase label - ‘probability’: confidence score - attrs: all phase probabilities
- Return type:
xr.Dataset
Notes
Use locate_with_uncertainty() to get prediction probabilities as tuple
- locate_with_uncertainty(composition)[source]#
Predict phase with uncertainty estimation via predict_proba.
- Parameters:
composition (array-like) – Composition vector. Dimensionality depends on ternary mode: - ternary=True: Must be 3D (will be transformed to 2D for RFC) - ternary=False: Any dimension matching training data
- Returns:
phase (str) – Predicted phase label
probability (float) – Confidence score for predicted phase (0-1)
all_probabilities (dict) – Probability scores for all phases {phase_label: probability}
- generate(label)[source]#
Generate scattering data for a given phase label.
- Parameters:
label (str) – Phase label (must exist in sasview_models config)
- Returns:
ds – Dataset containing: - ‘q’: scattering vector - ‘I’: scattered intensity (with noise) - ‘I_noiseless’: scattered intensity (without noise) - ‘dI’: uncertainty - attrs: phase label, model name
- Return type:
xr.Dataset
- expose(*args, **kwargs)[source]#
Mimic the expose command from other instrument servers.
- Returns:
ds – Combined dataset from locate() and generate() with composition info
- Return type:
xr.Dataset
- plot_decision_boundaries(grid_resolution=200, **kwargs)[source]#
Plot RFC decision boundaries with training data overlay.
- Parameters:
grid_resolution (int) – Number of grid points per axis for decision boundary mesh