Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_show_matchwin' into 'main'
Browse files Browse the repository at this point in the history
Bugfix/fix show matchwin

Closes #86

See merge request danschef/arosics!41
  • Loading branch information
Daniel Scheffler committed Oct 16, 2023
2 parents 96625b9 + 1655f94 commit 17e30a1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
History
=======

1.9.3 (2023-10-16)
------------------

* !41: Fixed #86 (ValueError when calling CoReg.show_matchWin(interactive=True))
and improved interactive output of CoReg.show_matchWin.


1.9.2 (2023-08-11)
------------------

Expand Down
43 changes: 29 additions & 14 deletions arosics/CoReg.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ def show_matchWin(self,
hv = None
if not hv:
raise ImportError(
"This method requires the library 'holoviews'. It can be installed for Anaconda with "
"This method requires the library 'holoviews'. It can be installed for Conda with "
"the shell command 'conda install -c conda-forge holoviews bokeh'.")

hv.notebook_extension('matplotlib')
Expand All @@ -706,38 +706,53 @@ def show_matchWin(self,
otherWin_corr = self._get_deshifted_otherWin() if after_correction in [True, None] else None
xmin, xmax, ymin, ymax = self.matchBox.boundsMap

def get_hv_image(geoArr):
def get_hv_image(geoArr: GeoArray):
from skimage.exposure import rescale_intensity # import here to avoid static TLS ImportError

arr_masked = np.ma.masked_equal(geoArr[:], geoArr.nodata)
vmin = np.nanpercentile(arr_masked.compressed(), pmin)
vmax = np.nanpercentile(arr_masked.compressed(), pmax)
arr2plot = rescale_intensity(arr_masked, in_range=(vmin, vmax), out_range='int8')

return hv.Image(arr2plot, bounds=(xmin, ymin, xmax, ymax))\
.opts(style={'cmap': 'gray',
'vmin': vmin,
'vmax': vmax,
'interpolation': 'none'},
plot={'fig_inches': figsize,
# 'fig_size': 100,
'show_grid': True})
return (
hv.Image(
arr2plot,
bounds=(xmin, ymin, xmax, ymax)
).options(
cmap='gray',
vmin=vmin,
vmax=vmax,
interpolation='none',
fig_inches=figsize,
show_grid=True
)
)

hvIm_matchWin = get_hv_image(self.matchWin)
hvIm_otherWin_orig = get_hv_image(self.otherWin)
hvIm_otherWin_corr = get_hv_image(otherWin_corr) if after_correction in [True, None] else None

if after_correction is None:
# view both states
print('Matching window before and after correction (above and below): ')
print('Matching window before and after correction (left and right): ')

# get layouts (docs on options: https://holoviews.org/user_guide)
layout_before = (hvIm_matchWin + hvIm_matchWin).opts(plot=dict(fig_inches=figsize))
layout_after = (hvIm_otherWin_orig + hvIm_otherWin_corr).opts(plot=dict(fig_inches=figsize))
layout_before = (
hvIm_matchWin.options(title='BEFORE co-registration') +
hvIm_matchWin.options(title='AFTER co-registration')
).options(
fig_inches=figsize
)
layout_after = (
hvIm_otherWin_orig.options(title='BEFORE co-registration') +
hvIm_otherWin_corr.options(title='AFTER co-registration')
).options(
fig_inches=figsize
)

# plot!
imgs = {1: layout_before, 2: layout_after}
hmap = hv.HoloMap(imgs, kdims=['image']).collate().cols(1)
hmap = hv.HoloMap(imgs, kdims=['image']).collate().cols(2)

else:
# view state before or after correction
Expand Down
2 changes: 1 addition & 1 deletion tests/test_COREG.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def test_plotting_after_shift_calculation(self): # , mock_show):
CR.show_matchWin(interactive=False, after_correction=True)
CR.show_matchWin(interactive=False, after_correction=False)
try:
__IPYTHON__ # noqa
# __IPYTHON__ # noqa
CR.show_cross_power_spectrum(interactive=True)
CR.show_matchWin(interactive=True, after_correction=None) # only works if test is started with ipython
CR.show_matchWin(interactive=True, after_correction=True)
Expand Down

0 comments on commit 17e30a1

Please sign in to comment.