Skip to main content

Faster-Raster

pypi image License

fasterraster is a fast multi-threaded python library for performing raster operations using openMP and numpy objects complete with simple IO.

Motivation

fasterraster was developed to quickly perform raster operations, enabling self-supervised learning for raster based analyses. fasterraster provides a cython wrapper for optimized openMP c code. Data objects are handled by numpy allowing for straightforward memory management. Currently only computation of visual/morphological features have been implemented however this is open to expansion in the future. All code is still in development and thus it is recommended to test fully before use.

Installation

fasterraster has currently been tested on Linux and Microsoft windows operating systems. You will need python>=3.6 installed. It is recommended to install fasterraster within a virtual environment.

Install using pip

To install fasterraster from PyPI using pip:

pip install fasterraster

Install from source

To build fasterraster from source, download this repository and run:

python3 setup.py build_ext --inplace

Note: You will need to have the required build dependencies installed.

Example

import timeit
import numpy as np
import fasterraster as fr
from pathlib import Path

NTESTS = 10

# Load a .bil file containing a DEM
fname = Path('./test_data/dem.bil')
dem = fr.read(fname)

# regular python implementation of hillshade function
# from https://www.neonscience.org/resources/learning-hub/tutorials/create-hillshade-py
def py_hillshade(dem, cell_size, azimuth=330, altitude=30):
    azimuth = 360.0 - azimuth

    dem = dem / cell_size
    x, y = np.gradient(dem)
    slope = np.pi/2. - np.arctan(np.sqrt(x*x + y*y))
    aspect = np.arctan2(-x, y)
    azimuthrad = azimuth*np.pi/180.
    altituderad = altitude*np.pi/180.
 
    shaded = np.sin(altituderad)*np.sin(slope)
    + np.cos(altituderad)*np.cos(slope) * np.cos(
    (azimuthrad - np.pi/2.) - aspect)
    
    return 255*(shaded + 1)/2

# Time hillshade computation using regular python
time = timeit.timeit(lambda: py_hillshade(dem.raster, dem.XDIM), number=NTESTS)
print(f'python hillshade averaged {time/NTESTS:.3f} seconds')

# Time hillshade computation using fasterraster for num-threads
num_threads = [1,2,4,8]
for numt in num_threads:
    time = timeit.timeit(lambda: fr.hillshade_faster_mp(dem.raster, numt), number=NTESTS)
    print(f'hillshade averaged {time/NTESTS:.3f} seconds for {numt} threads')

Example output:

python hillshade averaged 2.880 seconds
hillshade averaged 0.081 seconds for 1 threads
hillshade averaged 0.041 seconds for 2 threads
hillshade averaged 0.034 seconds for 4 threads
hillshade averaged 0.024 seconds for 8 threads

Release files for fasterraster 0.0.5

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

Source distribution (sdist)

Source distribution for fasterraster 0.0.5
File Size Uploaded
fasterraster-0.0.5.tar.gz 25.8 kB Details

Release files / fasterraster-0.0.5.tar.gz

Download URL fasterraster-0.0.5.tar.gz
Size 25.8 kB
Tags Source
SHA-256 checksum
How to use checksums
029d0c3406851487386527ffa27861615428aa98e10e692ff8f682bd94a7eb2e
BLAKE2b-256 checksum
How to use checksums
29a397d9da526a1c31eae4481e53480f5785fc2581ccb32eecdb0c8bc4e972a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.0.5 This release

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

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