Skip to content
Snippets Groups Projects
Commit 21792f29 authored by Mark HOEBEKE's avatar Mark HOEBEKE
Browse files

Merge branch 'fixes--graph-titles-legends-fixes' into 'develop'

Fixes in graph titles / legends / axis labels.

See merge request !6
parents f90a935f 7fa292fa
No related branches found
No related tags found
3 merge requests!12Updated master with most recent from develop.,!10Merge latest from develop into main before releasing,!6Fixes in graph titles / legends / axis labels.
......@@ -59,6 +59,8 @@ def load_data(config):
m_df['Coordinates'] = list(zip(m_df['Latitude'], m_df['Longitude']))
m_df['Accepted taxon name'] = m_df['Accepted taxon name'].apply(str)
m_df.replace(to_replace={'Accepted taxon name': r"^(.*)$"}, value={'Accepted taxon name': r"<i>\1</i>"},
regex=True, inplace=True)
# Create additional columns used for aggregated bar charts.
m_df["Sampling datetime"] = pd.to_datetime(m_df['Sampling date'])
......@@ -68,6 +70,7 @@ def load_data(config):
m_df['Date offset'] = (m_df['Sampling datetime'].dt.month * 100 + m_df['Sampling datetime'].dt.day - 320) % 1300
m_df['Season'] = pd.cut(m_df['Date offset'], [0, 300, 602, 900, 1300],
labels=['Spring', 'Summer', 'Autumn', 'Winter'])
m_df.to_pickle(CACHED_MACROFAUNA_FILENAME)
if os.path.exists(CACHED_GRANULOMETRY_FILENAME):
......
......@@ -427,7 +427,8 @@ def add_remove_macrofauna_controls(next_index,active_tab_index,children,button_c
survey_select
])
taxon_options = [ taxon_name.replace("<i>","").replace("</i>","") for taxon_name in taxon_options]
taxon_value = [ taxon_name.replace("<i>","").replace("</i>","") for taxon_name in taxon_value]
taxon_dropdown = dcc.Dropdown(
id={"type": "macrofauna-taxon-dropdown", "index": next_index},
options=taxon_options,
......@@ -491,7 +492,7 @@ def add_remove_macrofauna_controls(next_index,active_tab_index,children,button_c
new_graph_type_choice,
new_agregation_choice,
],
label=f"M-Graph {next_index + 1}",
label=f"Macrofauna Graph {next_index + 1}",
)
patched_children.append(new_tab)
......@@ -572,7 +573,7 @@ def add_remove_granulometry_controls(next_index,active_tab_index,children,button
])
new_graph_type_choice = html.Div([
dbc.Label('G-Graph Type :'),
dbc.Label('Granulometry Graph Type :'),
dcc.Dropdown(
id={"type": 'granulometry-graph-type', "index": next_index},
options=[
......@@ -608,7 +609,7 @@ def add_remove_granulometry_controls(next_index,active_tab_index,children,button
new_graph_type_choice,
new_agregation_choice,
],
label=f"G-Graph {next_index + 1}",
label=f"Granulometry Graph {next_index + 1}",
)
patched_children.append(new_tab)
......@@ -745,7 +746,7 @@ def add_remove_top_taxon_controls(next_index,active_tab_index,children,button_cl
new_graph_type_choice,
new_agregation_choice,
],
label=f"T-Graph {next_index + 1}")
label=f"Top {next_index + 1}")
patched_children.append(new_tab)
......@@ -907,7 +908,8 @@ def update_taxon_dropdown(survey, id):
:return: List of updated taxon dropdown options.
"""
survey_df = bdt.macrofauna_df[bdt.macrofauna_df['Survey'] == survey]
return sorted(survey_df['Accepted taxon name'].unique())
taxon_names = [ taxon_name.replace("<i>","").replace("</i>","") for taxon_name in sorted(survey_df['Accepted taxon name'].unique())]
return taxon_names
@callback(
......@@ -971,6 +973,8 @@ def update_macrofauna_graph(survey, selected_taxa, start_date, end_date, aggrega
# Filter the dataframe based on the selected taxonomic groups and date range
if selected_taxa is None:
selected_taxa=[]
else:
selected_taxa = [ f"<i>{taxon_name}</i>" for taxon_name in selected_taxa]
if start_date is None:
start_date = datetime.date(1900,1,1)
......@@ -1011,7 +1015,7 @@ def update_macrofauna_graph(survey, selected_taxa, start_date, end_date, aggrega
pie_data = filtered_df.groupby('Accepted taxon name', as_index=False)['Count'].mean()
fig = px.pie(pie_data, names='Accepted taxon name',
values='Count',
title=f"M-Graph {graph_type} {id['index'] + 1}: Occurrence Count of selected taxon in survey {survey} ",)
title=f"Macrofauna Graph {graph_type} {id['index'] + 1}: Avg. number of individuals per m² in survey {survey}",)
elif graph_type == 'box':
time_group='Sampling date'
......@@ -1028,7 +1032,7 @@ def update_macrofauna_graph(survey, selected_taxa, start_date, end_date, aggrega
x=time_group,
y='Count',
color='Accepted taxon name',
title=f"M-Graph {graph_type} {id['index'] + 1}: Occurrence distribution in survey {survey} ",
title=f"Macrofauna Graph {graph_type} {id['index'] + 1}: Avg. number of individuals per m² in survey {survey}",
)
fig.update_yaxes(title="Avg. individuals per m²")
......@@ -1072,8 +1076,8 @@ def update_macrofauna_graph(survey, selected_taxa, start_date, end_date, aggrega
traces.append(trace)
layout = go.Layout(
title=f"M-Graph {graph_type} {id['index'] + 1}: Occurrences in survey {survey} ",
xaxis={'title': 'Sampling date'}, yaxis={'title': 'Avg. individuals per m²'})
title=f"Macrofauna Graph {graph_type} {id['index'] + 1}: Average number of individuals per m² in survey {survey} ",
xaxis={'title': 'Sampling date'}, yaxis={'title': 'Avg. number of individuals per m²'})
fig = go.Figure(data=traces, layout=layout)
if aggregation == 'sample':
......@@ -1212,8 +1216,8 @@ def update_granulometry_graph(selected_survey, start_date, end_date, aggregation
fig.update_layout(
barmode='group',
xaxis_title='Sampling Date - Survey',
yaxis_title='Value',
title=f"G-Graph {graph_type} {id['index'] + 1}: Occurrence Value of Mesh sizes in selected Surveys",
yaxis_title='Weight of Fractions (%)',
title=f"Granulometry Graph {graph_type} {id['index'] + 1}: Weight percentages of particle size fractions",
legend_title='Mesh Size',
xaxis_tickangle=-45,
)
......@@ -1236,8 +1240,8 @@ def update_granulometry_graph(selected_survey, start_date, end_date, aggregation
fig.update_layout(
barmode='stack',
xaxis_title='Sampling Date - Survey',
yaxis_title='Value',
title=f"G-Graph {graph_type} {id['index'] + 1}: Occurrence Value of Mesh sizes in selected Surveys",
yaxis_title='Weight of Fractions (%)',
title=f"Granulometry Graph {graph_type} {id['index'] + 1}: Weight percentages of particle size fractions",
legend_title='Mesh Size',
xaxis_tickangle=-45,
legend_traceorder='normal',
......@@ -1256,7 +1260,7 @@ def update_granulometry_graph(selected_survey, start_date, end_date, aggregation
fig = px.pie(
pie_data,
names='Mesh size', values='Value',
title=f"G-Graph {graph_type} {id['index'] + 1}: Occurrence Value of Mesh size in selected surveys",
title=f"Granulometry Graph {graph_type} {id['index'] + 1}: Weight percentages of particle size fractions",
facet_col='Survey',
facet_col_wrap=min(num_survey, 3),
height=fig_height, # Set the height of the figure dynamically
......@@ -1338,7 +1342,6 @@ def update_top_taxon_graph(survey, graph_type, start_date, end_date, aggregation
(bdt.macrofauna_df['Sampling datetime'].dt.date <= end_date)
].copy()
top_taxons = filtered_df['Accepted taxon name'].value_counts().head(top_taxon_input).index.tolist()
top_taxons.append('Others')
......@@ -1366,7 +1369,7 @@ def update_top_taxon_graph(survey, graph_type, start_date, end_date, aggregation
if graph_type == 'pie':
fig = px.pie(filtered_df, names='Accepted taxon name', labels={'Accepted taxon name': 'Accepted taxon name'},
title=f"T-Graph {graph_type} {id['index'] + 1}: Top {top_taxon_input} taxon in survey {survey}")
title=f"Top Graph {graph_type} {id['index'] + 1}: Top {top_taxon_input} taxons in survey {survey}")
fig.update_layout(legend_title_text=(f"Top {top_taxon_input} Taxons"),
title="Avg. individuals per m²")
......@@ -1376,7 +1379,7 @@ def update_top_taxon_graph(survey, graph_type, start_date, end_date, aggregation
x=time_group,
y='Count',
color='Accepted taxon name',
title=f"T-Graph {graph_type} {id['index'] + 1}: Top {top_taxon_input} taxon in survey {survey}",
title=f"Top Graph {graph_type} {id['index'] + 1}: Top {top_taxon_input} taxons in survey {survey}",
)
fig.update_yaxes(title="Avg. individuals per m²")
fig.update_layout(
......@@ -1387,7 +1390,7 @@ def update_top_taxon_graph(survey, graph_type, start_date, end_date, aggregation
elif graph_type == 'histogram':
fig = px.histogram(filtered_df, x=time_group, y='Count', color='Accepted taxon name',
labels={'Accepted taxon name': 'Accepted taxon name'},
title=f"T-Graph {graph_type} {id['index'] + 1}: Top {top_taxon_input} taxon in survey {survey}" )
title=f"Top Graph {graph_type} {id['index'] + 1}: Top {top_taxon_input} taxons in survey {survey}" )
fig.update_layout(
xaxis=dict(title='Sampling Date',),
yaxis=dict(title='Avg. individuals per m²'),
......@@ -1398,7 +1401,7 @@ def update_top_taxon_graph(survey, graph_type, start_date, end_date, aggregation
elif graph_type == 'stacked histogram':
fig = px.histogram(filtered_df, x=time_group, y='Count', color='Accepted taxon name',
barmode='stack', labels={'Accepted taxon name': 'Accepted taxon name'},
title=f"T-Graph {graph_type} {id['index'] + 1}: Top {top_taxon_input} taxon in survey {survey}" )
title=f"Top Graph {graph_type} {id['index'] + 1}: Top {top_taxon_input} taxon in survey {survey}" )
fig.update_yaxes(title="Avg. individuals per m²")
fig.update_layout(
xaxis=dict(title='Sampling Date', ),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment