def _detsat_one(filename, ext, sigma=<NUM_LIT>, low_thresh=<NUM_LIT:0.1>, h_thresh=<NUM_LIT:0.5>,<EOL>small_edge=<NUM_LIT>, line_len=<NUM_LIT:200>, line_gap=<NUM_LIT>,<EOL>percentile=(<NUM_LIT>, <NUM_LIT>), buf=<NUM_LIT:200>, plot=False, verbose=False):
if verbose:<EOL><INDENT>t_beg = time.time()<EOL><DEDENT>fname = '<STR_LIT>'.format(filename, ext)<EOL>if ext not in (<NUM_LIT:1>, <NUM_LIT:4>, '<STR_LIT>', ('<STR_LIT>', <NUM_LIT:1>), ('<STR_LIT>', <NUM_LIT:2>)):<EOL><INDENT>warnings.warn('<STR_LIT>'<EOL>'<STR_LIT>'.format(ext), AstropyUserWarning)<EOL><DEDENT>image = fits.getdata(filename, ext)<EOL>p1, p2 = np.percentile(image, percentile)<EOL>if p1 < <NUM_LIT:0>:<EOL><INDENT>p1 = <NUM_LIT:0.0><EOL><DEDENT>if verbose:<EOL><INDENT>print('<STR_LIT>'.format(p1, p2))<EOL><DEDENT>image = exposure.rescale_intensity(image, in_range=(p1, p2))<EOL>immax = np.max(image)<EOL>edge = canny(image, sigma=sigma,<EOL>low_threshold=immax * low_thresh,<EOL>high_threshold=immax * h_thresh)<EOL>morph.remove_small_objects(edge, min_size=small_edge, connectivity=<NUM_LIT:8>,<EOL>in_place=True)<EOL>angle = np.radians(np.arange(<NUM_LIT:2>, <NUM_LIT>, <NUM_LIT:0.5>, dtype=float))<EOL>if plot and plt is not None:<EOL><INDENT>h, theta, d = transform.hough_line(edge, theta=angle)<EOL>plt.ion()<EOL><DEDENT>result = transform.probabilistic_hough_line(<EOL>edge, threshold=<NUM_LIT>, line_length=line_len,<EOL>line_gap=line_gap, theta=angle)<EOL>result = np.asarray(result)<EOL>n_result = len(result)<EOL>satellite = False<EOL>if n_result > <NUM_LIT:1>:<EOL><INDENT>if verbose:<EOL><INDENT>print('<STR_LIT>'.format(n_result))<EOL><DEDENT>x0 = result[:, <NUM_LIT:0>, <NUM_LIT:0>]<EOL>y0 = result[:, <NUM_LIT:0>, <NUM_LIT:1>]<EOL>x1 = result[:, <NUM_LIT:1>, <NUM_LIT:0>]<EOL>y1 = result[:, <NUM_LIT:1>, <NUM_LIT:1>]<EOL>ymax, xmax = image.shape<EOL>topx = xmax - buf<EOL>topy = ymax - buf<EOL>if verbose:<EOL><INDENT>print('<STR_LIT>'<EOL>'<STR_LIT>'.format(min(x0), min(x1), min(y0), min(y1)))<EOL>print('<STR_LIT>'<EOL>'<STR_LIT>'.format(max(x0), max(x1), max(y0), max(y1)))<EOL>print('<STR_LIT>'.format(buf))<EOL>print('<STR_LIT>'.format(topx, topy))<EOL><DEDENT>trail_angle = np.degrees(np.arctan((y1 - y0) / (x1 - x0)))<EOL>round_angle = (<NUM_LIT:5> * np.round(trail_angle * <NUM_LIT>)).astype(int)<EOL>mask = round_angle % <NUM_LIT> != <NUM_LIT:0><EOL>if not np.any(mask):<EOL><INDENT>if verbose:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>return np.empty(<NUM_LIT:0>)<EOL><DEDENT>round_angle = round_angle[mask]<EOL>trail_angle = trail_angle[mask]<EOL>result = result[mask]<EOL>ang, num = stats.mode(round_angle)<EOL>truth = round_angle == ang[<NUM_LIT:0>]<EOL>if verbose:<EOL><INDENT>print('<STR_LIT>'.format(trail_angle))<EOL>print('<STR_LIT>'.format(round_angle))<EOL>print('<STR_LIT>'.format(ang[<NUM_LIT:0>]))<EOL><DEDENT>trail_angle = trail_angle[truth]<EOL>result = result[truth]<EOL>n_result = len(result)<EOL>if verbose:<EOL><INDENT>print('<STR_LIT>'.format(trail_angle))<EOL><DEDENT>if n_result < <NUM_LIT:1>:<EOL><INDENT>return np.empty(<NUM_LIT:0>)<EOL><DEDENT>elif n_result > <NUM_LIT>:<EOL><INDENT>warnings.warn(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(n_result, fname),<EOL>AstropyUserWarning)<EOL>return np.empty(<NUM_LIT:0>)<EOL><DEDENT>x0 = result[:, <NUM_LIT:0>, <NUM_LIT:0>]<EOL>y0 = result[:, <NUM_LIT:0>, <NUM_LIT:1>]<EOL>x1 = result[:, <NUM_LIT:1>, <NUM_LIT:0>]<EOL>y1 = result[:, <NUM_LIT:1>, <NUM_LIT:1>]<EOL>min_x0 = min(x0)<EOL>min_y0 = min(y0)<EOL>min_x1 = min(x1)<EOL>min_y1 = min(y1)<EOL>max_x0 = max(x0)<EOL>max_y0 = max(y0)<EOL>max_x1 = max(x1)<EOL>max_y1 = max(y1)<EOL>mean_angle = np.mean(trail_angle)<EOL>if (((min_y0 < buf) or (min_y1 < buf)) and<EOL>((max_y0 > topy) or (max_y1 > topy))):<EOL><INDENT>satellite = True<EOL>if verbose:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT><DEDENT>elif (((min_x0 < buf) or (min_x1 < buf)) and<EOL>((max_x0 > topx) or (max_x1 > topx))):<EOL><INDENT>satellite = True<EOL>if verbose:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT><DEDENT>elif (((min_x0 < buf) or (min_x1 < buf)) and<EOL>((min_y0 < buf) or (min_y1 < buf)) and<EOL>(-<NUM_LIT:1> > mean_angle > -<NUM_LIT>)):<EOL><INDENT>satellite = True<EOL>if verbose:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT><DEDENT>elif (((min_x0 < buf) or (min_x1 < buf)) and<EOL>((max_y0 > topy) or (max_y1 > topy)) and<EOL>(<NUM_LIT> > mean_angle > <NUM_LIT:1>)):<EOL><INDENT>satellite = True<EOL>if verbose:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT><DEDENT>elif (((max_x0 > topx) or (max_x1 > topx)) and<EOL>((max_y0 > topy) or (max_y1 > topy)) and<EOL>(-<NUM_LIT:1> > mean_angle > -<NUM_LIT>)):<EOL><INDENT>satellite = True<EOL>if verbose:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT><DEDENT>elif (((max_x0 > topx) or (max_x1 > topx)) and<EOL>((min_y0 < buf) or (min_y1 < buf)) and<EOL>(<NUM_LIT> > mean_angle > <NUM_LIT:1>)):<EOL><INDENT>satellite = True<EOL>if verbose:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>if satellite:<EOL><INDENT>if verbose:<EOL><INDENT>print('<STR_LIT>'.format(n_result))<EOL>print('<STR_LIT>')<EOL>print(trail_angle)<EOL>print('<STR_LIT>')<EOL>for i, ((px0, py0), (px1, py1)) in enumerate(result, <NUM_LIT:1>):<EOL><INDENT>print('<STR_LIT>'.format(<EOL>i, px0, py0, px1, py1))<EOL><DEDENT><DEDENT>if plot and plt is not None:<EOL><INDENT>mean = np.median(image)<EOL>stddev = image.std()<EOL>lower = mean - stddev<EOL>upper = mean + stddev<EOL>fig1, ax1 = plt.subplots()<EOL>ax1.imshow(edge, cmap=plt.cm.gray)<EOL>ax1.set_title('<STR_LIT>'.format(fname))<EOL>for (px0, py0), (px1, py1) in result:  <EOL><INDENT>ax1.plot((px0, px1), (py0, py1), scalex=False, scaley=False)<EOL><DEDENT>fig2, ax2 = plt.subplots()<EOL>ax2.imshow(<EOL>np.log(<NUM_LIT:1> + h),<EOL>extent=(np.rad2deg(theta[-<NUM_LIT:1>]), np.rad2deg(theta[<NUM_LIT:0>]),<EOL>d[-<NUM_LIT:1>], d[<NUM_LIT:0>]), aspect=<NUM_LIT>)<EOL>ax2.set_title('<STR_LIT>')<EOL>ax2.set_xlabel('<STR_LIT>')<EOL>ax2.set_ylabel('<STR_LIT>')<EOL>fig3, ax3 = plt.subplots()<EOL>ax3.imshow(image, vmin=lower, vmax=upper, cmap=plt.cm.gray)<EOL>ax3.set_title(fname)<EOL>for (px0, py0), (px1, py1) in result:  <EOL><INDENT>ax3.plot((px0, px1), (py0, py1), scalex=False, scaley=False)<EOL><DEDENT>plt.draw()<EOL><DEDENT><DEDENT>else:  <EOL><INDENT>result = np.empty(<NUM_LIT:0>)<EOL>if verbose:<EOL><INDENT>print('<STR_LIT>'.format(n_result))<EOL><DEDENT>if plot and plt is not None:<EOL><INDENT>fig1, ax1 = plt.subplots()<EOL>ax1.imshow(edge, cmap=plt.cm.gray)<EOL>ax1.set_title(fname)<EOL>for (px0, py0), (px1, py1) in result:<EOL><INDENT>ax1.plot((px0, px1), (py0, py1), scalex=False, scaley=False)<EOL><DEDENT><DEDENT><DEDENT>if verbose:<EOL><INDENT>t_end = time.time()<EOL>print('<STR_LIT>'.format(t_end - t_beg))<EOL><DEDENT>return result<EOL>
Called by :func:`detsat`.