Fix pycodestyle errors

pull/10/head
Pierros Papadeas 2018-07-22 10:36:20 +03:00
parent 658cc9e7c3
commit eedac86f08
No known key found for this signature in database
GPG Key ID: 8DB97129D9982991
6 changed files with 82 additions and 73 deletions

View File

@ -232,10 +232,10 @@ def extract_tracks(fname, trkrmin, drdtmin, trksig, ntrkmin, path):
"classfd/classfd.dat")
elif id.catalog.find("inttles.tle") > 0:
outfname = os.path.join(path,
"/classfd/inttles.dat")
"classfd/inttles.dat")
else:
outfname = os.path.join(path,
"/catalog/catalog.dat")
"catalog/catalog.dat")
f = open(outfname, "a")
f.write("%s\n" % iod_line)
@ -305,13 +305,13 @@ def extract_tracks(fname, trkrmin, drdtmin, trksig, ntrkmin, path):
# Copy files
if id.catalog.find("classfd.tle") > 0:
copy_files(fname.replace(".fits", "*"),
os.path.join(path, "/classfd"))
os.path.join(path, "classfd"))
elif id.catalog.find("inttles.tle") > 0:
copy_files(fname.replace(".fits", "*"),
os.path.join(path, "/classfd"))
os.path.join(path, "classfd"))
else:
copy_files(fname.replace(".fits", "*"),
os.path.join(path, "/catalog"))
os.path.join(path, "catalog"))
elif id.catalog.find("classfd.tle") > 0:
# Track and stack
@ -373,11 +373,11 @@ def extract_tracks(fname, trkrmin, drdtmin, trksig, ntrkmin, path):
print(iod_line)
if id.catalog.find("classfd.tle") > 0:
outfname = os.path.join(path, "/classfd/classfd.dat")
outfname = os.path.join(path, "classfd/classfd.dat")
elif id.catalog.find("inttles.tle") > 0:
outfname = os.path.join(path, "/classfd/inttles.dat")
outfname = os.path.join(path, "classfd/inttles.dat")
else:
outfname = os.path.join(path, "/catalog/catalog.dat")
outfname = os.path.join(path, "catalog/catalog.dat")
f = open(outfname, "a")
f.write("%s\n" % iod_line)
@ -444,13 +444,13 @@ def extract_tracks(fname, trkrmin, drdtmin, trksig, ntrkmin, path):
# Copy files
if id.catalog.find("classfd.tle") > 0:
copy_files(fname.replace(".fits", "*"),
os.path.join(path, "/classfd"))
os.path.join(path, "classfd"))
elif id.catalog.find("inttles.tle") > 0:
copy_files(fname.replace(".fits", "*"),
os.path.join(path, "/classfd"))
os.path.join(path, "classfd"))
else:
copy_files(fname.replace(".fits", "*"),
os.path.joine(path, "/catalog"))
os.path.joine(path, "catalog"))
if __name__ == '__main__':
@ -489,9 +489,12 @@ if __name__ == '__main__':
# Create output dirs
path = args.file_dir
os.makedirs(os.path.join(path, "classfd"))
os.makedirs(os.path.join(path, "catalog"))
os.makedirs(os.path.join(path, "unid"))
if not os.path.exists(os.path.join(path, "classfd")):
os.makedirs(os.path.join(path, "classfd"))
if not os.path.exists(os.path.join(path, "catalog")):
os.makedirs(os.path.join(path, "catalog"))
if not os.path.exists(os.path.join(path, "unid")):
os.makedirs(os.path.join(path, "unid"))
# Get files
files = sorted(glob.glob(os.path.join(path, "2*.fits")))

View File

@ -39,7 +39,7 @@ else:
# Move to processing directory
os.chdir(args.file_dir)
table = ascii.read(args.input, format="csv")
t = Time(table['mjd'], format="mjd", scale="utc")

View File

@ -49,7 +49,7 @@ if __name__ == "__main__":
# Move to processing directory
os.chdir(args.file_dir)
# Get files
files = sorted(glob.glob("2*.fits"))
@ -70,8 +70,8 @@ if __name__ == "__main__":
generate_satellite_predictions(fname)
# Extract lines with 3D Hough transform
ids=find_hough3d_lines(fname)
ids = find_hough3d_lines(fname)
# Stars available and used
nused = np.sum(pix_catalog.flag == 1)
nstars = pix_catalog.nstars

View File

@ -7,36 +7,40 @@ from stvid.stio import satid
from stvid.stio import observation
from tempfile import mkstemp
def generate_satellite_predictions(fname):
# Format command
command = "satid %s %s.png/png"%(fname, fname)
command = "satid %s %s.png/png" % (fname, fname)
# Run command
output = subprocess.check_output(command, shell=True,
stderr=subprocess.STDOUT)
return
return output
def find_hough3d_lines(fname,ntrkmin=20,dr=8):
def find_hough3d_lines(fname, ntrkmin=20, dr=8):
# Read four frame
ff=fourframe(fname)
ff = fourframe(fname)
# Mask frame
ff.mask(10,10,5,5)
ff.mask(10, 10, 5, 5)
# Compute selection mask
x,y,z,t,sig=ff.selection_mask(5.0,40.0)
x, y, z, t, sig = ff.selection_mask(5.0, 40.0)
# Save points to temporary file
f,fpath=mkstemp()
with open(fpath,"w") as f:
f, fpath = mkstemp()
with open(fpath, "w") as f:
for i in range(len(t)):
f.write("%f,%f,%f\n"%(x[i],y[i],z[i]))
f.write("%f,%f,%f\n" % (x[i], y[i], z[i]))
f.close()
# Run 3D Hough line-finding algorithm
command="hough3dlines -dx %d -minvotes %d %s"%(dr,ntrkmin,fpath)
output=subprocess.check_output(command,shell=True,stderr=subprocess.STDOUT)
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)
@ -44,22 +48,22 @@ def find_hough3d_lines(fname,ntrkmin=20,dr=8):
# Clean output (a bit cluncky)
cleaned_output = output.replace("npoints=", "")
cleaned_output = cleaned_output.replace(", a=(", " ")
cleaned_output = cleaned_output.replace("), b=("," ")
cleaned_output = cleaned_output.replace("), b=(", " ")
cleaned_output = cleaned_output.replace(")", "")
cleaned_output = cleaned_output.replace(",", " ")
print(cleaned_output)
# Generate identifications
lines=[]
s=cleaned_output.split()
lines = []
s = cleaned_output.split()
for i in range(len(s)//7):
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)
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]

View File

@ -4,6 +4,7 @@ import os
import subprocess
import numpy as np
class pixel_catalog:
"""Pixel catalog"""

View File

@ -6,6 +6,7 @@ from astropy.time import Time
from astropy import wcs
from scipy import ndimage
class observation:
"""Satellite observation"""
@ -94,8 +95,8 @@ class fourframe:
self.zavg, self.zstd, self.zmax, self.znum = hdu[0].data
# Generate sigma frame
self.zsig=(self.zmax-self.zavg)/(self.zstd+1e-9)
self.zsig = (self.zmax-self.zavg)/(self.zstd+1e-9)
# Frame properties
self.ny, self.nx = self.zavg.shape
self.nz = hdu[0].header['NFRAMES']
@ -144,46 +145,46 @@ class fourframe:
self.w.wcs.ctype = self.ctype
self.w.wcs.set_pv([(2, 1, 45.0)])
def mask(self, xmin, xmax, ymin, ymax):
x, y = np.meshgrid(np.arange(self.nx), np.arange(self.ny))
c = (x >= xmin) & (x <= self.nx-xmax)\
& (y >= ymin)\
& (y <= self.ny-ymax)
self.mask = np.ones_like(self.zavg)
self.mask[~c] = 0.0
self.zavg *= self.mask
self.zstd *= self.mask
self.zmax *= self.mask
self.znum *= self.mask
self.zsig *= self.mask
def mask(self,xmin,xmax,ymin,ymax):
x,y=np.meshgrid(np.arange(self.nx),np.arange(self.ny))
c=(x>=xmin) & (x<=self.nx-xmax) & (y>=ymin) & (y<=self.ny-ymax)
self.mask=np.ones_like(self.zavg)
self.mask[~c]=0.0
self.zavg*=self.mask
self.zstd*=self.mask
self.zmax*=self.mask
self.znum*=self.mask
self.zsig*=self.mask
def selection_mask(self,sigma,zstd):
def selection_mask(self, sigma, zstd):
"""Create a selection mask"""
c1=ndimage.uniform_filter(self.znum,3,mode='constant')
c2=ndimage.uniform_filter(self.znum*self.znum,3,mode='constant')
z=np.sqrt(c2-c1*c1)
c1 = ndimage.uniform_filter(self.znum, 3, mode='constant')
c2 = ndimage.uniform_filter(self.znum*self.znum, 3, mode='constant')
z = np.sqrt(c2-c1*c1)
# Standard deviation mask
c=z<zstd
m1=np.zeros_like(self.zavg)
m1[c]=1.0
c = z < zstd
m1 = np.zeros_like(self.zavg)
m1[c] = 1.0
# Sigma mask
c=self.zsig<sigma
m2=np.zeros_like(self.zavg)
m2[~c]=1.0
self.zsel=m1*m2
c = self.zsig < sigma
m2 = np.zeros_like(self.zavg)
m2[~c] = 1.0
self.zsel = m1*m2
# Generate points
c=self.zsel==1.0
xm,ym=np.meshgrid(np.arange(self.nx),np.arange(self.ny))
x,y=np.ravel(xm[c]),np.ravel(ym[c])
inum=np.ravel(self.znum[c]).astype('int')
sig=np.ravel(self.zsig[c])
t=np.array([self.dt[i] for i in inum])
c = self.zsel == 1.0
xm, ym = np.meshgrid(np.arange(self.nx), np.arange(self.ny))
x, y = np.ravel(xm[c]), np.ravel(ym[c])
inum = np.ravel(self.znum[c]).astype('int')
sig = np.ravel(self.zsig[c])
t = np.array([self.dt[i] for i in inum])
return x,y,inum,t,sig
return x, y, inum, t, sig
def significant_pixels_along_track(self, sigma, x0, y0,
dxdt, dydt, rmin=10.0):
"""Extract significant pixels along a track"""