Commit 5773e8a6 authored by Hoek, Steven's avatar Hoek, Steven
Browse files

Extra documentation added

parent f4fcddcf
......@@ -24,7 +24,7 @@ __author__ = "Steven B. Hoek"
class RioRaster(Raster, GridEnvelope2D):
'''
A raster that makes use of the rasterio package for access to various file formats, but
with an interface similar to the classes found in the formats folder of package lmgeo
with an interface similar to the classes found in the formats folder of package lmgeo.
'''
data = None
nbands = 1 # default
......@@ -37,7 +37,12 @@ class RioRaster(Raster, GridEnvelope2D):
__ext = "tif" # default
def __init__(self, filepath, *datatype):
# Initialise
'''Initialisation of a RioRaster instance
Input variables:
filepath - full path to the file
datatype - e.g. integer or float, indicated as 'i' or 'f' repectively
'''
Raster.__init__(self, filepath)
GridEnvelope2D.__init__(self, 1, 1, 0.0, 0.0, 0.1, 0.1)
......@@ -58,6 +63,19 @@ class RioRaster(Raster, GridEnvelope2D):
return result
def open(self, mode, ncols=1, nrows=1, nbands=1, xll=0, yll=0, cellsize=100, nodatavalue=-9999.0):
'''After the instance has been initialised, it might be necessary to specify the size of the
raster grid, the size of the cells. This is esp. true in the case of write mode: mode == 'w'.
Input variables:
mode - read ('r') or write ('w')
ncols - number of columns of the raster grid
nrows - number of rows of the raster grid
nbands - number of bands
xll - x-coordinate of the lower left point
yll - y-coordinate of the lower left point
cellsize - cell size
nodatavalue - value used to indicate that there are no data for that cell
'''
# Initialise
fn = os.path.join(self.folder, self.name)
......
......@@ -18,6 +18,15 @@ class StripManager():
__currow = 0
def __init__(self, rg, stripheight):
'''
Initialisation of the strip manager with strip height.
Input variables:
rg - raster grid which serves as the source for the strip
stripheight - height of the strip to be produced
'''
# Check the inputs
if not isinstance(rg, Raster):
raise TypeError("Input is not a raster!")
......@@ -39,6 +48,8 @@ class StripManager():
self.__datatype = rg.datatype
def move(self, rowoffset):
'''Skip lines, i.e. rowoffset in number'''
if rowoffset < 0: raise ValueError("Row offset cannot be negative!")
for i in range(rowoffset):
try:
line = self.__rg.next(False)
......@@ -53,7 +64,7 @@ class StripManager():
'''
Returns a strip with a number of rows, possibly with as first rows those in the buffer
For the first strip, the buffer can be None and the rowoverlap > 0; for later rows,
when the buffer contains rows, the rowoverlap can be left unspecified
when the buffer contains rows, the rowoverlap can be left unspecified.
'''
result = None
......@@ -115,6 +126,7 @@ class StripManager():
return self.__nrows
class StripIterator:
''' Class that actally makes sure that the StripManager is iterable'''
def __init__(self, stripmanager):
self.__stripmanager = stripmanager
......
......@@ -51,6 +51,15 @@ class TileManager():
and at the bottom. Aim might be to make sures all delivered tiles are of the same width and
height. So-called topleft edges can be added also: at the top and to the left. Aim might be
to analyse the tiles whilst avoiding "edge effects".
Input variables:
rg - raster grid which serves as the source
tilewidth - width of the tiles to be produced
tileheight - height of the tiles to be produced
coloverlap - number of columns that should overlap per edge
rowoverlap - number of lines that should overlap per edge
bottomright_edges - edges should be added at the bottom and to the right of the tile (T/F)
topleft_edges - edges should be added to the top and to the left of the tile (T/F)
'''
# Check the inputs
if not isinstance(rg, Raster):
......@@ -294,7 +303,6 @@ class TileManager():
@tileheight.setter
def tileheight(self, tileheight):
# TODO: differentiate dx and dy!
self.__depth = tileheight
self.__stripmanager.stripheight = tileheight
......@@ -304,7 +312,6 @@ class TileManager():
@tilewidth.setter
def tilewidth(self, tilewidth):
# TODO: differentiate dx and dy!
self.__width = tilewidth
@property
......@@ -341,6 +348,7 @@ class TileManager():
class TileIterator:
''' Class that actally makes sure that the TileManager is iterable'''
def __init__(self, tilemanager):
self.__tilemanager = tilemanager
......@@ -392,6 +400,13 @@ class TileStitcher():
edges on all sides and values from all overlapping edges are ignored. Option "average" is yet to be implemented
fully. Idea is that the values in the output raster are obtained by taking the average of all the values contained
in the overlapping edges. For option "average" edges are assumed to exist on all sides.
Input variables:
tilewidth - width of the tiles to be processed, without column overlap
tileheight - height of the tiles to be processed, without row overlap
coloverlap - number of columns that should overlap per edge
rowoverlap - number of lines that should overlap per edge
option - no-edges, bottomright, topleft, allsides or average: what kind of edges do the tiles have and how to process them.
'''
self.__tilewidth = tilewidth
self.__tileheight = tileheight
......@@ -417,6 +432,16 @@ class TileStitcher():
self.__nbands = 1
def add(self, filename, separator="_"):
'''Method for adding to the TileStitcher a tile that should be used for the stitching. It is assumed
that the filename follows a pattern. Not considering the file extensions, the filenames are expected
to end with numbers indicating the place of the tile in the mesh, i.e. by means of the zero-based row
and the column numbers. These numbers are separated from each other and from the rest of the filename
by means of separators. The default separator is an underscore "_".
Input variables:
filename - name of the image file that is storing the tile
separator - special token that is used to separate the figures
'''
# Initialise
if not os.path.exists(filename):
raise ValueError("File %s does not exist!" % filename)
......@@ -434,6 +459,11 @@ class TileStitcher():
'''
After all the tiles have been added, this method can be invoked with an output raster
which is still closed!
Input variables:
RasterClass - the class that should be used for the output raster, from lmgeo.formats
datatype - e.g. integer or float, indicated as 'i' or 'f' repectively
outputraster - actual instance of the RasterClass that serves as output raster.
'''
# Check whether output raster is already open
if (outputraster.nrows != 1) and (outputraster.ncols != 1):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment