Skip to main content

PyRasta

PyPi license Maintenance PyPI version fury.io

Some tools for fast and easy raster processing, based on gdal (numpy usage is reduced to the minimum).

Introduction

PyRasta is a small Python library which aims at interfacing gdal functions and methods in an easy way, so that users may only focus on the processes they want to apply rather than on the code. The library is based on gdal stream and multiprocessing in order to reduce CPU time due to large numpy array imports. This is especially useful for basic raster arithmetic operations, sliding window methods as well as zonal statistics.

Basic available operations

  • Merging, clipping, re-projecting, padding, resampling, rescaling, windowing
  • Rasterize and Polygonize
  • Raster calculator to design your own operations
  • Fast raster zonal statistics
  • Automatically download and merge SRTM DEM(s) from CGIAR online database

Install

Pip installation should normally take care of everything for you.

Using PIP

The easiest way to install PyRasta is by using pip in a terminal

$ pip install pyrasta

Note on GDAL

Installing GDAL through pip might be tricky as it only gets the bindings, so be sure the library is already installed on your machine, and that the headers are located in the right folder. Another solution may to install it through a third-party distribution such as conda:

(your_virtual_environment) $ conda install gdal

If you are tempted by directly installing GDAL/OGR and the GDAL Python libraries on your machine, see here for the steps you should follow.

Examples

Build digital elevation model from CGIAR SRTM site

from pyrasta.tools.srtm import from_cgiar_online_database
bounds = (23, 34, 32, 45)
dem = from_cgiar_online_database(bounds)

Fast clipping of raster by extent or by mask

from pyrasta.raster import Raster
import geopandas
raster_by_extent = Raster("/path/to/your/raster").clip(bounds=(10, 40, 15, 45))
raster_by_mask = Raster("/path/to/your/raster").clip(mask=geopandas.GeoDataFrame.from_file("/path/to/your/layer"))

Fast Zonal Statistics

Fast computing of raster zonal statistics within features of a given geographic layer, by loading in memory only the data we need (and not the whole numpy array as it is often the case in other packages) + using multiprocessing. You may use the basic statistic functions already available in the package, or define your own customized functions.

from pyrasta.raster import Raster
import geopandas
rstats = Raster("/path/to/your/raster").zonal_stats(geopandas.GeoDataFrame.from_file("/path/to/your/layer"),
                                                    stats=["mean", "median", "min", "max"],
                                                    customized_stats={"my_stat": my_stat})

Author

Benjamin Pillot


image

Metadata

Release files for pyrasta 1.4.0

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

Source distribution (sdist)

Source distribution for pyrasta 1.4.0
File Size Uploaded
pyrasta-1.4.0.tar.gz 114.2 kB Details

Release files / pyrasta-1.4.0.tar.gz

Download URL pyrasta-1.4.0.tar.gz
Size 114.2 kB
Tags Source
SHA-256 checksum
How to use checksums
dd3b183f22f802f559227a2b1a8a1ce9a5565436a973fe4a7bda4b99dc22564d
BLAKE2b-256 checksum
How to use checksums
6693881538bed8898c98a86ee9fb0c4912f9006771cad0f03ee0afb1aa0e1ad2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.16

Release history Release notifications | RSS feed

This release

1.4.0 This release

1 release file

1.3.28

1 release file

1.3.27

1 release file

1.3.26

1 release file

1.3.25

1 release file

1.3.24

1 release file

1.3.23

1 release file

1.3.22

1 release file

1.3.21

1 release file

1.3.20

1 release file

1.3.19

1 release file

1.3.18

1 release file

1.3.17

1 release file

1.3.16

1 release file

1.3.15

1 release file

1.3.14

1 release file

1.3.13

1 release file

1.3.11

1 release file

1.3.10

1 release file

1.3.9

1 release file

1.3.8

1 release file

1.3.7

1 release file

1.3.6

1 release file

1.3.5

1 release file

1.3.4

1 release file

1.3.3

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3

1 release file

1.2.92

1 release file

1.2.91

1 release file

1.2.9

1 release file

1.2.8

1 release file

1.2.7

1 release file

1.2.6

1 release file

1.2.5

1 release file

1.2.4

1 release file

1.2.3

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2

1 release file

1.1

1 release file

1.0

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