-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcdbs_fitsver.py
98 lines (73 loc) · 1.79 KB
/
cdbs_fitsver.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
"""
CDBS FITS verification.
Requires
--------
#. CDBS `fitsverify`
#. CDBS `certify`
"""
# STDLIB
import os
import subprocess
# THIRD-PARTY
import pyfits
__author__ = 'Pey Lian Lim'
__organization__ = 'Space Telescope Science Institute'
def is_fits(fitsFile):
"""
Run CDBS `fitsverify` and extract success code.
Also run `pyfits.verify` that will throw Exception on failure.
.. note::
Special setup needed to run `fitsverify`.
Instructions available from CDBS.
Parameters
----------
fitsFile: string
FITS image to verify.
Returns
-------
isFits: bool
`True` if ok.
Raises
------
Exception
On some verification failure.
"""
isFits = False
# ----- PYFITS VERIFY -----
# Exception on failure. Else nothing happens.
with pyfits.open(fitsFile) as pf:
pf.verify(option='exception')
# ----- CDBS FITSVERIFY -----
# If no error, returns 0:
# Verification found 0 warning(s) and 0 error(s).
# Else, returns 1:
# Abort Verification: Fatal Error.
s = subprocess.check_output(['fitsverify', fitsFile])
if 'FAIL' not in s:
isFits = True
return isFits
def pass_certify(fitsFile):
"""
Run CDBS `certify` and extract success code.
.. note::
Special SETENV required. Contact CDBS.
Parameters
----------
fitsFile: string
FITS image to certify.
Returns
-------
isPassed: bool
`True` if ok.
"""
isPassed = False
# If no error, returns 0:
# == Checking xxx.fits ==
# (blank line)
# Else, returns 1:
# == Checking xxx.fits ==
# (one error on each line)
s = subprocess.call(['certify', fitsFile])
if s == 0:
isPassed = True
return isPassed