def compute_offset_sad(dem1, dem2, pad=(<NUM_LIT:9>,<NUM_LIT:9>), plot=False):
<EOL>kernel = dem2[pad[<NUM_LIT:0>]:-pad[<NUM_LIT:0>], pad[<NUM_LIT:1>]:-pad[<NUM_LIT:1>]]<EOL>m = np.zeros((pad[<NUM_LIT:0>]*<NUM_LIT:2>+<NUM_LIT:1>, pad[<NUM_LIT:1>]*<NUM_LIT:2>+<NUM_LIT:1>))<EOL>i = j = <NUM_LIT:0><EOL>for i in range(m.shape[<NUM_LIT:0>]):<EOL><INDENT>print(i)<EOL>for j in range(m.shape[<NUM_LIT:1>]):<EOL><INDENT>print(j)<EOL>ref = dem1[i:i+kernel.shape[<NUM_LIT:0>], j:j+kernel.shape[<NUM_LIT:1>]]<EOL>diff = ref - kernel<EOL>diff_iqr = malib.calcperc(diff, (<NUM_LIT>,<NUM_LIT>))<EOL>diff = np.ma.masked_outside(diff, *diff_iqr)<EOL>"""<STR_LIT>"""<EOL>m[i,j] = np.ma.abs(diff).sum()/diff.count()<EOL><DEDENT><DEDENT>m = -m  <EOL>int_argmax = np.array(np.unravel_index(m.argmax(), m.shape))<EOL>int_offset = int_argmax - pad<EOL>sp_argmax = np.array(find_subpixel_peak_position(m, '<STR_LIT>'))<EOL>sp_offset = sp_argmax - pad<EOL>if plot:<EOL><INDENT>plt.figure()<EOL>plt.title('<STR_LIT>')<EOL>plt.imshow(m)<EOL>plt.scatter(*sp_argmax[::-<NUM_LIT:1>])<EOL><DEDENT>return m, int_offset, sp_offset<EOL>
Compute subpixel horizontal offset between input rasters using sum of absolute differences (SAD) method