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
Tickets/DM 7756 #19
Tickets/DM 7756 #19
Conversation
and perform a few trivial manual cleanups. There are a few more substantial warnings that were left alone (several list comprehensions that redefine a variable and several instances of assigning a variable to a lambda expression)
lookup = dict(zip(map(refNamer, patchRefList), selectedData)) | ||
refNamer = lambda patchRef: tuple( | ||
map(int, patchRef.dataId["patch"].split(","))) | ||
lookup = dict(list(zip(list(map(refNamer, patchRefList)), selectedData))) |
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.
I don't think these list(
calls are needed here as the lists are transient.
@@ -244,28 +271,40 @@ def parse_args(self, *args, **kwargs): | |||
|
|||
keys = namespace.butler.getKeys(self.calibName) | |||
parsed = {} | |||
for name, value in namespace.calibId.items(): | |||
for name, value in list(namespace.calibId.items()): |
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.
Remove the list()
wrapper.
|
||
# Ensure we can generate filenames for each output | ||
for ccdName in ccdIdLists: | ||
dataId = dict(outputId.items() + [(k, ccdName[i]) for i, k in enumerate(self.config.ccdKeys)]) | ||
dataId = dict(list(outputId.items()) + [(k, ccdName[i]) |
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.
list()
not needed.
@@ -415,16 +463,17 @@ def scatterProcess(self, pool, ccdIdLists): | |||
@param ccdIdLists Dict of data identifier lists for each CCD name | |||
@return Dict of lists of returned data for each CCD name | |||
""" | |||
dataIdList = sum(ccdIdLists.values(), []) | |||
dataIdList = sum(list(ccdIdLists.values()), []) |
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.
I don't think list()
is needed here.
indices = dict(sum([[(tuple(dataId.values()) if dataId is not None else None, (ccdName, expNum)) | ||
for expNum, dataId in enumerate(expList)] | ||
for ccdName, expList in ccdIdLists.items()], [])) | ||
for ccdName, expList in list(ccdIdLists.items())], [])) |
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.
Remove list()
self.log.info("Scatter processing") | ||
|
||
resultList = pool.map(self.process, dataIdList) | ||
|
||
# Piece everything back together | ||
data = dict((ccdName, [None] * len(expList)) for ccdName, expList in ccdIdLists.items()) | ||
data = dict((ccdName, [None] * len(expList)) | ||
for ccdName, expList in list(ccdIdLists.items())) |
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.
Remove list()
@@ -518,7 +568,7 @@ def scale(self, ccdIdLists, data): | |||
""" | |||
self.log.info("Scale on %s" % NODE) | |||
return dict((name, Struct(ccdScale=None, expScales=[None] * len(ccdIdLists[name]))) | |||
for name in ccdIdLists.keys()) | |||
for name in list(ccdIdLists.keys())) |
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.
Remove list()
and keys()
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.
There are many list()
and keys()
calls that can be removed.
@@ -535,9 +585,9 @@ def scatterCombine(self, pool, outputId, ccdIdLists, scales): | |||
""" | |||
self.log.info("Scatter combination") | |||
data = [Struct(ccdIdList=ccdIdLists[ccdName], scales=scales[ccdName], | |||
outputId=dict(outputId.items() + | |||
outputId=dict(list(outputId.items()) + |
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.
Remove list()
[(k, ccdName[i]) for i, k in enumerate(self.config.ccdKeys)])) for | ||
ccdName in ccdIdLists.keys()] | ||
ccdName in list(ccdIdLists.keys())] |
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.
Remove list()
and keys()
|
||
return dict((ccdName, Struct(ccdScale=compScales[indices[ccdName]], expScales=expScales)) | ||
for ccdName in ccdIdLists.keys()) | ||
for ccdName in list(ccdIdLists.keys())) |
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.
Remove list()
and keys()
.
key = lambda dataRef: tuple(dataRef.dataId[k] for k in sorted(dataRef.dataId.keys())) | ||
inputs = dict((key(select.dataRef), select) for select in selectDataList) | ||
key = lambda dataRef: tuple( | ||
dataRef.dataId[k] for k in sorted(dataRef.dataId.keys())) |
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.
I think sorted(dataRef.dataId)
should work if this is dict-like.
for name in ccdIdLists.keys(): | ||
bgMatrix = np.array([[0.0] * len(expList) | ||
for expList in list(ccdIdLists.values())]) | ||
for name in list(ccdIdLists.keys()): |
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.
remove list()
and keys()
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.
These changes look reasonable to me.
...in order to make the code PEP8 compliant and easier to read.
This simply changed two instances of `catch Exception, e:` to `catch Exception as e:`
Modernize with futurize -2 Group imports properly Change `import numpy` to `import numpy as np` Add `# noqa` to one line added by futurize to hide a pep8 warning
futurize added some unnecessary `list(...)` for safety; I removed the ones that are not required.
...to avoid redefining local variables
630dfa6
to
0c22efb
Compare
Make the code compatible with both python 2 and python 3
Modernize the code and make it mostly pep8 compliant (a few list comprehensions still redefine a local variable).