LSSTDESC / imSim

GalSim based Rubin Observatory image simulation package
https://lsstdesc.org/imSim
BSD 3-Clause "New" or "Revised" License
36 stars 15 forks source link

Determine list of image metadata keywords that should be in the primary HDU #178

Closed jchiang87 closed 1 year ago

jchiang87 commented 6 years ago

This is to support jointcal processing. See https://github.com/LSSTDESC/DC2-production/issues/275

cwwalter commented 6 years ago

Can we calculate this ourselves from pointing, or must we use the OpSim database? It's nice to not have to depend on having a database for standalone imSim usage.

jchiang87 commented 6 years ago

We have a function to calculate it using the altitude info from the instance catalog (which also has an airmass entry that we don't use).

cwwalter commented 6 years ago

I've made this issue more general. In addition to Airmass which came up before (for jointcal and also for DCR correction), @rmjarvis has pointed out that gain is also important.

I will first try to see if there is a canonical list of what the real data is supposed to include. Then we can make a list of what should be added (either in imSim or by DM) and if we have any feedback of things that should be in the real data that are missing.

jmeyers314 commented 6 years ago

I'd add • parallactic angle • temperature • pressure • water-vapor partial pressure to the list if they're available, as these all also affect DCR.

cwwalter commented 6 years ago

Thank you Josh.

Others interested in metadata that they think is necessary please feel free to add to this thread. I did some research and talked to some of the DM group working on this issue (especially @ktlim). Here is a bit of what I learned:

My current rough understanding of the architecture is as follows and architecture experts may correct or expand this:

In the process of generating Calibration Products or preparing for a
Data Release Production, new values for metadata items may be
generated from time to time as our understanding of them improves.
For example, we may update the conversion from voltage to physical
units for a telemetry item, change the method of interpolation for a
slowly-changing item, or change the method of averaging for a
rapidly-changing item.  Some simply incorrect values caused by
hardware or software failure may be replaced.  All changes of this
type will result in new versions of the image metadata in the raw
image metadata tables.  The Data Release Production, Calibration
Products Productions, and the image access services may all request
various versions of the image metadata: the version recorded at pixel
capture time ("original"), the latest and "best" version, or a
specific version from a particular (processing, not observation)
date/time.  This will be implemented in the Butler as a composite
dataset with pixels from a file and metadata from the database.

Other information can be added by DM as processing progresses. There will hopefully be a very preliminary list (subject to change at any time) on the time scale of a month.

I believe our goal is to write files that will include the information added by the entire system before any new information is added by DM. In other words: we should endeavor to make the amp files look as much like what comes out of the telescope system as a whole as possible. If we determine there are things we think should be included but is not currently envisioned we should suggest them.

cwwalter commented 5 years ago

Added from #166:

Metadata to add to the eimage and raw file headers:

DATE-OBS in eimage files. Random seed value used for cosmic ray draws, read noise, and dark current.

cwwalter commented 5 years ago

We should also add imSim metadata to the headers. These could be configuration values but at a minimum we should be recording the imSim version string in the header so we can tell after the fact what version of the code made the file.

We might also consider recording associated software versions if we can access them.

timj commented 5 years ago

Please ensure you have INSTRUME and TELESCOP. DATE-OBS as you say, preferably DATE-END (could be the MJD- versions of those). OBSGEO-[XYZ] are part of the FITS standard and would be nice. It would be great if we could have a "SIMULATE = T" header (I've been talking to @ktlim and people in telescope and site about having a way to indicate that part of the system was in simulation). ORIGIN = 'IMSIM' would also be good.

jchiang87 commented 5 years ago

@timj Is this everything? We've asked DM for help on desired header contents before. It would be good to head off further complaints by being able to implement the complete list.

timj commented 5 years ago

@jchiang87 I've been working with @menanteau on the AuxTel LATISS header (you can see the current state at https://github.com/lsst-dm/HeaderService/blob/master/etc/ATSCam/primary_hdu.header ) but we have nothing formally defined in LSE-400 yet. @ktlim is tasked with bringing that information together.

cwwalter commented 5 years ago

I believe we have now added what we can currently based on #192 and https://github.com/lsst/sims_GalSimInterface/pull/75 (which added the keywords requested by @timj) So. This issue will stay open since we have more to do but I am now removing the DC2 keyword.

boutigny commented 5 years ago

Following today's #desc-dm-dc2 meeting regarding the extra metadata that should be added in or derived from the raw header in order to run jointcal, I digged out the following from an old thread:

    _boresightRaDec = visitInfo->getBoresightRaDec();
    _airMass = visitInfo->getBoresightAirmass();
    _mjd = visitInfo->getDate().get(lsst::daf::base::DateTime::MJD);
    double latitude = visitInfo->getObservatory().getLatitude();
    _lstObs = visitInfo->getEra();
    _hourAngle = visitInfo->getBoresightHourAngle();
timj commented 5 years ago

ERA can come directly from knowing the time and observatory location so there doesn't need to be a header for that. All these visitInfo items are filled in from the astro_metadata_translator ObservationInfo class.

I've been pushing airmass, and hour angle corresponding to the DATE-OBS and DATE-END. In AuxTel I've suggested AMSTART, AMEND, HASTART, HAEND for these values. Observatory latitude comes from OBSGEO-[XYZ] headers.

jchiang87 commented 5 years ago

@boutigny I'm assuming that visitInfo object you refer to in your thread excerpt would be constructed via code like this:

import lsst.daf.persistence as dp
butler = dp.Butler('data_repo')
visit_info = butler.get('raw_visitInfo', dataId=dict(visit=161899, raftName='R22', detectorName='S11'))

in which case the header keywords that need to be set in the PHDU of the raw files are the ones accessed here: https://github.com/lsst/afw/blob/master/src/image/VisitInfo.cc#L317

timj commented 5 years ago

@jchiang87 those headers you link to are added by afw on output and are not headers that are required for raw data. VisitInfo raw data headers are created by the astro_metadata_translator's ObservationInfo parsing the raw header and converting to VisitInfo in obs_base.

jchiang87 commented 5 years ago

So how do we ensure that the info that are needed for jointcal are in the raw headers with the right keywords. Dominique posted access via a VisitInfo object, so I assumed that since he was worried about raw files that the raw_visitInfo data product would need to serve up that info. As far as I can tell, using the obs_lsst mapper code as-is, this implies those keywords need to be set in the raw headers, i.e., running the code snippet I posted results in a visit info object that has the data that Dominique's example points to.

timj commented 5 years ago

In legacy obs packages (of which obs_lsst is) the VisitInfo is populated using some defaults from obs_base. See LsstCamMakeRawVisitInfo -- that only sets dark time and date at the moment from what I can see. Once I convert it to the ObservationInfo scheme then everything will be like obs_decam/cfht/subaru.

AFW uses some long keywords that would be best avoided in raw data. In my earlier reply I indicated my preference for the headers that should be used to get this information. If you have headers anywhere for these quantities then the translator will be able to handle it (as I say, do not worry about ERA).

boutigny commented 5 years ago

In jointcal these quantities are accessed through visitInfo in https://github.com/lsst/jointcal/blob/master/src/CcdImage.cc#L110 In my early tests, following Robert's guidance, I modified https://github.com/lsst/obs_lsst/blob/master/python/lsst/obs/lsst/lsstCamMapper.py#L41 to pass these values to visitinfo from the rawheaders. So if I understand correctly this whole mechanism is changing ?

timj commented 5 years ago

Yes. That mechanism is old and has changed. See https://github.com/lsst/obs_subaru/blob/master/python/lsst/obs/hsc/makeHscRawVisitInfo.py

I'm doing all this on a ticket branch for obs_lsst though since I'm still finishing up the new translators.

cwwalter commented 4 years ago

After all the work on obs_lsst by @timj and @jchiang87 etc. Can this be closed with the merging of PR #194? Or are there other outstanding headers we may not yet be including?

cwwalter commented 1 year ago

@jchiang87 Are we in good shape for this now? There have been several sets added (e.g. in #194).

jchiang87 commented 1 year ago

This issue is very old and refers to metadata handling that has changed at least a couple times since it was first posted. I would recommend closing this and making a new issue that addresses the current keyword issues. I can make a new issue shortly.

cwwalter commented 1 year ago

OK closing.