This repository has been archived by the owner on May 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MeasureNight.py
executable file
·119 lines (103 loc) · 4.44 KB
/
MeasureNight.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python
# encoding: utf-8
"""
untitled.py
Created by Josh Walawender on 2012-10-29.
Copyright (c) 2012 . All rights reserved.
"""
import sys
import os
import subprocess
import re
import fnmatch
import numpy
import time
from argparse import ArgumentParser
import IQMon
help_message = '''
The help message goes here.
'''
def GetImtype(imageFile):
RawFile = os.path.abspath(imageFile)
RawFileDirectory, RawFilename = os.path.split(RawFile)
RawBasename, RawExt = os.path.splitext(RawFilename)
DataNightDirectory, DataNightString = os.path.split(os.path.split(RawFileDirectory)[0])
infoFile = os.path.join(DataNightDirectory, DataNightString, "CR2info", RawBasename+'.info')
infoFO = open(infoFile, 'r')
info = infoFO.read()
lines = info.split("\n")
infoFO.close()
imtype = None
for line in lines:
IsMatch = re.match("IMTYPE:\s+(\w+)", line)
if IsMatch:
imtype = IsMatch.group(1)
return imtype
def main(argv=None):
##-------------------------------------------------------------------------
## Parse Command Line Arguments
##-------------------------------------------------------------------------
## create a parser object for understanding command-line arguments
parser = ArgumentParser(description="Describe the script")
## add flags
parser.add_argument("-n", "--no-clobber",
dest="clobber", action="store_false", default=True,
help="Delete previous logs and summary files for this night. (default = True)")
## add arguments
parser.add_argument("-d", "--date",
dest="date", required=False, default="", type=str,
help="UT date of night to analyze. (i.e. '2013-08-05')")
args = parser.parse_args()
##-------------------------------------------------------------------------
## Set date to tonight if not specified
##-------------------------------------------------------------------------
now = time.gmtime()
DateString = time.strftime("%Y-%m-%d", now)
if not args.date:
args.date = DateString
## Set Path to Data for this night
DataPath = os.path.join("/skycamdata")
ImagesDirectory = os.path.join(DataPath, args.date, "CR2")
print "Analyzing data for night of "+args.date
if os.path.exists(ImagesDirectory):
print " Found "+ImagesDirectory
##
## Loop Through All Images in Images Directory
##
Files = sorted(os.listdir(ImagesDirectory))
print "Found %d files in images directory" % len(Files)
if len(Files) >= 1:
## Parse filename for date and time
MatchFilename = re.compile("IMG0_(\d{4})\.CR2")
Properties = []
for File in Files:
IsMatch = MatchFilename.match(File)
if IsMatch:
filenumber = IsMatch.group(1)
imtype = GetImtype(os.path.join(ImagesDirectory, File))
if imtype and imtype == "OBJECT":
Properties.append([filenumber, File])
SortedImageFiles = numpy.array([row[1] for row in sorted(Properties)])
print "%d out of %d files meet selection criteria." % (len(SortedImageFiles), len(Files))
for Image in SortedImageFiles:
if fnmatch.fnmatch(Image, "*.CR2"):
now = time.gmtime()
TimeString = time.strftime("%Y/%m/%d %H:%M:%S UT -", now)
DateString = time.strftime("%Y%m%dUT", now)
ProcessCall = ["/home/panoptesmlo/bin/Panoptes/MeasureImage.py"]
if args.clobber and Image == SortedImageFiles[0]:
ProcessCall.append("--clobber")
ProcessCall.append(os.path.join(ImagesDirectory, Image))
print "%s Calling MeasureImage.py with %s" % (TimeString, ProcessCall)
try:
MIoutput = subprocess.check_output(ProcessCall, stderr=subprocess.STDOUT)
for line in MIoutput.split("\n"):
print line
except:
print "Call to MeasureImage.py Failed: {0} {1} {2}".format(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])
else:
print "No image files found in directory: "+ImagesDirectory
else:
print "No Images or Logs directory for this night"
if __name__ == "__main__":
sys.exit(main())