/fire2a-lib

Algorithms and tools python package

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

Friendly graphical user interface click here

PyPI workflow auto pdoc workflow PyPI Version Python Versions License Downloads Code Style

fire2a-lib python package

Fire Advanced Analyitics research group scriptable knowledge base

  • Novel Algorithms related to landscape risk metrics, spatial decision optimization models, etc.
  • (Cell2) Fire (W) Simulator integration algorithms to facilitating placing firebreaks, measuring forest fire impacts, etc.
  • (Q)GIS algorithms to common tasks related to rasters, polygons, spatial clustering, etc.

Quickstart

Simplest: Use within QGIS

  1. Install QGIS
  2. Open QGIS Python Console
  3. To install, type :
!pip install fire2a-lib
  1. Visit fire2a-lib documentation, example:
from fire2a.downstream_protection_value import digraph_from_messages
digraph = digraph_from_messages('messages01.csv')

Command line usage

  1. Install QGIS
  • Docker users check qgis container
  • [Optional but] Recommended for Windows: Make the bundled python writable by your user :
    • A. Open cmd administrator terminal, type (adjust path): icacls "C:\Program Files\QGIS 3.38.3\apps\Python312" /grant %username%:F
    • B. Open powershell...
    • C. Explore till 2ndary click the folder>Properties...
  1. Locate python, prepare environment
  • 2.A. Windows
    • Open OsGeo4W Shell application,
    • Run bin\python-qgis.bat once to configure all environment variables in the current session.
    • Also you could: bin\python-qgis.bat your_script.py
    • Recommended persistent integrations
  • 2.B. macOS
    • Open terminal application,
    • Use this python: /Applications/QGIS.app/Contents/MacOS/bin/python (see creating an alias below)
    • TODO: are all environment variables right?
  • 2.C. Linux
    python3 -m venv --system-site-packages qgis_venv
    source qgis_venv/bin/activate
    
  1. Install
python -m pip install fire2a-lib ipython (...)
  1. Visit fire2a-lib documentation, example for getting the burn probability from a simulator results directory:
python -m fire2a.cell2fire -vvv --base-raster ../fuels.asc --authid EPSG:25831 --scar-sample Grids/Grids2/ForestGrid03.csv --scar-poly propagation_scars.shp --burn-prob burn_probability.tif

Scripting/Developing tips

  • Check standalone scripting for more info on initializing a headless QGIS environment
  • Usage examples
  • macOS users add a permanent alias, on the terminal app
    echo "alias pythonq='/Applications/QGIS.app/Contents/MacOS/bin/python'" >> ~/.zshrc

Interactive

  • debbuging:
breakpoint()
from IPython import embed
embed()
  • sessions, with: IPython, qtconsole, jupyter-lab, or IPyConsole (QGIS plugin) compatible
# Interactive explore from IPython
In [1]: from fire2a.<press-tab>

# Select and Copy a whole module from line 1 up -but not included- to 'def main def main(argv=None):' line 
In [2]: %paste

# Choose your args 
In [3]: args = arg_parser.parse_args(['-vvv', '--base-raster', ...
# Skip:
    if argv is sys.argv:
        argv = sys.argv[1:]
    args = arg_parser(argv)

# Ready

Code of Conduct

Everyone interacting in the project's codebases, issue trackers, chat rooms, and fora is expected to follow the PSF Code of Conduct.