-
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 all 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 |
---|---|---|
|
@@ -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, | ||
#104 : 104 | ||
107 : 105, | ||
113 : 107, | ||
115 : 109, | ||
#111 : 111, | ||
108 : 110, | ||
114 : 108, | ||
remap = {112: 106, | ||
# 104: 104 | ||
107: 105, | ||
113: 107, | ||
115: 109, | ||
# 111: 111, | ||
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,30 +76,29 @@ 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 | ||
# print "Processing %s" % fits | ||
fileNames[(visit, ccd)] = fits | ||
# | ||
|
||
# Ignore visits that have already been fixed | ||
# | ||
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 | ||
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 +120,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.