-
Notifications
You must be signed in to change notification settings - Fork 17
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
port obs_subaru to python3 Tickets/dm 7306 #42
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,9 @@ | |
# the GNU General Public License along with this program. If not, | ||
# see <https://www.lsstcorp.org/LegalNotices/>. | ||
# | ||
from __future__ import print_function | ||
from builtins import map | ||
from builtins import range | ||
import pyfits | ||
import sys | ||
import re | ||
|
@@ -36,10 +39,11 @@ | |
|
||
hack = True | ||
|
||
|
||
def getSecCenter(sec): | ||
sec = re.sub('\'', '', sec) | ||
sec = re.sub('\[|\:|\,|\]', ' ', sec) | ||
fields = map(int, sec.split()) | ||
fields = list(map(int, sec.split())) | ||
# these indices run from 1..N | ||
# to run from 0..N-1 subtract off 2 from each sum | ||
return 0.5 * (fields[0] + fields[1] - 2), 0.5 * (fields[2] + fields[3] - 2) | ||
|
@@ -59,6 +63,7 @@ def printCameraGeom(filename, buff): | |
buff.write(' } \n') | ||
buff.write('} \n') | ||
|
||
|
||
def printAmpDefaults(buff): | ||
# http://cfht.hawaii.edu/Instruments/Imaging/MegaPrime/rawdata.html | ||
# | ||
|
@@ -72,6 +77,7 @@ def printAmpDefaults(buff): | |
buff.write(' overclockV: 32 \n') | ||
buff.write('} \n') | ||
|
||
|
||
def printCcdAmpDefaults(buff): | ||
# Depending on how much we need to undo the imsplice operation | ||
# here are the defaults from straight off the camera | ||
|
@@ -104,6 +110,7 @@ def printCcdAmpDefaults(buff): | |
buff.write(' } \n') | ||
buff.write('} \n') | ||
|
||
|
||
def printCcdDiskLayout(buff): | ||
buff.write('CcdDiskLayout: { \n') | ||
buff.write(' HduPerAmp: true \n') | ||
|
@@ -149,6 +156,7 @@ def printRaftCcdGeom(buff, ccdId, ccdname, xidx, yidx, xpos, ypos): | |
buff.write(' orientation: 0.000000 0.000000 0.000000 \n') | ||
buff.write(' } \n') | ||
|
||
|
||
def printElectronics(buff, ccdId, ccdname, xidx, yidx, infoA, infoB): | ||
# http://www.cfht.hawaii.edu/Instruments/Imaging/Megacam/specsinformation.html | ||
|
||
|
@@ -215,11 +223,11 @@ def printElectronics(buff, ccdId, ccdname, xidx, yidx, infoA, infoB): | |
# everything else. Raft w.r.t. boresight; CCD w.r.t. Raft center; Amp | ||
# w.r.t CCD center. | ||
|
||
buffCamera = open('Camera.paf', 'w') | ||
buffCamera = open('Camera.paf', 'w') | ||
buffElectro = open('Electronics.paf', 'w') | ||
|
||
infile = sys.argv[1] # full MEF file; e.g. 871034p.fits | ||
ptr = pyfits.open(infile) | ||
ptr = pyfits.open(infile) | ||
|
||
printCameraGeom(infile, buffCamera) | ||
printAmpDefaults(buffCamera) | ||
|
@@ -228,29 +236,29 @@ def printElectronics(buff, ccdId, ccdname, xidx, yidx, infoA, infoB): | |
|
||
# 0th layer is pure metadata | ||
for ccd in range(1, len(ptr)): | ||
#for ccd in [1, 28]: | ||
ccdId = ptr[ccd].header['EXTVER'] | ||
ccdBoundary = ptr[ccd].header['DETSEC'] | ||
ccdName = ptr[ccd].header['CCDNAME'] | ||
#for ccd in [1, 28]: | ||
ccdId = ptr[ccd].header['EXTVER'] | ||
ccdBoundary = ptr[ccd].header['DETSEC'] | ||
ccdName = ptr[ccd].header['CCDNAME'] | ||
amp1Boundary = ptr[ccd].header['DETSECA'] | ||
amp2Boundary = ptr[ccd].header['DETSECB'] | ||
|
||
ccdxc, ccdyc = getSecCenter(ccdBoundary) | ||
xpos = (ccdxc - detCenterX) * cfhtPixelScale | ||
ypos = (ccdyc - detCenterY) * cfhtPixelScale | ||
xpos = (ccdxc - detCenterX) * cfhtPixelScale | ||
ypos = (ccdyc - detCenterY) * cfhtPixelScale | ||
|
||
gain1 = ptr[ccd].header['GAINA'] | ||
gain2 = ptr[ccd].header['GAINB'] | ||
gain1 = ptr[ccd].header['GAINA'] | ||
gain2 = ptr[ccd].header['GAINB'] | ||
|
||
rdnoise1 = ptr[ccd].header['RDNOISEA'] | ||
rdnoise2 = ptr[ccd].header['RDNOISEB'] | ||
rdnoise1 = ptr[ccd].header['RDNOISEA'] | ||
rdnoise2 = ptr[ccd].header['RDNOISEB'] | ||
|
||
# assume non-linear = saturation since we have no non-linearity curves | ||
saturate1 = ptr[ccd].header['MAXLINA'] | ||
saturate2 = ptr[ccd].header['MAXLINB'] | ||
saturate1 = ptr[ccd].header['MAXLINA'] | ||
saturate2 = ptr[ccd].header['MAXLINB'] | ||
|
||
print ccdId, ccdBoundary, amp1Boundary, amp2Boundary, gain1, gain2, rdnoise1, rdnoise2, \ | ||
saturate1, saturate2 | ||
print(ccdId, ccdBoundary, amp1Boundary, amp2Boundary, gain1, gain2, rdnoise1, rdnoise2, \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The line continuation \ isn't needed here anymore There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I rewrapped that at a better place. |
||
saturate1, saturate2) | ||
|
||
# flip y | ||
xidx = ccdId % 9 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,7 @@ | |
108 110 | ||
114 108 | ||
""" | ||
|
||
#!/usr/bin/env python | ||
from __future__ import print_function | ||
|
||
import glob | ||
import os | ||
|
@@ -37,17 +36,19 @@ | |
# | ||
# Desired remapping | ||
# | ||
remap = {112 : 106, | ||
remap = {112: 106, | ||
#104 : 104 | ||
107 : 105, | ||
113 : 107, | ||
115 : 109, | ||
107: 105, | ||
113: 107, | ||
115: 109, | ||
#111 : 111, | ||
108 : 110, | ||
114 : 108, | ||
108: 110, | ||
114: 108, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The spacing choices here are confusing me... not sure if these should be treated more like indices, i.e., There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They're assignments: it's a dict. I cleaned up the commented lines, though. |
||
|
||
# Gather list of files | ||
|
||
|
||
def globber(field="*", filename="*.fits"): | ||
return glob.glob(os.path.join(args.root, field, "*-*-*", "*", "*", filename)) | ||
|
||
|
@@ -61,7 +62,7 @@ def globber(field="*", filename="*.fits"): | |
if args.fields: | ||
for f in args.fields: | ||
files += globber(field=f) | ||
print 'Processing %d files...' % len(files) | ||
print('Processing %d files...' % len(files)) | ||
|
||
# Set up regex for parsing directory structure | ||
reField = r'([\w .+-]+)' | ||
|
@@ -75,13 +76,13 @@ def globber(field="*", filename="*.fits"): | |
for fileNo, fits in enumerate(files): | ||
m = re.search(regex, fits) | ||
if not m: | ||
print "Warning: skipping unrecognized filename:", fits | ||
print("Warning: skipping unrecognized filename:", fits) | ||
continue | ||
|
||
field, dateObs, pointing, filterId, visit, ccd = m.groups() | ||
visit = int(visit) | ||
ccd = int(ccd) | ||
if not visits.has_key(visit): | ||
if visit not in visits: | ||
visits[visit] = set() | ||
visits[visit].add(ccd) | ||
#print "Processing %s" % fits | ||
|
@@ -91,14 +92,14 @@ def globber(field="*", filename="*.fits"): | |
# | ||
for visit, ccds in visits.items(): | ||
if 105 in ccds: # already refiled | ||
print "%d is already refiled" % visit | ||
print("%d is already refiled" % visit) | ||
del visits[visit] | ||
continue | ||
|
||
if set(remap.keys()) != set([_ for _ in ccds if remap.get(_)]): # no focus chips are available | ||
continue | ||
|
||
print visit | ||
print(visit) | ||
try: | ||
tmpDir = None | ||
for old, new in remap.items(): | ||
|
@@ -120,4 +121,3 @@ def globber(field="*", filename="*.fits"): | |
os.rmdir(tmpDir) | ||
# | ||
# | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be turned into a list comprehension syntax instead of lambda? Would that be faster/more pythonic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference, I think this would be a more modern version:
But since this executable code doesn't have any tests, I'm loathe to change it.