diff --git a/notebooks/utils.py b/notebooks/utils.py
index 2d9e491..0c78f5e 100644
--- a/notebooks/utils.py
+++ b/notebooks/utils.py
@@ -14,6 +14,7 @@
import pandas as pd
import rasterio
from catboost import CatBoostClassifier, Pool
+from IPython.core.display import HTML as core_HTML
from IPython.display import display
from loguru import logger
from matplotlib.patches import Rectangle
@@ -30,6 +31,7 @@
logging.getLogger("rasterio").setLevel(logging.ERROR)
+############# DEFINING TEMPORAL EXTENT #############
class date_slider:
"""Class that provides a slider for selecting a processing period.
The processing period is fixed in length, amounting to one year.
@@ -38,40 +40,121 @@ class date_slider:
def __init__(self, start_date=datetime(2018, 1, 1), end_date=datetime(2023, 12, 1)):
- self.start_date = start_date
- self.end_date = end_date
-
+ # Define the slider
dates = pd.date_range(start_date, end_date, freq="MS")
options = [(date.strftime("%b %Y"), date) for date in dates]
self.interval_slider = widgets.SelectionRangeSlider(
options=options,
index=(0, 11), # Default to a 11-month interval
orientation="horizontal",
+ description="",
continuous_update=False,
- readout=True,
behaviour="drag",
- layout={"width": "90%", "height": "100px", "margin": "0 auto 0 auto"},
style={
"handle_color": "dodgerblue",
},
+ layout=widgets.Layout(
+ width="600px",
+ margin="0 0 0 10px",
+ ),
+ readout=False,
)
- self.selected_range = [
- pd.to_datetime(start_date),
- pd.to_datetime(start_date) + pd.DateOffset(months=12) - timedelta(days=1),
- ]
- def on_slider_change(self, change):
- start, end = change["new"]
- # keep the interval fixed
- expected_end = start + pd.DateOffset(months=11)
- if end != expected_end:
- end = start + pd.DateOffset(months=11)
- self.interval_slider.value = (start, end)
- self.selected_range = (start, end + pd.DateOffset(months=1) - timedelta(days=1))
+ # Define the HTML text widget for the selected range and focus time
+ initial_range = [
+ (pd.to_datetime(start_date)).strftime("%d %b %Y"),
+ (
+ pd.to_datetime(start_date)
+ + pd.DateOffset(months=12)
+ - timedelta(days=1)
+ ).strftime("%d %b %Y"),
+ ]
+ initial_focus_time = (
+ pd.to_datetime(start_date) + pd.DateOffset(months=6)
+ ).strftime("%b %Y")
+ self.html_text = widgets.HTML(
+ value=f"Selected range: {initial_range[0]} - {initial_range[1]}
Focus time: {initial_focus_time}",
+ placeholder="HTML placeholder",
+ description="",
+ layout=widgets.Layout(justify_content="center", display="flex"),
+ )
- def show_slider(self):
+ # Attach slider observer
self.interval_slider.observe(self.on_slider_change, names="value")
+ # Add custom CSS for the ticks
+ custom_css = """
+
+ """
+
+ # # Generate ticks
+ tick_dates = pd.date_range(
+ start_date, pd.to_datetime(end_date) + pd.DateOffset(months=1), freq="4MS"
+ )
+ tick_labels = [date.strftime("%b %Y") for date in tick_dates]
+ n_labels = len(tick_labels)
+ ticks_html = ""
+ for i, label in enumerate(tick_labels):
+ position = (i / (n_labels - 1)) * 100 # Position as a percentage
+ ticks_html += f"""
+