stvid/stvid/satellite.py

70 lines
2.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python
from __future__ import print_function
import os
import subprocess
from stvid.stio import fourframe
from stvid.stio import satid
from stvid.stio import observation
from tempfile import mkstemp
2018-07-22 01:36:20 -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)
# Run command
output = subprocess.check_output(command, shell=True,
stderr=subprocess.STDOUT)
2018-07-22 01:36:20 -06:00
return output
2018-07-22 01:36:20 -06:00
def find_hough3d_lines(fname, ntrkmin=20, dr=8):
# Read four frame
2018-07-22 01:36:20 -06:00
ff = fourframe(fname)
# Mask frame
2018-07-22 01:36:20 -06:00
ff.mask(10, 10, 5, 5)
# Compute selection mask
2018-07-22 01:36:20 -06:00
x, y, z, t, sig = ff.selection_mask(5.0, 40.0)
# Save points to temporary file
2018-07-22 01:36:20 -06:00
f, fpath = mkstemp()
with open(fpath, "w") as f:
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]))
f.close()
# Run 3D Hough line-finding algorithm
2018-07-22 01:36:20 -06:00
command = "hough3dlines -dx %d -minvotes %d %s" % (dr, ntrkmin, fpath)
output = subprocess.check_output(command,
shell=True,
stderr=subprocess.STDOUT)
# Remove file
os.remove(fpath)
# Clean output (a bit cluncky)
cleaned_output = output.replace("npoints=", "")
cleaned_output = cleaned_output.replace(", a=(", " ")
2018-07-22 01:36:20 -06:00
cleaned_output = cleaned_output.replace("), b=(", " ")
cleaned_output = cleaned_output.replace(")", "")
cleaned_output = cleaned_output.replace(",", " ")
print(cleaned_output)
# Generate identifications
2018-07-22 01:36:20 -06:00
lines = []
s = cleaned_output.split()
for i in range(len(s)//7):
2018-07-22 01:36:20 -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])
xmin = x0-z0*dx/dz
xmax = x0+(ff.nz-z0)*dx/dz
ymin = y0-z0*dy/dz
ymax = y0+(ff.nz-z0)*dy/dz
line = "%.23s %8.3f %8.3f %8.3f %8.3f %8.5f %s unidentified sunlit" %\
(ff.nfd, xmin, ymin, xmax, ymax, ff.texp, 99999)
lines.append(line)
return [satid(line) for line in lines]