lombricquiver
  • Home
  • About
  • User Guide
    • Getting Started
    • At Easy
    • Usage Examples
    • Comparison
  • Documentation
    • API Reference
  • Previous
  • Next
  • Edit on GitHub
  • Wrapper - AT EASY
  • Select a region of interest - (ROI)
  • Select Date
  • Select Time
  • Adding features to the animation

Wrapper - AT EASY¶

This notebook is dedicated to demonstrate the capabilities of lombricquiver, focusing on UI experience and wrapping up all the pre-processing, settings and scene animation within a few lines of code.

If you want to dive into lombricquiver, please go through Getting Started, Usage Examples and Examples files on github repository.

In [1]:
Copied!
import ipyleaflet
from ipyleaflet import Map, DrawControl
import ipywidgets as widgets
from IPython.display import display
import ipywidgets as widgets
from lombricquiver.wrapper import wrapper_vector_field_animation
import datetime
import ipyleaflet from ipyleaflet import Map, DrawControl import ipywidgets as widgets from IPython.display import display import ipywidgets as widgets from lombricquiver.wrapper import wrapper_vector_field_animation import datetime

Select a region of interest - (ROI)¶

In [2]:
Copied!
## Europe
m = Map(center=(50.0, 6.5), zoom=4)

# Create draw control for rectangles only
draw_control = DrawControl()
draw_control.rectangle = {"shapeOptions": {"fillOpacity": 0.3}}
draw_control.polygon = {}  # Disable polygon
draw_control.polyline = {}  # Disable polyline
draw_control.circle = {}  # Disable circle
draw_control.marker = {}  # Disable marker

# Global variable to store the bbox
rectangle_bbox = None

# Output widget
output = widgets.Output()

# Handle rectangle drawing
def handle_draw(target, action, geo_json):
    global rectangle_bbox
    
    if action == 'created':
        with output:
            output.clear_output()
            # Get current map bounds using built-in method
            bounds = m.bounds
            print(f"Map bounds: {bounds}")
            
            # Extract bbox from drawn rectangle
            coords = geo_json['geometry']['coordinates'][0]
            lons = [coord[0] for coord in coords]
            lats = [coord[1] for coord in coords]
            rectangle_bbox = [min(lons), min(lats), max(lons), max(lats)]
            print(f"Rectangle bbox: {rectangle_bbox}")
            print(f"Bbox stored in variable 'rectangle_bbox'")

# Function to get the current bbox
def get_bbox():
    """Return the current rectangle bbox"""
    return rectangle_bbox

draw_control.on_draw(handle_draw)
m.add_control(draw_control)

# Display
display(m)
display(output)
## Europe m = Map(center=(50.0, 6.5), zoom=4) # Create draw control for rectangles only draw_control = DrawControl() draw_control.rectangle = {"shapeOptions": {"fillOpacity": 0.3}} draw_control.polygon = {} # Disable polygon draw_control.polyline = {} # Disable polyline draw_control.circle = {} # Disable circle draw_control.marker = {} # Disable marker # Global variable to store the bbox rectangle_bbox = None # Output widget output = widgets.Output() # Handle rectangle drawing def handle_draw(target, action, geo_json): global rectangle_bbox if action == 'created': with output: output.clear_output() # Get current map bounds using built-in method bounds = m.bounds print(f"Map bounds: {bounds}") # Extract bbox from drawn rectangle coords = geo_json['geometry']['coordinates'][0] lons = [coord[0] for coord in coords] lats = [coord[1] for coord in coords] rectangle_bbox = [min(lons), min(lats), max(lons), max(lats)] print(f"Rectangle bbox: {rectangle_bbox}") print(f"Bbox stored in variable 'rectangle_bbox'") # Function to get the current bbox def get_bbox(): """Return the current rectangle bbox""" return rectangle_bbox draw_control.on_draw(handle_draw) m.add_control(draw_control) # Display display(m) display(output)
Map(center=[50.0, 6.5], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_out_…
Output()
In [8]:
Copied!
## Retrieve lat lon coordinates from the rectangle bbox
min_lon, min_lat, max_lon, max_lat = rectangle_bbox
## Retrieve lat lon coordinates from the rectangle bbox min_lon, min_lat, max_lon, max_lat = rectangle_bbox

Select Date¶

In [ ]:
Copied!
# Global variable to store selected date
selected_date = None

# Create date picker widget (simplest approach)
date_picker = widgets.DatePicker(
    description='Select Date:',
    value=datetime.date(2024,1,1),  # Default to today
    disabled=False
)

# Output widget to display selected date
output = widgets.Output()

# Function to handle date selection
def on_date_change(change):
    global selected_date
    selected_date = change['new']
    
    with output:
        output.clear_output()
        print(f"Selected date: {selected_date}")
        print(f"Formatted: {selected_date.strftime('%Y-%m-%d')}")

# Attach the event handler
date_picker.observe(on_date_change, names='value')

# Function to get the selected date
def get_selected_date():
    """Return the currently selected date"""
    return selected_date

# Display the calendar
display(date_picker)
display(output)
# Global variable to store selected date selected_date = None # Create date picker widget (simplest approach) date_picker = widgets.DatePicker( description='Select Date:', value=datetime.date(2024,1,1), # Default to today disabled=False ) # Output widget to display selected date output = widgets.Output() # Function to handle date selection def on_date_change(change): global selected_date selected_date = change['new'] with output: output.clear_output() print(f"Selected date: {selected_date}") print(f"Formatted: {selected_date.strftime('%Y-%m-%d')}") # Attach the event handler date_picker.observe(on_date_change, names='value') # Function to get the selected date def get_selected_date(): """Return the currently selected date""" return selected_date # Display the calendar display(date_picker) display(output)
DatePicker(value=datetime.date(2024, 1, 1), description='Select Date:', step=1)
Output()
In [21]:
Copied!
selected_date.strftime('%Y-%m-%d')
selected_date.strftime('%Y-%m-%d')
Out[21]:
'2023-06-06'

Select Time¶

In [4]:
Copied!
# Time options: 00:00 to 23:00
time_options = [f"{hour:02d}:00" for hour in range(24)]

# Create dropdown widget
time_selector = widgets.Dropdown(
    options=time_options,
    description='Select Time:',
    value="00:00",
    style={'description_width': 'initial'}
)

# Initialize variable
selected_time = time_selector.value

# Define observer function
def on_time_change(change):
    global selected_time
    selected_time = change['new']
    print(f"Time selected: {selected_time}")

# Attach observer
time_selector.observe(on_time_change, names='value')

# Display the widget
display(time_selector)
# Time options: 00:00 to 23:00 time_options = [f"{hour:02d}:00" for hour in range(24)] # Create dropdown widget time_selector = widgets.Dropdown( options=time_options, description='Select Time:', value="00:00", style={'description_width': 'initial'} ) # Initialize variable selected_time = time_selector.value # Define observer function def on_time_change(change): global selected_time selected_time = change['new'] print(f"Time selected: {selected_time}") # Attach observer time_selector.observe(on_time_change, names='value') # Display the widget display(time_selector)
Dropdown(description='Select Time:', options=('00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '…
In [8]:
Copied!
selected_time
selected_time
Out[8]:
'10:00'
In [5]:
Copied!
my_api_key = 'edh_pat_2c59e9fe84c8eca2eb93f46a103a833fbfc6f4d752f9f1289ca957330b1d683e6137026aeb8d7750deb7972c4521413e'
my_api_key = 'edh_pat_2c59e9fe84c8eca2eb93f46a103a833fbfc6f4d752f9f1289ca957330b1d683e6137026aeb8d7750deb7972c4521413e'
In [17]:
Copied!
int(selected_time[:2])
int(selected_time[:2])
Out[17]:
10
In [6]:
Copied!
Animation = wrapper_vector_field_animation(
    API_KEY = my_api_key,
    date = selected_date.strftime('%Y-%m-%d'),
    roi = rectangle_bbox,
    time = selected_time
)
Animation = wrapper_vector_field_animation( API_KEY = my_api_key, date = selected_date.strftime('%Y-%m-%d'), roi = rectangle_bbox, time = selected_time )
Checking Connection with Destination Earth
Retrieving data from ERA5...
Pre-Processing Data...
Pre-processing complete. Creating animation...
Geographic extent: -5.75°E to 10.00°E, 42.25°N to 50.50°N
Aspect ratio: 1.32
Figure dimensions: 5.31 × 7.00 inches
c:\Users\Emanuel\miniconda3\envs\manim\Lib\site-packages\cartopy\io\__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/10m_physical/ne_10m_land.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
c:\Users\Emanuel\miniconda3\envs\manim\Lib\site-packages\cartopy\io\__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/10m_physical/ne_10m_coastline.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
c:\Users\Emanuel\miniconda3\envs\manim\Lib\site-packages\cartopy\io\__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/10m_cultural/ne_10m_admin_0_boundary_lines_land.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
Final image size: 1594 × 2100 pixels
Image saved as:base_layer.png
All good, background image path set to: base_layer.png
In [7]:
Copied!
## Run Manim Scene using inline
%manim -ql -v WARNING Animation
## Run Manim Scene using inline %manim -ql -v WARNING Animation
Manim Community v0.19.0

                                                          
Your browser does not support the video element.

Adding features to the animation¶

In [9]:
Copied!
Animation = wrapper_vector_field_animation(
    API_KEY = my_api_key,
    date = selected_date.strftime('%Y-%m-%d'),
    roi = rectangle_bbox,
    time = selected_time,
    include_features = True,
    title = 'ERA5 Wind Animation',
    colorized_animation = True,
    colorscheme = 'viridis'
)
Animation = wrapper_vector_field_animation( API_KEY = my_api_key, date = selected_date.strftime('%Y-%m-%d'), roi = rectangle_bbox, time = selected_time, include_features = True, title = 'ERA5 Wind Animation', colorized_animation = True, colorscheme = 'viridis' )
Checking Connection with Destination Earth
Retrieving data from ERA5...
Pre-Processing Data...
Pre-processing complete. Creating animation...
Geographic extent: 63.00°E to 90.00°E, 6.50°N to 36.00°N
Aspect ratio: 0.85
Figure dimensions: 8.21 × 7.00 inches
Final image size: 2461 × 2100 pixels
Image saved as:base_layer.png
All good, background image path set to: base_layer.png
In [10]:
Copied!
## Run Manim Scene using inline
%manim -ql -v WARNING Animation
## Run Manim Scene using inline %manim -ql -v WARNING Animation
Manim Community v0.19.0

Colorbar saved as the following file_name: colorbar
                                                          
Your browser does not support the video element.

Copyright © 2023 Emanuel Goulart
Documentation built with MkDocs.

Keyboard Shortcuts

Keys Action
? Open this help
n Next page
p Previous page
s Search