### A code block in the cliplib was surrounded with "try" and "finally" to make...

`A code block in the cliplib was surrounded with "try" and "finally" to make sure the raster is always reset whatever happens.`
parent d8c9aa2c
 ... ... @@ -132,32 +132,34 @@ def get_masked_clip_result(datagrid, nvlp, mask, initvalue=0): # Extract data from the datagrid and return it as a 2-dimensional array shape = (nvlp.nrows, nvlp.ncols) datatype = get_datatype(datagrid.dataformat) if initvalue == 0: result = np.zeros(shape, dtype=datatype) result = np.zeros(shape, dtype=datatype) if initvalue != 0: result = initvalue # Now calculate which part of the datagrid we need # Assume that the datagrid coincides exactly with the "country pixels" mink = int(round((nvlp.xll - datagrid.xll) / nvlp.dx)) maxk = mink + nvlp.ncols - 1 maxi = datagrid.nrows - int(round((nvlp.yll - datagrid.yll) / nvlp.dy)) - 1 mini = maxi - nvlp.nrows + 1 # Loop over the rows - assume that the file position is zero for i in range(datagrid.nrows): if i < mini: datagrid.next(False) continue if i > maxi: break line = datagrid.next() arrline = line[mink:maxk+1] if isinstance(arrline, array): arrline = np.array(arrline) arrline.shape = (nvlp.ncols) result[i - mini, :] = arrline try: # Now calculate which part of the datagrid we need # Assume that the datagrid coincides exactly with the "country pixels" mink = int(round((nvlp.xll - datagrid.xll) / nvlp.dx)) maxk = mink + nvlp.ncols - 1 maxi = datagrid.nrows - int(round((nvlp.yll - datagrid.yll) / nvlp.dy)) - 1 mini = maxi - nvlp.nrows + 1 # Wind up datagrid.reset() result = ma.masked_array(result, mask) return result # Loop over the rows - assume that the file position is zero for i in range(datagrid.nrows): if i < mini: datagrid.next(False) continue if i > maxi: break line = datagrid.next() arrline = line[mink:maxk+1] if isinstance(arrline, array): arrline = np.array(arrline) arrline.shape = (nvlp.ncols) result[i - mini, :] = arrline finally: # Wind up datagrid.reset() result = ma.masked_array(result, mask) return result def most_left(line, value): result = -1 ... ... @@ -238,7 +240,7 @@ def join_envelopes(nvlps): return result # Method create_raster that is to return an envelope and an array with data # Input is a minimum envelope and a masked array with values # Input is a minimal envelope and a masked array with values def create_raster(countrydata, envelope=None, nodatavalue=None, debug="n"): # Assume that the countrydata are tuples with envelope and masked arrays if envelope == None: ... ...