Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-7886: pyfits to astropy #136

Merged
merged 5 commits into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 16 additions & 17 deletions bin.src/genDefectFits.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re

import numpy
import pyfits
from astropy.io import fits
import collections

from lsst.obs.hsc import HscMapper
Expand All @@ -27,19 +27,18 @@ def genDefectFits(cameraName, source, targetDir):

defects = dict()

f = open(source, "r")
for line in f:
line = re.sub("\#.*", "", line).strip()
if len(line) == 0:
continue
ccd, x0, y0, width, height = re.split("\s+", line)
ccd = int(ccd)
if ccd not in ccds:
raise RuntimeError("Unrecognised ccd: %d" % ccd)
if ccd not in defects:
defects[ccd] = list()
defects[ccd].append(Defect(x0=int(x0), y0=int(y0), width=int(width), height=int(height)))
f.close()
with open(source, "r") as f:
for line in f:
line = re.sub("\#.*", "", line).strip()
if len(line) == 0:
continue
ccd, x0, y0, width, height = re.split("\s+", line)
ccd = int(ccd)
if ccd not in ccds:
raise RuntimeError("Unrecognised ccd: %d" % ccd)
if ccd not in defects:
defects[ccd] = list()
defects[ccd].append(Defect(x0=int(x0), y0=int(y0), width=int(width), height=int(height)))

for ccd in ccds:
# Make empty defect FITS file for CCDs with no defects
Expand All @@ -49,11 +48,11 @@ def genDefectFits(cameraName, source, targetDir):
columns = list()
for colName in Defect._fields:
colData = numpy.array([d._asdict()[colName] for d in defects[ccd]])
col = pyfits.Column(name=colName, format="I", array=colData)
col = fits.Column(name=colName, format="I", array=colData)
columns.append(col)

cols = pyfits.ColDefs(columns)
table = pyfits.BinTableHDU.from_columns(cols)
cols = fits.ColDefs(columns)
table = fits.BinTableHDU.from_columns(cols)

table.header['NAME'] = ccd

Expand Down
4 changes: 2 additions & 2 deletions bin.src/makeGeom.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from __future__ import absolute_import, division, print_function
from builtins import map
from builtins import range
import pyfits
from astropy.io import fits
import sys
import re
import os
Expand Down Expand Up @@ -227,7 +227,7 @@ def printElectronics(buff, ccdId, ccdname, xidx, yidx, infoA, infoB):
buffElectro = open('Electronics.paf', 'w')

infile = sys.argv[1] # full MEF file; e.g. 871034p.fits
ptr = pyfits.open(infile)
ptr = fits.open(infile)

printCameraGeom(infile, buffCamera)
printAmpDefaults(buffCamera)
Expand Down
4 changes: 2 additions & 2 deletions bin.src/showPsfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import re
import sys

from astropy.io import fits
import numpy as np
from matplotlib.mlab import griddata
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -249,8 +250,7 @@ def main(dataDir, visit, title="", outputTxtFileName=None,
plt.axis([-20000, 20000, -20000, 20000])

def frameInfoFrom(filepath):
import pyfits
with pyfits.open(filepath) as hdul:
with fits.open(filepath) as hdul:
h = hdul[0].header
'object=ABELL2163 filter=HSC-I exptime=360.0 alt=62.11143274 azm=202.32265181 hst=(23:40:08.363-23:40:48.546)'
return 'object=%s filter=%s exptime=%.1f azm=%.2f hst=%s' % (h['OBJECT'], h['FILTER01'], h['EXPTIME'], h['AZIMUTH'], h['HST'])
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/obs/subaru/strayLight/rotatorAngle.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import sys
import numpy as np
import astropy.io.fits as pyfits
from astropy.io import fits

### fixed parameters
ltt_d = 19.82556 # dome latitude in degree
Expand Down Expand Up @@ -203,7 +203,7 @@ def _gsCPposNorth(ra_t_d, de_t_d, inr_d, mjd):

def _getDataArrayFromFITSFileWithHeader(pathToFITSFile):
"""return array of pixel data"""
fitsfile = pyfits.open(pathToFITSFile)
fitsfile = fits.open(pathToFITSFile)
dataArray = fitsfile[0].data
fitsHeader = fitsfile[0].header
fitsfile.close()
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/obs/subaru/strayLight/yStrayLight.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import os

import numpy
import astropy.io.fits as pyfits
from astropy.io import fits
import scipy.interpolate

from lsst.pex.config import Config, Field
Expand Down Expand Up @@ -144,7 +144,7 @@ def get_ybackground(filename, angle_start, angle_end=None):

@return (numpy.array[][])
"""
hdulist = pyfits.open(filename)
hdulist = fits.open(filename)
header = hdulist[0].header

# full-size ccd height & channel width
Expand Down
3 changes: 1 addition & 2 deletions ups/obs_subaru.table
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ setupRequired(daf_persistence)
setupRequired(obs_base)
setupRequired(pipe_tasks)
setupRequired(meas_astrom)
setupRequired(pyfits)
setupRequired(astropy)
setupRequired(sconsUtils)
setupRequired(pybind11)
setupRequired(numpy)
Expand All @@ -18,4 +18,3 @@ envPrepend(DYLD_LIBRARY_PATH, ${PRODUCT_DIR}/lib)
envPrepend(LSST_LIBRARY_PATH, ${PRODUCT_DIR}/lib)
envPrepend(PYTHONPATH, ${PRODUCT_DIR}/python)
envPrepend(PATH, ${PRODUCT_DIR}/bin)