nakas Claude commited on
Commit
16b6fdb
·
1 Parent(s): e4c2591

fix: Coordinate dimension mismatch for Combined Smoke HRRR data

Browse files

🔧 CRITICAL FIX: Coordinate System Alignment

## Problem Identified:
- Real HRRR data: shape (1059, 1799) - actual HRRR grid
- Synthetic coordinates: shape (50, 60) - demo grid
- Error: "conflicting sizes for dimension 'lat': length 50 vs 1059"

## Solution Implemented:
- Use proper HRRR CONUS coordinate ranges for real data:
- Latitude: 20.192° to 52.863° (1059 points)
- Longitude: -134.096° to -60.917° (1799 points)
- Keep synthetic coordinates (25°-50°, -125°--70°) for demo data
- Apply fix to all Combined Smoke functions:
- quick_kmz_generation()
- create_smoke_map() main forecast
- quick_kmz_wrapper() Folium maps

## Result:
- Eliminates xarray dimension conflicts
- Enables proper KMZ generation with real HRRR data
- Maintains demo mode compatibility

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (2) hide show
  1. .DS_Store +0 -0
  2. app.py +14 -10
.DS_Store CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
 
app.py CHANGED
@@ -1385,9 +1385,10 @@ class HRRRSmokeApp:
1385
  if datasets:
1386
  combined_smoke = self.polygon_generator.combine_smoke_parameters(datasets)
1387
 
1388
- # Create combined xarray dataset
1389
- lats = np.linspace(25, 50, 50)
1390
- lons = np.linspace(-125, -70, 60)
 
1391
  ds = xr.Dataset({
1392
  'combined_smoke': (['lat', 'lon'], combined_smoke)
1393
  }, coords={'lat': lats, 'lon': lons})
@@ -1735,9 +1736,10 @@ class HRRRSmokeApp:
1735
  print(f"Quick KMZ: Successfully fetched {len(datasets)} parameters: {list(datasets.keys())}")
1736
  combined_smoke = self.polygon_generator.combine_smoke_parameters(datasets)
1737
 
1738
- # Use synthetic coordinates for now since real HRRR coords are complex
1739
- lats = np.linspace(25, 50, combined_smoke.shape[0])
1740
- lons = np.linspace(-125, -70, combined_smoke.shape[1])
 
1741
  ds = xr.Dataset({
1742
  'combined_smoke': (['lat', 'lon'], combined_smoke)
1743
  }, coords={'lat': lats, 'lon': lons})
@@ -2106,8 +2108,9 @@ with gr.Blocks(title="HRRR Smoke Forecast", theme=gr.themes.Soft()) as app:
2106
 
2107
  if datasets:
2108
  combined_smoke = smoke_app.polygon_generator.combine_smoke_parameters(datasets)
2109
- lats = np.linspace(25, 50, 50)
2110
- lons = np.linspace(-125, -70, 60)
 
2111
  ds = xr.Dataset({
2112
  'combined_smoke': (['lat', 'lon'], combined_smoke)
2113
  }, coords={'lat': lats, 'lon': lons})
@@ -2116,8 +2119,9 @@ with gr.Blocks(title="HRRR Smoke Forecast", theme=gr.themes.Soft()) as app:
2116
  ['MASSDEN', 'PM25', 'VIS', 'COLMD', 'FRPAVG'], forecast_hour
2117
  )
2118
  combined_smoke = smoke_app.polygon_generator.combine_smoke_parameters(datasets)
2119
- lats = np.linspace(25, 50, 50)
2120
- lons = np.linspace(-125, -70, 60)
 
2121
  ds = xr.Dataset({
2122
  'combined_smoke': (['lat', 'lon'], combined_smoke)
2123
  }, coords={'lat': lats, 'lon': lons})
 
1385
  if datasets:
1386
  combined_smoke = self.polygon_generator.combine_smoke_parameters(datasets)
1387
 
1388
+ # Create combined xarray dataset with proper HRRR grid coordinates
1389
+ print(f"Main forecast: Creating coordinates for HRRR grid: {combined_smoke.shape}")
1390
+ lats = np.linspace(20.192, 52.863, combined_smoke.shape[0]) # HRRR CONUS lat range
1391
+ lons = np.linspace(-134.096, -60.917, combined_smoke.shape[1]) # HRRR CONUS lon range
1392
  ds = xr.Dataset({
1393
  'combined_smoke': (['lat', 'lon'], combined_smoke)
1394
  }, coords={'lat': lats, 'lon': lons})
 
1736
  print(f"Quick KMZ: Successfully fetched {len(datasets)} parameters: {list(datasets.keys())}")
1737
  combined_smoke = self.polygon_generator.combine_smoke_parameters(datasets)
1738
 
1739
+ # Create coordinates matching the actual HRRR grid dimensions
1740
+ print(f"Creating coordinates for HRRR grid: {combined_smoke.shape}")
1741
+ lats = np.linspace(20.192, 52.863, combined_smoke.shape[0]) # HRRR CONUS lat range
1742
+ lons = np.linspace(-134.096, -60.917, combined_smoke.shape[1]) # HRRR CONUS lon range
1743
  ds = xr.Dataset({
1744
  'combined_smoke': (['lat', 'lon'], combined_smoke)
1745
  }, coords={'lat': lats, 'lon': lons})
 
2108
 
2109
  if datasets:
2110
  combined_smoke = smoke_app.polygon_generator.combine_smoke_parameters(datasets)
2111
+ # Use HRRR grid coordinates for Folium wrapper too
2112
+ lats = np.linspace(20.192, 52.863, combined_smoke.shape[0])
2113
+ lons = np.linspace(-134.096, -60.917, combined_smoke.shape[1])
2114
  ds = xr.Dataset({
2115
  'combined_smoke': (['lat', 'lon'], combined_smoke)
2116
  }, coords={'lat': lats, 'lon': lons})
 
2119
  ['MASSDEN', 'PM25', 'VIS', 'COLMD', 'FRPAVG'], forecast_hour
2120
  )
2121
  combined_smoke = smoke_app.polygon_generator.combine_smoke_parameters(datasets)
2122
+ # Use demo coordinates for synthetic data (50x60 grid)
2123
+ lats = np.linspace(25, 50, combined_smoke.shape[0])
2124
+ lons = np.linspace(-125, -70, combined_smoke.shape[1])
2125
  ds = xr.Dataset({
2126
  'combined_smoke': (['lat', 'lon'], combined_smoke)
2127
  }, coords={'lat': lats, 'lon': lons})