28 #include "boost/algorithm/string/trim.hpp" 30 #include "lsst/pex/exceptions.h" 42 using lsst::daf::base::DateTime;
52 auto const nan = std::numeric_limits<double>::quiet_NaN();
63 return metadata.exists(key) ? metadata.getAsDouble(key) : nan;
87 std::string
const& comment) {
88 if (std::isfinite(value)) {
89 metadata.set(key, value);
104 std::string
const& comment) {
105 return setDouble(metadata, key, angle.asDegrees(), comment);
124 std::ostringstream os;
125 os <<
"Unknown RotType enum: " <<
static_cast<int>(
rotType);
126 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, os.str());
134 RotType rotTypeEnumFromStr(std::string
const& rotTypeName) {
135 if (rotTypeName ==
"UNKNOWN") {
137 }
else if (rotTypeName ==
"SKY") {
139 }
else if (rotTypeName ==
"HORIZON") {
141 }
else if (rotTypeName ==
"MOUNT") {
144 std::ostringstream os;
145 os <<
"Unknown RotType name: \"" << rotTypeName <<
"\"";
146 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, os.str());
149 class VisitInfoSchema {
155 table::Key<std::int64_t>
tai;
157 table::Key<geom::Angle>
era;
173 static VisitInfoSchema
const&
get() {
174 static VisitInfoSchema instance;
179 VisitInfoSchema(
const VisitInfoSchema&) =
delete;
180 VisitInfoSchema& operator=(
const VisitInfoSchema&) =
delete;
183 VisitInfoSchema(VisitInfoSchema&&) =
delete;
184 VisitInfoSchema& operator=(VisitInfoSchema&&) =
delete;
190 exposureTime(schema.addField<
double>(
"exposuretime",
"exposure duration",
"s")),
191 darkTime(schema.addField<
double>(
"darktime",
"time from CCD flush to readout",
"s")),
192 tai(schema.addField<std::int64_t>(
193 "tai",
"TAI date and time at middle of exposure as nsec from unix epoch",
"nsec")),
194 ut1(schema.addField<
double>(
"ut1",
"UT1 date and time at middle of exposure",
"MJD")),
195 era(schema.addField<
geom::Angle>(
"era",
"earth rotation angle at middle of exposure",
"")),
197 "sky position of boresight at middle of exposure")),
202 "refracted apparent topocentric position of boresight at middle of exposure",
"")),
204 "boresightazalt_alt",
205 "refracted apparent topocentric position of boresight at middle of exposure",
"")),
207 "boresightairmass",
"airmass at boresight, relative to zenith at sea level",
"")),
209 "boresightrotangle",
"rotation angle at boresight at middle of exposure",
"")),
210 rotType(schema.addField<
int>(
"rottype",
"rotation type; see VisitInfo.getRotType for details",
214 "latitude of telescope (+ is east of Greenwich)",
"")),
216 elevation(schema.addField<
double>(
"elevation",
"elevation of telescope",
"")),
218 airTemperature(schema.addField<
double>(
"airtemperature",
"air temperature",
"C")),
219 airPressure(schema.addField<
double>(
"airpressure",
"air pressure",
"Pascal")),
220 humidity(schema.addField<
double>(
"humidity",
"humidity (%)",
"")) {
221 schema.getCitizen().markPersistent();
225 class VisitInfoFactory :
public table::io::PersistableFactory {
227 virtual std::shared_ptr<table::io::Persistable> read(InputArchive
const& archive,
228 CatalogVector
const& catalogs)
const {
229 VisitInfoSchema
const& keys = VisitInfoSchema::get();
233 table::BaseRecord
const& record = catalogs.front().front();
234 std::shared_ptr<VisitInfo> result(
new VisitInfo(
235 record.get(keys.exposureId), record.get(keys.exposureTime), record.get(keys.darkTime),
236 ::DateTime(record.get(keys.tai), ::DateTime::TAI), record.get(keys.ut1), record.get(keys.era),
237 record.get(keys.boresightRaDec),
238 coord::Coord(record.get(keys.boresightAzAlt_az), record.get(keys.boresightAzAlt_alt)),
239 record.get(keys.boresightAirmass), record.get(keys.boresightRotAngle),
240 static_cast<RotType>(record.get(keys.rotType)),
241 coord::Observatory(record.get(keys.longitude), record.get(keys.latitude),
242 record.get(keys.elevation)),
243 coord::Weather(record.get(keys.airTemperature), record.get(keys.airPressure),
244 record.get(keys.humidity))));
248 explicit VisitInfoFactory(std::string
const&
name) : table::io::PersistableFactory(name) {}
251 std::string getVisitInfoPersistenceName() {
return "VisitInfo"; }
253 VisitInfoFactory registration(getVisitInfoPersistenceName());
262 std::vector<std::string> keyList = {
263 "EXPID",
"EXPTIME",
"DARKTIME",
"DATE-AVG",
"TIMESYS",
"TIME-MID",
"MJD-AVG-UT1",
264 "AVG-ERA",
"BORE-RA",
"BORE-DEC",
"BORE-AZ",
"BORE-ALT",
"BORE-AIRMASS",
"BORE-ROTANG",
265 "ROTTYPE",
"OBS-LONG",
"OBS-LAT",
"OBS-ELEV",
"AIRTEMP",
"AIRPRESS",
"HUMIDITY"};
266 for (
auto&& key : keyList) {
267 if (metadata.exists(key)) {
268 metadata.remove(key);
279 setDouble(metadata,
"EXPTIME", visitInfo.
getExposureTime(),
"Exposure time (sec)");
280 setDouble(metadata,
"DARKTIME", visitInfo.
getDarkTime(),
"Time from CCD flush to readout (sec)");
281 if (visitInfo.
getDate().isValid()) {
282 metadata.set(
"DATE-AVG", visitInfo.
getDate().toString(::DateTime::TAI),
283 "TAI date at middle of observation");
284 metadata.set(
"TIMESYS",
"TAI");
286 setDouble(metadata,
"MJD-AVG-UT1", visitInfo.
getUt1(),
"UT1 MJD date at ctr of obs");
287 setAngle(metadata,
"AVG-ERA", visitInfo.
getEra(),
"Earth rot ang at ctr of obs (deg)");
289 setAngle(metadata,
"BORE-RA", boresightRaDec[0],
"ICRS RA (deg) at boresight");
290 setAngle(metadata,
"BORE-DEC", boresightRaDec[1],
"ICRS Dec (deg) at boresight");
292 setAngle(metadata,
"BORE-AZ", boresightAzAlt[0],
"Refr app topo az (deg) at bore");
293 setAngle(metadata,
"BORE-ALT", boresightAzAlt[1],
"Refr app topo alt (deg) at bore");
294 setDouble(metadata,
"BORE-AIRMASS", visitInfo.
getBoresightAirmass(),
"Airmass at boresight");
295 setAngle(metadata,
"BORE-ROTANG", visitInfo.
getBoresightRotAngle(),
"Rotation angle (deg) at boresight");
296 metadata.set(
"ROTTYPE", rotTypeStrFromEnum(visitInfo.
getRotType()),
"Type of rotation angle");
298 setAngle(metadata,
"OBS-LONG", observatory.getLongitude(),
"Telescope longitude (+E, deg)");
299 setAngle(metadata,
"OBS-LAT", observatory.getLatitude(),
"Telescope latitude (deg)");
300 setDouble(metadata,
"OBS-ELEV", observatory.getElevation(),
"Telescope elevation (m)");
302 setDouble(metadata,
"AIRTEMP", weather.getAirTemperature(),
"Outside air temperature (C)");
303 setDouble(metadata,
"AIRPRESS", weather.getAirPressure(),
"Outdoor air pressure (P)");
304 setDouble(metadata,
"HUMIDITY", weather.getHumidity(),
"Relative humidity (%)");
312 _darkTime(getDouble(metadata,
"DARKTIME")),
314 _ut1(getDouble(metadata,
"MJD-AVG-UT1")),
315 _era(getAngle(metadata,
"AVG-ERA")),
316 _boresightRaDec(coord::
IcrsCoord(getAngle(metadata,
"BORE-RA"), getAngle(metadata,
"BORE-DEC"))),
317 _boresightAzAlt(coord::
Coord(getAngle(metadata,
"BORE-AZ"), getAngle(metadata,
"BORE-ALT"))),
318 _boresightAirmass(getDouble(metadata,
"BORE-AIRMASS")),
319 _boresightRotAngle(getAngle(metadata,
"BORE-ROTANG")),
321 _observatory(getAngle(metadata,
"OBS-LONG"), getAngle(metadata,
"OBS-LAT"),
322 getDouble(metadata,
"OBS-ELEV")),
323 _weather(getDouble(metadata,
"AIRTEMP"), getDouble(metadata,
"AIRPRESS"),
324 getDouble(metadata,
"HUMIDITY")) {
326 if (metadata.exists(key)) {
327 _exposureId = metadata.getAsInt64(key);
331 if (metadata.exists(key)) {
333 _exposureTime = metadata.getAsDouble(key);
334 }
catch (lsst::pex::exceptions::TypeError& err) {
336 std::string exptimeStr = metadata.getAsString(key);
337 _exposureTime = std::stod(exptimeStr);
342 if (metadata.exists(key)) {
343 if (metadata.exists(
"TIMESYS")) {
344 auto timesysName = boost::algorithm::trim_right_copy(metadata.getAsString(
"TIMESYS"));
345 if (timesysName !=
"TAI") {
349 std::ostringstream os;
350 os <<
"TIMESYS = \"" << timesysName
351 <<
"\"; VisitInfo requires TIMESYS to exist and to equal \"TAI\"";
352 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, os.str());
355 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
356 "TIMESYS not found; VistitInfo requires TIMESYS to exist and to equal \"TAI\"");
358 _date = ::DateTime(boost::algorithm::trim_right_copy(metadata.getAsString(key)), ::DateTime::TAI);
363 if (metadata.exists(key)) {
364 _date = ::DateTime(boost::algorithm::trim_right_copy(metadata.getAsString(key)), ::DateTime::UTC);
369 if (metadata.exists(key)) {
370 _rotType = rotTypeEnumFromStr(metadata.getAsString(key));
386 VisitInfoSchema
const& keys = VisitInfoSchema::get();
388 std::shared_ptr<table::BaseRecord> record = cat.
addNew();
392 record->set(keys.tai,
getDate().nsecs(::DateTime::TAI));
393 record->set(keys.ut1,
getUt1());
394 record->set(keys.era,
getEra());
397 record->set(keys.boresightAzAlt_az, boresightAzAlt[0]);
398 record->set(keys.boresightAzAlt_alt, boresightAzAlt[1]);
401 record->set(keys.rotType, static_cast<int>(
getRotType()));
403 record->set(keys.latitude, observatory.getLatitude());
404 record->set(keys.longitude, observatory.getLongitude());
405 record->set(keys.elevation, observatory.getElevation());
407 record->set(keys.airTemperature, weather.getAirTemperature());
408 record->set(keys.airPressure, weather.getAirPressure());
409 record->set(keys.humidity, weather.getHumidity());
std::int64_t RecordId
Type used for unique IDs for records.
double getBoresightAirmass() const
get airmass at the boresight, relative to zenith at sea level (and at the middle of the exposure...
table::Key< double > exposureTime
table::Key< table::RecordId > exposureId
lsst::afw::geom::Angle Angle
table::Key< double > darkTime
lsst::afw::coord::Coord Coord
table::Key< std::string > name
coord::Coord getBoresightAzAlt() const
get refracted apparent topocentric Az/Alt position at the boresight (and at the middle of the exposur...
An object passed to Persistable::write to allow it to persist itself.
table::CoordKey boresightRaDec
A custom container class for records, based on std::vector.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
table::Key< std::int64_t > tai
Information about a single exposure of an imaging camera.
AngleUnit constexpr degrees
constant with units of degrees
double getUt1() const
get UT1 (universal time) MJD date at middle of exposure
double getDarkTime() const
get time from CCD flush to exposure readout, including shutter open time (despite the name); (sec) ...
lsst::daf::base::PropertyList PropertyList
bool operator==(VisitInfo const &other) const
table::Key< geom::Angle > latitude
static CoordKey addFields(afw::table::Schema &schema, std::string const &name, std::string const &doc)
Add a pair of _ra, _dec fields to a Schema, and return a CoordKey that points to them.
Rotation angle is unknown.
geom::Angle getBoresightHourAngle() const
lsst::daf::base::PropertySet PropertySet
void setVisitInfoMetadata(daf::base::PropertyList &metadata, VisitInfo const &visitInfo)
Set FITS metadata from a VisitInfo.
A class representing an angle.
A base class for image defects.
table::RecordId getExposureId() const
get exposure ID
table::Key< geom::Angle > longitude
lsst::afw::coord::IcrsCoord IcrsCoord
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
table::Key< double > boresightAirmass
double getExposureTime() const
get exposure duration (shutter open time); (sec)
coord::IcrsCoord getBoresightRaDec() const
get ICRS RA/Dec position at the boresight (and at the middle of the exposure, if it varies with time)...
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
RotType getRotType() const
get rotation type of boresightRotAngle
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
Position angle of focal plane +Y, measured from N through E.
daf::base::DateTime getDate() const
get uniform date and time at middle of exposure
table::Key< double > airPressure
table::Key< geom::Angle > boresightAzAlt_az
lsst::afw::geom::Angle getLongitude() const
get telescope longitude (positive values are E of Greenwich)
table::Key< int > rotType
geom::Angle getBoresightRotAngle() const
Get rotation angle at boresight at middle of exposure.
VisitInfo(table::RecordId exposureId, double exposureTime, double darkTime, daf::base::DateTime const &date, double ut1, geom::Angle const &era, coord::IcrsCoord const &boresightRaDec, coord::Coord const &boresightAzAlt, double boresightAirmass, geom::Angle const &boresightRotAngle, RotType const &rotType, coord::Observatory const &observatory, coord::Weather const &weather)
Construct a VisitInfo.
int stripVisitInfoKeywords(daf::base::PropertySet &metadata)
Remove VisitInfo-related keywords from the metadata.
Position angle of focal plane +Y, measured from +Alt through +Az.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
table::Key< double > airTemperature
table::Key< geom::Angle > era
coord::Observatory getObservatory() const
get observatory longitude, latitude and elevation
table::Key< double > elevation
table::Key< double > humidity
table::Key< geom::Angle > boresightRotAngle
coord::Weather getWeather() const
get basic weather information
The position sent to the instrument rotator; the details depend on the rotator.
table::Key< geom::Angle > boresightAzAlt_alt
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
geom::Angle getLocalEra() const
geom::Angle getEra() const
get earth rotation angle at middle of exposure