diff --git a/iop4lib/instruments/dipol.py b/iop4lib/instruments/dipol.py index ef9e0ae9..1077e4b8 100644 --- a/iop4lib/instruments/dipol.py +++ b/iop4lib/instruments/dipol.py @@ -630,6 +630,16 @@ def _build_wcs_for_polarimetry_images_photo_quads(cls, redf: 'ReducedFit', summa quads_1 = np.array(list(itertools.combinations(sets_L[0], 4))) quads_2 = np.array(list(itertools.combinations(sets_L[1], 4))) + # remove quads of points that have an area less than 5% of the image + def PolyArea(x,y): + # order points clockwise + idx = np.argsort(np.arctan2(y-y.mean(), x-x.mean())) + x, y = x[idx], y[idx] + return 0.5*np.abs(np.dot(x,np.roll(y,1))-np.dot(y,np.roll(x,1))) + + quads_1 = np.array([quad for quad in quads_1 if PolyArea(quad[:,0], quad[:,1]) > 0.05*(redf_pol.width*redf_pol.height)]) + quads_2 = np.array([quad for quad in quads_2 if PolyArea(quad[:,0], quad[:,1]) > 0.05*(redf_pol.width*redf_pol.height)]) + if len(quads_1) == 0 or len(quads_2) == 0: logger.error(f"No quads found in {redf_pol} and {redf_phot}, returning success = False.") return BuildWCSResult(success=False) @@ -803,7 +813,7 @@ def _build_wcs_for_polarimetry_images_photo_quads(cls, redf: 'ReducedFit', summa fig.clear() - result = BuildWCSResult(success=True, wcslist=wcslist, info={'redf_phot__pk':redf_phot.pk, 'redf_phot__fileloc':redf_phot.fileloc, n_seg_threshold:n_seg_threshold, npixels:npixels}) + result = BuildWCSResult(success=True, wcslist=wcslist, info={'redf_phot__pk':redf_phot.pk, 'redf_phot__fileloc':redf_phot.fileloc, 'n_seg_threshold':n_seg_threshold, 'npixels':npixels}) return result