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-26697: Deprecate needing to pre-pair exposures in PTC task, and calculate an appropriate pair based on header data. #52

Merged
merged 9 commits into from Sep 16, 2020

Conversation

plazas
Copy link
Contributor

@plazas plazas commented Sep 14, 2020

No description provided.

@plazas plazas requested a review from czwa September 14, 2020 18:35
Copy link
Contributor

@czwa czwa left a comment

Choose a reason for hiding this comment

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

I'm concerned with the makePairs method, as it seems like it only will accept two exposures at a given exposure time, and that it may not pair the shortest time interval pair, so there's less guarantee that the illumination will be stable.

@@ -255,9 +254,9 @@ def __setattr__(self, attribute, value):
self.__dict__[attribute] = value

def getVisitsUsed(self, ampName):
Copy link
Contributor

Choose a reason for hiding this comment

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

We're not really using visits anywhere, right? Can we drop it everywhere in favor of 'exposure', or should that be a separate ticket? We'll want to do it at some point.

@@ -446,12 +413,42 @@ def runDataRef(self, dataRef, visitPairs):

butler.put(linearizer, datasetType='Linearizer', dataId={'detector': detNum,
'detectorName': detName, 'calibDate': calibDate})

self.log.info(f"Writing PTC data to {dataRef.getUri(write=True)}")
rerunDir = list(dataRef.getButler().storage.repositoryCfgs.keys())[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a lot of work for something that the butler should be handling. I also don't think that this will work in gen3.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need this line then? {{dataRef.getUri(write=True)}} fails. This line is printing the location of the dataset pickle file. Is there another way of getting this, if we decide that we need to print this information?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to say where we're writing things. A simple "Writing PTC data." will note that it's done with the calculation.

expTime = tempFlat.getInfo().getVisitInfo().getExposureTime()
listAtExpTime = sortedPairs.setdefault(expTime, [])
if len(listAtExpTime) < 2:
listAtExpTime.append(tempFlat)
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we want to sort on DATE-OBS or SEQNUM or something to prevent multiple flat ramps being paired incorrectly? This also looks like it will toss any extra exposures, even when they could be used as well.

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 thought we were assuming for this task that the user would pass flat fields from a single PTC ramp. Are you suggesting that we should check that the DATE-OBS is the same for all exposures? Or do you have something else in mind? What if the flat ramp starts one night and continues to the next day, resulting in the images having different dates?
The way we calculate the PTC now is by taking the difference between two flats at the same expTime to reduce PRNU. If for some reason there are more than two flats for the same expTime, we still need to pick two (the first two, in this code). Do you have something in mind for using possible extra exposures at the same expTime?

Copy link
Contributor

@czwa czwa Sep 14, 2020

Choose a reason for hiding this comment

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

I thought it would be general for any number of inputs. The ramps that I'd looked at (from LATISS, though, so maybe different from how they're taking them on BOT) had four exposures at each exposure time. More entries should provide better fits, as we're less dependent on any single pair.
If this is rejecting inputs just because it duplicates an exposure time, then the code should have a log message that something has been dropped. Since this is a user input, I think the expectation is that everything specified on the command line will be used.

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 do remember the LATIISS ramps with more than 2 exposures per exposure time, but I think that the PTC, as it's implemented now, uses the difference of only two. I'll add a message as you suggest.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think dropping exposures is a mistake. This also isn't deterministic: for a set of equal exposure time exposures 1^2^3^4, 1^3^2^4, etc. will all give different outputs. Even if you want to keep only one pair for each exposure time, you need to do some sort operation to ensure that order transposes all give the same result.

Copy link
Contributor

@czwa czwa Sep 15, 2020

Choose a reason for hiding this comment

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

I think this is the "date = %Y-%m-%d %H:%M:%S" vs "date = %Y-%m-%d" difference. Sorting along the first (which I think is what getVisitInfo().getDate() returns) should sort resolve this issue.

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 don't know, is it? If that is the case, how are you suggesting to use the date of observation to end up with only two flats at the same exposure time? (in case of Nflats with same expTime > 2).

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 just saw Chris's comment (after I posted mine, replying to Tim). Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

Yes, VisitInfo stores the full date, not just the day.

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks right to me. If you can double check that it's deterministic (something like the example above where exposures are specified out of order but still return the in-order sorting), then I think this is done.


Parameters
----------
dataReflist : `list` [`lsst.daf.peristence.ButlerDataRef`]
Copy link
Member

Choose a reason for hiding this comment

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

Is there a plan for making this gen3 compatible? (also typo in the class name).

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 step one of that conversion. https://jira.lsstcorp.org/browse/DM-21786 is the umbrella ticket for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing out the typo. Regarding gen3 compatibility, I'm not sure about what you are referring to. Are you talking about the "makePairs" function in particular? Or the PTC task in general? If the latter, yes, this ticket is part of a larger ticket (DM-21786) to convert the PTC task to gen3.

Copy link
Member

Choose a reason for hiding this comment

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

I was just noting that this is brand new code that will have to be rewritten on a November timeline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is that after DM-21786 the PTC task will be fully converted to gen3.


Return
------
sortedPairs : `dict`
Copy link
Member

@timj timj Sep 14, 2020

Choose a reason for hiding this comment

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

I think you need to say dict of what? Keys are exposure time in seconds and values are list of Exposure? But only the first two exposures that have that same exposure time? And what is sorting what? I don't see any sorting at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I agree, I'll add more information about the dictionary: the keys and values are as you describe. The input exposures are not necessarily sorted by ascending time in the command line, so this function organizes them in a dictionary. I can change the name sorted to something else (e.g., just "pairs").

Copy link
Member

Choose a reason for hiding this comment

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

I definitely would not use sorted anywhere in the function if nothing is doing any sorting.

expTime = tempFlat.getInfo().getVisitInfo().getExposureTime()
listAtExpTime = sortedPairs.setdefault(expTime, [])
if len(listAtExpTime) < 2:
listAtExpTime.append(tempFlat)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks right to me. If you can double check that it's deterministic (something like the example above where exposures are specified out of order but still return the in-order sorting), then I think this is done.

@plazas plazas merged commit 4cba61e into master Sep 16, 2020
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

3 participants