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();
64 return metadata.exists(key) ? metadata.getAsDouble(key) : nan;
88 std::string
const& comment) {
89 if (std::isfinite(value)) {
90 metadata.set(key, value);
105 std::string
const& comment) {
106 return setDouble(metadata, key, angle.asDegrees(), comment);
125 std::ostringstream os;
126 os <<
"Unknown RotType enum: " <<
static_cast<int>(
rotType);
127 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, os.str());
135 RotType rotTypeEnumFromStr(std::string
const& rotTypeName) {
136 if (rotTypeName ==
"UNKNOWN") {
138 }
else if (rotTypeName ==
"SKY") {
140 }
else if (rotTypeName ==
"HORIZON") {
142 }
else if (rotTypeName ==
"MOUNT") {
145 std::ostringstream os;
146 os <<
"Unknown RotType name: \"" << rotTypeName <<
"\"";
147 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, os.str());
150 class VisitInfoSchema {
156 table::Key<std::int64_t>
tai;
158 table::Key<geom::Angle>
era;
174 static VisitInfoSchema
const&
get() {
175 static VisitInfoSchema instance;
180 VisitInfoSchema(
const VisitInfoSchema&) =
delete;
181 VisitInfoSchema& operator=(
const VisitInfoSchema&) =
delete;
184 VisitInfoSchema(VisitInfoSchema&&) =
delete;
185 VisitInfoSchema& operator=(VisitInfoSchema&&) =
delete;
192 darkTime(
schema.addField<double>(
"darktime",
"time from CCD flush to readout",
"s")),
194 "tai",
"TAI date and time at middle of exposure as nsec from unix epoch",
"nsec")),
195 ut1(
schema.addField<double>(
"ut1",
"UT1 date and time at middle of exposure",
"MJD")),
196 era(
schema.addField<geom::
Angle>(
"era",
"earth rotation angle at middle of exposure",
"")),
198 "sky position of boresight at middle of exposure")),
203 "refracted apparent topocentric position of boresight at middle of exposure",
"")),
205 "boresightazalt_alt",
206 "refracted apparent topocentric position of boresight at middle of exposure",
"")),
208 "boresightairmass",
"airmass at boresight, relative to zenith at sea level",
"")),
210 "boresightrotangle",
"rotation angle at boresight at middle of exposure",
"")),
211 rotType(
schema.addField<int>(
"rottype",
"rotation type; see VisitInfo.getRotType for details",
215 "latitude of telescope (+ is east of Greenwich)",
"")),
217 elevation(
schema.addField<double>(
"elevation",
"elevation of telescope",
"")),
221 humidity(
schema.addField<double>(
"humidity",
"humidity (%)",
"")) {
222 schema.getCitizen().markPersistent();
226 class VisitInfoFactory :
public table::io::PersistableFactory {
228 virtual std::shared_ptr<table::io::Persistable> read(InputArchive
const& archive,
229 CatalogVector
const& catalogs)
const {
230 VisitInfoSchema
const& keys = VisitInfoSchema::get();
234 table::BaseRecord
const& record = catalogs.front().front();
235 std::shared_ptr<VisitInfo>
result(
new VisitInfo(
236 record.get(keys.exposureId), record.get(keys.exposureTime), record.get(keys.darkTime),
237 ::DateTime(record.get(keys.tai), ::DateTime::TAI), record.get(keys.ut1), record.get(keys.era),
238 record.get(keys.boresightRaDec),
239 coord::Coord(record.get(keys.boresightAzAlt_az), record.get(keys.boresightAzAlt_alt)),
240 record.get(keys.boresightAirmass), record.get(keys.boresightRotAngle),
241 static_cast<RotType>(record.get(keys.rotType)),
242 coord::Observatory(record.get(keys.longitude), record.get(keys.latitude),
243 record.get(keys.elevation)),
244 coord::Weather(record.get(keys.airTemperature), record.get(keys.airPressure),
245 record.get(keys.humidity))));
249 explicit VisitInfoFactory(std::string
const&
name) : table::io::PersistableFactory(name) {}
252 std::string getVisitInfoPersistenceName() {
return "VisitInfo"; }
254 VisitInfoFactory registration(getVisitInfoPersistenceName());
263 std::vector<std::string> keyList = {
264 "EXPID",
"EXPTIME",
"DARKTIME",
"DATE-AVG",
"TIMESYS",
"TIME-MID",
"MJD-AVG-UT1",
265 "AVG-ERA",
"BORE-RA",
"BORE-DEC",
"BORE-AZ",
"BORE-ALT",
"BORE-AIRMASS",
"BORE-ROTANG",
266 "ROTTYPE",
"OBS-LONG",
"OBS-LAT",
"OBS-ELEV",
"AIRTEMP",
"AIRPRESS",
"HUMIDITY"};
267 for (
auto&& key : keyList) {
268 if (metadata.exists(key)) {
269 metadata.remove(key);
280 setDouble(metadata,
"EXPTIME", visitInfo.
getExposureTime(),
"Exposure time (sec)");
281 setDouble(metadata,
"DARKTIME", visitInfo.
getDarkTime(),
"Time from CCD flush to readout (sec)");
282 if (visitInfo.
getDate().isValid()) {
283 metadata.set(
"DATE-AVG", visitInfo.
getDate().toString(::DateTime::TAI),
284 "TAI date at middle of observation");
285 metadata.set(
"TIMESYS",
"TAI");
287 setDouble(metadata,
"MJD-AVG-UT1", visitInfo.
getUt1(),
"UT1 MJD date at ctr of obs");
288 setAngle(metadata,
"AVG-ERA", visitInfo.
getEra(),
"Earth rot ang at ctr of obs (deg)");
290 setAngle(metadata,
"BORE-RA", boresightRaDec[0],
"ICRS RA (deg) at boresight");
291 setAngle(metadata,
"BORE-DEC", boresightRaDec[1],
"ICRS Dec (deg) at boresight");
293 setAngle(metadata,
"BORE-AZ", boresightAzAlt[0],
"Refr app topo az (deg) at bore");
294 setAngle(metadata,
"BORE-ALT", boresightAzAlt[1],
"Refr app topo alt (deg) at bore");
295 setDouble(metadata,
"BORE-AIRMASS", visitInfo.
getBoresightAirmass(),
"Airmass at boresight");
296 setAngle(metadata,
"BORE-ROTANG", visitInfo.
getBoresightRotAngle(),
"Rotation angle (deg) at boresight");
297 metadata.set(
"ROTTYPE", rotTypeStrFromEnum(visitInfo.
getRotType()),
"Type of rotation angle");
299 setAngle(metadata,
"OBS-LONG", observatory.getLongitude(),
"Telescope longitude (+E, deg)");
300 setAngle(metadata,
"OBS-LAT", observatory.getLatitude(),
"Telescope latitude (deg)");
301 setDouble(metadata,
"OBS-ELEV", observatory.getElevation(),
"Telescope elevation (m)");
303 setDouble(metadata,
"AIRTEMP", weather.getAirTemperature(),
"Outside air temperature (C)");
304 setDouble(metadata,
"AIRPRESS", weather.getAirPressure(),
"Outdoor air pressure (P)");
305 setDouble(metadata,
"HUMIDITY", weather.getHumidity(),
"Relative humidity (%)");
313 _darkTime(getDouble(metadata,
"DARKTIME")),
315 _ut1(getDouble(metadata,
"MJD-AVG-UT1")),
316 _era(getAngle(metadata,
"AVG-ERA")),
317 _boresightRaDec(coord::
IcrsCoord(getAngle(metadata,
"BORE-RA"), getAngle(metadata,
"BORE-DEC"))),
318 _boresightAzAlt(coord::
Coord(getAngle(metadata,
"BORE-AZ"), getAngle(metadata,
"BORE-ALT"))),
319 _boresightAirmass(getDouble(metadata,
"BORE-AIRMASS")),
320 _boresightRotAngle(getAngle(metadata,
"BORE-ROTANG")),
322 _observatory(getAngle(metadata,
"OBS-LONG"), getAngle(metadata,
"OBS-LAT"),
323 getDouble(metadata,
"OBS-ELEV")),
324 _weather(getDouble(metadata,
"AIRTEMP"), getDouble(metadata,
"AIRPRESS"),
325 getDouble(metadata,
"HUMIDITY")) {
327 if (metadata.exists(key)) {
328 _exposureId = metadata.getAsInt64(key);
332 if (metadata.exists(key)) {
334 _exposureTime = metadata.getAsDouble(key);
335 }
catch (lsst::pex::exceptions::TypeError& err) {
337 std::string exptimeStr = metadata.getAsString(key);
338 _exposureTime = std::stod(exptimeStr);
343 if (metadata.exists(key)) {
344 if (metadata.exists(
"TIMESYS")) {
345 auto timesysName = boost::algorithm::trim_right_copy(metadata.getAsString(
"TIMESYS"));
346 if (timesysName !=
"TAI") {
350 std::ostringstream os;
351 os <<
"TIMESYS = \"" << timesysName
352 <<
"\"; VisitInfo requires TIMESYS to exist and to equal \"TAI\"";
353 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, os.str());
356 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
357 "TIMESYS not found; VistitInfo requires TIMESYS to exist and to equal \"TAI\"");
359 _date = ::DateTime(boost::algorithm::trim_right_copy(metadata.getAsString(key)), ::DateTime::TAI);
364 if (metadata.exists(key)) {
365 _date = ::DateTime(boost::algorithm::trim_right_copy(metadata.getAsString(key)), ::DateTime::UTC);
370 if (metadata.exists(key)) {
371 _rotType = rotTypeEnumFromStr(metadata.getAsString(key));
387 VisitInfoSchema
const& keys = VisitInfoSchema::get();
389 std::shared_ptr<table::BaseRecord> record = cat.
addNew();
393 record->set(keys.tai,
getDate().nsecs(::DateTime::TAI));
394 record->set(keys.ut1,
getUt1());
395 record->set(keys.era,
getEra());
398 record->set(keys.boresightAzAlt_az, boresightAzAlt[0]);
399 record->set(keys.boresightAzAlt_alt, boresightAzAlt[1]);
402 record->set(keys.rotType, static_cast<int>(
getRotType()));
404 record->set(keys.latitude, observatory.getLatitude());
405 record->set(keys.longitude, observatory.getLongitude());
406 record->set(keys.elevation, observatory.getElevation());
408 record->set(keys.airTemperature, weather.getAirTemperature());
409 record->set(keys.airPressure, weather.getAirPressure());
410 record->set(keys.humidity, weather.getHumidity());
std::int64_t RecordId
Type used for unique IDs for records.
geom::Angle getBoresightHourAngle() const
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
geom::Angle getBoresightRotAngle() const
Get rotation angle at boresight at middle of exposure.
bool operator==(VisitInfo const &other) const
lsst::afw::geom::Angle Angle
lsst::afw::coord::Coord Coord
table::Key< geom::Angle > longitude
table::RecordId getExposureId() const
get exposure ID
An object passed to Persistable::write to allow it to persist itself.
table::Key< double > airTemperature
A custom container class for records, based on std::vector.
coord::Coord getBoresightAzAlt() const
get refracted apparent topocentric Az/Alt position at the boresight (and at the middle of the exposur...
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
AngleUnit constexpr radians
constant with units of radians
table::CoordKey boresightRaDec
Information about a single exposure of an imaging camera.
AngleUnit constexpr degrees
constant with units of degrees
table::Key< double > boresightAirmass
geom::Angle getEra() const
get earth rotation angle at middle of exposure
table::Key< int > rotType
Rotation angle is unknown.
void setVisitInfoMetadata(daf::base::PropertyList &metadata, VisitInfo const &visitInfo)
Set FITS metadata from a VisitInfo.
A class representing an angle.
table::Key< double > exposureTime
double getBoresightAirmass() const
get airmass at the boresight, relative to zenith at sea level (and at the middle of the exposure...
lsst::afw::geom::Angle getLongitude() const
get telescope longitude (positive values are E of Greenwich)
lsst::afw::coord::IcrsCoord IcrsCoord
table::Key< geom::Angle > latitude
table::Key< double > humidity
daf::base::DateTime getDate() const
get uniform date and time at middle of exposure
coord::Weather getWeather() const
get basic weather information
table::Key< table::RecordId > exposureId
table::Key< std::string > name
table::Key< double > elevation
table::Key< geom::Angle > boresightRotAngle
table::Key< geom::Angle > era
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
double getUt1() const
get UT1 (universal time) MJD date at middle of exposure
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
table::Key< double > airPressure
Position angle of focal plane +Y, measured from N through E.
lsst::daf::base::PropertySet PropertySet
geom::Angle getLocalEra() const
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.
table::Key< geom::Angle > boresightAzAlt_az
int stripVisitInfoKeywords(daf::base::PropertySet &metadata)
Remove VisitInfo-related keywords from the metadata.
Position angle of focal plane +Y, measured from +Alt through +Az.
table::Key< geom::Angle > boresightAzAlt_alt
table::Key< std::int64_t > tai
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
coord::Observatory getObservatory() const
get observatory longitude, latitude and elevation
table::Key< double > darkTime
double getExposureTime() const
get exposure duration (shutter open time); (sec)
RotType getRotType() const
get rotation type of boresightRotAngle
The position sent to the instrument rotator; the details depend on the rotator.
afw::table::Schema schema
double getDarkTime() const
get time from CCD flush to exposure readout, including shutter open time (despite the name); (sec) ...
lsst::daf::base::PropertyList PropertyList
coord::IcrsCoord getBoresightRaDec() const
get ICRS RA/Dec position at the boresight (and at the middle of the exposure, if it varies with time)...
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.