Skip to main content

API Reference

This section describes the classes and functions of the AstroSpectro code repository in enough detail to use them from your own scripts or to contribute to them. Each page follows the same layout: overview, signature, parameters, returns, methods, example, notes.

These pages document what the code does today. They are checked against src/ and are not generated from the docstrings, so where a docstring and the code disagree, the page follows the code and says so. For the reasoning behind each step, follow the links to the Concepts and Core Pipeline pages.

Modules live in src/ and are imported without a prefix (from pipeline.classifier import SpectralClassifier, from dimred import PCAAnalyzer). Put src/ on sys.path, or call utils.setup_project_env() as the notebooks do.


Core pipeline — src/pipeline/​

The order below is the order of execution for one spectrum, then for a training session.

PageModuleMain classesRole
Preprocessorpreprocessor.pySpectraPreprocessor, ProcessedSpectrumRead a LAMOST FITS file, rebuild the wavelength axis, normalise the flux, sanitise the inverse-variance.
FeatureEngineerpeak_detector.py, feature_engineering.pyPeakDetector, FeatureEngineer, SpectralLineLibraryDetect absorption lines, compute the feature vector, add catalogue-derived columns.
Classifierclassifier.pySpectralClassifier, CollinearityFilter, ThresholdTunedClassifierPrepare labels, select features, search hyper-parameters, evaluate, persist.
MasterPipelinemaster.pyMasterPipelineOrchestrate every step, from batch selection to logged artefacts.

processing.py (ProcessingPipeline) glues the first two together with a multi-process worker; it is described in Processing pipeline and has no API page yet.

Dimensionality reduction — src/dimred/​

The sub-package exposes its public names through dimred/__init__.py: from dimred import DimRedDataLoader, PCAAnalyzer, EmbeddingEngine, HDBSCANAnalyzer, ….

PageModuleMain classes and functionsRole
Data loaderdata_loader.pyDimRedDataLoader, SpectralMatrixLoaderMerge features and Gaia metadata, filter, scale; or build a flux matrix on a common wavelength grid.
PCA analyzerpca_analyzer.pyPCAAnalyzerPCA with variance, loadings, correlations with physical parameters, reconstruction error.
Embeddingembedding.pyEmbeddingEngine, compare_embeddingsReproducible UMAP and t-SNE, stability and negative control.
HDBSCAN analyzerhdbscan_analyzer.pyHDBSCANAnalyzer, compute_sensitivity, compute_feature_profilesDensity clustering on an embedding and physical profile of each cluster.

The results obtained with these classes are in the Dimensionality Reduction section, which is built on the PHY-3500 · G1 · 43,019 spectra dataset.


Modules without a reference page yet​

ModulePublic names
dimred/autoencoder.pySpectralAutoencoder, tester_candidat, latent_arithmetic
dimred/xgboost_bridge.pyload_and_predict (exported as xgboost_predict)
dimred/run_reporter.pysave_pca_run, save_umap_tsne_run, save_autoencoder_run
dimred/dimred_visualizer.pyDimRedVisualizer
tools/SmartDownloader, SpectraManager, AstroVisualizer, DatasetBuilder, enrich_catalog_with_gaia, generate_catalog_from_fits

Until these pages exist, the source files carry full docstrings.

Keeping this section in sync

The reference is written by hand and verified against the code at the date of each page. A future step could generate it from the docstrings; the discrepancies noted on the pages (for example in MasterPipeline.run_training_session) would then need to be fixed in the code first.


See also​