Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Test folium/leaflet map functionality | |
| """ | |
| def test_folium_availability(): | |
| """Test if folium is available and basic functionality works""" | |
| try: | |
| import folium | |
| from folium.plugins import HeatMap | |
| print("β Folium and HeatMap available") | |
| FOLIUM_AVAILABLE = True | |
| except ImportError as e: | |
| print(f"β Folium not available: {e}") | |
| FOLIUM_AVAILABLE = False | |
| return False | |
| # Test basic map creation | |
| try: | |
| m = folium.Map(location=[39.5, -98.5], zoom_start=5) | |
| print("β Basic folium map creation works") | |
| except Exception as e: | |
| print(f"β Basic map creation failed: {e}") | |
| return False | |
| # Test polygon creation | |
| try: | |
| # Sample polygon coordinates (roughly Colorado) | |
| coords = [ | |
| [40.0, -109.0], | |
| [40.0, -102.0], | |
| [37.0, -102.0], | |
| [37.0, -109.0], | |
| [40.0, -109.0] # Close polygon | |
| ] | |
| folium.Polygon( | |
| locations=coords, | |
| popup="Test Smoke Plume", | |
| tooltip="Test polygon", | |
| fillColor='#AAAAAA', | |
| color='#888888', | |
| weight=2, | |
| fillOpacity=0.6, | |
| opacity=0.8 | |
| ).add_to(m) | |
| print("β Polygon creation works") | |
| except Exception as e: | |
| print(f"β Polygon creation failed: {e}") | |
| return False | |
| # Test heat map | |
| try: | |
| heat_data = [ | |
| [40.0, -105.0, 0.8], # Denver area with intensity | |
| [39.7, -104.9, 0.9], # Higher intensity nearby | |
| [39.5, -105.2, 0.6] # Lower intensity | |
| ] | |
| HeatMap( | |
| heat_data, | |
| min_opacity=0.2, | |
| radius=15, | |
| gradient={ | |
| 0.0: 'rgba(0,0,0,0)', | |
| 0.5: 'rgba(128,128,128,0.6)', | |
| 1.0: 'rgba(64,64,64,0.9)' | |
| } | |
| ).add_to(m) | |
| print("β Heat map creation works") | |
| except Exception as e: | |
| print(f"β Heat map creation failed: {e}") | |
| return False | |
| # Test layer control | |
| try: | |
| folium.LayerControl().add_to(m) | |
| print("β Layer control works") | |
| except Exception as e: | |
| print(f"β Layer control failed: {e}") | |
| return False | |
| # Test tile layers | |
| try: | |
| folium.TileLayer( | |
| tiles='CartoDB positron', | |
| name='Clean', | |
| overlay=False, | |
| control=True | |
| ).add_to(m) | |
| print("β Tile layer creation works") | |
| except Exception as e: | |
| print(f"β Tile layer creation failed: {e}") | |
| return False | |
| print("π¬οΈ Folium smoke visualization test completed successfully!") | |
| print("All core folium features are working properly:") | |
| print(" β Map creation") | |
| print(" β Polygon rendering with grayscale styling") | |
| print(" β Heat map visualization") | |
| print(" β Layer controls") | |
| print(" β Multiple tile layer support") | |
| return True | |
| def test_grayscale_styling(): | |
| """Test grayscale color scheme for smoke""" | |
| grayscale_styles = { | |
| 'light': { | |
| 'fillColor': '#E8E8E8', # Light gray | |
| 'color': '#CCCCCC', # Border | |
| 'weight': 1, | |
| 'fillOpacity': 0.4, | |
| 'opacity': 0.6 | |
| }, | |
| 'medium': { | |
| 'fillColor': '#AAAAAA', # Medium gray | |
| 'color': '#888888', # Border | |
| 'weight': 2, | |
| 'fillOpacity': 0.6, | |
| 'opacity': 0.8 | |
| }, | |
| 'heavy': { | |
| 'fillColor': '#666666', # Dark gray | |
| 'color': '#444444', # Border | |
| 'weight': 2, | |
| 'fillOpacity': 0.8, | |
| 'opacity': 1.0 | |
| } | |
| } | |
| print("π¨ Grayscale Smoke Styling Test:") | |
| for category, style in grayscale_styles.items(): | |
| print(f" {category.capitalize():6s}: Fill={style['fillColor']}, Border={style['color']}, Opacity={style['fillOpacity']}") | |
| print("β Grayscale styling configuration validated") | |
| return True | |
| if __name__ == "__main__": | |
| print("π¬οΈ Testing Folium/Leaflet Smoke Visualization") | |
| print("=" * 50) | |
| folium_works = test_folium_availability() | |
| grayscale_works = test_grayscale_styling() | |
| if folium_works and grayscale_works: | |
| print("\nπ All tests passed! Folium smoke visualization is ready.") | |
| else: | |
| print("\nβ οΈ Some tests failed. Check dependencies or implementation.") |