fix crop and clean up
This commit is contained in:
@@ -270,7 +270,7 @@ def del_aligned(s, Omega):
|
|||||||
|
|
||||||
|
|
||||||
# Implement Graham algorithm
|
# Implement Graham algorithm
|
||||||
def convex_hull(A):
|
def convex_hull(H):
|
||||||
"""
|
"""
|
||||||
Implement Graham algorithm to find the convex hull of a given list of
|
Implement Graham algorithm to find the convex hull of a given list of
|
||||||
points, handling aligned points.
|
points, handling aligned points.
|
||||||
@@ -283,9 +283,12 @@ def convex_hull(A):
|
|||||||
List of points defining the convex hull of the input list A.
|
List of points defining the convex hull of the input list A.
|
||||||
"""
|
"""
|
||||||
S = empty_stack()
|
S = empty_stack()
|
||||||
Omega = min_lexico(A)
|
Omega = min_lexico(H)
|
||||||
sort_angles_distances(Omega, A)
|
sort_angles_distances(Omega, H)
|
||||||
A = del_aligned(A, Omega)
|
A = del_aligned(H, Omega)
|
||||||
|
if len(A) < 3:
|
||||||
|
return H
|
||||||
|
else:
|
||||||
stack(S, A[0])
|
stack(S, A[0])
|
||||||
stack(S, A[1])
|
stack(S, A[1])
|
||||||
stack(S, A[2])
|
stack(S, A[2])
|
||||||
@@ -328,25 +331,24 @@ def image_hull(image, step=5, null_val=0., inside=True):
|
|||||||
H = []
|
H = []
|
||||||
shape = np.array(image.shape)
|
shape = np.array(image.shape)
|
||||||
row, col = np.indices(shape)
|
row, col = np.indices(shape)
|
||||||
for i in range(0, shape[0], step):
|
for i in range(0, int(min(shape)/2), step):
|
||||||
r = row[i, :][image[i, :] > null_val]
|
r1, r2 = row[i, :][image[i, :] > null_val], row[-i, :][image[-i, :] > null_val]
|
||||||
c = col[i, :][image[i, :] > null_val]
|
c1, c2 = col[i, :][image[i, :] > null_val], col[-i, :][image[-i, :] > null_val]
|
||||||
if len(r) > 1 and len(c) > 1:
|
if r1.shape[0] > 1:
|
||||||
H.append((r[0], c[0]))
|
H.append((r1[0], c1[0]))
|
||||||
H.append((r[-1], c[-1]))
|
H.append((r1[-1], c1[-1]))
|
||||||
for j in range(0, shape[1], step):
|
if r2.shape[0] > 1:
|
||||||
r = row[:, j][image[:, j] > null_val]
|
H.append((r2[0], c2[0]))
|
||||||
c = col[:, j][image[:, j] > null_val]
|
H.append((r2[-1], c2[-1]))
|
||||||
if len(r) > 1 and len(c) > 1:
|
|
||||||
if not ((r[0], c[0]) in H):
|
|
||||||
H.append((r[0], c[0]))
|
|
||||||
if not ((r[-1], c[-1]) in H):
|
|
||||||
H.append((r[-1], c[-1]))
|
|
||||||
S = np.array(convex_hull(H))
|
S = np.array(convex_hull(H))
|
||||||
|
|
||||||
x_min, y_min = S[:, 0] < S[:, 0].mean(), S[:, 1] < S[:, 1].mean()
|
x_min, y_min = S[:, 0] < S[:, 0].mean(), S[:, 1] < S[:, 1].mean()
|
||||||
x_max, y_max = S[:, 0] > S[:, 0].mean(), S[:, 1] > S[:, 1].mean()
|
x_max, y_max = S[:, 0] > S[:, 0].mean(), S[:, 1] > S[:, 1].mean()
|
||||||
# Get the 4 extrema
|
# Get the 4 extrema
|
||||||
|
# S0 = S[x_min*y_min][np.argmin(S[x_min*y_min][:, 0])]
|
||||||
|
# S1 = S[x_min*y_max][np.argmax(S[x_min*y_max][:, 1])]
|
||||||
|
# S2 = S[x_max*y_min][np.argmin(S[x_max*y_min][:, 1])]
|
||||||
|
# S3 = S[x_max*y_max][np.argmax(S[x_max*y_max][:, 0])]
|
||||||
S0 = S[x_min*y_min][np.abs(0-S[x_min*y_min].sum(axis=1)).min() == np.abs(0-S[x_min*y_min].sum(axis=1))][0]
|
S0 = S[x_min*y_min][np.abs(0-S[x_min*y_min].sum(axis=1)).min() == np.abs(0-S[x_min*y_min].sum(axis=1))][0]
|
||||||
S1 = S[x_min*y_max][np.abs(shape[1]-S[x_min*y_max].sum(axis=1)).min() == np.abs(shape[1]-S[x_min*y_max].sum(axis=1))][0]
|
S1 = S[x_min*y_max][np.abs(shape[1]-S[x_min*y_max].sum(axis=1)).min() == np.abs(shape[1]-S[x_min*y_max].sum(axis=1))][0]
|
||||||
S2 = S[x_max*y_min][np.abs(shape[0]-S[x_max*y_min].sum(axis=1)).min() == np.abs(shape[0]-S[x_max*y_min].sum(axis=1))][0]
|
S2 = S[x_max*y_min][np.abs(shape[0]-S[x_max*y_min].sum(axis=1)).min() == np.abs(shape[0]-S[x_max*y_min].sum(axis=1))][0]
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ from os.path import join as path_join
|
|||||||
from astropy.io import fits
|
from astropy.io import fits
|
||||||
from astropy.wcs import WCS
|
from astropy.wcs import WCS
|
||||||
from lib.convex_hull import clean_ROI
|
from lib.convex_hull import clean_ROI
|
||||||
from lib.utils import princ_angle
|
|
||||||
|
|
||||||
|
|
||||||
def get_obs_data(infiles, data_folder="", compute_flux=False):
|
def get_obs_data(infiles, data_folder="", compute_flux=False):
|
||||||
|
|||||||
@@ -442,11 +442,11 @@ def get_error(data_array, headers, error_array=None, data_mask=None, sub_type=No
|
|||||||
Returns:
|
Returns:
|
||||||
data_array : numpy.ndarray
|
data_array : numpy.ndarray
|
||||||
Array containing the data to study minus the background.
|
Array containing the data to study minus the background.
|
||||||
headers : header list
|
|
||||||
Updated headers associated with the images in data_array.
|
|
||||||
error_array : numpy.ndarray
|
error_array : numpy.ndarray
|
||||||
Array containing the background values associated to the images in
|
Array containing the background values associated to the images in
|
||||||
data_array.
|
data_array.
|
||||||
|
headers : header list
|
||||||
|
Updated headers associated with the images in data_array.
|
||||||
background : numpy.ndarray
|
background : numpy.ndarray
|
||||||
Array containing the pixel background value for each image in
|
Array containing the pixel background value for each image in
|
||||||
data_array.
|
data_array.
|
||||||
|
|||||||
Reference in New Issue
Block a user