Giter Site home page Giter Site logo

pyrasta's Introduction

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

pyrasta's People

Contributors

benjaminpillot avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.