<div dir="ltr"><div>Hello all,</div><div><br></div><div>Here is my final report on my GSoC project, Improved Integration of GRASS GIS and Jupyter Notebooks. Thank you to all who provided comments, feedback and tested my work in Binder. Also, a <b>huge</b> thank you to my mentors Vaclav Petras, Helena Mitasova and Stefan Blumentrath.</div><div><br></div><div>You can find a more detailed version of this report on the wiki page: <a href="https://trac.osgeo.org/grass/wiki/GSoC/2021/JupyterAndGRASS">https://trac.osgeo.org/grass/wiki/GSoC/2021/JupyterAndGRASS</a></div><div><br></div><div>You can also test out grass.jupyter, the subpackage I wrote this summer, from your browser in Binder here: <a href="https://mybinder.org/v2/gh/OSGeo/grass/c173461?urlpath=lab%2Ftree%2Fdoc%2Fnotebooks%2Fgrass_jupyter.ipynb">https://mybinder.org/v2/gh/OSGeo/grass/c173461?urlpath=lab%2Ftree%2Fdoc%2Fnotebooks%2Fgrass_jupyter.ipynb</a></div><div><br></div><div>Best,</div><div>Caitlin</div><div><b><br></b></div><b>Improved Integration of GRASS GIS and Jupyter Notebooks</b><br><br><b>Abstract:</b><br>This project introduces a new subpackage for GRASS GIS, grass.jupyter that improves the integration of GRASS GIS with Jupyter Notebooks. The grass.jupyter subpackage introduces a new startup function, init(), and two display classes, GrassRenderer and InteractiveMap, specifically for making the usage of GRASS in Jupyter more simple and intuitive. GrassRenderer renders GRASS maps as PNG images and InteractiveMap displays rasters and vectors interactively with folium [1], a leaflet library for Python.<br><br><b>The state of integration BEFORE GSoC:</b><br>The previous integration of GRASS GIS and Jupyter Notebooks required a cumbersome environment variable setup after launching GRASS from within the notebook. There is an external python library grass_session that can be installed to shorten this launch substantially but, as an external library, it is not included in a typical GRASS install. Additionally, maps were rendered as PNG images using a relatively unintuitive sequence: calling d.erase, then modules from the display family and finally rendering the image with IPython.display.Image(). There was also no simple way to zoom or toggle between layers.<br><br><b>The state of integration AFTER GSoC:</b><br>With the help of my mentors, I introduced a new package grass.jupyter that contains a new init() function to shorten the launch and two display-related classes, GrassRenderer and InteractiveMap. GrassRenderer wraps the previous approach, rendering PNG images but with a more intuitive syntax. InteractiveMap, the other display-related class in `grass.jupyter`, allows users to view GRASS vectors and rasters in folium, a leaflet library for Python. After creating an instance of InteractiveMap, users can add vectors and rasters with add_vector() and add_raster(). Users can also add a layer control element with add_layer_control(). <br><br><b>Conclusion:</b><br>In this project, I was successful in accomplishing the three goals stated at the beginning (thanks to my mentors!):<br><ol><li>creating new initiation functions for the launch of GRASS GIS in Jupyter Notebooks (init())</li><li>creating functions for more intuitive map display (GrassRenderer)</li><li>introducing an interactive map display function (InteractiveMap)</li></ol>I am grateful for the support I've received this summer and for the opportunity to contribute to GRASS GIS. I'm looking forward to continuing to improve `grass.jupyter`.<br><br><b>Future Work:</b><br><ul><li>Height and width defaults in `GrassRenderer` should be derived from computational region</li><li>init() should fail and report an appropriate error if a mapset that doesn't exist is provided</li><li>Add folium Tooltip method to InteractiveMap, allowing users to access vector attribute data by clicking on feature</li><li>Add simpleCRS option to add_raster method in InteractiveMap</li><li>Improve color options in InteractiveMap</li><li>Add option to display rasters as vectors (pixels -> polygon) in InteractiveMap</li><li>Clip vectors to computational region in InteractiveMap (currently the whole vector dataset is displayed)</li><li>Add more interactive functions such as a timeline slider for temporal datasets</li><li>InteractiveMap doesn't allow users to fully access folium. In the future, a new interface that allows users direct access to folium should be added. For example, it could look like: gj.Raster("elevation").add_to(folium_map)</li></ul><b>Permanent Links:</b><br><i>OSGeo Wiki Page:</i> <a href="https://trac.osgeo.org/grass/wiki/GSoC/2021/JupyterAndGRASS">https://trac.osgeo.org/grass/wiki/GSoC/2021/JupyterAndGRASS</a><br><i>OSGeo-GRASS github project page:</i> <a href="https://github.com/OSGeo/grass/projects/7">https://github.com/OSGeo/grass/projects/7</a><br><i>Github repo</i>: <a href="https://github.com/chaedri/grass/tree/master/python/grass/jupyter">https://github.com/chaedri/grass/tree/master/python/grass/jupyter</a><br><br><b>Binder Examples:</b><br><a href="https://mybinder.org/v2/gh/OSGeo/grass/c173461?urlpath=lab%2Ftree%2Fdoc%2Fnotebooks%2Fgrass_jupyter.ipynb">https://mybinder.org/v2/gh/OSGeo/grass/c173461?urlpath=lab%2Ftree%2Fdoc%2Fnotebooks%2Fgrass_jupyter.ipynb</a><br><a href="https://mybinder.org/v2/gh/OSGeo/grass/c173461?urlpath=lab%2Ftree%2Fdoc%2Fnotebooks%2Fbasic_example_grass_jupyter.ipynb">https://mybinder.org/v2/gh/OSGeo/grass/c173461?urlpath=lab%2Ftree%2Fdoc%2Fnotebooks%2Fbasic_example_grass_jupyter.ipynb</a><br><a href="https://mybinder.org/v2/gh/OSGeo/grass/c173461?urlpath=lab%2Ftree%2Fdoc%2Fnotebooks%2Fhydrology.ipynb">https://mybinder.org/v2/gh/OSGeo/grass/c173461?urlpath=lab%2Ftree%2Fdoc%2Fnotebooks%2Fhydrology.ipynb</a><br><a href="https://mybinder.org/v2/gh/OSGeo/grass/c173461?urlpath=lab%2Ftree%2Fdoc%2Fnotebooks%2Fviewshed_analysis.ipynb">https://mybinder.org/v2/gh/OSGeo/grass/c173461?urlpath=lab%2Ftree%2Fdoc%2Fnotebooks%2Fviewshed_analysis.ipynb</a><br><a href="https://mybinder.org/v2/gh/OSGeo/grass/c173461?urlpath=lab%2Ftree%2Fdoc%2Fnotebooks%2Fsolar_potential.ipynb">https://mybinder.org/v2/gh/OSGeo/grass/c173461?urlpath=lab%2Ftree%2Fdoc%2Fnotebooks%2Fsolar_potential.ipynb</a><div><br></div><div><b>References:</b></div><div>[1]
<a href="https://python-visualization.github.io/folium/index.html">https://python-visualization.github.io/folium/index.html</a><br><br></div></div>