From 0162e1b397163ea2b026512fd2ec96c5676291f0 Mon Sep 17 00:00:00 2001 From: cdkl Date: Thu, 7 Mar 2024 21:38:31 -0500 Subject: [PATCH 1/4] Fix sunrise/sunset scatters Sunrise/sunset scatter plots are misplaced for * Date ranges that are a subset of the entire DB date range * Species whose first/last detections are inside the bounds of the current date range. This fixes those problems. --- scripts/plotly_streamlit.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/scripts/plotly_streamlit.py b/scripts/plotly_streamlit.py index e376ded7a..a69f5c0b1 100755 --- a/scripts/plotly_streamlit.py +++ b/scripts/plotly_streamlit.py @@ -181,9 +181,9 @@ def time_resample(df, resample_time): font_size = 15 -def sunrise_sunset_scatter(num_days_to_display): - latitude = df2['Lat'][0] - longitude = df2['Lon'][0] +def sunrise_sunset_scatter(date_range): + latitude = df2['Lat'][-1] + longitude = df2['Lon'][-1] sun = Sun(latitude, longitude) @@ -193,13 +193,13 @@ def sunrise_sunset_scatter(num_days_to_display): sunset_week_list = [] sunrise_text_list = [] sunset_text_list = [] + daysback_range = [] now = datetime.now() - for past_day in range(num_days_to_display): - d = timedelta(days=num_days_to_display - past_day - 1) + current_date = start_date - current_date = now - d + for current_date in date_range: # current_date = datetime.fromisocalendar(2022, week + 1, 5) # time_zone = datetime.now() sun_rise = sun.get_local_sunrise_time(current_date) @@ -214,17 +214,17 @@ def sunrise_sunset_scatter(num_days_to_display): sunset_text_list.append(temp_time) sunrise_list.append(sun_rise_time) sunset_list.append(sun_dusk_time) - sunrise_week_list.append(past_day) - sunset_week_list.append(past_day) + + daysback_range.append(current_date.strftime('%d-%m-%Y')) - sunrise_week_list.append(None) sunrise_list.append(None) sunrise_text_list.append(None) sunrise_list.extend(sunset_list) - sunrise_week_list.extend(sunset_week_list) sunrise_text_list.extend(sunset_text_list) + daysback_range.append(None) + daysback_range.extend(daysback_range) - return sunrise_week_list, sunrise_list, sunrise_text_list + return daysback_range, sunrise_list, sunrise_text_list def hms_to_dec(t): @@ -464,12 +464,7 @@ def hms_to_str(t): # text=labels, texttemplate="%{text}", autocolorscale=False, colorscale=selected_pal ) - num_days_to_display = len(fig_x) - sunrise_week_list, sunrise_list, sunrise_text_list = sunrise_sunset_scatter(num_days_to_display) - daysback_range = fig_x - daysback_range.append(None) - daysback_range.extend(daysback_range) - daysback_range = daysback_range[:-1] + daysback_range, sunrise_list, sunrise_text_list = sunrise_sunset_scatter(day_hour_freq.index.tolist()) sunrise_sunset = go.Scatter(x=daysback_range, y=sunrise_list, From e92655de29f974b1ec9e2ebc1f32cf239f1524bd Mon Sep 17 00:00:00 2001 From: cdkl Date: Thu, 7 Mar 2024 22:04:24 -0500 Subject: [PATCH 2/4] Clean up lint errors --- scripts/plotly_streamlit.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/plotly_streamlit.py b/scripts/plotly_streamlit.py index a69f5c0b1..b6453e9c1 100755 --- a/scripts/plotly_streamlit.py +++ b/scripts/plotly_streamlit.py @@ -189,14 +189,10 @@ def sunrise_sunset_scatter(date_range): sunrise_list = [] sunset_list = [] - sunrise_week_list = [] - sunset_week_list = [] sunrise_text_list = [] sunset_text_list = [] daysback_range = [] - now = datetime.now() - current_date = start_date for current_date in date_range: @@ -214,7 +210,7 @@ def sunrise_sunset_scatter(date_range): sunset_text_list.append(temp_time) sunrise_list.append(sun_rise_time) sunset_list.append(sun_dusk_time) - + daysback_range.append(current_date.strftime('%d-%m-%Y')) sunrise_list.append(None) From 7189f2414eb1a610650f2f7dbfa0430c0d411b9a Mon Sep 17 00:00:00 2001 From: cdkl Date: Thu, 7 Mar 2024 22:07:25 -0500 Subject: [PATCH 3/4] Fix the lint errors created by fixing lint errors --- scripts/plotly_streamlit.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/plotly_streamlit.py b/scripts/plotly_streamlit.py index b6453e9c1..88fc0e249 100755 --- a/scripts/plotly_streamlit.py +++ b/scripts/plotly_streamlit.py @@ -12,7 +12,6 @@ import plotly.express as px from sklearn.preprocessing import normalize from suntime import Sun -from datetime import datetime profile = False if profile: From d9ca94be81b24e28c1fd3f92bcf711a644f3bacc Mon Sep 17 00:00:00 2001 From: cdkl Date: Tue, 12 Mar 2024 18:05:30 -0400 Subject: [PATCH 4/4] Restore old lat/lon determination We'll enhance this separately --- scripts/plotly_streamlit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/plotly_streamlit.py b/scripts/plotly_streamlit.py index 88fc0e249..6153d4e12 100755 --- a/scripts/plotly_streamlit.py +++ b/scripts/plotly_streamlit.py @@ -181,8 +181,8 @@ def time_resample(df, resample_time): def sunrise_sunset_scatter(date_range): - latitude = df2['Lat'][-1] - longitude = df2['Lon'][-1] + latitude = df2['Lat'][0] + longitude = df2['Lon'][0] sun = Sun(latitude, longitude)