Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import sys
from rios import applier
from rios import cuiprogress
import numpy
def calcstats(info, inputs, outputs):
# Calc standard deviation of bands for each pixel
stdev_pixels = numpy.std(inputs.inimage, axis=0)
# Reshape to make 3-dimensional array (required for output)
outputs.outimage = stdev_pixels.reshape((1,stdev_pixels.shape[0],stdev_pixels.shape[1]))
# Set up input and output files
infiles = applier.FilenameAssociations()
infiles.inimage = 'tmean_monthly_1980.tif'
outfiles = applier.FilenameAssociations()
outfiles.outimage = 'tstdev_1980.tif'
# Set up options for output file
controls = applier.ApplierControls()
controls.setOutputDriverName("GTiff") # Output
controls.setCalcStats(True) # Create stats and overviews for output file
controls.progress = cuiprogress.CUIProgressBar() # Show progress
applier.apply(calcstats, infiles, outfiles, controls=controls)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment