stations_map
djangomain.dash_apps.stations_map
¤
Dash app for selecting stations and rendering them on an interactive map.
This module defines a DjangoDash application with two station checklist sections, plus a third block for spatial layer controls. GeoTIFF layers are loaded from MapLayerImport entries and rendered below station points.
Attributes¤
SCROLL_HEIGHT = '150px'
module-attribute
¤
_COLOR_MAP = {'My Stations': '#e74c3c', 'Public': '#3498db'}
module-attribute
¤
_DEFAULT_MAP_STYLE = 'carto-positron'
module-attribute
¤
_MAP_STYLE_OPTIONS = [{'label': 'Carto Positron', 'value': 'carto-positron'}, {'label': 'Carto Darkmatter', 'value': 'carto-darkmatter'}, {'label': 'OpenStreetMap', 'value': 'open-street-map'}]
module-attribute
¤
_STATION_KEYS = ('station_id', 'station_code', 'station_name', 'station_latitude', 'station_longitude')
module-attribute
¤
_map_col = dbc.Col(dcc.Graph(id='map_graph', style={'height': '50vh'}, config={'scrollZoom': True}, figure={'data': [], 'layout': {'mapbox': {'style': _DEFAULT_MAP_STYLE, 'zoom': 3.6, 'center': {'lat': -9.182731, 'lon': -60.658738}}, 'margin': {'r': 0, 't': 0, 'l': 0, 'b': 0}, 'uirevision': True, 'legend': {'title': '', 'x': 0.01, 'y': 0.99, 'bgcolor': 'rgba(255,255,255,0.8)'}}}), width=9, style={'padding': '0'})
module-attribute
¤
_sidebar = dbc.Col([_map_style_block(), html.Div(_station_block('owned', 'My Stations'), id='owned-block'), _station_block('public', 'Public Stations'), _spatial_data_block()], width=3, style={'overflowY': 'auto', 'height': '100vh', 'borderRight': '1px solid #dee2e6', 'paddingRight': '12px'})
module-attribute
¤
app = DjangoDash('StationsMap', external_stylesheets=[dbc.themes.BOOTSTRAP])
module-attribute
¤
Classes¤
Station
¤
Bases: PermissionsBase
Main representation of a station, including several metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
visibility |
str
|
Visibility level of the object, including an "internal" option. |
station_id |
int
|
Primary key. |
station_code |
str
|
Unique code for the station. |
station_name |
str
|
Brief description of the station. |
station_type |
StationType
|
Type of the station. |
country |
Country
|
Country where the station is located. |
region |
Region
|
Region within the Country where the station is located. |
ecosystem |
Ecosystem
|
Ecosystem associated with the station. |
institution |
Institution
|
Institutional partner responsible for the station. |
place_basin |
PlaceBasin
|
Place-Basin association. |
station_state |
bool
|
Is the station operational? |
timezone |
str
|
Timezone of the station. |
station_latitude |
Decimal
|
Latitude of the station, in degrees [-90 to 90]. |
station_longitude |
Decimal
|
Longitude of the station, in degrees [-180 to 180]. |
station_altitude |
int
|
Altitude of the station. |
influence_km |
Decimal
|
Area of influence in km2. |
station_file |
ImageField
|
Photography of the station. |
station_external |
bool
|
Is the station external? |
variables |
str
|
Comma-separated list of variables measured by the station. |
Attributes¤
variables_list
property
¤
Return the list of variables measured by the station.
Only variables with data in the database are returned.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: List of variables measured by the station. |
Functions¤
__str__()
¤
Return the station code.
Source code in station/models.py
458 459 460 | |
get_absolute_url()
¤
Return the absolute url of the station.
Source code in station/models.py
462 463 464 | |
set_object_permissions()
¤
Set object-level permissions.
This method is called by the save method of the model to set the object-level permissions based on the visibility level of the object. In addition to the standard permissions for the station, the view_measurements permission is set which controls who can view the measurements associated to the station.
Source code in station/models.py
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
Functions¤
_all_none_buttons(block_id)
¤
Build the bulk-selection button group for a station checklist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block_id
|
str
|
Prefix used to build the button component ids. |
required |
Returns:
| Type | Description |
|---|---|
ButtonGroup
|
Button group containing All and None buttons. |
Source code in djangomain/dash_apps/stations_map.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
_build_options(codes)
¤
Build Dash checklist option dicts from an iterable of station codes.
Each option label is "<code> - <name>" when the station has a name,
otherwise just the code. Codes are sorted alphabetically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
codes
|
Any
|
Station codes to include. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, str]]
|
Option dicts with |
Source code in djangomain/dash_apps/stations_map.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
_build_spatial_layer_row(layer_id, layer_name, visible)
¤
Build one selected-layer row with a visibility toggle and remove button.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str
|
Map layer identifier used by callbacks. |
required |
layer_name
|
str
|
Label shown to the user. |
required |
visible
|
bool
|
Whether the layer is currently visible on the map. |
required |
Returns:
| Type | Description |
|---|---|
Div
|
Row containing checkbox, name, and a remove button. |
Source code in djangomain/dash_apps/stations_map.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
_ensure_list(value)
¤
Normalise a callback input value to a plain Python list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Input that may be |
required |
Returns:
| Type | Description |
|---|---|
list
|
Empty list for falsy input; the original list; or a single-item list wrapping a scalar value. |
Source code in djangomain/dash_apps/stations_map.py
242 243 244 245 246 247 248 249 250 251 252 253 254 | |
_get_request_user(kwargs)
¤
Get callback request user from django_plotly_dash callback kwargs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwargs
|
dict
|
Callback keyword arguments from django_plotly_dash. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Authenticated user object when present, else None. |
Source code in djangomain/dash_apps/stations_map.py
292 293 294 295 296 297 298 299 300 301 302 | |
_map_style_block()
¤
Build controls for selecting the map base style.
Returns:
| Type | Description |
|---|---|
Card
|
Card containing the base map style selector. |
Source code in djangomain/dash_apps/stations_map.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
_normalise_spatial_layer_store(store_data)
¤
Normalise layer-store payload to an ordered list of unique entries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store_data
|
Any
|
List-like payload containing layer ids or entry dictionaries. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
Entries with |
Source code in djangomain/dash_apps/stations_map.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
_scrollable_checklist(block_id)
¤
Build a checklist wrapped in a fixed-height scroll container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block_id
|
str
|
Prefix used to build the checklist component id. |
required |
Returns:
| Type | Description |
|---|---|
Div
|
Scrollable container holding a |
Source code in djangomain/dash_apps/stations_map.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
_spatial_data_block()
¤
Build controls for selecting and toggling spatial layers.
Returns:
| Type | Description |
|---|---|
Card
|
Card containing a layer picker and selected-layer list. |
Source code in djangomain/dash_apps/stations_map.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
_station_block(block_id, title)
¤
Build a station-selection card containing bulk controls and a checklist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block_id
|
str
|
Prefix used for internal control ids. |
required |
title
|
str
|
Text rendered in the card header. |
required |
Returns:
| Type | Description |
|---|---|
Card
|
Card containing an All/None button group and a scrollable checklist. |
Source code in djangomain/dash_apps/stations_map.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
_station_rows_for_codes(codes, station_group)
¤
Build map rows for selected station codes in display order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
codes
|
Any
|
Selected station codes in desired output order. |
required |
station_group
|
str
|
Label used to tag rows for trace grouping. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
Station row dictionaries ready for map trace construction. |
Source code in djangomain/dash_apps/stations_map.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
_triggered_component(callback_context)
¤
Return component id from django-plotly-dash callback context.
Source code in djangomain/dash_apps/stations_map.py
334 335 336 337 338 339 | |
available_map_layers_by_id(user)
¤
Return user-viewable GeoTIFF layers keyed by dash dropdown id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
Any | None
|
Django user used to resolve object-level permissions. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, str]]
|
Layer metadata keyed by maplayer id. Returns an empty dict when the user is None or lookup fails. |
Source code in djangomain/dash_apps/geotiff_layers.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
build_mapbox_layers(layers_raw, user)
¤
Build mapbox layout layers for currently visible spatial layers.
GeoTIFF sources are resolved server-side from currently authorised MapLayerImport objects and never from client store values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layers_raw
|
list
|
Trusted spatial layer payload from server-side callback state. |
required |
user
|
Any
|
Django user used for per-object authorization. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
Mapbox image layer dictionaries for visible and authorized GeoTIFF layers. |
Source code in djangomain/dash_apps/geotiff_layers.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
checklist_selection(options, _n_all, _n_none, current_value, callback_context)
¤
Resolve station checklist selection for all/none and refresh events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
Any
|
Checklist options for the matched block. |
required |
_n_all
|
Any
|
Click count for the "All" button. |
required |
_n_none
|
Any
|
Click count for the "None" button. |
required |
current_value
|
Any
|
Currently selected option values. |
required |
callback_context
|
Any
|
Dash callback context used to inspect trigger source. |
required |
Returns:
| Type | Description |
|---|---|
list
|
Updated selected values for the matched checklist. |
Source code in djangomain/dash_apps/stations_map.py
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 | |
populate_options(all_raw, **kwargs)
¤
Populate owned and public checklist options from visible station codes.
For authenticated users the owned section is shown and populated with stations that belong to the current user; the remaining visible stations go into the public section. For anonymous users all visible stations are treated as public and the owned section is hidden.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
all_raw
|
Any
|
Raw children value of the hidden
|
required |
**kwargs
|
Any
|
Extra keyword arguments injected by |
{}
|
Returns:
| Type | Description |
|---|---|
tuple[list[dict[str, str]], list[dict[str, str]], dict]
|
Owned checklist options, public checklist options, and a CSS style dict for the owned block. |
Source code in djangomain/dash_apps/stations_map.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
sync_spatial_layer_controls(_stations_raw, _map_style_value, dropdown_layer_id, _remove_clicks, visibility_values, remove_ids, visibility_ids, store_data, callback_context, **kwargs)
¤
Sync spatial-layer picker, selected-list rows, and map visibility state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_stations_raw
|
Any
|
Unused trigger input for station list changes. |
required |
_map_style_value
|
Any
|
Current map style value. |
required |
dropdown_layer_id
|
Any
|
Layer id selected from the add-layer dropdown. |
required |
_remove_clicks
|
Any
|
Click counts from per-layer remove buttons. |
required |
visibility_values
|
Any
|
Visibility booleans for selected layer checkboxes. |
required |
remove_ids
|
Any
|
Pattern-matching ids for the remove buttons. |
required |
visibility_ids
|
Any
|
Pattern-matching ids for the visibility checkboxes. |
required |
store_data
|
Any
|
Current selected-layer store payload. |
required |
callback_context
|
Any
|
Dash callback context used to inspect trigger source. |
required |
**kwargs
|
Any
|
Callback kwargs containing request context. |
{}
|
Returns:
| Type | Description |
|---|---|
tuple[list[dict[str, Any]], list[dict[str, str]], None, list]
|
Selected layer store data, add-layer dropdown options, reset dropdown value, and selected-layer row components. |
Source code in djangomain/dash_apps/stations_map.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 | |
update_map(owned_selected, public_selected, spatial_layer_store, map_style_value, callback_context, **kwargs)
¤
Build a scatter-mapbox figure for currently selected stations and layers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
owned_selected
|
Any
|
Selected station codes from the owned checklist. |
required |
public_selected
|
Any
|
Selected station codes from the public checklist. |
required |
spatial_layer_store
|
Any
|
Selected spatial layers and their visibility. |
required |
map_style_value
|
str
|
Requested map style value. |
required |
callback_context
|
Any
|
Dash callback context used to inspect trigger source. |
required |
**kwargs
|
Any
|
Callback kwargs containing request context. |
{}
|
Returns:
| Type | Description |
|---|---|
Patch | object
|
Patch update for the map figure or no_update. |
Source code in djangomain/dash_apps/stations_map.py
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 | |