28 #include "boost/algorithm/string/trim.hpp" 62 double getDouble(daf::base::PropertySet
const& metadata,
std::string const&
key) {
63 return metadata.exists(key) ? metadata.getAsDouble(key) :
nan;
86 bool setDouble(daf::base::PropertySet& metadata,
std::string const& key,
double value,
89 metadata.set(key, value);
105 return setDouble(metadata, key, angle.
asDegrees(), comment);
125 os <<
"Unknown RotType enum: " <<
static_cast<int>(
rotType);
135 if (rotTypeName ==
"UNKNOWN") {
137 }
else if (rotTypeName ==
"SKY") {
139 }
else if (rotTypeName ==
"HORIZON") {
141 }
else if (rotTypeName ==
"MOUNT") {
145 os <<
"Unknown RotType name: \"" << rotTypeName <<
"\"";
149 class VisitInfoSchema {
155 table::Key<std::int64_t>
tai;
157 table::Key<lsst::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")),
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")),
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",
"latitude of telescope (+ is east of Greenwich)",
"")),
217 elevation(schema.addField<
double>(
"elevation",
"elevation of telescope",
"")),
219 airTemperature(schema.addField<
double>(
"airtemperature",
"air temperature",
"C")),
220 airPressure(schema.addField<
double>(
"airpressure",
"air pressure",
"Pascal")),
221 humidity(schema.addField<
double>(
"humidity",
"humidity (%)",
"")) {
222 schema.getCitizen().markPersistent();
226 class VisitInfoFactory :
public table::io::PersistableFactory {
229 CatalogVector
const& catalogs)
const {
230 VisitInfoSchema
const&
keys = VisitInfoSchema::get();
234 table::BaseRecord
const& record = catalogs.front().front();
236 new VisitInfo(record.get(keys.exposureId), record.get(keys.exposureTime),
237 record.get(keys.darkTime),
::DateTime(record.get(keys.tai), ::DateTime::TAI),
238 record.
get(keys.ut1), record.get(keys.era), record.get(keys.boresightRaDec),
240 record.get(keys.boresightAzAlt_alt)),
241 record.get(keys.boresightAirmass), record.get(keys.boresightRotAngle),
242 static_cast<RotType>(record.get(keys.rotType)),
243 coord::Observatory(record.get(keys.longitude), record.get(keys.latitude),
244 record.get(keys.elevation)),
245 coord::Weather(record.get(keys.airTemperature), record.get(keys.airPressure),
246 record.get(keys.humidity))));
250 explicit VisitInfoFactory(
std::string const&
name) : table::io::PersistableFactory(name) {}
253 std::string getVisitInfoPersistenceName() {
return "VisitInfo"; }
255 VisitInfoFactory registration(getVisitInfoPersistenceName());
265 "EXPID",
"EXPTIME",
"DARKTIME",
"DATE-AVG",
"TIMESYS",
"TIME-MID",
"MJD-AVG-UT1",
266 "AVG-ERA",
"BORE-RA",
"BORE-DEC",
"BORE-AZ",
"BORE-ALT",
"BORE-AIRMASS",
"BORE-ROTANG",
267 "ROTTYPE",
"OBS-LONG",
"OBS-LAT",
"OBS-ELEV",
"AIRTEMP",
"AIRPRESS",
"HUMIDITY"};
268 for (
auto&& key : keyList) {
269 if (metadata.
exists(key)) {
281 setDouble(metadata,
"EXPTIME", visitInfo.
getExposureTime(),
"Exposure time (sec)");
282 setDouble(metadata,
"DARKTIME", visitInfo.
getDarkTime(),
"Time from CCD flush to readout (sec)");
285 "TAI date at middle of observation");
286 metadata.
set(
"TIMESYS",
"TAI");
288 setDouble(metadata,
"MJD-AVG-UT1", visitInfo.
getUt1(),
"UT1 MJD date at ctr of obs");
289 setAngle(metadata,
"AVG-ERA", visitInfo.
getEra(),
"Earth rot ang at ctr of obs (deg)");
291 setAngle(metadata,
"BORE-RA", boresightRaDec[0],
"ICRS RA (deg) at boresight");
292 setAngle(metadata,
"BORE-DEC", boresightRaDec[1],
"ICRS Dec (deg) at boresight");
294 setAngle(metadata,
"BORE-AZ", boresightAzAlt[0],
"Refr app topo az (deg) at bore");
295 setAngle(metadata,
"BORE-ALT", boresightAzAlt[1],
"Refr app topo alt (deg) at bore");
296 setDouble(metadata,
"BORE-AIRMASS", visitInfo.
getBoresightAirmass(),
"Airmass at boresight");
297 setAngle(metadata,
"BORE-ROTANG", visitInfo.
getBoresightRotAngle(),
"Rotation angle (deg) at boresight");
298 metadata.
set(
"ROTTYPE", rotTypeStrFromEnum(visitInfo.
getRotType()),
"Type of rotation angle");
300 setAngle(metadata,
"OBS-LONG", observatory.getLongitude(),
"Telescope longitude (+E, deg)");
301 setAngle(metadata,
"OBS-LAT", observatory.getLatitude(),
"Telescope latitude (deg)");
302 setDouble(metadata,
"OBS-ELEV", observatory.getElevation(),
"Telescope elevation (m)");
304 setDouble(metadata,
"AIRTEMP", weather.getAirTemperature(),
"Outside air temperature (C)");
305 setDouble(metadata,
"AIRPRESS", weather.getAirPressure(),
"Outdoor air pressure (P)");
306 setDouble(metadata,
"HUMIDITY", weather.getHumidity(),
"Relative humidity (%)");
314 _darkTime(getDouble(metadata,
"DARKTIME")),
316 _ut1(getDouble(metadata,
"MJD-AVG-UT1")),
317 _era(getAngle(metadata,
"AVG-ERA")),
319 lsst::geom::
SpherePoint(getAngle(metadata,
"BORE-RA"), getAngle(metadata,
"BORE-DEC"))),
321 lsst::geom::
SpherePoint(getAngle(metadata,
"BORE-AZ"), getAngle(metadata,
"BORE-ALT"))),
322 _boresightAirmass(getDouble(metadata,
"BORE-AIRMASS")),
323 _boresightRotAngle(getAngle(metadata,
"BORE-ROTANG")),
325 _observatory(getAngle(metadata,
"OBS-LONG"), getAngle(metadata,
"OBS-LAT"),
326 getDouble(metadata,
"OBS-ELEV")),
327 _weather(getDouble(metadata,
"AIRTEMP"), getDouble(metadata,
"AIRPRESS"),
328 getDouble(metadata,
"HUMIDITY")) {
330 if (metadata.
exists(key)) {
335 if (metadata.
exists(key)) {
346 if (metadata.
exists(key)) {
347 if (metadata.
exists(
"TIMESYS")) {
348 auto timesysName = boost::algorithm::trim_right_copy(metadata.
getAsString(
"TIMESYS"));
349 if (timesysName !=
"TAI") {
354 os <<
"TIMESYS = \"" << timesysName
355 <<
"\"; VisitInfo requires TIMESYS to exist and to equal \"TAI\"";
360 "TIMESYS not found; VistitInfo requires TIMESYS to exist and to equal \"TAI\"");
367 if (metadata.
exists(key)) {
373 if (metadata.
exists(key)) {
374 _rotType = rotTypeEnumFromStr(metadata.
getAsString(key));
390 VisitInfoSchema
const&
keys = VisitInfoSchema::get();
396 record->set(keys.tai,
getDate().nsecs(::DateTime::TAI));
397 record->set(keys.ut1,
getUt1());
398 record->set(keys.era,
getEra());
401 record->set(keys.boresightAzAlt_az, boresightAzAlt[0]);
402 record->set(keys.boresightAzAlt_alt, boresightAzAlt[1]);
405 record->set(keys.rotType, static_cast<int>(
getRotType()));
407 record->set(keys.latitude, observatory.getLatitude());
408 record->set(keys.longitude, observatory.getLongitude());
409 record->set(keys.elevation, observatory.getElevation());
411 record->set(keys.airTemperature, weather.getAirTemperature());
412 record->set(keys.airPressure, weather.getAirPressure());
413 record->set(keys.humidity, weather.getHumidity());
426 double _parallactic_y, _parallactic_x,
result;
431 result = atan2(_parallactic_y, _parallactic_x);
439 os <<
"darkTime=" << visitInfo.
getDarkTime() <<
", ";
441 os <<
"UT1=" << visitInfo.
getUt1() <<
", ";
442 os <<
"ERA=" << visitInfo.
getEra() <<
", ";
447 os <<
"rotType=" <<
static_cast<int>(visitInfo.
getRotType()) <<
", ";
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...
double getAsDouble(std::string const &name) const
lsst::geom::SpherePoint getBoresightAzAlt() const
get refracted apparent topocentric Az/Alt position at the boresight (and at the middle of the exposur...
table::Key< double > exposureTime
table::Key< table::RecordId > exposureId
double get(DateSystem system=MJD, Timescale scale=TAI) const
table::Key< double > darkTime
constexpr double asDegrees() const noexcept
VisitInfo(table::RecordId exposureId, double exposureTime, double darkTime, daf::base::DateTime const &date, double ut1, lsst::geom::Angle const &era, lsst::geom::SpherePoint const &boresightRaDec, lsst::geom::SpherePoint const &boresightAzAlt, double boresightAirmass, lsst::geom::Angle const &boresightRotAngle, RotType const &rotType, coord::Observatory const &observatory, coord::Weather const &weather)
Construct a VisitInfo.
lsst::geom::Angle getLocalEra() const
An object passed to Persistable::write to allow it to persist itself.
table::CoordKey boresightRaDec
#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.
lsst::geom::SpherePoint getBoresightRaDec() const
get ICRS RA/Dec position at the boresight (and at the middle of the exposure, if it varies with time)...
double getUt1() const
get UT1 (universal time) MJD date at middle of exposure
void set(std::string const &name, T const &value)
std::string toString(Timescale scale) const
double getDarkTime() const
get time from CCD flush to exposure readout, including shutter open time (despite the name); (sec) ...
virtual void remove(std::string const &name)
table::Key< lsst::geom::Angle > boresightAzAlt_alt
ItemVariant const * other
table::Key< lsst::geom::Angle > longitude
bool operator==(VisitInfo const &other) const
AngleUnit constexpr radians
Rotation angle is unknown.
table::Key< lsst::geom::Angle > latitude
void setVisitInfoMetadata(daf::base::PropertyList &metadata, VisitInfo const &visitInfo)
Set FITS metadata from a VisitInfo.
std::ostream & operator<<(std::ostream &os, VisitInfo const &visitInfo)
AngleUnit constexpr degrees
A base class for image defects.
table::RecordId getExposureId() const
get exposure ID
int64_t getAsInt64(std::string const &name) const
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
bool exists(std::string const &name) const
table::Key< double > boresightAirmass
double getExposureTime() const
get exposure duration (shutter open time); (sec)
table::Key< lsst::geom::Angle > era
std::unique_ptr< SchemaItem< U > > result
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
RotType getRotType() const
get rotation type of boresightRotAngle
lsst::geom::Angle getLongitude() const
get telescope longitude (positive values are E of Greenwich)
lsst::geom::Angle getEra() const
get earth rotation angle at middle of exposure
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
#define LSST_EXCEPT(type,...)
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< double > angle
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.
table::Key< int > rotType
int stripVisitInfoKeywords(daf::base::PropertySet &metadata)
Remove VisitInfo-related keywords from the metadata.
Position angle of focal plane +Y, measured from +Alt through +Az.
lsst::geom::Angle getBoresightParAngle() const
Get parallactic angle at the boresight.
lsst::geom::SpherePoint SpherePoint
lsst::geom::Angle getBoresightRotAngle() const
Get rotation angle at boresight at middle of exposure.
std::string getAsString(std::string const &name) const
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
table::Key< double > airTemperature
coord::Observatory getObservatory() const
get observatory longitude, latitude and elevation
table::Key< double > elevation
table::Key< double > humidity
coord::Weather getWeather() const
get basic weather information
The position sent to the instrument rotator; the details depend on the rotator.
lsst::geom::Angle getBoresightHourAngle() const
table::Key< lsst::geom::Angle > boresightAzAlt_az
table::Key< lsst::geom::Angle > boresightRotAngle
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.