-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added track database for refactored tc and track selector
- Loading branch information
1 parent
2967e0a
commit bd0f3fb
Showing
6 changed files
with
178 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
window: | ||
title: Select Cyclone Track ... | ||
width: 800 | ||
height: 500 | ||
module: cht_cyclones.track_selector | ||
variable_group: cyclone_track_selector | ||
modal: true | ||
cancel: true | ||
element: | ||
- style: edit | ||
variable: distance | ||
method: edit_filter | ||
text: Distance (km) | ||
position: | ||
x: 100 | ||
y: 70 | ||
width: 50 | ||
height: 20 | ||
- style: edit | ||
variable: year0 | ||
method: edit_filter | ||
text: Year | ||
position: | ||
x: 100 | ||
y: 45 | ||
width: 50 | ||
height: 20 | ||
- style: edit | ||
variable: year1 | ||
method: edit_filter | ||
position: | ||
x: 160 | ||
y: 45 | ||
width: 50 | ||
height: 20 | ||
- style: mapbox | ||
id: track_selector_map | ||
position: | ||
x: 20 | ||
y: 100 | ||
width: -20 | ||
height: -20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import os | ||
|
||
def track_selector(database, app, lon=0.0, lat=0.0, distance=1000.0, year_min=1850, year_max=2030): | ||
|
||
app.gui.setvar("cyclone_track_selector", "lon", lon) | ||
app.gui.setvar("cyclone_track_selector", "lat", lat) | ||
app.gui.setvar("cyclone_track_selector", "distance", distance) | ||
app.gui.setvar("cyclone_track_selector", "year0", year_min) | ||
app.gui.setvar("cyclone_track_selector", "year1", year_max) | ||
app.gui.setvar("cyclone_track_selector", "name", "") | ||
|
||
data = {} | ||
data["track_database"] = database | ||
|
||
# Read GUI config file | ||
config_file = os.path.join(os.path.dirname(__file__), "cyclone_track_selector.yml") | ||
okay, data = app.gui.popup(config_file, id="track_selector", data=data) | ||
|
||
track = None | ||
if okay: | ||
# Get the track from the database | ||
track = database.get_track(data["database_index"]) | ||
|
||
return track, okay | ||
|
||
def map_ready(widget): | ||
|
||
print("Selector map is ready !") | ||
|
||
gui = widget.element.gui | ||
|
||
mp = gui.popup_window["track_selector"].find_element_by_id("track_selector_map").widget | ||
mp.jump_to(0.0, 0.0, 1) | ||
data = gui.popup_data | ||
# Container layers | ||
data["track_selector"]["main_layer"] = mp.add_layer("track_selector") | ||
# Tracks layers | ||
data["track_selector"]["track_layer"] = data["track_selector"]["main_layer"].add_layer( | ||
"tracks", | ||
type="line_selector", | ||
file_name="tracks.geojson", | ||
select=select_track, | ||
selection_type="single", | ||
line_color="dodgerblue", | ||
line_width=2, | ||
line_color_selected="red", | ||
line_width_selected=3, | ||
hover_param="description", | ||
) | ||
|
||
# Update data in tracks layer | ||
update_tracks(gui) | ||
|
||
|
||
def update_tracks(gui): | ||
|
||
data = gui.popup_data | ||
|
||
tdb = data["track_selector"]["track_database"] | ||
tracks_layer = data["track_selector"]["track_layer"] | ||
|
||
# Get filter data | ||
distance = gui.getvar("cyclone_track_selector", "distance") | ||
year_min = gui.getvar("cyclone_track_selector", "year0") | ||
year_max = gui.getvar("cyclone_track_selector", "year1") | ||
lon = gui.getvar("cyclone_track_selector", "lon") | ||
lat = gui.getvar("cyclone_track_selector", "lat") | ||
|
||
# Get indices based on filter | ||
index = tdb.filter( | ||
lon=lon, lat=lat, distance=distance, year_min=year_min, year_max=year_max | ||
) | ||
|
||
# Get GeoDataFrame of tracks | ||
gdf = tdb.to_gdf(index=index) | ||
|
||
tracks_layer.set_data(gdf, 0) | ||
|
||
|
||
def map_moved(coords, widget): | ||
pass | ||
|
||
|
||
def select_track(feature, widget): | ||
widget.element.gui.popup_data["track_selector"]["database_index"] = feature["properties"]["database_index"] | ||
|
||
|
||
def edit_filter(val, widget): | ||
update_tracks(widget.element.gui) |