riu-rd commited on
Commit
d64bc5f
·
verified ·
1 Parent(s): 284420b

Updated Temp and Bio

Browse files
klimainsights/pages/__pycache__/biodiversity.cpython-311.pyc CHANGED
Binary files a/klimainsights/pages/__pycache__/biodiversity.cpython-311.pyc and b/klimainsights/pages/__pycache__/biodiversity.cpython-311.pyc differ
 
klimainsights/pages/__pycache__/temperature.cpython-311.pyc CHANGED
Binary files a/klimainsights/pages/__pycache__/temperature.cpython-311.pyc and b/klimainsights/pages/__pycache__/temperature.cpython-311.pyc differ
 
klimainsights/pages/biodiversity.py CHANGED
@@ -14,6 +14,7 @@ px.set_mapbox_access_token(MAPBOX_TOKEN)
14
  # Import Data
15
  biodiversity_gdf = gpd.read_file(datasets_folder / 'biodiversity.geojson')
16
  temperature_gdf = gpd.read_file(datasets_folder / 'temperature.geojson')
 
17
 
18
  melt_value = temperature_gdf.drop(columns=[col for col in temperature_gdf.columns if 'TempDiff' in col])
19
  melt_value.columns = [col.split('_')[0] if '_value' in col else col for col in melt_value.columns]
@@ -38,7 +39,7 @@ layout = dbc.Container(className="d-flex justify-content-center align-items-cent
38
  id='bio-switch',
39
  on=False,
40
  color="#b58900",
41
- label="Show Avg Temp Increase Per Province"
42
  ),
43
  html.H4(className="mt-2", children=[
44
  "Exploring Biodiversity in the Philippines"
@@ -46,22 +47,22 @@ layout = dbc.Container(className="d-flex justify-content-center align-items-cent
46
  html.P(className="", children=[
47
  "Discover the rich biodiversity of the Philippines and understand its distribution across different regions. Use the selector to filter by geographic region and explore the geospatial distribution of biodiversity as well as the composition of endangered species."
48
  ]),
 
 
 
 
 
 
 
 
49
  dcc.Loading(type="circle", children=[dcc.Graph(id="biodiversity-choropleth")])
50
  ])
51
  ]),
52
  dbc.Col(className="rounded z-3 biodiversity-map-height overflow-hidden", width=12, md=8, children=[
53
  html.Div(className="text-dark z-3 align-self-start", children=[
54
  html.Div(className='d-flex flex-row justify-content-between align-items-center', children=[
55
- html.Div(className='w-50', children=[
56
  dcc.Dropdown(options=['Luzon', 'Visayas', 'Mindanao'], value='Luzon', id='region-dropdown', multi=False, searchable=False, clearable=False)
57
- ]),
58
- html.Div(className='w-50', children=[
59
- dcc.Dropdown(options=[{'label': 'Total', 'value': 'total_species'},
60
- {'label': 'Critically Endangered', 'value': 'Critically Endangered'},
61
- {'label': 'Endangered', 'value': 'Endangered'},
62
- {'label': 'Vulnerable', 'value': 'Vulnerable'}],
63
- value='total_species', id='species-dropdown',
64
- multi=False, searchable=False, clearable=False)
65
  ])
66
  ]),
67
  html.Div(children=[
@@ -100,7 +101,7 @@ def update_choropleth(region, species_type):
100
  txt = species_type
101
  # Create choropleth map using Plotly Express
102
  choropleth_fig = px.choropleth_mapbox(filtered_data,
103
- height=550,
104
  geojson=filtered_data.geometry,
105
  locations=filtered_data.index,
106
  color=species_type, # Change based on biodiversity metric
@@ -127,19 +128,14 @@ def update_choropleth(region, species_type):
127
  # Bar Figure
128
  @callback(
129
  Output('endangered-species-bar', 'figure'),
130
- [Input('region-dropdown', 'value'), Input('species-dropdown', 'value'), Input('bio-switch', 'on'), Input('biodiversity-choropleth', 'clickData')]
131
  )
132
- def update_bar(region, species_type, bio_switch, click_data):
133
  # if region == "Sea":
134
  # filtered_data = biodiversity_gdf[(biodiversity_gdf['area_type'].isin(['Sea']))].reset_index().drop(columns='index')
135
  # else:
136
 
137
- filtered_data = biodiversity_gdf[biodiversity_gdf['island_group'] == region].sort_values(by=species_type, ascending=True, ignore_index=True)
138
-
139
- if species_type == "total_species":
140
- txt = "Total"
141
- else:
142
- txt = species_type
143
 
144
  if bio_switch:
145
  if click_data is not None:
@@ -178,17 +174,34 @@ def update_bar(region, species_type, bio_switch, click_data):
178
 
179
  else:
180
  bar_fig = px.bar(filtered_data,
181
- x=species_type,
182
- y='name',
183
- title=txt + " Species Composition in " + region,
184
- orientation='h',
185
- height=750,
186
- color_discrete_sequence=['lightblue']
187
- )
188
  bar_fig.update_layout(
189
- xaxis_title=txt + " Count",
190
- yaxis_title="Province",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  )
192
- hover_template = '<b>%{y}</b><br>' + txt + ' Count: %{x}<extra></extra>'
193
  bar_fig.update_traces(hovertemplate=hover_template)
194
  return bar_fig
 
14
  # Import Data
15
  biodiversity_gdf = gpd.read_file(datasets_folder / 'biodiversity.geojson')
16
  temperature_gdf = gpd.read_file(datasets_folder / 'temperature.geojson')
17
+ biodiversity_gdf = biodiversity_gdf.rename(columns={"Critically Endangered": "Critical"})
18
 
19
  melt_value = temperature_gdf.drop(columns=[col for col in temperature_gdf.columns if 'TempDiff' in col])
20
  melt_value.columns = [col.split('_')[0] if '_value' in col else col for col in melt_value.columns]
 
39
  id='bio-switch',
40
  on=False,
41
  color="#b58900",
42
+ label="Show Avg Temp Increase Per Province",
43
  ),
44
  html.H4(className="mt-2", children=[
45
  "Exploring Biodiversity in the Philippines"
 
47
  html.P(className="", children=[
48
  "Discover the rich biodiversity of the Philippines and understand its distribution across different regions. Use the selector to filter by geographic region and explore the geospatial distribution of biodiversity as well as the composition of endangered species."
49
  ]),
50
+ html.Div(className='w-100', children=[
51
+ dcc.Dropdown(options=[{'label': 'Total', 'value': 'total_species'},
52
+ {'label': 'Critically Endangered', 'value': 'Critical'},
53
+ {'label': 'Endangered', 'value': 'Endangered'},
54
+ {'label': 'Vulnerable', 'value': 'Vulnerable'}],
55
+ value='total_species', id='species-dropdown',
56
+ multi=False, searchable=False, clearable=False)
57
+ ]),
58
  dcc.Loading(type="circle", children=[dcc.Graph(id="biodiversity-choropleth")])
59
  ])
60
  ]),
61
  dbc.Col(className="rounded z-3 biodiversity-map-height overflow-hidden", width=12, md=8, children=[
62
  html.Div(className="text-dark z-3 align-self-start", children=[
63
  html.Div(className='d-flex flex-row justify-content-between align-items-center', children=[
64
+ html.Div(className='w-100', children=[
65
  dcc.Dropdown(options=['Luzon', 'Visayas', 'Mindanao'], value='Luzon', id='region-dropdown', multi=False, searchable=False, clearable=False)
 
 
 
 
 
 
 
 
66
  ])
67
  ]),
68
  html.Div(children=[
 
101
  txt = species_type
102
  # Create choropleth map using Plotly Express
103
  choropleth_fig = px.choropleth_mapbox(filtered_data,
104
+ height=500,
105
  geojson=filtered_data.geometry,
106
  locations=filtered_data.index,
107
  color=species_type, # Change based on biodiversity metric
 
128
  # Bar Figure
129
  @callback(
130
  Output('endangered-species-bar', 'figure'),
131
+ [Input('region-dropdown', 'value'), Input('bio-switch', 'on'), Input('biodiversity-choropleth', 'clickData')]
132
  )
133
+ def update_bar(region, bio_switch, click_data):
134
  # if region == "Sea":
135
  # filtered_data = biodiversity_gdf[(biodiversity_gdf['area_type'].isin(['Sea']))].reset_index().drop(columns='index')
136
  # else:
137
 
138
+ filtered_data = biodiversity_gdf[(biodiversity_gdf['area_type'].isin(['Land'])) & (biodiversity_gdf['island_group'].isin([region]))].sort_values(by='total_species', ascending=True, ignore_index=True)
 
 
 
 
 
139
 
140
  if bio_switch:
141
  if click_data is not None:
 
174
 
175
  else:
176
  bar_fig = px.bar(filtered_data,
177
+ x=['Vulnerable', 'Endangered', 'Critical'],
178
+ y='name',
179
+ title='Number of Unique Species<br>at Risk in ' + region,
180
+ orientation='h',
181
+ height=750,
182
+ color_discrete_sequence=['yellow', 'orange', 'red'],
183
+ )
184
  bar_fig.update_layout(
185
+ xaxis_title='Unique Species',
186
+ yaxis_title='Province',
187
+ legend_title='IUCN Category',
188
+ legend=dict(
189
+ x=0.99,
190
+ y=0.01,
191
+ xanchor='right',
192
+ yanchor='bottom',
193
+ traceorder='normal',
194
+ font=dict(
195
+ family='Arial',
196
+ size=12,
197
+ color='black'
198
+ ),
199
+ bgcolor='rgba(255, 255, 255, 0.6)',
200
+ bordercolor='rgba(0, 0, 0, 0.6)',
201
+ borderwidth=1,
202
+ ),
203
+ margin=dict(l=0, r=0, t=70, b=60)
204
  )
205
+ hover_template = '<b>%{y}</b><br>Unique Species: %{x}<extra></extra>'
206
  bar_fig.update_traces(hovertemplate=hover_template)
207
  return bar_fig
klimainsights/pages/temperature.py CHANGED
@@ -279,12 +279,19 @@ def update_bar_fig(island_value, switch):
279
  Input('temp-map-dropdown', 'value')
280
  )
281
  def update_map_fig(decade_value):
 
 
 
 
 
 
282
  map_fig = px.choropleth_mapbox(temperature_gdf,
283
  geojson=temperature_gdf.geometry,
284
  locations=temperature_gdf.index,
285
  color=decade_value,
286
- color_continuous_scale='turbo',
287
  range_color=[25, 33],
 
288
  mapbox_style='streets',
289
  zoom=5,
290
  center={"lat": 12.8797, "lon": 122.7740},
@@ -293,7 +300,7 @@ def update_map_fig(decade_value):
293
  map_fig.update_layout(
294
  coloraxis_colorbar=dict(title=f"{remove_value(decade_value)}<br>Average<br>Temperature(°C)", yanchor="top", xanchor='left',
295
  y=1, x=0, ticks="outside", ticklabelposition="outside left", thickness=10, title_font_color='#0c232c',
296
- tickvals=[i for i in range(25, 33)],
297
  tickmode='array',
298
  ticksuffix='°C',
299
  tickfont=dict(
 
279
  Input('temp-map-dropdown', 'value')
280
  )
281
  def update_map_fig(decade_value):
282
+ tempscale = [
283
+ [0, 'blue'],
284
+ [0.75, 'red'],
285
+ [1, 'rgb(255, 96, 96)']
286
+ ]
287
+
288
  map_fig = px.choropleth_mapbox(temperature_gdf,
289
  geojson=temperature_gdf.geometry,
290
  locations=temperature_gdf.index,
291
  color=decade_value,
292
+ color_continuous_scale=tempscale,
293
  range_color=[25, 33],
294
+ # color_continuous_midpoint=28,
295
  mapbox_style='streets',
296
  zoom=5,
297
  center={"lat": 12.8797, "lon": 122.7740},
 
300
  map_fig.update_layout(
301
  coloraxis_colorbar=dict(title=f"{remove_value(decade_value)}<br>Average<br>Temperature(°C)", yanchor="top", xanchor='left',
302
  y=1, x=0, ticks="outside", ticklabelposition="outside left", thickness=10, title_font_color='#0c232c',
303
+ tickvals=[i for i in range(0, 33)],
304
  tickmode='array',
305
  ticksuffix='°C',
306
  tickfont=dict(
plotly_interactions.ipynb CHANGED
@@ -13,6 +13,7 @@
13
  "import plotly.express as px\n",
14
  "from pathlib import Path\n",
15
  "from klimainsights.environment.settings import MAPBOX_TOKEN\n",
 
16
  "\n",
17
  "datasets_folder = Path('./klimainsights/data')\n",
18
  "px.set_mapbox_access_token(MAPBOX_TOKEN)"
@@ -94,6 +95,26 @@
94
  "temp_melted_gdf.head()"
95
  ]
96
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  {
98
  "cell_type": "code",
99
  "execution_count": null,
@@ -629,6 +650,15 @@
629
  "- DropDown/RadioButtons that switch between \"Luzon, Visayas, and Mindanao\" (same button as BIO 2)"
630
  ]
631
  },
 
 
 
 
 
 
 
 
 
632
  {
633
  "cell_type": "code",
634
  "execution_count": null,
@@ -636,31 +666,47 @@
636
  "outputs": [],
637
  "source": [
638
  "# Set Island Group\n",
639
- "land_gdf = biodiversity_gdf[(biodiversity_gdf['area_type'].isin(['Land'])) & (biodiversity_gdf['island_group'].isin(['Luzon']))].sort_values(by='total_species', ascending=True)\n",
640
  "\n",
641
  "# Create stacked bar plot using Plotly Express\n",
642
- "fig = px.bar(land_gdf,\n",
643
- " x=['Vulnerable', 'Endangered', 'Critically Endangered'], \n",
644
  " y='name', \n",
645
- " title='Number of Unique Endangered Species in Luzon',\n",
646
- " labels={'Vulnerable', 'Endangered', 'Critically Endangered'}, \n",
647
  " orientation='h', \n",
648
- " height=600, \n",
649
  " color_discrete_sequence=['yellow', 'orange', 'red'], \n",
650
  " )\n",
651
  "\n",
652
- "fig.update_layout(\n",
653
- " xaxis_title='Number of Unique Species', \n",
654
  " yaxis_title='Province',\n",
655
- " legend_title='Category',\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
656
  ")\n",
657
  "\n",
658
- "hover_template = '<b>%{customdata[0]}</b><br>Unique Species: %{x}<extra></extra>'\n",
659
  "\n",
660
- "fig.update_traces(hovertemplate=hover_template,\n",
661
  " customdata=land_gdf[['name']])\n",
662
  "\n",
663
- "fig.show()"
664
  ]
665
  },
666
  {
 
13
  "import plotly.express as px\n",
14
  "from pathlib import Path\n",
15
  "from klimainsights.environment.settings import MAPBOX_TOKEN\n",
16
+ "import math\n",
17
  "\n",
18
  "datasets_folder = Path('./klimainsights/data')\n",
19
  "px.set_mapbox_access_token(MAPBOX_TOKEN)"
 
95
  "temp_melted_gdf.head()"
96
  ]
97
  },
98
+ {
99
+ "cell_type": "code",
100
+ "execution_count": null,
101
+ "metadata": {},
102
+ "outputs": [],
103
+ "source": [
104
+ "lowest = math.floor(temp_melted_gdf['value'].min())\n",
105
+ "highest = math.ceil(temp_melted_gdf['value'].max())\n",
106
+ "lowest_1960 = math.floor(temperature_gdf['1960s_value'].min())\n",
107
+ "highest_1960 = math.ceil(temperature_gdf['1960s_value'].max())\n",
108
+ "\n",
109
+ "print(f\"All Time Low: {lowest}\")\n",
110
+ "print(f\"Midpoint: {(highest + lowest) / 2:.0f}\")\n",
111
+ "print(f\"All Time High: {highest}\")\n",
112
+ "print(\"- - - - - -\")\n",
113
+ "print(f\"All Time Low 1960s: {lowest_1960}\")\n",
114
+ "print(f\"Midpoint 1960s: {(highest_1960 + lowest_1960) / 2:.0f}\")\n",
115
+ "print(f\"All Time High 1960s: {highest_1960}\")"
116
+ ]
117
+ },
118
  {
119
  "cell_type": "code",
120
  "execution_count": null,
 
650
  "- DropDown/RadioButtons that switch between \"Luzon, Visayas, and Mindanao\" (same button as BIO 2)"
651
  ]
652
  },
653
+ {
654
+ "cell_type": "code",
655
+ "execution_count": null,
656
+ "metadata": {},
657
+ "outputs": [],
658
+ "source": [
659
+ "filtered_data = biodiversity_gdf[biodiversity_gdf['island_group'] == 'Luzon'].sort_values(by='total_species', ascending=True, ignore_index=True)"
660
+ ]
661
+ },
662
  {
663
  "cell_type": "code",
664
  "execution_count": null,
 
666
  "outputs": [],
667
  "source": [
668
  "# Set Island Group\n",
669
+ "land_gdf = biodiversity_gdf[(biodiversity_gdf['area_type'].isin(['Land'])) & (biodiversity_gdf['island_group'].isin(['Luzon']))].sort_values(by='total_species', ascending=True, ignore_index=True)\n",
670
  "\n",
671
  "# Create stacked bar plot using Plotly Express\n",
672
+ "bar_fig = px.bar(land_gdf,\n",
673
+ " x={'Vulnerable':\"Vulnerable\", 'Endangered':\"Endangered\", 'Critically Endangered':\"Critical\"}, \n",
674
  " y='name', \n",
675
+ " title='Number of Unique Species<br>at Risk in Luzon',\n",
676
+ " labels={'Vulnerable':\"Vulnerable\", 'Endangered':\"Endangered\", 'Critically Endangered':\"Critical\"}, \n",
677
  " orientation='h', \n",
678
+ " height=750, \n",
679
  " color_discrete_sequence=['yellow', 'orange', 'red'], \n",
680
  " )\n",
681
  "\n",
682
+ "bar_fig.update_layout(\n",
683
+ " xaxis_title='Unique Species', \n",
684
  " yaxis_title='Province',\n",
685
+ " legend_title='IUCN Category',\n",
686
+ " legend=dict(\n",
687
+ " x=0.99,\n",
688
+ " y=0.01,\n",
689
+ " xanchor='right',\n",
690
+ " yanchor='bottom',\n",
691
+ " traceorder='normal',\n",
692
+ " font=dict(\n",
693
+ " family='Arial',\n",
694
+ " size=12,\n",
695
+ " color='black'\n",
696
+ " ),\n",
697
+ " bgcolor='rgba(255, 255, 255, 0.6)',\n",
698
+ " bordercolor='rgba(0, 0, 0, 0.6)',\n",
699
+ " borderwidth=1,\n",
700
+ " ),\n",
701
+ " margin=dict(l=0, r=0, t=70, b=60)\n",
702
  ")\n",
703
  "\n",
704
+ "hover_template = '<b>%{y}</b><br>Unique Species: %{x}<extra></extra>'\n",
705
  "\n",
706
+ "bar_fig.update_traces(hovertemplate=hover_template,\n",
707
  " customdata=land_gdf[['name']])\n",
708
  "\n",
709
+ "bar_fig.show()"
710
  ]
711
  },
712
  {