-
Notifications
You must be signed in to change notification settings - Fork 1
/
filter.py
68 lines (53 loc) · 1.45 KB
/
filter.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
from ccdproc import CCDData
import astropy.io.fits as fits, astropy.units as units
import numpy as np
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--list', default='list.list')
parser.add_argument('--output', default='output.list')
parser.add_argument('--reference', default=False)
parser.add_argument('--threshold', default=0.2, type=float)
args = parser.parse_args()
def error(description):
print("Error: " + description)
exit()
def warning(description):
print("Warning: " + description)
def log(description):
print(description)
try:
lst_f = open(args.list, 'r')
except:
error("List file list not found: " + args.list)
lst = lst_f.read()
lst = lst.replace('\r\n', '\n')
lst = lst.replace('\r', '\n')
lst = lst.split('\n')
log("Loading file(s)...")
f = open(args.output, 'w')
first = True
avg = float(args.reference) or False
lst_out = []
for i in lst:
try:
#if True:
data = CCDData.read(i, unit='adu')
log('Reading file ' + i)
if avg == False:
avg = np.mean(data)
log('Reference pixel value: ' + str(avg))
else:
avg_tmp = np.mean(data)
log('Pixel value: ' + str(avg_tmp))
var = float(avg_tmp) / avg
if var > 1 + args.threshold or var < 1 - args.threshold:
log('Discarded image ' + i)
else:
log('Accepted image ' + i)
lst_out.append(i)
except:
log("Error while reading file " + i)
out = '\n'.join(lst_out)
log('Writing output to ' + args.output)
with open(args.output, 'w') as f:
f.write(out)