2018-05-07 14:19:05 -06:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from __future__ import print_function
|
|
|
|
import subprocess
|
|
|
|
from stvid.stio import fourframe
|
|
|
|
from stvid.stio import satid
|
2019-05-12 08:11:15 -06:00
|
|
|
|
2018-07-22 01:36:20 -06:00
|
|
|
|
2018-05-07 14:19:05 -06:00
|
|
|
def generate_satellite_predictions(fname):
|
|
|
|
# Format command
|
2018-07-22 01:36:20 -06:00
|
|
|
command = "satid %s %s.png/png" % (fname, fname)
|
2018-05-07 14:19:05 -06:00
|
|
|
|
|
|
|
# Run command
|
2019-05-12 08:11:15 -06:00
|
|
|
output = subprocess.check_output(command,
|
|
|
|
shell=True,
|
2018-05-07 14:19:05 -06:00
|
|
|
stderr=subprocess.STDOUT)
|
|
|
|
|
2018-07-22 01:36:20 -06:00
|
|
|
return output
|
|
|
|
|
2018-05-07 14:19:05 -06:00
|
|
|
|
2018-07-22 01:36:20 -06:00
|
|
|
def find_hough3d_lines(fname, ntrkmin=20, dr=8):
|
2018-05-07 14:19:05 -06:00
|
|
|
# Read four frame
|
2018-07-22 01:36:20 -06:00
|
|
|
ff = fourframe(fname)
|
2018-05-07 14:19:05 -06:00
|
|
|
|
|
|
|
# Mask frame
|
2018-07-22 01:36:20 -06:00
|
|
|
ff.mask(10, 10, 5, 5)
|
2018-05-07 14:19:05 -06:00
|
|
|
|
|
|
|
# Compute selection mask
|
2018-07-22 01:36:20 -06:00
|
|
|
x, y, z, t, sig = ff.selection_mask(5.0, 40.0)
|
|
|
|
|
2019-04-22 08:11:46 -06:00
|
|
|
# Skip if not enough points
|
2019-05-12 08:11:15 -06:00
|
|
|
if len(t) < 2:
|
2019-04-22 08:11:46 -06:00
|
|
|
return []
|
2019-05-12 08:11:15 -06:00
|
|
|
|
2018-05-07 14:19:05 -06:00
|
|
|
# Save points to temporary file
|
2019-04-22 08:11:46 -06:00
|
|
|
with open("/tmp/hough.dat", "w") as f:
|
2018-05-07 14:19:05 -06:00
|
|
|
for i in range(len(t)):
|
2018-07-22 01:36:20 -06:00
|
|
|
f.write("%f,%f,%f\n" % (x[i], y[i], z[i]))
|
2018-05-07 14:19:05 -06:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
# Run 3D Hough line-finding algorithm
|
2019-05-12 08:11:15 -06:00
|
|
|
command = "hough3dlines -dx %d -minvotes %d %s" % (dr, ntrkmin,
|
|
|
|
"/tmp/hough.dat")
|
2019-04-22 08:11:46 -06:00
|
|
|
try:
|
|
|
|
output = subprocess.check_output(command,
|
|
|
|
shell=True,
|
|
|
|
stderr=subprocess.STDOUT)
|
2019-05-12 08:11:15 -06:00
|
|
|
except Exception:
|
2019-04-22 08:11:46 -06:00
|
|
|
return []
|
2018-05-07 14:19:05 -06:00
|
|
|
|
|
|
|
# Clean output (a bit cluncky)
|
2019-04-28 03:01:31 -06:00
|
|
|
cleaned_output = output.decode("utf-8").replace("npoints=", "")
|
2018-05-07 14:19:05 -06:00
|
|
|
cleaned_output = cleaned_output.replace(", a=(", " ")
|
2018-07-22 01:36:20 -06:00
|
|
|
cleaned_output = cleaned_output.replace("), b=(", " ")
|
2018-05-07 14:19:05 -06:00
|
|
|
cleaned_output = cleaned_output.replace(")", "")
|
|
|
|
cleaned_output = cleaned_output.replace(",", " ")
|
2019-04-22 08:11:46 -06:00
|
|
|
|
2018-05-07 14:19:05 -06:00
|
|
|
# Generate identifications
|
2018-07-22 01:36:20 -06:00
|
|
|
lines = []
|
|
|
|
s = cleaned_output.split()
|
2019-05-12 08:11:15 -06:00
|
|
|
for i in range(len(s) // 7):
|
2019-04-22 08:11:46 -06:00
|
|
|
# Extract points
|
2019-05-12 08:11:15 -06:00
|
|
|
x0, y0, z0 = float(s[1 + 7 * i]), float(s[2 + 7 * i]), float(s[3 +
|
|
|
|
7 * i])
|
|
|
|
dx, dy, dz = float(s[4 + 7 * i]), float(s[5 + 7 * i]), float(s[6 +
|
|
|
|
7 * i])
|
|
|
|
|
2019-04-22 08:11:46 -06:00
|
|
|
# Reconstruct start and end points
|
2019-05-12 08:11:15 -06:00
|
|
|
xmin = x0 - z0 * dx / (dz + 1e-9)
|
|
|
|
xmax = x0 + (ff.nz - z0) * dx / (dz + 1e-9)
|
|
|
|
ymin = y0 - z0 * dy / (dz + 1e-9)
|
|
|
|
ymax = y0 + (ff.nz - z0) * dy / (dz + 1e-9)
|
2019-04-22 08:11:46 -06:00
|
|
|
|
|
|
|
# Output line
|
|
|
|
line = "%.23s %8.3f %8.3f %8.3f %8.3f %8.5f %s unidentified sunlit\n" %\
|
|
|
|
(ff.nfd, xmin, ymin, xmax, ymax, ff.texp, 99999-i)
|
2018-05-07 14:19:05 -06:00
|
|
|
lines.append(line)
|
|
|
|
|
2019-04-22 08:11:46 -06:00
|
|
|
# Store identifications
|
|
|
|
fp = open(fname + ".id", "a")
|
|
|
|
for line in lines:
|
|
|
|
fp.write(line)
|
|
|
|
fp.close()
|
2019-05-12 08:11:15 -06:00
|
|
|
|
2018-05-07 14:19:05 -06:00
|
|
|
return [satid(line) for line in lines]
|