Skip to main content

sgsPy - Structurally Guided Sampling

Downloads

sgsPy is a toolbox package of stratification and sampling methods for use on ALS metrics, designed to be fast and efficient on very large raster images.

Installation

sgsPy can be downloaded on either Windows or Linux from the Python Package Index (PyPI) with the following command:

pip install sgspy

Overview

sgsPy is based on the widely-used sgsR package, intended originally to help develop representative ground sample networks using auxiliary information like ALS data. sgsPy takes much of the existing functionality of the R package and improves upon its performance, allowing Python users to integrate structurally guided sampling approaches to their workflows.

While the original intention for the package was to be used with ALS metrics, any form of raster data can be used in lieu of ALS metrics.

If you encounter any bugs, unclear documentation, or have any feature ideas then please contribute by posting an issue. https://github.com/jbmeyer2001/sgsPy/issues

The currently implemented functionality includes:

Quickstart guide

files

Some helpful files to get started with can be found in the https://github.com/jbmeyer2001/sgsPy/tree/main/tests/files folder. Specifically mraster.tif, inventory_polygons.shp along with its associated .dbf, .prj, and .shx files, access.shp along with its associated .dbf, .prj, and .shx files, existing.shp along with its associated .dbf, .prj, and .shx files.

raster and vector data

The two classes used by the stratification, sampling, and calculating methods are the sgspy.SpatialRaster [SpatialRaster documentation] and sgspy.SpatialVector [SpatialVector documentation]. The beginning of any process using the sgspy package will involve creating an instance of one or more of these classes. This can be done by providing a file path. It can also be done by converting an object from a popular geospatial package.

import sgspy

#creating SpatialRaster and SpatialVector using file paths
rast = sgspy.SpatialRaster("mraster.tif")
vect = sgspy.SpatialVector("access.shp")

#plotting
rast.plot(band=0)
rast.plot(band="pzabove2")

#accessing underlying data as a numpy array
zq90_arr = rast.band("zq90")
first_band_arr = rast.band(0)

#to/from GDAL raster dataset
ds = gdal.Open("mraster.tif")
rast = sgspy.SpatialRaster.from_gdal(ds)
new_ds = rast.to_gdal()

#to/from rasterio dataset
ds = rasterio.open("mraster.tif")
rast = sgspy.SpatialRaster.from_rasterio(ds)
new_ds = rast.to_rasterio()

#to/from geopandas
gdf = gpd.read_file("inventory_polygons.shp")
vect = sgspy.SpatialVector.from_geopandas(gdf)
new_gdf = gpd.to_geopandas(vect)

example

More extensive examples on how to use each method is available in the user documentation. The following shows how one might use three of the different methods available in sgspy to create a new sampling network.

import sgspy

# create SpatialRaster object from desired tif file
rast = sgspy.SpatialRaster("mraster.tif")

# use principal component analysis for dimensionality reduction (to two components or raster layers)
pca = sgspy.calculate.pca(rast, num_comp=2)

# stratifiy the two components into 5 equally sized quantiles, and map the two layers into a single mapped output
srast = sgspy.stratify.quantiles(pca, quantiles={"comp_1":5, "comp2":5}, map=True)

# use stratified random sampling to sample each (of the 25 total) mapped strata proportional to it's number of pixels in the raster band
# additionaly, plot the output and write it to samples.shp
samples = sgspy.sample.strat(srast, band="map_strat", num_samples=200, num_strata=25, allocation="prop", plot=True, filename="samples.shp")

Funding

The development of the sgsPy package was funded by the Ontario Future Forests (KTTD 2B-2024) grant.

Developer information

This section includes installation steps for both Windows and Linux, in addition to notes on running the code. See the Developer Documentation for information on the underlying C++ implementations.

Linux installation:

  1. Ensure you have Python with pip installed, and git.
  2. clone the repository with the following command:
git clone https://github.com/jbmeyer2001/sgsPy.git
  1. create and activate a python virtual environment (highly recommended)
python -m venv .venv
source ./.venv/bin/activate
  1. install dependency requirements. If you do not already have these, the dependency installation will fail.
  • build-essential (if you don't already have a C++ compiler)
  • pkg-config
  • auto-conf
  • libtool
  • bison
  • flex
  • patchelf
sudo apt install build-essential
sudo apt install pkg-config
sudo apt install auto-conf
sudo apt install libtool
sudo apt install bison
sudo apt install flex
sudo apt install patchelf
  1. Run the following command to install and build project C++ dependencies.
bash scripts/install.sh
  1. Run the following command to build the project
bash scripts/build.sh
  1. If you intend to run the tests (using pytest), both pytest and geopandas are required and can be installed as follows:
pip install pytest
pip install geopandas

Windows installation:

NOTE: The commands given are for a Windows Powershell command prompt.

  1. ensure you have Python with pip, git, and a C++ compiler.

  2. If you do not already have a C++ compiler, one can installed by installing the Microsoft Visual Studio IDE with C++ build tools.

  3. clone the repository with the following command.

git clone https://github.com/jbmeyer2001/sgsPy.git
  1. create and activate a Python virtual environment (highly recommended).
python -m venv .venv
./.venv/Scripts/activate
  1. Run the following command to install and build project C++ dependencies. remaining dependencies
./scripts/install
  1. Run the following command to build the project
./scripts/build
  1. If you intend to run the tests (using pytest), both pytest and geopandas are required and can be installed as follow:
pip install pytest
pip install geopandas

How to run sgsPy:

Tests may be ran by running the following command from within the folder containing this file. Both pytest and geopandas must be installed to run the tests.

pytest

Metadata

Release files for sgspy 1.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for sgspy 1.0.11
File Actions
sgspy-1.0.11-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for sgspy-1.0.11-cp314-cp314-win_amd64.whl
sgspy-1.0.11-cp314-cp314-manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64 Details for sgspy-1.0.11-cp314-cp314-manylinux_2_28_x86_64.whl
sgspy-1.0.11-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for sgspy-1.0.11-cp313-cp313-win_amd64.whl
sgspy-1.0.11-cp313-cp313-manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64 Details for sgspy-1.0.11-cp313-cp313-manylinux_2_28_x86_64.whl
sgspy-1.0.11-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for sgspy-1.0.11-cp312-cp312-win_amd64.whl
sgspy-1.0.11-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details for sgspy-1.0.11-cp312-cp312-manylinux_2_28_x86_64.whl
sgspy-1.0.11-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for sgspy-1.0.11-cp311-cp311-win_amd64.whl
sgspy-1.0.11-cp311-cp311-manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64 Details for sgspy-1.0.11-cp311-cp311-manylinux_2_28_x86_64.whl
sgspy-1.0.11-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details for sgspy-1.0.11-cp310-cp310-win_amd64.whl
sgspy-1.0.11-cp310-cp310-manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64 Details for sgspy-1.0.11-cp310-cp310-manylinux_2_28_x86_64.whl

Total release size: 317.6 MB

Release files / sgspy-1.0.11-cp314-cp314-win_amd64.whl

Download URL sgspy-1.0.11-cp314-cp314-win_amd64.whl
Size 28.0 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
52705d49d8662fc88bef43ea2d3da44525dd35f582cee5549c48d5cf16f3c33c
BLAKE2b-256 checksum
How to use checksums
273bd20e9a6c660f0526753abadf0c6e1344220193f70abbe6f2bb727dbfc9e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 4, 2026.

Transparency log

Release files / sgspy-1.0.11-cp314-cp314-manylinux_2_28_x86_64.whl

Download URL sgspy-1.0.11-cp314-cp314-manylinux_2_28_x86_64.whl
Size 36.2 MB
Tags CPython 3.14 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
7c9a4cea4eb137993f329abbb906a41134125d6a862cc258e68f3a992a555ffa
BLAKE2b-256 checksum
How to use checksums
a81cf6aa96b408573acb895e4f9fcbdd4b56405776ca40e5ca35336c2935047d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 4, 2026.

Transparency log

Release files / sgspy-1.0.11-cp313-cp313-win_amd64.whl

Download URL sgspy-1.0.11-cp313-cp313-win_amd64.whl
Size 27.2 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
6d1239fc1e160e8044766c6c97b84c59416086a80e117b2ff2411e66c88ac936
BLAKE2b-256 checksum
How to use checksums
bf7cfd74a588424e1b5f622b2d8ffaec39290a870b000789219f932197482480
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 4, 2026.

Transparency log

Release files / sgspy-1.0.11-cp313-cp313-manylinux_2_28_x86_64.whl

Download URL sgspy-1.0.11-cp313-cp313-manylinux_2_28_x86_64.whl
Size 36.2 MB
Tags CPython 3.13 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
b24f9525d3fa503260dd76dae6ce6616d14369c47c14f1112fb221aafcb0a6ba
BLAKE2b-256 checksum
How to use checksums
db1dc46af1d633f0a7f252945b5000dde9a46544815b740a337a16c258491710
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 4, 2026.

Transparency log

Release files / sgspy-1.0.11-cp312-cp312-win_amd64.whl

Download URL sgspy-1.0.11-cp312-cp312-win_amd64.whl
Size 27.2 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
6c1f4b73359a55e6133c679cc6233a99669ac5760c75cf1f76ba27852ad19d73
BLAKE2b-256 checksum
How to use checksums
b4861d19f723124c1ee430e6d5062ee392769698d3e09d5f107b4a71c63db09b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 4, 2026.

Transparency log

Release files / sgspy-1.0.11-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL sgspy-1.0.11-cp312-cp312-manylinux_2_28_x86_64.whl
Size 36.2 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
f6b352967d9c0435aea1de5051e5e258bcf0b8fc019c119334574b922c841829
BLAKE2b-256 checksum
How to use checksums
5a26234745429da751ebb9cd2297111138ad0462b947270168fb7fbb1122691e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 4, 2026.

Transparency log

Release files / sgspy-1.0.11-cp311-cp311-win_amd64.whl

Download URL sgspy-1.0.11-cp311-cp311-win_amd64.whl
Size 27.2 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
42bead2cc46d778e17cb6fe7307f29d6ac2fd5635b316d0977039e74ec69f55a
BLAKE2b-256 checksum
How to use checksums
10ed40a1f80b4a4363d8f0d6aa0f05e89291eacd4d4d1237781969ffa32f6fc7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 4, 2026.

Transparency log

Release files / sgspy-1.0.11-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL sgspy-1.0.11-cp311-cp311-manylinux_2_28_x86_64.whl
Size 36.2 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
83da56fb54ffbb94f4f2a63ba99af0e0fa0ec930b5cdebb4cd58c9cc91c20124
BLAKE2b-256 checksum
How to use checksums
99dc9ffa186787ffdf35c5368d8cf6b70774ca172039e602d75cd31aecf5d4ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 4, 2026.

Transparency log

Release files / sgspy-1.0.11-cp310-cp310-win_amd64.whl

Download URL sgspy-1.0.11-cp310-cp310-win_amd64.whl
Size 27.2 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
f6c9cb0849fcfa03c497c8fa6f030d28f9f6d86ff49da90bdc24c1a06b9b01fa
BLAKE2b-256 checksum
How to use checksums
acd0ab929655b8217f9abeea7f2eee08b266ac0db71af93931e99f366901d4e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 4, 2026.

Transparency log

Release files / sgspy-1.0.11-cp310-cp310-manylinux_2_28_x86_64.whl

Download URL sgspy-1.0.11-cp310-cp310-manylinux_2_28_x86_64.whl
Size 36.2 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
016a5750d25f694d064cc28e93b3fb16030bdfc1886c40f80e478887e482fb63
BLAKE2b-256 checksum
How to use checksums
9f8777aa06753ed308dfb0327f6f530d54f4883cff9dc2dcf648288de6f68d6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 4, 2026.

Transparency log

Security for sgspy 1.0.11

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 10 files in this release have been uploaded with provenance metadata.

Select from 10 files

Attestation for sgspy-1.0.11-cp314-cp314-win_amd64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page