imagereader

Contains the functions needed for opening and reading input files, and the ReadWorkerMgr class used to manage concurrent read workers.

class rios.imagereader.ReadWorkerMgr[source]

Simple class to hold all the things we need to sustain for the read worker threads

static readWorkerFunc(readTaskQue, blockBuffer, controls, tmpfileMgr, rasterizeMgr, workinggrid, allInfo, timings, forceExit, exceptionQue)[source]

This function runs in each read worker thread. The readTaskQue gives it tasks to perform (i.e. single blocks of data to read), and it loops until there are no more to do. Each block is sent back through the blockBuffer.

shutdown()[source]

Shut down the read worker manager

startReadWorkers(blockList, infiles, allInfo, controls, tmpfileMgr, rasterizeMgr, workinggrid, inBlockBuffer, timings, exceptionQue)[source]

Start the requested number of read worker threads, within the current process. All threads will read single blocks from individual files and place them into the inBlockBuffer.

Return value is an instance of ReadWorkerMgr, which must remain active until all reading is complete.

rios.imagereader.openForWorkingGrid(filename, workinggrid, fileInfo, controls, tmpfileMgr, rasterizeMgr, symbolicName)[source]

If the fileInfo for the given filename is a raster, aligned with the working grid, just open it. If it is a raster, but not aligned, do a warp VRT that makes it aligned, and open that instead. If it is a vector, then first rasterize into a temp file and use that.

Either way, return a GDAL Dataset object and a list of band objects corresponding to the selected bands.

rios.imagereader.readBlockAllFiles(infiles, workinggrid, blockDefn, allInfo, gdalObjCache, controls, tmpfileMgr, rasterizeMgr)[source]

Read all input files for a single block. Return the complete BlockAssociations object (i.e. ‘inputs’).

rios.imagereader.readBlockOneFile(blockDefn, symbolicName, seqNum, filename, gdalObjCache, controls, tmpfileMgr, rasterizeMgr, workinggrid, allInfo)[source]

Read the requested block, as per blockDefn, of the requested file, as per (symbolicName, seqNum, filename). If the file has already been opened, its GDAL objects will be in the gdalObjCache, otherwise it will be opened and those objects placed in the cache.

Return a numpy array for the block, of shape (numBands, numRows, numCols).

rios.imagereader.readIntoArray(outArray, ds, bandObj, top_wg, left_wg, xsize, ysize, workinggrid, margin)[source]

Read the requested block from the given band/dataset, and place it into the given output array. If the block falls off the edge of the file extent, the request is trimmed back, and the resulting smaller block is placed into the correct part of the array, leaving the surrounding array elements unchanged.

The request coordinates (top, left, xsize, ysize) do not include the margin (i.e. overlap), so that is accounted for explicitly here. If margin > 0, the array is thus larger by (2*margin) in each direction.

NOTE: While it may seem that this could be done using a VRT, our tests of that approach found that it imposes a substantial overhead, and doing it ourselves is much faster.

rios.imagereader.reprojResolution(xRes, yRes, x, y, srcSRS, tgtSRS)[source]

Return a reprojected version of the given resolution. The (xRes yRes) values are given in the srcSRS project, and are translated to something as similar as possible in the tgtSRS projection. The rough location is given by (x, y) (in the src projection), so the transformation is at its best around that point, and would be progressively worse the further one gets from there (due to the increased distortion from the different projections).

rios.imagereader.reprojectionRequired(imgInfo, workinggrid)[source]

Compare the details of the given imgInfo and the workinggrid, to work out if a reprojection is required. Return True if so.

rios.imagereader.specialProjFixes(projwkt)[source]

Does any special fixes required for the projection. Returns the fixed projection WKT string.

Specifically this does two things, both of which are to cope with rubbish that Imagine has put into the projection. Firstly, it removes the crappy TOWGS84 parameters which Imagine uses for GDA94, and secondly removes the crappy name which Imagine gives to the correct GDA94.

If neither of these things is found, returns the string unchanged.