Fix sunrise/sunset scatter plots (#16)
* 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. * Clean up lint errors * Fix the lint errors created by fixing lint errors * Restore old lat/lon determination We'll enhance this separately
This commit is contained in:
+10
-20
@@ -12,7 +12,6 @@ from sqlite3 import Connection
|
||||
import plotly.express as px
|
||||
from sklearn.preprocessing import normalize
|
||||
from suntime import Sun
|
||||
from datetime import datetime
|
||||
|
||||
profile = False
|
||||
if profile:
|
||||
@@ -181,7 +180,7 @@ top_N_species = (df5.value_counts()[:top_N])
|
||||
font_size = 15
|
||||
|
||||
|
||||
def sunrise_sunset_scatter(num_days_to_display):
|
||||
def sunrise_sunset_scatter(date_range):
|
||||
latitude = df2['Lat'][0]
|
||||
longitude = df2['Lon'][0]
|
||||
|
||||
@@ -189,17 +188,13 @@ def sunrise_sunset_scatter(num_days_to_display):
|
||||
|
||||
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 past_day in range(num_days_to_display):
|
||||
d = timedelta(days=num_days_to_display - past_day - 1)
|
||||
|
||||
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 +209,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)
|
||||
|
||||
sunrise_week_list.append(None)
|
||||
daysback_range.append(current_date.strftime('%d-%m-%Y'))
|
||||
|
||||
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 +459,7 @@ if daily is False:
|
||||
# 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,
|
||||
|
||||
Reference in New Issue
Block a user