Spaces:
Sleeping
Sleeping
File size: 5,885 Bytes
32ba915 7184c06 32ba915 7184c06 32ba915 7184c06 32ba915 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
"""
Test script to verify the new ML Polymer Aging features are working correctly
"""
import numpy as np
import sys
import os
# Add modules to path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
def test_advanced_spectroscopy():
"""Test advanced spectroscopy module"""
print("Testing Advanced Spectroscopy Module...")
try:
from modules.advanced_spectroscopy import (
MultiModalSpectroscopyEngine,
AdvancedPreprocessor,
SpectroscopyType,
SPECTRAL_CHARACTERISTICS,
)
# Create engine
engine = MultiModalSpectroscopyEngine()
# Generate sample spectrum
wavenumbers = np.linspace(400, 4000, 1000)
intensities = np.random.normal(0.1, 0.02, len(wavenumbers))
# Add some peaks
peaks = [1715, 2920, 2850]
for peak in peaks:
peak_idx = np.argmin(np.abs(wavenumbers - peak))
intensities[peak_idx - 5 : peak_idx + 5] += 0.5
# Register spectrum
spectrum_id = engine.register_spectrum(
wavenumbers, intensities, SpectroscopyType.FTIR
)
# Preprocess
result = engine.preprocess_spectrum(spectrum_id)
print(f"β
Spectrum registered: {spectrum_id}")
print(f"β
Quality score: {result['quality_score']:.3f}")
print(
f"β
Processing steps: {len(result['processing_metadata']['steps_applied'])}"
)
return True
except Exception as e:
print(f"β Advanced Spectroscopy test failed: {e}")
return False
def test_modern_ml_architecture():
"""Test modern ML architecture module"""
print("\nTesting Modern ML Architecture...")
try:
from modules.modern_ml_architecture import (
ModernMLPipeline,
SpectralTransformer,
prepare_transformer_input,
)
# Create pipeline with minimal configuration
pipeline = ModernMLPipeline()
# Test basic functionality without full initialization
print(f"β
Modern ML Pipeline imported successfully")
print(f"β
SpectralTransformer class available")
print(f"β
Utility functions working")
# Test transformer input preparation
spectral_data = np.random.random(500)
X_transformer = prepare_transformer_input(spectral_data, max_length=500)
print(f"β
Transformer input shape: {X_transformer.shape}")
return True
except Exception as e:
print(f"β Modern ML Architecture test failed: {e}")
return False
def test_enhanced_data_pipeline():
"""Test enhanced data pipeline module"""
print("\nTesting Enhanced Data Pipeline...")
try:
from modules.enhanced_data_pipeline import (
EnhancedDataPipeline,
DataQualityController,
SyntheticDataAugmentation,
)
# Create pipeline
pipeline = EnhancedDataPipeline()
# Test quality controller
quality_controller = DataQualityController()
# Generate sample spectrum
wavenumbers = np.linspace(400, 4000, 1000)
intensities = np.random.normal(0.1, 0.02, len(wavenumbers))
# Assess quality
assessment = quality_controller.assess_spectrum_quality(
wavenumbers, intensities
)
print(f"β
Data pipeline initialized")
print(f"β
Quality assessment score: {assessment['overall_score']:.3f}")
print(f"β
Validation status: {assessment['validation_status']}")
# Test synthetic data augmentation
augmentation = SyntheticDataAugmentation()
augmented = augmentation.augment_spectrum(
wavenumbers, intensities, num_variations=3
)
print(f"β
Generated {len(augmented)} synthetic variants")
return True
except Exception as e:
print(f"β Enhanced Data Pipeline test failed: {e}")
return False
def test_database_functionality():
"""Test database functionality"""
print("\nTesting Database Functionality...")
try:
from modules.enhanced_data_pipeline import EnhancedDataPipeline
pipeline = EnhancedDataPipeline()
# Get database statistics
stats = pipeline.get_database_statistics()
print(f"β
Database initialized")
print(f"β
Total spectra: {stats['total_spectra']}")
print(f"β
Database tables created successfully")
return True
except Exception as e:
print(f"β Database test failed: {e}")
return False
def main():
"""Run all tests"""
print("π§ͺ ML Polymer Aging Feature Validation Tests")
print("=" * 50)
tests = [
test_advanced_spectroscopy,
test_modern_ml_architecture,
test_enhanced_data_pipeline,
test_database_functionality,
]
passed = 0
total = len(tests)
for test in tests:
if test():
passed += 1
print("\n" + "=" * 50)
print(f"π― Test Results: {passed}/{total} tests passed")
if passed == total:
print("π ALL TESTS PASSED - ML Polymer Aging features are working correctly!")
print("\nβ
Critical features validated:")
print(" β’ FTIR integration and multi-modal spectroscopy")
print(" β’ Modern ML architecture with transformers and ensembles")
print(" β’ Enhanced data pipeline with quality control")
print(" β’ Database functionality for synthetic data generation")
else:
print("β οΈ Some tests failed - please check the implementation")
return passed == total
if __name__ == "__main__":
main()
|