def align_georasters(raster, alignraster, how=np.mean, cxsize=None, cysize=None):
(ndv1, xsize1, ysize1, geot1, projection1, datatype1) = (raster.nodata_value, raster.shape[<NUM_LIT:1>],<EOL>raster.shape[<NUM_LIT:0>], raster.geot,<EOL>raster.projection, raster.datatype)<EOL>(ndv2, xsize2, ysize2, geot2, projection2, datatype2) = (alignraster.nodata_value,<EOL>alignraster.shape[<NUM_LIT:1>],<EOL>alignraster.shape[<NUM_LIT:0>],<EOL>alignraster.geot,<EOL>alignraster.projection,<EOL>alignraster.datatype)<EOL>if projection1.ExportToMICoordSys() == projection2.ExportToMICoordSys():<EOL><INDENT>blocksize = (np.round(max(geot2[<NUM_LIT:1>]/geot1[<NUM_LIT:1>], <NUM_LIT:1>)).astype(np.int), np.round(max(geot2[-<NUM_LIT:1>]/geot1[-<NUM_LIT:1>], <NUM_LIT:1>)).astype(np.int))<EOL>mraster = raster.raster<EOL>mmin = mraster.min()<EOL>if block_reduce != (<NUM_LIT:1>, <NUM_LIT:1>):<EOL><INDENT>mraster = block_reduce(mraster, blocksize, func=how)<EOL><DEDENT>blocksize = (np.round(max(geot1[<NUM_LIT:1>]/geot2[<NUM_LIT:1>], <NUM_LIT:1>)).astype(np.int), np.round(max(geot1[-<NUM_LIT:1>]/geot2[-<NUM_LIT:1>], <NUM_LIT:1>)).astype(np.int))<EOL>araster = alignraster.raster<EOL>amin = araster.min()<EOL>if block_reduce != (<NUM_LIT:1>, <NUM_LIT:1>):<EOL><INDENT>araster = block_reduce(araster, blocksize, func=how)<EOL><DEDENT>if geot1[<NUM_LIT:0>] <= geot2[<NUM_LIT:0>]:<EOL><INDENT>row3, mcol = map_pixel(geot2[<NUM_LIT:0>], geot2[<NUM_LIT:3>], geot1[<NUM_LIT:1>] *blocksize[<NUM_LIT:0>],<EOL>geot1[-<NUM_LIT:1>]*blocksize[<NUM_LIT:1>], geot1[<NUM_LIT:0>], geot1[<NUM_LIT:3>])<EOL>acol = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>row3, acol = map_pixel(geot1[<NUM_LIT:0>], geot1[<NUM_LIT:3>], geot2[<NUM_LIT:1>], geot2[-<NUM_LIT:1>], geot2[<NUM_LIT:0>], geot2[<NUM_LIT:3>])<EOL>mcol = <NUM_LIT:0><EOL><DEDENT>if geot1[<NUM_LIT:3>] <= geot2[<NUM_LIT:3>]:<EOL><INDENT>arow, col3 = map_pixel(geot1[<NUM_LIT:0>], geot1[<NUM_LIT:3>], geot2[<NUM_LIT:1>], geot2[-<NUM_LIT:1>], geot2[<NUM_LIT:0>], geot2[<NUM_LIT:3>])<EOL>mrow = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>mrow, col3 = map_pixel(geot2[<NUM_LIT:0>], geot2[<NUM_LIT:3>], geot1[<NUM_LIT:1>] *blocksize[<NUM_LIT:0>],<EOL>geot1[-<NUM_LIT:1>]*blocksize[<NUM_LIT:1>], geot1[<NUM_LIT:0>], geot1[<NUM_LIT:3>])<EOL>arow = <NUM_LIT:0><EOL><DEDENT>mraster = mraster[mrow:, mcol:]<EOL>araster = araster[arow:, acol:]<EOL>if cxsize and cysize:<EOL><INDENT>araster = araster[:cysize, :cxsize]<EOL>mraster = mraster[:cysize, :cxsize]<EOL><DEDENT>else:<EOL><INDENT>rows = min(araster.shape[<NUM_LIT:0>], mraster.shape[<NUM_LIT:0>])<EOL>cols = min(araster.shape[<NUM_LIT:1>], mraster.shape[<NUM_LIT:1>])<EOL>araster = araster[:rows, :cols]<EOL>mraster = mraster[:rows, :cols]<EOL><DEDENT>mraster = np.ma.masked_array(mraster, mask=mraster < mmin, fill_value=ndv1)<EOL>araster = np.ma.masked_array(araster, mask=araster < amin, fill_value=ndv2)<EOL>geot = (max(geot1[<NUM_LIT:0>], geot2[<NUM_LIT:0>]), geot1[<NUM_LIT:1>]*blocksize[<NUM_LIT:0>], geot1[<NUM_LIT:2>], min(geot1[<NUM_LIT:3>], geot2[<NUM_LIT:3>]),<EOL>geot1[<NUM_LIT:4>], geot1[-<NUM_LIT:1>]*blocksize[<NUM_LIT:1>])<EOL>mraster = GeoRaster(mraster, geot, projection=projection1,<EOL>nodata_value=ndv1, datatype=datatype1)<EOL>araster = GeoRaster(araster, geot, projection=projection2,<EOL>nodata_value=ndv2, datatype=datatype2)<EOL>return (mraster, araster)<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>")<EOL>return (-<NUM_LIT:1>, -<NUM_LIT:1>)<EOL><DEDENT>
Align two rasters so that data overlaps by geographical location
Usage: (alignedraster_o, alignedraster_a) = AlignRasters(raster, alignraster, how=np.mean)
where
    raster: string with location of raster to be aligned
    alignraster: string with location of raster to which raster will be aligned
    how: function used to aggregate cells (if the rasters have different sizes)
It is assumed that both rasters have the same size