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

port obs_subaru to python3 Tickets/dm 7306 #42

Merged
merged 4 commits into from Nov 11, 2016
Merged

Conversation

parejkoj
Copy link
Contributor

@parejkoj parejkoj commented Nov 9, 2016

No description provided.

Copy link
Contributor

@mrawls mrawls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally this looks good, just a handful of little things.

@@ -62,7 +66,7 @@ def __init__(self, path, version, validStart, validEnd=None):
# Fix up end dates so there are no collisions.
# Defects files for a CCD are valid from the date they are registered until the next date.
# This means that any defects file should carry ALL the defects that are present at that time.
for ccd, rowList in rowsPerCcd.iteritems():
for ccd, rowList in rowsPerCcd.items():
rowList.sort(key=lambda row: row.validStart) # ISO-8601 will sort just fine without conversion from str
Copy link
Contributor

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?

Copy link
Contributor Author

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:

from operator import attrgetter
rowList.sort(key=attrgetter('validStart'))

But since this executable code doesn't have any tests, I'm loathe to change it.


print ccdId, ccdBoundary, amp1Boundary, amp2Boundary, gain1, gain2, rdnoise1, rdnoise2, \
saturate1, saturate2
print(ccdId, ccdBoundary, amp1Boundary, amp2Boundary, gain1, gain2, rdnoise1, rdnoise2, \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line continuation \ isn't needed here anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rewrapped that at a better place.

108 : 110,
114 : 108,
108: 110,
114: 108,
}
Copy link
Contributor

Choose a reason for hiding this comment

The 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., 100:101 or new assignments, i.e., 100: 101.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.


plots, labels = [], []
for v, r, d in zip(visits, ra, dec):
field = fields.get(v)
if verbose:
print "Drawing %s %s \r" % (v, field),
print("Drawing %s %s \r" % (v, field), end=' ')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is having both the end=' ' and flushing stdout desired here? I'm guessing yes, since this happens again a bit later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are different things: putting end=' ' adds a space (like the hanging comma did in python2), while stdout.flush() flushes the buffer (very useful in a multi-threaded environment, or if other things are processing).

Copy link
Contributor Author

@parejkoj parejkoj Nov 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although, now that you mention it: python3's print() has a flush=True argument. I'll just use that instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, there are a few other places where stdout is flushed, so maybe you could quickly apply that there too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only see two in showDither.py, which I've done.

@@ -329,7 +339,8 @@ def frameInfoFrom(filepath):
if mat:
v1 = int(mat.group(1))
v2 = int(mat.group(2))
v3 = mat.group(3); v3 = int(v3) if v3 else 1
v3 = mat.group(3)
v3 = int(v3) if v3 else 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debatable if having this on two lines actually improves clarity or not; perhaps do v3 = int(mat.group(3)) if mat.group(3) else 1 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... That could probably go either way. Sadly, it's another untestable bin/ file that I'd rather not muck around in.

@@ -946,7 +980,7 @@ def mosaicIo(dirName, mosaics=None, mode=None):
if mode == "r":
import glob
for f in glob.glob(os.path.join(dirName, "*.fits")) + \
glob.glob(os.path.join(dirName, "*.fits.gz")):
glob.glob(os.path.join(dirName, "*.fits.gz")):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parentheses preferred to line continuation \ character

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pulled the globbing into a "files" variable.

visit & median flux & exposure time & line type & line colour \\
\hline"""
\hline""")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentations here are confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's doing something with latex and a raw string.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but can't each portion of the print statement still be consistently indented? Or does that actually confuse latex?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No: raw strings are raw with all formatting intact, so they have to look like this for latex (as far as I'm aware).

print r"""\caption{\label{%sLegend} Index of lines in %s radial profiles}
\end{longtable}""" % (filterName, filterName)
print(r"""\caption{\label{%sLegend} Index of lines in %s radial profiles}
\end{longtable}""" % (filterName, filterName))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More confusing indentations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More latex raw strings.

'green' if v in domeflats else \
'black' if v in science else \
'red' if v in skyflats else \
'blue'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is messy, but I can't think of a better way to do it offhand.

if tract < 0 or tract >= 128:
raise RuntimeError('tract not in range [0,128)')
patchX, patchY = map(int, dataId['patch'].split(','))
patchX, patchY = list(map(int, dataId['patch'].split(',')))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another possibly less-than-desirable list(map()) situation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and it can be a generator because the result is immediately unpacked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

listcomped it

Leaving as a separate commit as it'll be hard to rebase into the various other
pep8/futurize steps.
Copy link
Contributor

@mrawls mrawls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, assuming Jenkins is happy too!

@parejkoj parejkoj merged commit b165576 into master Nov 11, 2016
@ktlim ktlim deleted the tickets/DM-7306 branch August 25, 2018 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants