-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheck-refs.py
70 lines (59 loc) · 2.12 KB
/
check-refs.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
import gc
import os
import sys
import glob
import numpy as np
from astropy.io import fits
def doStuff(fits_file):
# Open file
with fits.open(fits_file, memmap=True) as hdul:
# Read in hdu[2] DATA_TABLE
data = hdul['DATA_TABLE'].data
# Mask of all REF type rows
mask = data['scan_type']=='OTF'
# All REF type scanID
listOTF = hdul['DATA_TABLE'].data['scanID'][mask]
if (len(list(set(listOTF))) == 1):
otf = list(set(listOTF))[0]
elif (len(list(set(listOTF))) == 0):
print(fits_file, "error no otf!")
new_file = f"{fits_file}.bad"
os.rename(fits_file, new_file)
return
elif (len(list(set(listOTF))) > 1):
print(fits_file, "error more than one otf")
new_file = f"{fits_file}.bad"
os.rename(fits_file, new_file)
return
# Mask of all REF type rows
mask = data['scan_type']=='REF'
# All REF type scanID
listREF = hdul['DATA_TABLE'].data['scanID'][mask]
if not listREF.size:
print(fits_file, "error no REFs!")
new_file = f"{fits_file}.bad"
os.rename(fits_file, new_file)
return
# Mask of all HOT type rows
mask = data['scan_type']=='HOT'
# All REF type scanID
listHOT = hdul['DATA_TABLE'].data['scanID'][mask]
if not listHOT.size:
print(fits_file, "error no HOTs!")
new_file = f"{fits_file}.bad"
os.rename(fits_file, new_file)
return
earliestREF = list(sorted(set(listREF)))[0]
latestREF = list(sorted(set(listREF)))[len(list(set(listREF)))-1]
if( earliestREF < otf < latestREF ):
print(earliestREF, otf, latestREF, " OK", len(set(listREF)))
else:
print(earliestREF, otf, latestREF, " ERROR")
new_file = f"{fits_file}.bad"
os.rename(fits_file, new_file)
directory = "./"
partial = sys.argv[1]
fits_files = sorted(glob.glob(f"{directory}/{partial}.fits"))
for fits_file in fits_files:
doStuff(fits_file)
gc.collect()