timeki commited on
Commit
989d387
·
1 Parent(s): 5fe1543

Add drias indicators

Browse files
climateqa/engine/talk_to_data/config.py CHANGED
@@ -51,6 +51,23 @@ DRIAS_MODELS = [
51
  'REMO2009_MPI-ESM-LR',
52
  'CCLM4-8-17_HadGEM2-ES'
53
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  DRIAS_UI_TEXT = """
56
  Hi, I'm **Talk to Drias**, designed to answer your questions using [**DRIAS - TRACC 2023**](https://www.drias-climat.fr/accompagnement/sections/401) data.
 
51
  'REMO2009_MPI-ESM-LR',
52
  'CCLM4-8-17_HadGEM2-ES'
53
  ]
54
+ # Mapping between indicator columns and their units
55
+ INDICATOR_TO_UNIT = {
56
+ "total_winter_precipitation": "mm",
57
+ "total_summer_precipitation": "mm",
58
+ "total_annual_precipitation": "mm",
59
+ "total_remarkable_daily_precipitation": "mm",
60
+ "frequency_of_remarkable_daily_precipitation": "days",
61
+ "extreme_precipitation_intensity": "mm",
62
+ "mean_winter_temperature": "°C",
63
+ "mean_summer_temperature": "°C",
64
+ "mean_annual_temperature": "°C",
65
+ "number_tropical_nights": "days",
66
+ "maximum_summer_temperature": "°C",
67
+ "number_of_days_with_tx_above_30": "days",
68
+ "number_of_days_with_tx_above_35": "days",
69
+ "number_of_days_with_dry_ground": "days"
70
+ }
71
 
72
  DRIAS_UI_TEXT = """
73
  Hi, I'm **Talk to Drias**, designed to answer your questions using [**DRIAS - TRACC 2023**](https://www.drias-climat.fr/accompagnement/sections/401) data.
climateqa/engine/talk_to_data/plot.py CHANGED
@@ -9,6 +9,9 @@ from climateqa.engine.talk_to_data.sql_query import (
9
  indicator_for_given_year_query,
10
  indicator_per_year_at_location_query,
11
  )
 
 
 
12
 
13
 
14
  class Plot(TypedDict):
@@ -58,6 +61,7 @@ def plot_indicator_evolution_at_location(params: dict) -> Callable[..., Figure]:
58
  indicator = params["indicator_column"]
59
  location = params["location"]
60
  indicator_label = " ".join([word.capitalize() for word in indicator.split("_")])
 
61
 
62
  def plot_data(df: pd.DataFrame) -> Figure:
63
  """Generates the actual plot from the data.
@@ -111,6 +115,7 @@ def plot_indicator_evolution_at_location(params: dict) -> Callable[..., Figure]:
111
  name=f"Yearly {indicator_label}",
112
  mode="lines",
113
  marker=dict(color="#1f77b4"),
 
114
  )
115
 
116
  # Sliding average dashed line
@@ -121,11 +126,12 @@ def plot_indicator_evolution_at_location(params: dict) -> Callable[..., Figure]:
121
  name="10 years rolling average",
122
  line=dict(dash="dash"),
123
  marker=dict(color="#d62728"),
 
124
  )
125
  fig.update_layout(
126
  title=f"Plot of {indicator_label} in {location} ({model_label})",
127
  xaxis_title="Year",
128
- yaxis_title=indicator_label,
129
  template="plotly_white",
130
  )
131
  return fig
@@ -161,6 +167,8 @@ def plot_indicator_number_of_days_per_year_at_location(
161
  """
162
  indicator = params["indicator_column"]
163
  location = params["location"]
 
 
164
 
165
  def plot_data(df: pd.DataFrame) -> Figure:
166
  """Generate the figure thanks to the dataframe
@@ -195,15 +203,14 @@ def plot_indicator_number_of_days_per_year_at_location(
195
  y=indicators,
196
  width=0.5,
197
  marker=dict(color="#1f77b4"),
 
198
  )
199
  )
200
 
201
- indicator_label = " ".join([word.capitalize() for word in indicator.split("_")])
202
-
203
  fig.update_layout(
204
  title=f"{indicator_label} in {location} ({model_label})",
205
  xaxis_title="Year",
206
- yaxis_title=indicator,
207
  yaxis=dict(range=[0, max(indicators)]),
208
  bargap=0.5,
209
  template="plotly_white",
@@ -243,6 +250,7 @@ def plot_distribution_of_indicator_for_given_year(
243
  indicator = params["indicator_column"]
244
  year = params["year"]
245
  indicator_label = " ".join([word.capitalize() for word in indicator.split("_")])
 
246
 
247
  def plot_data(df: pd.DataFrame) -> Figure:
248
  """Generate the figure thanks to the dataframe
@@ -277,13 +285,14 @@ def plot_distribution_of_indicator_for_given_year(
277
  opacity=0.8,
278
  histnorm="percent",
279
  marker=dict(color="#1f77b4"),
 
280
  )
281
  )
282
 
283
  fig.update_layout(
284
  title=f"Distribution of {indicator_label} in {year} ({model_label})",
285
- xaxis_title=indicator_label,
286
- yaxis_title="Frequency",
287
  plot_bgcolor="rgba(0, 0, 0, 0)",
288
  showlegend=False,
289
  )
@@ -322,6 +331,7 @@ def plot_map_of_france_of_indicator_for_given_year(
322
  indicator = params["indicator_column"]
323
  year = params["year"]
324
  indicator_label = " ".join([word.capitalize() for word in indicator.split("_")])
 
325
 
326
  def plot_data(df: pd.DataFrame) -> Figure:
327
  fig = go.Figure()
@@ -358,6 +368,8 @@ def plot_map_of_france_of_indicator_for_given_year(
358
  cmax=max(indicators), # Maximum color range
359
  showscale=True, # Show colorbar
360
  ),
 
 
361
  )
362
  )
363
 
@@ -365,7 +377,7 @@ def plot_map_of_france_of_indicator_for_given_year(
365
  mapbox_style="open-street-map", # Use OpenStreetMap
366
  mapbox_zoom=3,
367
  mapbox_center={"lat": 46.6, "lon": 2.0},
368
- coloraxis_colorbar=dict(title=f"{indicator_label}"), # Add legend
369
  title=f"{indicator_label} in {year} in France ({model_label}) " # Title
370
  )
371
  return fig
 
9
  indicator_for_given_year_query,
10
  indicator_per_year_at_location_query,
11
  )
12
+ from climateqa.engine.talk_to_data.config import INDICATOR_TO_UNIT
13
+
14
+
15
 
16
 
17
  class Plot(TypedDict):
 
61
  indicator = params["indicator_column"]
62
  location = params["location"]
63
  indicator_label = " ".join([word.capitalize() for word in indicator.split("_")])
64
+ unit = INDICATOR_TO_UNIT.get(indicator, "")
65
 
66
  def plot_data(df: pd.DataFrame) -> Figure:
67
  """Generates the actual plot from the data.
 
115
  name=f"Yearly {indicator_label}",
116
  mode="lines",
117
  marker=dict(color="#1f77b4"),
118
+ hovertemplate=f"{indicator_label}: %{{y:.2f}} {unit}<br>Year: %{{x}}<extra></extra>"
119
  )
120
 
121
  # Sliding average dashed line
 
126
  name="10 years rolling average",
127
  line=dict(dash="dash"),
128
  marker=dict(color="#d62728"),
129
+ hovertemplate=f"10-year average: %{{y:.2f}} {unit}<br>Year: %{{x}}<extra></extra>"
130
  )
131
  fig.update_layout(
132
  title=f"Plot of {indicator_label} in {location} ({model_label})",
133
  xaxis_title="Year",
134
+ yaxis_title=f"{indicator_label} ({unit})",
135
  template="plotly_white",
136
  )
137
  return fig
 
167
  """
168
  indicator = params["indicator_column"]
169
  location = params["location"]
170
+ indicator_label = " ".join([word.capitalize() for word in indicator.split("_")])
171
+ unit = INDICATOR_TO_UNIT.get(indicator, "")
172
 
173
  def plot_data(df: pd.DataFrame) -> Figure:
174
  """Generate the figure thanks to the dataframe
 
203
  y=indicators,
204
  width=0.5,
205
  marker=dict(color="#1f77b4"),
206
+ hovertemplate=f"{indicator_label}: %{{y:.2f}} {unit}<br>Year: %{{x}}<extra></extra>"
207
  )
208
  )
209
 
 
 
210
  fig.update_layout(
211
  title=f"{indicator_label} in {location} ({model_label})",
212
  xaxis_title="Year",
213
+ yaxis_title=f"{indicator_label} ({unit})",
214
  yaxis=dict(range=[0, max(indicators)]),
215
  bargap=0.5,
216
  template="plotly_white",
 
250
  indicator = params["indicator_column"]
251
  year = params["year"]
252
  indicator_label = " ".join([word.capitalize() for word in indicator.split("_")])
253
+ unit = INDICATOR_TO_UNIT.get(indicator, "")
254
 
255
  def plot_data(df: pd.DataFrame) -> Figure:
256
  """Generate the figure thanks to the dataframe
 
285
  opacity=0.8,
286
  histnorm="percent",
287
  marker=dict(color="#1f77b4"),
288
+ hovertemplate=f"{indicator_label}: %{{x:.2f}} {unit}<br>Frequency: %{{y:.2f}}%<extra></extra>"
289
  )
290
  )
291
 
292
  fig.update_layout(
293
  title=f"Distribution of {indicator_label} in {year} ({model_label})",
294
+ xaxis_title=f"{indicator_label} ({unit})",
295
+ yaxis_title="Frequency (%)",
296
  plot_bgcolor="rgba(0, 0, 0, 0)",
297
  showlegend=False,
298
  )
 
331
  indicator = params["indicator_column"]
332
  year = params["year"]
333
  indicator_label = " ".join([word.capitalize() for word in indicator.split("_")])
334
+ unit = INDICATOR_TO_UNIT.get(indicator, "")
335
 
336
  def plot_data(df: pd.DataFrame) -> Figure:
337
  fig = go.Figure()
 
368
  cmax=max(indicators), # Maximum color range
369
  showscale=True, # Show colorbar
370
  ),
371
+ text=[f"{indicator_label}: {value:.2f} {unit}" for value in indicators], # Add hover text showing the indicator value
372
+ hoverinfo="text" # Only show the custom text on hover
373
  )
374
  )
375
 
 
377
  mapbox_style="open-street-map", # Use OpenStreetMap
378
  mapbox_zoom=3,
379
  mapbox_center={"lat": 46.6, "lon": 2.0},
380
+ coloraxis_colorbar=dict(title=f"{indicator_label} ({unit})"), # Add legend
381
  title=f"{indicator_label} in {year} in France ({model_label}) " # Title
382
  )
383
  return fig
style.css CHANGED
@@ -671,3 +671,26 @@ div#tab-vanna{
671
  #table-names thead{
672
  display: none;
673
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
671
  #table-names thead{
672
  display: none;
673
  }
674
+
675
+ /* DRIAS Data Table Styles */
676
+ #vanna-table {
677
+ height: 400px !important;
678
+ overflow-y: auto !important;
679
+ }
680
+
681
+ #vanna-table > div[class*="table"] {
682
+ height: 400px !important;
683
+ overflow-y: None !important;
684
+ }
685
+
686
+ #vanna-table .table-wrap {
687
+ height: 400px !important;
688
+ overflow-y: None !important;
689
+ }
690
+
691
+ #vanna-table thead {
692
+ position: sticky;
693
+ top: 0;
694
+ background: white;
695
+ z-index: 1;
696
+ }