Package: nismod-snail
Tutorials|IssuesThis code is under early development🤔 What is this?This is a Python package to help with analysis of the potential impacts of
climate hazards and other perils on infrastructure networks.InstallationInstall using pip:pip install nismod-snailThis should bring all dependencies with it. If any of these cause difficulties,
try using acondaenvironment:conda env create -n snail_env \
    python=3.8 geopandas shapely rasterio python-igraph
conda activate snail_env
pip install nismod-snailIf all worked okay, you should be able to run python and import snail:$ python
>>> import snail
>>> help(snail)
Help on package snail:

NAME
    snail - snail - the spatial networks impact assessment libraryUsing thesnailcommandOnce installed, you can usesnaildirectly from the command line.Split features on a grid defined by its transform, width and height:snailsplit\--featuresinput.shp\--transform10-1800-190\--width360\--height180\--outputsplit.gpkgSplit features on a grid defined by a GeoTIFF, optionally adding the values from each raster band to each split feature as a new attribute:snailsplit\--featureslines.geojson\--rastergridded_data.tif\--attribute\--outputsplit_lines_with_raster_values.geojsonSplit multiple vector feature files along the grids defined by multiple raster files, attributing all raster values:snailprocess-fsfeatures.csv-rsrasters.csvWhere at a minimum, each CSV has a columnpathwith the path to each file.TransformA note ontransform- these six numbers define the transform fromi,jcell index (column/row) coordinates in the rectangular grid tox,ygeographic coordinates, in the coordinate reference system of the input and output files. They effectively form the first two rows of a 3x3 matrix:| x |   | a  b  c | | i |
| y | = | d  e  f | | j |
| 1 |   | 0  0  1 | | 1 |In cases without shear or rotation,aandedefine scaling or grid cell size, whilecandfdefine the offset or grid upper-left corner:| x_scale 0       x_offset |
| 0       y_scale y_offset |
| 0       0       1        |Seerasterio/affineandGDAL Raster Data Modelfor more documentation.DevelopmentClone this repository usingGitHub Desktopor on
the command line:git clone git@github.com:nismod/snail.gitChange directory into the root of the project:cd snailTo create and activate a conda environment with snail's dependencies installed:conda env create -f .environment.yml
conda activate snail-devRun this to install the source code as a package:pip install .If you're working on snail itself, install it as "editable" along with test and
development packages:pip install -e .[dev]Run tests usingpytestandpytest-covto check coverage:pytest --cov=snail --cov-report=term-missingRun a formatter (black) to fix code
formatting:black src/snailWhen working on the tutorial notebooks, it is recommended to install and
configurenbstripoutso data and outputs
are not committed in the notebook files:nbstripout --installC++ libraryThe C++ library inextension/srccontains the core routines to find intersections of
lines with raster grids.Before working on the C++ library, fetch source code for Catch2 unit testing
library (this is included as a git submodule):git submodule update --init --recursiveBuild the library and run tests:cmake -Bbuild ./extension
cmake --build build/
./build/run_testsRun code style auto-formatting:clang-format -i extension/src/*.{cpp,hpp}Run lints and checks:clang-tidy --checks 'cppcoreguidelines-*' extension/src/*.{cpp,hpp}This may need some includes forpybind11- which will vary depending on your
python installation. For example, with python via miniconda:clang-tidy --checks 'cppcoreguidelines-*' extension/src/* -- \
    -I/home/username/miniconda3/include/python3.11/ \
    -I./pybind11/include/Or with C++ headers installed on a Linux machine:clang-tidy --checks 'cppcoreguidelines-*' extension/src/* -- \
    -std=c++14  \
    -I/usr/include/x86_64-linux-gnu/c++/11 \
    -I/usr/include/c++/11 \
    -I{$PWD}/extension/extern/pybind11/include \
    -I/usr/include/python3.10Integration of C++ and Python using pybind11Thesnail.core.intersectionsmodule is built usingpybind11withscikit-build-core(seedocs)extension/src/intersections.cppdefines the module interface using thePYBIND11_MODULEmacropyproject.tomldefines the build requirements for snail, which includes
pybind11 and scikit-build-coreAcknowledgmentsMIT LicenseCopyright (c) 2020-23 Tom Russell and allsnail contributorsThis library is developed by researchers in theOxford Programme for Sustainable
Infrastructure Systemsat the University of Oxford,
funded by multiple research projects.This research received funding from the FCDO Climate Compatible Growth Programme.
The views expressed here do not necessarily reflect the UK government's official
policies.