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-15310: {{Refactor ForcedPhotImageTask.runDataRef to new run.}} #127

Merged
merged 1 commit into from Aug 28, 2018

Conversation

czwa
Copy link
Contributor

@czwa czwa commented Aug 21, 2018

Small refactor of ForcedPhotImageTask to add a run method. ForcedPhotCcd and ForcedPhotCoadd will both inherit this method.

@czwa czwa requested a review from r-owen August 21, 2018 18:06
Copy link
Contributor

@r-owen r-owen 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. Just a few minor requested changes.

@@ -121,17 +121,14 @@ def __init__(self, butler=None, refSchema=None, **kwds):
self.makeSubtask('catalogCalculation', schema=self.measurement.schema)

def runDataRef(self, dataRef, psfCache=None):
"""!Measure a single exposure using forced detection for a reference catalog.
"""!Organize a single exposure for forced detection for a reference catalog.
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest reverting this change. This method does measure -- though it calls run to do the job. Consider appending "using a dataRef" to the old brief description, instead, to differentiate it from the brief description for run.

@@ -157,9 +171,10 @@ def runDataRef(self, dataRef, psfCache=None):
)
self.catalogCalculation.run(measCat)

self.writeOutput(dataRef, measCat)
return(measCat)
Copy link
Contributor

Choose a reason for hiding this comment

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

In Python return is a keyword, not a function, so return measCat. That said, run should almost always return an lsst.pipe.base.Struct (for future expansion without breaking existing code) so I suggest:
return lsst.pipe.base.Struct(measCat=measCat)
and updating the @return documentation accordingly.

@param[in] refWcs The WCS for the references.
@param[in] dataRef An lsst.daf.persistence.ButlerDataRef. Needed for method calls and logging.

@param[out] measCat Reference sources are generated with generateMeasCat() in the measurement
Copy link
Contributor

@r-owen r-owen Aug 21, 2018

Choose a reason for hiding this comment

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

This is a returned value instead of an argument that is modified, so use @return instead of @param[out].

Also I find the description confusing. I assume measCat is measured sources, not reference sources, but the description starts with "Reference sources". Consider something like "Measured sources" or "Measured forced sources" or "Sources measured by generateMeasCat"


def makeIdFactory(self, dataRef):

Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest undoing this change (i.e. remove the blank line you inserted)

Copy link
Contributor

@r-owen r-owen left a comment

Choose a reason for hiding this comment

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

As per @yalsayyad I think some change are needed, or perhaps just giving up on the refactor

@@ -143,6 +140,23 @@ def runDataRef(self, dataRef, psfCache=None):
if psfCache is not None:
exposure.getPsf().setCacheSize(psfCache)
refCat = self.fetchReferences(dataRef, exposure)

measCat = self.run(exposure, refCat, refWcs, dataRef)
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 a struct containing measCat, so this code looks wrong. I think you want something like this:

runResult = self.run(...)
self.writeOutput(dataRef, runResult.measCat)


self.writeOutput(dataRef, measCat)

def run(self, exposure, refCat, refWcs, dataRef):
Copy link
Contributor

Choose a reason for hiding this comment

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

As @yalsayyad pointed out on the ticket, please don't pass the dataRef to run.

If self.attachFootprints really needs a dataRef (I haven't looked through the stack to see how that is used) then I don't see an obvious alternative and it may be best to abandon this refactoring.

If self.attachFootprints doesn't actually need the dataRef (but can use something less butler-ish as a replacement) then the rest of the info can be passed into run as arguments: an id factory, an exposure ID and the dataId (the latter as an optional argument, since it's just used for logging).

@czwa
Copy link
Contributor Author

czwa commented Aug 23, 2018

I've updated the branch to include changes to remove the dataRef entirely from the run() method.

Copy link
Contributor

@r-owen r-owen left a comment

Choose a reason for hiding this comment

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

Looks great. One small requested doc change.

@param[in] exposureId Optional unique exposureId used for random seed in measurement task.

@return result An lsst.pipe.base.Struct containing the catalog of forced measurement results
from measurement.run().
Copy link
Contributor

Choose a reason for hiding this comment

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

Please name the field(s) here, e.g.

An lsst.pipe.base.Struct containing:
- measCat: a catalog of forced measurement results (lsst.afw.table.SourceCatalog)

@czwa czwa merged commit 94c5ffa into master Aug 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants