GithubHelp home page GithubHelp logo

rio-mucho's Introduction

rio-mucho

Windowed parallel processing wrapper for rasterio

PyPI Build Status Coverage Status

Install

From pypi:

pip install rio-mucho

From github:

pip install pip install git+ssh://[email protected]/mapbox/rio-mucho.git@<branch>

Development:

git clone [email protected]:mapbox/rio-mucho.git
cd rio-mucho
pip install -e .

Usage

with riomucho.RioMucho([{inputs}], {output}, {run function},
    windows={windows},
    global_args={global arguments}, 
    options={options to write}) as rios:

    rios.run({processes})

Arguments

inputs

An list of file paths to open and read.

output

What file to write to.

run_function

A function to be applied to each window chunk. This should have input arguments of:

  1. A data input, which can be one of:
  • A list of numpy arrays of shape (x,y,z), one for each file as specified in input file list mode="simple_read" [default]
  • A numpy array of shape ({n input files x n band count}, {window rows}, {window cols}) mode=array_read"
  • A list of open sources for reading mode="manual_read"
  1. A rasterio window tuple
  2. A rasterio window index (ij)
  3. A global arguments object that you can use to pass in global arguments

This should return:

  1. An output array of ({depth|count}, {window rows}, {window cols}) shape, and of the correct data type for writing
def basic_run({data}, {window}, {ij}, {global args}):
    ## do something
    return {out}

Keyword arguments

windows={windows}

A list of rasterio (window, ij) tuples to operate on. [Default = src[0].block_windows()]

global_args={global arguments}

Since this is working in parallel, any other objects / values that you want to be accessible in the run_function. [Default = {}]

global_args = {
    'divide_value': 2
}

options={keyword args}

The options to pass to the writing output. [Default = srcs[0].meta]

Example

import riomucho, rasterio, numpy

def basic_run(data, window, ij, g_args):
    ## do something
    out = np.array(
        [d /= global_args['divide'] for d in data]
        )
    return out

# get windows from an input
with rasterio.open('/tmp/test_1.tif') as src:
    ## grabbing the windows as an example. Default behavior is identical.
    windows = [[window, ij] for ij, window in src.block_windows()]
    options = src.meta
    # since we are only writing to 2 bands
    options.update(count=2)

global_args = {
    'divide': 2
}

processes = 4

# run it
with riomucho.RioMucho(['input1.tif','input2.tif'], 'output.tif', basic_run,
    windows=windows,
    global_args=global_args, 
    options=options) as rm:

    rm.run(processes)

Utility functions

riomucho.utils.array_stack([array, array, array,...])

Given a list of ({depth}, {rows}, {cols}) numpy arrays, stack into a single ({list length * each image depth}, {rows}, {cols}) array. This is useful for handling variation between rgb inputs of a single file, or separate files for each.

One RGB file

files = ['rgb.tif']
open_files = [rasterio.open(f) for f in files]
rgb =riomucho.utils.array_stack([src.read() for src in open_files])

Separate RGB files

files = ['r.tif', 'g.tif', 'b.tif']
open_files = [rasterio.open(f) for f in files]
rgb = riomucho.utils.array_stack([src.read() for src in open_files])

rio-mucho's People

Contributors

dnomadb avatar jqtrde avatar perrygeo avatar sgillies 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.