Spaces:
Build error
Build error
add labels
Browse files
app.py
CHANGED
|
@@ -23,30 +23,32 @@ LEVELS = [1000, 925, 850, 700, 600, 500, 400, 300, 250, 200, 150, 100, 50]
|
|
| 23 |
SOIL_LEVELS = [1, 2]
|
| 24 |
DEFAULT_DATE = OpendataClient().latest()
|
| 25 |
|
| 26 |
-
# First
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
| 47 |
}
|
| 48 |
|
| 49 |
-
# Add pressure level
|
| 50 |
for var in ["t", "u", "v", "w", "q", "z"]:
|
| 51 |
var_name = {
|
| 52 |
"t": "Temperature",
|
|
@@ -58,7 +60,8 @@ for var in ["t", "u", "v", "w", "q", "z"]:
|
|
| 58 |
}[var]
|
| 59 |
|
| 60 |
for level in LEVELS:
|
| 61 |
-
|
|
|
|
| 62 |
|
| 63 |
def get_open_data(param, levelist=[]):
|
| 64 |
fields = {}
|
|
@@ -118,27 +121,23 @@ def plot_forecast(state, selected_variable):
|
|
| 118 |
ax.coastlines()
|
| 119 |
ax.add_feature(cfeature.BORDERS, linestyle=":")
|
| 120 |
triangulation = tri.Triangulation(longitudes, latitudes)
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
plt.title(f"{selected_variable} at {state['date']}")
|
| 123 |
plt.colorbar(contour)
|
| 124 |
return fig
|
| 125 |
|
| 126 |
-
#
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
for level in LEVELS]
|
| 135 |
-
)
|
| 136 |
-
|
| 137 |
-
# Finally create the dropdown choices
|
| 138 |
-
DROPDOWN_CHOICES = [
|
| 139 |
-
(f"{VARIABLE_DESCRIPTIONS[var_id]} ({var_id})", var_id)
|
| 140 |
-
for var_id in sorted(AVAILABLE_VARIABLES)
|
| 141 |
-
]
|
| 142 |
|
| 143 |
def gradio_interface(date_str, lead_time, device, selected_variable):
|
| 144 |
try:
|
|
@@ -156,7 +155,7 @@ demo = gr.Interface(
|
|
| 156 |
gr.Radio(choices=["cuda", "cpu"], value="cuda", label="Compute Device"),
|
| 157 |
gr.Dropdown(
|
| 158 |
choices=DROPDOWN_CHOICES,
|
| 159 |
-
value="
|
| 160 |
label="Select Variable to Plot",
|
| 161 |
info="Choose a meteorological variable to visualize"
|
| 162 |
)
|
|
|
|
| 23 |
SOIL_LEVELS = [1, 2]
|
| 24 |
DEFAULT_DATE = OpendataClient().latest()
|
| 25 |
|
| 26 |
+
# First organize variables into categories
|
| 27 |
+
VARIABLE_GROUPS = {
|
| 28 |
+
"Surface Variables": {
|
| 29 |
+
"10u": "10m U Wind Component",
|
| 30 |
+
"10v": "10m V Wind Component",
|
| 31 |
+
"2d": "2m Dewpoint Temperature",
|
| 32 |
+
"2t": "2m Temperature",
|
| 33 |
+
"msl": "Mean Sea Level Pressure",
|
| 34 |
+
"skt": "Skin Temperature",
|
| 35 |
+
"sp": "Surface Pressure",
|
| 36 |
+
"tcw": "Total Column Water",
|
| 37 |
+
"lsm": "Land-Sea Mask",
|
| 38 |
+
"z": "Surface Geopotential",
|
| 39 |
+
"slor": "Slope of Sub-gridscale Orography",
|
| 40 |
+
"sdor": "Standard Deviation of Orography",
|
| 41 |
+
},
|
| 42 |
+
"Soil Variables": {
|
| 43 |
+
"stl1": "Soil Temperature Level 1",
|
| 44 |
+
"stl2": "Soil Temperature Level 2",
|
| 45 |
+
"swvl1": "Soil Water Volume Level 1",
|
| 46 |
+
"swvl2": "Soil Water Volume Level 2",
|
| 47 |
+
},
|
| 48 |
+
"Pressure Level Variables": {} # Will fill this dynamically
|
| 49 |
}
|
| 50 |
|
| 51 |
+
# Add pressure level variables dynamically
|
| 52 |
for var in ["t", "u", "v", "w", "q", "z"]:
|
| 53 |
var_name = {
|
| 54 |
"t": "Temperature",
|
|
|
|
| 60 |
}[var]
|
| 61 |
|
| 62 |
for level in LEVELS:
|
| 63 |
+
var_id = f"{var}_{level}"
|
| 64 |
+
VARIABLE_GROUPS["Pressure Level Variables"][var_id] = f"{var_name} at {level}hPa"
|
| 65 |
|
| 66 |
def get_open_data(param, levelist=[]):
|
| 67 |
fields = {}
|
|
|
|
| 121 |
ax.coastlines()
|
| 122 |
ax.add_feature(cfeature.BORDERS, linestyle=":")
|
| 123 |
triangulation = tri.Triangulation(longitudes, latitudes)
|
| 124 |
+
|
| 125 |
+
# Use 'RdBu_r' instead of 'RdBu' to reverse the color scheme
|
| 126 |
+
contour = ax.tricontourf(triangulation, values, levels=20,
|
| 127 |
+
transform=ccrs.PlateCarree(),
|
| 128 |
+
cmap='RdBu_r')
|
| 129 |
plt.title(f"{selected_variable} at {state['date']}")
|
| 130 |
plt.colorbar(contour)
|
| 131 |
return fig
|
| 132 |
|
| 133 |
+
# Create dropdown choices with groups
|
| 134 |
+
DROPDOWN_CHOICES = []
|
| 135 |
+
for group_name, variables in VARIABLE_GROUPS.items():
|
| 136 |
+
# Add group separator
|
| 137 |
+
DROPDOWN_CHOICES.append((f"ββ {group_name} ββ", None))
|
| 138 |
+
# Add variables in this group
|
| 139 |
+
for var_id, desc in sorted(variables.items()):
|
| 140 |
+
DROPDOWN_CHOICES.append((f"{desc} ({var_id})", var_id))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
def gradio_interface(date_str, lead_time, device, selected_variable):
|
| 143 |
try:
|
|
|
|
| 155 |
gr.Radio(choices=["cuda", "cpu"], value="cuda", label="Compute Device"),
|
| 156 |
gr.Dropdown(
|
| 157 |
choices=DROPDOWN_CHOICES,
|
| 158 |
+
value="2t", # Default to 2m temperature
|
| 159 |
label="Select Variable to Plot",
|
| 160 |
info="Choose a meteorological variable to visualize"
|
| 161 |
)
|