def histogram_match(self, use_bands, blm_source=None, **kwargs):
assert has_rio, "<STR_LIT>"<EOL>data = self._read(self[use_bands,...], **kwargs)<EOL>data = np.rollaxis(data.astype(np.float32), <NUM_LIT:0>, <NUM_LIT:3>)<EOL>if <NUM_LIT:0> in data:<EOL><INDENT>data = np.ma.masked_values(data, <NUM_LIT:0>)<EOL><DEDENT>bounds = self._reproject(box(*self.bounds), from_proj=self.proj, to_proj="<STR_LIT>").bounds<EOL>if blm_source == '<STR_LIT>':<EOL><INDENT>from gbdxtools.images.browse_image import BrowseImage<EOL>ref = BrowseImage(self.cat_id, bbox=bounds).read()<EOL><DEDENT>else:<EOL><INDENT>from gbdxtools.images.tms_image import TmsImage<EOL>tms = TmsImage(zoom=self._calc_tms_zoom(self.affine[<NUM_LIT:0>]), bbox=bounds, **kwargs)<EOL>ref = np.rollaxis(tms.read(), <NUM_LIT:0>, <NUM_LIT:3>)<EOL><DEDENT>out = np.dstack([rio_match(data[:,:,idx], ref[:,:,idx].astype(np.double)/<NUM_LIT>)<EOL>for idx in range(data.shape[-<NUM_LIT:1>])])<EOL>if '<STR_LIT>' in kwargs or '<STR_LIT>' in kwargs:<EOL><INDENT>return self._histogram_stretch(out, **kwargs)<EOL><DEDENT>else:<EOL><INDENT>return out<EOL><DEDENT>
Match the histogram to existing imagery