autoemxsp.runners.analyze_sample module
Single-sample clustering and analysis of X-ray spectra.
This module loads configurations and acquired X-ray spectra for a single sample, performs clustering/statistical analysis, and prints results. It is suitable for both interactive use and integration into larger workflows.
Import this module in your own code and call the analyze_sample() function, passing the sample ID (and optional arguments) to perform analysis programmatically.
- Workflow:
Loads sample configuration from Spectra_collection_info.json
Loads acquired spectral data from Data.csv
Performs clustering/statistical analysis
Prints summary results
Notes
Requires sample_ID (and optionally results_path if not using the default directory).
Designed to be robust and flexible for both batch and single-sample workflows.
- Typical usage:
Edit the sample_ID and options in the script, or
Import and call analyze_sample() with your own arguments.
- param sample_ID:
Sample identifier.
- type sample_ID:
str
- param results_path:
Directory where results are stored. If None, sets to default autoemxsp/Results
- type results_path:
str, optional
- param output_filename_suffix:
Suffix for output files.
- type output_filename_suffix:
str, optional
- param ref_formulae:
Reference formulae for clustering. If the first entry is “” or None, the rest are appended to the list loaded from Comp_analysis_configs.json; otherwise, the provided list replaces it.
- type ref_formulae:
list of str, optional
- param els_excluded_clust_plot:
Elements to exclude from cluster plot.
- type els_excluded_clust_plot:
list of str, optional
- param clustering_features:
Features to use for clustering.
- type clustering_features:
list of str, optional
- param k_finding_method:
- Method for determining optimal number of clusters. Set to “forced” if a value of ‘k’ is specified manually.
Allowed methods are “silhouette”, “calinski_harabasz”, “elbow”.
- type k_finding_method:
str, optional
- param k_forced:
Forced number of clusters.
- type k_forced:
int, optional
- param max_analytical_error_percent:
Maximum analytical error allowed for clustering.
- type max_analytical_error_percent:
float, optional
- param quant_flags_accepted:
Accepted quantification flags.
- type quant_flags_accepted:
list of int, optional
- param plot_custom_plots:
Whether to use custom plots.
- type plot_custom_plots:
bool, optional
- param show_unused_compositions_cluster_plot:
Whether to show unused compositions in cluster plot.
- type show_unused_compositions_cluster_plot:
bool, optional
- param Created on Tue Jul 29 13:
- type Created on Tue Jul 29 13:
18:16 2025
- param @author:
- type @author:
Andrea
- autoemxsp.runners.analyze_sample.analyze_sample(sample_ID: str, results_path: str = None, output_filename_suffix: str = '', ref_formulae: List[str] | None = None, els_excluded_clust_plot: List[str] | None = None, clustering_features: List[str] | None = None, k_finding_method: str | None = None, k_forced: int | None = None, max_analytical_error_percent: float = 5, quant_flags_accepted: List[int] | None = None, plot_custom_plots: bool = False, show_unused_compositions_cluster_plot: bool = True) None[source]
Run clustering and analysis for a single sample.
- Parameters:
sample_ID (str) – Sample identifier.
results_path (str, optional) – Directory where results are loaded and stored. If None, defaults to autoemxsp/Results
output_filename_suffix (str, optional) – Suffix for output files.
ref_formulae (list of str, optional) – Reference formulae for clustering. If the first entry is “” or None, the rest are appended to the list loaded from Comp_analysis_configs.json; otherwise, the provided list replaces it.
els_excluded_clust_plot (list of str, optional) – Elements to exclude from cluster plot.
clustering_features (list of str, optional) – Features to use for clustering.
k_finding_method (str, optional) –
- Method for determining optimal number of clusters. Set to “forced” if a value of ‘k’ is specified manually.
Allowed methods are “silhouette”, “calinski_harabasz”, “elbow”.
k_forced (int, optional) – Forced number of clusters.
max_analytical_error_percent (float, optional) – Maximum analytical error allowed for clustering.
quant_flags_accepted (list of int, optional) – Accepted quantification flags.
plot_custom_plots (bool, optional) – Whether to use custom plots.
show_unused_compositions_cluster_plot (bool, optional) – Whether to show unused compositions in cluster plot.
- Returns:
comp_analyzer – The composition analysis object containing the results and methods for further analysis.
- Return type: