summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/__init__.py47
-rw-r--r--lib/mappings.py38
2 files changed, 85 insertions, 0 deletions
diff --git a/lib/__init__.py b/lib/__init__.py
new file mode 100644
index 0000000..08e421b
--- /dev/null
+++ b/lib/__init__.py
@@ -0,0 +1,47 @@
+import wcsutil
+from wcsutil import HSTWCS
+from pytools import fileutil, parseinput
+import pyfits
+
+#to avoid relative imports
+import mappings
+from mappings import basic_wcs
+import distortion
+import pywcs
+
+def restoreWCS(fnames):
+ """
+ Given a list of fits file names restore the original basic WCS kw
+ and write out the files. This overwrites the original files.
+ """
+ files = parseinput.parseinput(fnames)[0]
+ for f in files:
+ isfits, ftype = fileutil.isFits(f)
+ if not isfits or (isfits and ftype == 'waiver'):
+ print "RestoreWCS works only on multiextension fits files."
+ return
+ else:
+ fobj = pyfits.open(f, mode='update')
+ hdr0 = fobj[0].header
+ for ext in fobj:
+ try:
+ extname = ext.header['EXTNAME'].lower()
+ except KeyError:
+ continue
+ if extname in ['sci', 'err', 'sdq']:
+ hdr = ext.header
+ owcs = HSTWCS(hdr0, hdr)
+ #Changed restore to update the attributes ???
+ # this may need to be changed
+ backup = owcs.restore()
+ if not backup:
+ print '\No archived keywords found.\n'
+ continue
+ else:
+ for kw in basic_wcs:
+ nkw = ('O'+kw)[:7]
+ if backup.has_key(kw):
+ hdr.update(kw, hdr[nkw])
+ fobj.close()
+
+
diff --git a/lib/mappings.py b/lib/mappings.py
new file mode 100644
index 0000000..fed9b60
--- /dev/null
+++ b/lib/mappings.py
@@ -0,0 +1,38 @@
+from pytools import fileutil
+
+# This dictionary maps an instrument into an instrument class
+# The instrument class handles instrument specific keywords
+
+inst_mappings={'WFPC2': 'WFPC2WCS',
+ 'ACS': 'ACSWCS'
+ }
+
+DEGTORAD = fileutil.DEGTORAD
+RADTODEG = fileutil.RADTODEG
+
+# A dictionary which lists the allowed corrections for each instrument.
+# These are the default corrections applied also in the pipeline.
+#Dgeo correction is applied separately.
+allowed_corrections={'WFPC2': ['MakeWCS','CompSIP'],
+ 'ACS': ['TDDCorr', 'MakeWCS','CompSIP', 'VACorr']
+ }
+
+# A list of instrument specific keywords
+# Every instrument class must have methods which define each of these
+# as class attributes.
+ins_spec_kw = ['ltv1', 'ltv2', 'parity', 'binned','vafactor', 'chip',
+ 'naxis1', 'naxis2', 'filter1', 'filter2']
+
+# A list of keywords defined in the primary header.
+# The HSTWCS class sets this as attributes
+prim_hdr_kw = ['detector', 'offtab', 'idctab', 'date-obs',
+ 'pa_v3', 'ra_targ', 'dec_targ']
+
+# These are the keywords which are archived before MakeWCS is run
+basic_wcs = ['CD1_1', 'CD1_2', 'CD2_1', 'CD2_2', 'CRVAL1','CRVAL2','CTYPE1', 'CTYPE2',
+ 'CRPIX1', 'CRPIX2', 'CTYPE1', 'CTYPE2', 'ORIENTAT']
+
+dgeo_vals = {'ACS':
+ {'naxis1':65, 'naxis2':33, 'extver':1, 'crpix1':33.5, 'crpix2':16.5,
+ 'cdelt1':1., 'cdelt2':1., 'crval1':2048., 'crval2':1024.}
+ } \ No newline at end of file