Commit 7073ee9e authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Fixed exceptions within Tie_Point_Grid.plot_shift_distribution(),...

Fixed exceptions within Tie_Point_Grid.plot_shift_distribution(), calc_overall_mssim(), calc_rmse. Added test_tie_point_grid.py.
parent 7b141e5d
Pipeline #1510 passed with stages
in 2 minutes and 6 seconds
......@@ -427,7 +427,7 @@ class COREG_LOCAL(object):
if self.tieP_filter_level > 1:
# flag level 2 outliers
GDF_filt = GDF[GDF.L2_OUTLIER.__eq__(True)].copy()
plt.scatter(GDF_filt['plt_X'], GDF_filt['plt_Y'], c='r', marker=marker, s=150, alpha=1.0, label='MSSIM')
plt.scatter(GDF_filt['plt_X'], GDF_filt['plt_Y'], c='r', marker=marker, s=150, alpha=1.0, label='SSIM')
if self.tieP_filter_level > 2:
# flag level 3 outliers
GDF_filt = GDF[GDF.L3_OUTLIER.__eq__(True)].copy()
......
......@@ -401,27 +401,28 @@ class Tie_Point_Grid(object):
"""
tbl = self.CoRegPoints_table
tbl = tbl if include_outliers else tbl[~tbl['OUTLIER']].copy() if 'OUTLIER' in tbl.columns else tbl
tbl = tbl if include_outliers else tbl[tbl['OUTLIER'] == 0].copy() if 'OUTLIER' in tbl.columns else tbl
shifts = np.array(tbl['ABS_SHIFT'])
shifts_sq = [i * i for i in shifts if i != self.outFillVal]
return np.sqrt(sum(shifts_sq) / len(shifts_sq))
def calc_overall_mssim(self, include_outliers=False):
# type: (bool) -> float
"""Calculates the median value of all MSSIM values contained in tie point grid.
def calc_overall_ssim(self, include_outliers=False, after_correction=True):
# type: (bool, bool) -> float
"""Calculates the median value of all SSIM values contained in tie point grid.
:param include_outliers: whether to include tie points that have been marked as false-positives
:param after_correction: whether to compute median SSIM before correction or after
"""
tbl = self.CoRegPoints_table
tbl = tbl if include_outliers else tbl[~tbl['OUTLIER']].copy()
tbl = tbl if include_outliers else tbl[tbl['OUTLIER'] == 0].copy()
mssim_col = np.array(tbl['MSSIM'])
mssim_col = [i * i for i in mssim_col if i != self.outFillVal]
ssim_col = np.array(tbl['SSIM_AFTER' if after_correction else 'SSIM_BEFORE'])
ssim_col = [i * i for i in ssim_col if i != self.outFillVal]
return float(np.median(mssim_col))
return float(np.median(ssim_col))
def plot_shift_distribution(self, include_outliers=True, unit='m', interactive=False, figsize=None, xlim=None,
ylim=None, fontsize=12, title='shift distribution'):
......@@ -443,7 +444,7 @@ class Tie_Point_Grid(object):
tbl = self.CoRegPoints_table
tbl = tbl[tbl['ABS_SHIFT'] != self.outFillVal]
tbl_il = tbl[~tbl['OUTLIER']].copy() if 'OUTLIER' in tbl.columns else tbl
tbl_il = tbl[tbl['OUTLIER'] == 0].copy() if 'OUTLIER' in tbl.columns else tbl
tbl_ol = tbl[tbl['OUTLIER']].copy() if 'OUTLIER' in tbl.columns else None
x_attr = 'X_SHIFT_M' if unit == 'm' else 'X_SHIFT_PX'
y_attr = 'Y_SHIFT_M' if unit == 'm' else 'Y_SHIFT_PX'
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tests for the module arosics.Tie_Point_Grid."""
import unittest
# custom
from .cases import test_cases
from arosics import COREG_LOCAL, Tie_Point_Grid
class Test_Tie_Point_Grid(unittest.TestCase):
@classmethod
def setUp(cls):
CRL = COREG_LOCAL(test_cases['INTER1']['ref_path'], test_cases['INTER1']['tgt_path'],
**test_cases['INTER1']['kwargs_local'])
cls.TPG = Tie_Point_Grid(CRL.COREG_obj, CRL.grid_res,
max_points=100, # limit to 100 to reduce computational load
outFillVal=CRL.outFillVal,
resamp_alg_calc=CRL.rspAlg_calc,
tieP_filter_level=CRL.tieP_filter_level,
outlDetect_settings=dict(
min_reliability=CRL.min_reliability,
rs_max_outlier=CRL.rs_max_outlier,
rs_tolerance=CRL.rs_tolerance),
dir_out=CRL.projectDir,
CPUs=CRL.CPUs,
progress=CRL.progress,
v=CRL.v,
q=CRL.q)
def test_mean_shifts(self):
self.assertIsInstance(self.TPG.mean_x_shift_px, float)
self.assertIsInstance(self.TPG.mean_y_shift_px, float)
self.assertIsInstance(self.TPG.mean_x_shift_map, float)
self.assertIsInstance(self.TPG.mean_y_shift_map, float)
def test_get_CoRegPoints_table(self):
self.TPG.get_CoRegPoints_table()
def test_calc_rmse(self):
self.TPG.calc_rmse(include_outliers=False)
self.TPG.calc_rmse(include_outliers=True)
def test_calc_overall_ssim(self):
self.TPG.calc_overall_ssim(include_outliers=False, after_correction=True)
self.TPG.calc_overall_ssim(include_outliers=True, after_correction=False)
def test_plot_shift_distribution(self):
self.TPG.plot_shift_distribution()
@unittest.SkipTest
def test_dump_CoRegPoints_table(self):
raise NotImplementedError()
def test_to_GCPList(self):
self.TPG.to_GCPList()
@unittest.SkipTest
def test_to_PointShapefile(self):
# TODO requires to delete output later
self.TPG.to_PointShapefile()
@unittest.SkipTest
def test_to_vectorfield(self):
# TODO requires to delete output later
self.TPG.to_vectorfield()
@unittest.SkipTest
def test_to_Raster_using_Kriging(self):
# TODO requires to delete output later
self.TPG.to_Raster_using_Kriging(attrName='X_SHIFT_MAP')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment