CURENT / agvis

Geo-visualization for energy system
https://ltb.curent.org
GNU General Public License v3.0
7 stars 5 forks source link

Functionality: Using Python Code for Interactive AGVis Web Sessions #32

Open jinningwang opened 1 year ago

jinningwang commented 1 year ago

Using Python Code for Interactive AGVis Web Sessions

The functionality of interaction through Python code will improve the applicability. The main use of AGVis can be classified into two aspects: 1) starting, and 2) visualizing. AGVis web is hosted using Python http.server. The visualization part is using the Leaflet. The data exchange between ANDES and AGVis is through a socket file using DiME.

It is possible to let AGVis interact with the web and the Python code through the socket file, namely, DiME client and DiME server.

Starting

Description

The modules cli and system module (available at cli and system) allows users to launch AGVis from either the command line or IPython as showing below:

Command line:

agvis run --host 127.0.0.1 --port 8810

IPython:

import agvis

web = agvis.webapp()
web.run(open_browser=True)

Update on 04/28/2023

We have developed two modules, cli and web, which enhance the starting process of AGVis web. For more information on how to use the command line interface, please refer to our documentation on Command line usage.

In this implementation, we use http.server and socketserver.TCPServer to host the web application in the background. However, Flask can be a better choice for its flexibility and usability to allow interactive usage.

Reference: https://flask.palletsprojects.com/en/2.3.x/

Visualizing

Description

After starting a web using the following code:

web = agvis.webapp()
web.run(open_browser=True)

The further interaction can be:

web.load(agvis.get_case('ieee39.xlsx'))  # Load topology into the web
web.play(andes_case='ieee39.xlsx', andes_output='ieee39_out.csv')  # play the animation with given input

web.refresh()  # Refresh the web

...

web.stop()

One possible approach for integration is to use DiME, which can start and run a DiME server backend for communication between ANDES and AGVis. However, this approach may require the packaging of DiME. See https://github.com/CURENT/dime/issues/47 for more discussion.

Then, this improvement makes it possible to integrate AGVis as a built-in visualizer for ANDES and AMS in the future.