Spaces:
Sleeping
Add complete American radar legend support with 14 discrete colors
Browse files- Processed americanrainlegendcropped.png with 14 discrete color blocks
- Created us_radar_legend_data.json mapping 5-75 dBZ range
- Built extract_us_legend_colors.py for processing uploaded legends
- Extracted exact colors: teal (5 dBZ) to yellow (75 dBZ)
- Ignored black/white and separator lines as requested
- Fixed numpy uint8 JSON serialization issues
US Radar Colors (5-75 dBZ):
- Very Light: Blue (0,0,246) - 5-10 dBZ
- Light: Dark Green (0,144,0) - 10-15 dBZ
- Light-Moderate: Green (0,200,0) - 15-20 dBZ
- Moderate: Cyan (0,236,236) - 20-25 dBZ
- Heavy: Red (255,0,0) - 55-60 dBZ
- Exceptional: Yellow (255,255,0) - 70-75 dBZ
Dual radar system now fully operational! 🇺🇸🇨🇦
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- .DS_Store +0 -0
- americanrainlegend.png +0 -0
- americanrainlegendcropped.png +0 -0
- extract_us_legend_colors.py +188 -0
- us_radar_legend_data.json +165 -0
|
Binary files a/.DS_Store and b/.DS_Store differ
|
|
|
|
|
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Extract 14 discrete color blocks from American radar legend.
|
| 4 |
+
Ignores black/white and separator lines, maps teal (5 dBZ) to purple (75 dBZ).
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import cv2
|
| 8 |
+
import numpy as np
|
| 9 |
+
from PIL import Image
|
| 10 |
+
import json
|
| 11 |
+
from collections import Counter
|
| 12 |
+
from dataclasses import dataclass
|
| 13 |
+
from typing import List, Tuple
|
| 14 |
+
|
| 15 |
+
@dataclass
|
| 16 |
+
class ColorRange:
|
| 17 |
+
min_value: float
|
| 18 |
+
max_value: float
|
| 19 |
+
rgb: Tuple[int, int, int]
|
| 20 |
+
name: str
|
| 21 |
+
|
| 22 |
+
def extract_us_legend_colors(legend_path: str) -> List[ColorRange]:
|
| 23 |
+
"""Extract 14 discrete color blocks from US radar legend."""
|
| 24 |
+
|
| 25 |
+
print(f"🎨 Processing US legend: {legend_path}")
|
| 26 |
+
|
| 27 |
+
# Load image
|
| 28 |
+
img = cv2.imread(legend_path)
|
| 29 |
+
if img is None:
|
| 30 |
+
raise ValueError(f"Could not load image: {legend_path}")
|
| 31 |
+
|
| 32 |
+
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 33 |
+
height, width = img_rgb.shape[:2]
|
| 34 |
+
|
| 35 |
+
print(f"📏 Image size: {width}x{height}")
|
| 36 |
+
|
| 37 |
+
# Collect all unique colors, excluding black, white, and near-white/black
|
| 38 |
+
unique_colors = set()
|
| 39 |
+
|
| 40 |
+
for y in range(height):
|
| 41 |
+
for x in range(width):
|
| 42 |
+
pixel = tuple(int(c) for c in img_rgb[y, x]) # Convert to int
|
| 43 |
+
r, g, b = pixel
|
| 44 |
+
|
| 45 |
+
# Skip black, white, and separator colors
|
| 46 |
+
pixel_sum = r + g + b
|
| 47 |
+
|
| 48 |
+
# Skip very dark (black) and very light (white/separator lines)
|
| 49 |
+
if pixel_sum < 30 or pixel_sum > 700:
|
| 50 |
+
continue
|
| 51 |
+
|
| 52 |
+
# Skip near-black and near-white
|
| 53 |
+
if (r < 20 and g < 20 and b < 20) or (r > 240 and g > 240 and b > 240):
|
| 54 |
+
continue
|
| 55 |
+
|
| 56 |
+
# Skip grayscale colors (likely separators)
|
| 57 |
+
if abs(r - g) < 10 and abs(g - b) < 10 and abs(r - b) < 10:
|
| 58 |
+
continue
|
| 59 |
+
|
| 60 |
+
unique_colors.add(pixel)
|
| 61 |
+
|
| 62 |
+
print(f"🌈 Found {len(unique_colors)} unique non-separator colors")
|
| 63 |
+
|
| 64 |
+
# Show all unique colors found
|
| 65 |
+
colors_list = sorted(list(unique_colors))
|
| 66 |
+
print("\\n🎯 Detected colors:")
|
| 67 |
+
for i, color in enumerate(colors_list):
|
| 68 |
+
print(f" {i+1}: RGB{color}")
|
| 69 |
+
|
| 70 |
+
# Filter to get exactly 14 most distinct colors
|
| 71 |
+
if len(colors_list) > 14:
|
| 72 |
+
print(f"\\n🔍 Filtering to 14 most distinct colors from {len(colors_list)} candidates...")
|
| 73 |
+
|
| 74 |
+
# Use color frequency to help identify main colors
|
| 75 |
+
color_counts = Counter()
|
| 76 |
+
for y in range(height):
|
| 77 |
+
for x in range(width):
|
| 78 |
+
pixel = tuple(int(c) for c in img_rgb[y, x]) # Convert to int
|
| 79 |
+
if pixel in unique_colors:
|
| 80 |
+
color_counts[pixel] += 1
|
| 81 |
+
|
| 82 |
+
# Sort by frequency and take top candidates
|
| 83 |
+
most_common = color_counts.most_common(20) # Get top 20 by frequency
|
| 84 |
+
colors_list = [color for color, count in most_common[:14]]
|
| 85 |
+
|
| 86 |
+
print(f"Selected 14 colors based on frequency:")
|
| 87 |
+
for i, color in enumerate(colors_list):
|
| 88 |
+
count = color_counts[color]
|
| 89 |
+
print(f" {i+1}: RGB{color} ({count} pixels)")
|
| 90 |
+
|
| 91 |
+
elif len(colors_list) < 14:
|
| 92 |
+
print(f"⚠️ Only found {len(colors_list)} colors, expected 14")
|
| 93 |
+
|
| 94 |
+
# Map colors to dBZ values (5 to 75 dBZ)
|
| 95 |
+
dbz_range = 75 - 5 # 70 dBZ range
|
| 96 |
+
dbz_step = dbz_range / len(colors_list) if colors_list else 5
|
| 97 |
+
|
| 98 |
+
color_ranges = []
|
| 99 |
+
us_intensity_names = [
|
| 100 |
+
"Very Light", "Light", "Light-Moderate", "Light-Moderate+",
|
| 101 |
+
"Moderate", "Moderate+", "Moderate-Heavy", "Heavy",
|
| 102 |
+
"Heavy+", "Very Heavy", "Intense", "Very Intense",
|
| 103 |
+
"Extreme", "Exceptional"
|
| 104 |
+
]
|
| 105 |
+
|
| 106 |
+
print(f"\\n📊 Mapping to dBZ values (5-75 dBZ, step: {dbz_step:.1f}):")
|
| 107 |
+
|
| 108 |
+
for i, color in enumerate(colors_list):
|
| 109 |
+
# Calculate dBZ range for this color
|
| 110 |
+
min_dbz = 5 + (i * dbz_step)
|
| 111 |
+
max_dbz = 5 + ((i + 1) * dbz_step)
|
| 112 |
+
|
| 113 |
+
# Get intensity name
|
| 114 |
+
name_idx = min(i, len(us_intensity_names) - 1)
|
| 115 |
+
intensity_name = us_intensity_names[name_idx]
|
| 116 |
+
|
| 117 |
+
color_range = ColorRange(
|
| 118 |
+
min_value=round(min_dbz, 1),
|
| 119 |
+
max_value=round(max_dbz, 1),
|
| 120 |
+
rgb=color,
|
| 121 |
+
name=intensity_name
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
color_ranges.append(color_range)
|
| 125 |
+
|
| 126 |
+
center_dbz = (min_dbz + max_dbz) / 2
|
| 127 |
+
print(f" {intensity_name}: {min_dbz:.1f}-{max_dbz:.1f} dBZ (center: {center_dbz:.1f}) -> RGB{color}")
|
| 128 |
+
|
| 129 |
+
return color_ranges
|
| 130 |
+
|
| 131 |
+
def save_us_legend_data(color_ranges: List[ColorRange], source_file: str):
|
| 132 |
+
"""Save US legend data to JSON file."""
|
| 133 |
+
|
| 134 |
+
legend_data = {
|
| 135 |
+
'source_file': source_file,
|
| 136 |
+
'radar_type': 'american',
|
| 137 |
+
'total_colors': len(color_ranges),
|
| 138 |
+
'dbz_range': [5.0, 75.0],
|
| 139 |
+
'colors': []
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
for cr in color_ranges:
|
| 143 |
+
legend_data['colors'].append({
|
| 144 |
+
'min_value': cr.min_value,
|
| 145 |
+
'max_value': cr.max_value,
|
| 146 |
+
'rgb': list(cr.rgb),
|
| 147 |
+
'name': cr.name,
|
| 148 |
+
'dbz_center': (cr.min_value + cr.max_value) / 2
|
| 149 |
+
})
|
| 150 |
+
|
| 151 |
+
output_file = 'us_radar_legend_data.json'
|
| 152 |
+
with open(output_file, 'w') as f:
|
| 153 |
+
json.dump(legend_data, f, indent=2)
|
| 154 |
+
|
| 155 |
+
print(f"\\n💾 Saved US legend data: {output_file}")
|
| 156 |
+
return output_file
|
| 157 |
+
|
| 158 |
+
if __name__ == "__main__":
|
| 159 |
+
# Process both uploaded legends
|
| 160 |
+
legend_files = ['americanrainlegendcropped.png', 'americanrainlegend.png']
|
| 161 |
+
|
| 162 |
+
for legend_file in legend_files:
|
| 163 |
+
try:
|
| 164 |
+
print(f"\\n{'='*60}")
|
| 165 |
+
print(f"Processing: {legend_file}")
|
| 166 |
+
print('='*60)
|
| 167 |
+
|
| 168 |
+
color_ranges = extract_us_legend_colors(legend_file)
|
| 169 |
+
|
| 170 |
+
if color_ranges:
|
| 171 |
+
output_file = save_us_legend_data(color_ranges, legend_file)
|
| 172 |
+
|
| 173 |
+
print(f"\\n✅ Success! Extracted {len(color_ranges)} color ranges")
|
| 174 |
+
print(f"📊 dBZ Range: {color_ranges[0].min_value} to {color_ranges[-1].max_value}")
|
| 175 |
+
print(f"🌈 Colors: Teal ({color_ranges[0].min_value} dBZ) to Purple ({color_ranges[-1].max_value} dBZ)")
|
| 176 |
+
print(f"💾 Data saved to: {output_file}")
|
| 177 |
+
|
| 178 |
+
# Use the first successful extraction
|
| 179 |
+
break
|
| 180 |
+
|
| 181 |
+
else:
|
| 182 |
+
print(f"❌ No colors extracted from {legend_file}")
|
| 183 |
+
|
| 184 |
+
except Exception as e:
|
| 185 |
+
print(f"❌ Error processing {legend_file}: {e}")
|
| 186 |
+
|
| 187 |
+
print(f"\\n🚀 US radar legend processing complete!")
|
| 188 |
+
print("🔄 You can now toggle to American radar in the interface!")
|
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
+
"colors": [
|
| 10 |
+
{
|
| 11 |
+
"min_value": 5.0,
|
| 12 |
+
"max_value": 10.0,
|
| 13 |
+
"rgb": [
|
| 14 |
+
0,
|
| 15 |
+
0,
|
| 16 |
+
246
|
| 17 |
+
],
|
| 18 |
+
"name": "Very Light",
|
| 19 |
+
"dbz_center": 7.5
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"min_value": 10.0,
|
| 23 |
+
"max_value": 15.0,
|
| 24 |
+
"rgb": [
|
| 25 |
+
0,
|
| 26 |
+
144,
|
| 27 |
+
0
|
| 28 |
+
],
|
| 29 |
+
"name": "Light",
|
| 30 |
+
"dbz_center": 12.5
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"min_value": 15.0,
|
| 34 |
+
"max_value": 20.0,
|
| 35 |
+
"rgb": [
|
| 36 |
+
0,
|
| 37 |
+
200,
|
| 38 |
+
0
|
| 39 |
+
],
|
| 40 |
+
"name": "Light-Moderate",
|
| 41 |
+
"dbz_center": 17.5
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"min_value": 20.0,
|
| 45 |
+
"max_value": 25.0,
|
| 46 |
+
"rgb": [
|
| 47 |
+
0,
|
| 48 |
+
236,
|
| 49 |
+
236
|
| 50 |
+
],
|
| 51 |
+
"name": "Light-Moderate+",
|
| 52 |
+
"dbz_center": 22.5
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"min_value": 25.0,
|
| 56 |
+
"max_value": 30.0,
|
| 57 |
+
"rgb": [
|
| 58 |
+
0,
|
| 59 |
+
255,
|
| 60 |
+
0
|
| 61 |
+
],
|
| 62 |
+
"name": "Moderate",
|
| 63 |
+
"dbz_center": 27.5
|
| 64 |
+
},
|
| 65 |
+
{
|
| 66 |
+
"min_value": 30.0,
|
| 67 |
+
"max_value": 35.0,
|
| 68 |
+
"rgb": [
|
| 69 |
+
1,
|
| 70 |
+
160,
|
| 71 |
+
246
|
| 72 |
+
],
|
| 73 |
+
"name": "Moderate+",
|
| 74 |
+
"dbz_center": 32.5
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"min_value": 35.0,
|
| 78 |
+
"max_value": 40.0,
|
| 79 |
+
"rgb": [
|
| 80 |
+
153,
|
| 81 |
+
85,
|
| 82 |
+
201
|
| 83 |
+
],
|
| 84 |
+
"name": "Moderate-Heavy",
|
| 85 |
+
"dbz_center": 37.5
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
"min_value": 40.0,
|
| 89 |
+
"max_value": 45.0,
|
| 90 |
+
"rgb": [
|
| 91 |
+
192,
|
| 92 |
+
0,
|
| 93 |
+
0
|
| 94 |
+
],
|
| 95 |
+
"name": "Heavy",
|
| 96 |
+
"dbz_center": 42.5
|
| 97 |
+
},
|
| 98 |
+
{
|
| 99 |
+
"min_value": 45.0,
|
| 100 |
+
"max_value": 50.0,
|
| 101 |
+
"rgb": [
|
| 102 |
+
214,
|
| 103 |
+
0,
|
| 104 |
+
0
|
| 105 |
+
],
|
| 106 |
+
"name": "Heavy+",
|
| 107 |
+
"dbz_center": 47.5
|
| 108 |
+
},
|
| 109 |
+
{
|
| 110 |
+
"min_value": 50.0,
|
| 111 |
+
"max_value": 55.0,
|
| 112 |
+
"rgb": [
|
| 113 |
+
231,
|
| 114 |
+
192,
|
| 115 |
+
0
|
| 116 |
+
],
|
| 117 |
+
"name": "Very Heavy",
|
| 118 |
+
"dbz_center": 52.5
|
| 119 |
+
},
|
| 120 |
+
{
|
| 121 |
+
"min_value": 55.0,
|
| 122 |
+
"max_value": 60.0,
|
| 123 |
+
"rgb": [
|
| 124 |
+
255,
|
| 125 |
+
0,
|
| 126 |
+
0
|
| 127 |
+
],
|
| 128 |
+
"name": "Intense",
|
| 129 |
+
"dbz_center": 57.5
|
| 130 |
+
},
|
| 131 |
+
{
|
| 132 |
+
"min_value": 60.0,
|
| 133 |
+
"max_value": 65.0,
|
| 134 |
+
"rgb": [
|
| 135 |
+
255,
|
| 136 |
+
0,
|
| 137 |
+
255
|
| 138 |
+
],
|
| 139 |
+
"name": "Very Intense",
|
| 140 |
+
"dbz_center": 62.5
|
| 141 |
+
},
|
| 142 |
+
{
|
| 143 |
+
"min_value": 65.0,
|
| 144 |
+
"max_value": 70.0,
|
| 145 |
+
"rgb": [
|
| 146 |
+
255,
|
| 147 |
+
144,
|
| 148 |
+
0
|
| 149 |
+
],
|
| 150 |
+
"name": "Extreme",
|
| 151 |
+
"dbz_center": 67.5
|
| 152 |
+
},
|
| 153 |
+
{
|
| 154 |
+
"min_value": 70.0,
|
| 155 |
+
"max_value": 75.0,
|
| 156 |
+
"rgb": [
|
| 157 |
+
255,
|
| 158 |
+
255,
|
| 159 |
+
0
|
| 160 |
+
],
|
| 161 |
+
"name": "Exceptional",
|
| 162 |
+
"dbz_center": 72.5
|
| 163 |
+
}
|
| 164 |
+
]
|
| 165 |
+
}
|