28 #include "boost/algorithm/string/trim.hpp"
61 int constexpr SERIALIZATION_VERSION = 1;
73 double getDouble(daf::base::PropertySet
const& metadata,
std::string const&
key) {
74 return metadata.exists(
key) ? metadata.getAsDouble(
key) :
nan;
98 return metadata.exists(
key) ? metadata.getAsString(
key) :
"";
109 bool setDouble(daf::base::PropertySet& metadata,
std::string const&
key,
double value,
112 metadata.set(
key, value);
128 return setDouble(metadata,
key,
angle.asDegrees(), comment);
141 if (!value.
empty()) {
142 metadata.set(
key, value);
155 case RotType::UNKNOWN:
159 case RotType::HORIZON:
165 os <<
"Unknown RotType enum: " <<
static_cast<int>(
rotType);
175 if (rotTypeName ==
"UNKNOWN") {
176 return RotType::UNKNOWN;
177 }
else if (rotTypeName ==
"SKY") {
179 }
else if (rotTypeName ==
"HORIZON") {
180 return RotType::HORIZON;
181 }
else if (rotTypeName ==
"MOUNT") {
182 return RotType::MOUNT;
185 os <<
"Unknown RotType name: \"" << rotTypeName <<
"\"";
189 class VisitInfoSchema {
195 table::Key<std::int64_t>
tai;
197 table::Key<lsst::geom::Angle>
era;
218 static VisitInfoSchema
const& get() {
219 static VisitInfoSchema instance;
224 VisitInfoSchema(
const VisitInfoSchema&) =
delete;
225 VisitInfoSchema&
operator=(
const VisitInfoSchema&) =
delete;
228 VisitInfoSchema(VisitInfoSchema&&) =
delete;
229 VisitInfoSchema&
operator=(VisitInfoSchema&&) =
delete;
236 darkTime(
schema.addField<double>(
"darktime",
"time from CCD flush to readout",
"s")),
238 "tai",
"TAI date and time at middle of exposure as nsec from unix epoch",
"nsec")),
239 ut1(
schema.addField<double>(
"ut1",
"UT1 date and time at middle of exposure",
"MJD")),
243 "sky position of boresight at middle of exposure")),
248 "refracted apparent topocentric position of boresight at middle of exposure",
"")),
250 "boresightazalt_alt",
251 "refracted apparent topocentric position of boresight at middle of exposure",
"")),
253 "boresightairmass",
"airmass at boresight, relative to zenith at sea level",
"")),
255 "boresightrotangle",
"rotation angle at boresight at middle of exposure",
"")),
256 rotType(
schema.addField<int>(
"rottype",
"rotation type; see VisitInfo.getRotType for details",
260 "latitude",
"latitude of telescope (+ is east of Greenwich)",
"")),
262 elevation(
schema.addField<double>(
"elevation",
"elevation of telescope",
"")),
267 humidity(
schema.addField<double>(
"humidity",
"humidity (%)",
"")),
270 "instrumentlabel",
"Short name of the instrument that took this data",
"", 0)),
273 version(
schema.addField<int>(VERSION_KEY,
"version of this VisitInfo")) {}
275 std::string const VisitInfoSchema::VERSION_KEY =
"version";
277 class VisitInfoFactory :
public table::io::PersistableFactory {
280 CatalogVector
const& catalogs)
const override {
281 VisitInfoSchema
const&
keys = VisitInfoSchema::get();
284 table::BaseRecord
const& record = catalogs.front().front();
285 int version = getVersion(record);
286 if (
version > SERIALIZATION_VERSION) {
287 throw LSST_EXCEPT(pex::exceptions::TypeError,
"Cannot read VisitInfo FITS version > " +
295 new VisitInfo(record.get(
keys.exposureId), record.get(
keys.exposureTime),
296 record.get(
keys.darkTime), ::
DateTime(record.get(
keys.tai), ::DateTime::TAI),
297 record.
get(
keys.ut1), record.get(
keys.era), record.get(
keys.boresightRaDec),
299 record.get(
keys.boresightAzAlt_alt)),
300 record.get(
keys.boresightAirmass), record.get(
keys.boresightRotAngle),
302 coord::Observatory(record.get(
keys.longitude), record.get(
keys.latitude),
303 record.get(
keys.elevation)),
304 coord::Weather(record.get(
keys.airTemperature), record.get(
keys.airPressure),
305 record.get(
keys.humidity)),
310 explicit VisitInfoFactory(
std::string const&
name) : table::io::PersistableFactory(
name) {}
313 int getVersion(table::BaseRecord
const& record)
const {
316 auto versionKey = record.getSchema().find<
int>(VisitInfoSchema::VERSION_KEY);
317 return record.get(versionKey.key);
318 }
catch (pex::exceptions::NotFoundError
const&) {
325 std::string getVisitInfoPersistenceName() {
return "VisitInfo"; }
327 VisitInfoFactory registration(getVisitInfoPersistenceName());
337 "TIME-MID",
"MJD-AVG-UT1",
"AVG-ERA",
"BORE-RA",
"BORE-DEC",
338 "BORE-AZ",
"BORE-ALT",
"BORE-AIRMASS",
"BORE-ROTANG",
"ROTTYPE",
339 "OBS-LONG",
"OBS-LAT",
"OBS-ELEV",
"AIRTEMP",
"AIRPRESS",
340 "HUMIDITY",
"INSTRUMENT"};
341 for (
auto&&
key : keyList) {
354 setDouble(metadata,
"EXPTIME",
visitInfo.getExposureTime(),
"Exposure time (sec)");
355 setDouble(metadata,
"DARKTIME",
visitInfo.getDarkTime(),
"Time from CCD flush to readout (sec)");
357 metadata.
set(
"DATE-AVG",
visitInfo.getDate().toString(::DateTime::TAI),
358 "TAI date at middle of observation");
359 metadata.
set(
"TIMESYS",
"TAI");
361 setDouble(metadata,
"MJD-AVG-UT1",
visitInfo.getUt1(),
"UT1 MJD date at ctr of obs");
362 setAngle(metadata,
"AVG-ERA",
visitInfo.getEra(),
"Earth rot ang at ctr of obs (deg)");
364 setAngle(metadata,
"BORE-RA",
boresightRaDec[0],
"ICRS RA (deg) at boresight");
365 setAngle(metadata,
"BORE-DEC",
boresightRaDec[1],
"ICRS Dec (deg) at boresight");
366 auto boresightAzAlt =
visitInfo.getBoresightAzAlt();
367 setAngle(metadata,
"BORE-AZ", boresightAzAlt[0],
"Refr app topo az (deg) at bore");
368 setAngle(metadata,
"BORE-ALT", boresightAzAlt[1],
"Refr app topo alt (deg) at bore");
369 setDouble(metadata,
"BORE-AIRMASS",
visitInfo.getBoresightAirmass(),
"Airmass at boresight");
370 setAngle(metadata,
"BORE-ROTANG",
visitInfo.getBoresightRotAngle(),
"Rotation angle (deg) at boresight");
371 metadata.
set(
"ROTTYPE", rotTypeStrFromEnum(
visitInfo.getRotType()),
"Type of rotation angle");
372 auto observatory =
visitInfo.getObservatory();
373 setAngle(metadata,
"OBS-LONG", observatory.getLongitude(),
"Telescope longitude (+E, deg)");
374 setAngle(metadata,
"OBS-LAT", observatory.getLatitude(),
"Telescope latitude (deg)");
375 setDouble(metadata,
"OBS-ELEV", observatory.getElevation(),
"Telescope elevation (m)");
377 setDouble(metadata,
"AIRTEMP", weather.getAirTemperature(),
"Outside air temperature (C)");
378 setDouble(metadata,
"AIRPRESS", weather.getAirPressure(),
"Outdoor air pressure (P)");
379 setDouble(metadata,
"HUMIDITY", weather.getHumidity(),
"Relative humidity (%)");
380 setString(metadata,
"INSTRUMENT",
visitInfo.getInstrumentLabel(),
381 "Short name of the instrument that took this data");
389 _darkTime(getDouble(metadata,
"DARKTIME")),
391 _ut1(getDouble(metadata,
"MJD-AVG-UT1")),
392 _era(getAngle(metadata,
"AVG-ERA")),
397 _boresightAirmass(getDouble(metadata,
"BORE-AIRMASS")),
398 _boresightRotAngle(getAngle(metadata,
"BORE-ROTANG")),
400 _observatory(getAngle(metadata,
"OBS-LONG"), getAngle(metadata,
"OBS-LAT"),
401 getDouble(metadata,
"OBS-ELEV")),
402 _weather(getDouble(metadata,
"AIRTEMP"), getDouble(metadata,
"AIRPRESS"),
403 getDouble(metadata,
"HUMIDITY")),
404 _instrumentLabel(getString(metadata,
"INSTRUMENT")) {
423 if (metadata.
exists(
"TIMESYS")) {
424 auto timesysName = boost::algorithm::trim_right_copy(metadata.
getAsString(
"TIMESYS"));
425 if (timesysName !=
"TAI") {
430 os <<
"TIMESYS = \"" << timesysName
431 <<
"\"; VisitInfo requires TIMESYS to exist and to equal \"TAI\"";
436 "TIMESYS not found; VistitInfo requires TIMESYS to exist and to equal \"TAI\"");
455 return _exposureId ==
other.getExposureId() && _exposureTime ==
other.getExposureTime() &&
456 _darkTime ==
other.getDarkTime() && _date ==
other.getDate() && _ut1 ==
other.getUt1() &&
457 _era ==
other.getEra() && _boresightRaDec ==
other.getBoresightRaDec() &&
458 _boresightAzAlt ==
other.getBoresightAzAlt() && _boresightAirmass ==
other.getBoresightAirmass() &&
459 _boresightRotAngle ==
other.getBoresightRotAngle() && _rotType ==
other.getRotType() &&
460 _observatory ==
other.getObservatory() && _weather ==
other.getWeather() &&
461 _instrumentLabel ==
other.getInstrumentLabel();
466 return utils::hashCombine(17, _exposureId, _exposureTime, _darkTime, _date, _ut1, _era, _boresightRaDec,
467 _boresightAzAlt, _boresightAirmass, _boresightRotAngle, _rotType, _observatory,
468 _weather, _instrumentLabel);
474 VisitInfoSchema
const&
keys = VisitInfoSchema::get();
480 record->set(
keys.tai,
getDate().nsecs(::DateTime::TAI));
485 record->set(
keys.boresightAzAlt_az, boresightAzAlt[0]);
486 record->set(
keys.boresightAzAlt_alt, boresightAzAlt[1]);
491 record->set(
keys.latitude, observatory.getLatitude());
492 record->set(
keys.longitude, observatory.getLongitude());
493 record->set(
keys.elevation, observatory.getElevation());
495 record->set(
keys.airTemperature, weather.getAirTemperature());
496 record->set(
keys.airPressure, weather.getAirPressure());
497 record->set(
keys.humidity, weather.getHumidity());
499 record->set(
keys.version, SERIALIZATION_VERSION);
512 double _parallactic_y, _parallactic_x,
result;
517 result = atan2(_parallactic_y, _parallactic_x);
522 return std::make_unique<VisitInfo>(*
this);
526 return singleClassEquals(*
this,
other);
531 buffer <<
"VisitInfo(";
536 buffer <<
"UT1=" <<
getUt1() <<
", ";
537 buffer <<
"ERA=" <<
getEra() <<
", ";
542 buffer <<
"rotType=" <<
static_cast<int>(
getRotType()) <<
", ";
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
table::Key< double > angle
ItemVariant const * other
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
lsst::geom::Angle getLongitude() const noexcept
get telescope longitude (positive values are E of Greenwich)
Information about a single exposure of an imaging camera.
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
daf::base::DateTime getDate() const
get uniform date and time at middle of exposure
coord::Weather getWeather() const
get basic weather information
lsst::geom::Angle getLocalEra() const
double getUt1() const
get UT1 (universal time) MJD date at middle of exposure
double getBoresightAirmass() const
get airmass at the boresight, relative to zenith at sea level (and at the middle of the exposure,...
lsst::geom::Angle getBoresightHourAngle() const
lsst::geom::Angle getBoresightRotAngle() const
Get rotation angle at boresight at middle of exposure.
table::RecordId getExposureId() const
get exposure ID
std::size_t hash_value() const noexcept override
Return a hash of this object.
bool operator==(VisitInfo const &other) const
lsst::geom::Angle getEra() const
get earth rotation angle at middle of exposure
std::string toString() const override
Create a string representation of this object.
double getExposureTime() const
get exposure duration (shutter open time); (sec)
RotType getRotType() const
get rotation type of boresightRotAngle
bool equals(typehandling::Storable const &other) const noexcept override
Compare this object to another Storable.
lsst::geom::SpherePoint getBoresightAzAlt() const
get refracted apparent topocentric Az/Alt position at the boresight (and at the middle of the exposur...
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)
std::shared_ptr< typehandling::Storable > cloneStorable() const override
Create a new VisitInfo that is a copy of this one.
std::string getInstrumentLabel() const
double getDarkTime() const
get time from CCD flush to exposure readout, including shutter open time (despite the name); (sec)
coord::Observatory getObservatory() const
get observatory longitude, latitude and elevation
lsst::geom::Angle getBoresightParAngle() const
Get parallactic angle at the boresight.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
bool isValid() const noexcept
Return true if the key was initialized to valid offset.
An object passed to Persistable::write to allow it to persist itself.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
static std::shared_ptr< T > dynamicCast(std::shared_ptr< Persistable > const &ptr)
Dynamically cast a shared_ptr.
Interface supporting iteration over heterogenous containers.
Class for handling dates/times, including MJD, UTC, and TAI.
std::string toString(Timescale scale) const
Get date as an ISO8601-formatted string.
double get(DateSystem system=MJD, Timescale scale=TAI) const
Get date as a double in a specified representation, such as MJD.
Class for storing ordered metadata with comments.
void set(std::string const &name, T const &value)
Replace all values for a property name (possibly hierarchical) with a new scalar value.
Class for storing generic metadata.
std::string getAsString(std::string const &name) const
Get the last value for a string property name (possibly hierarchical).
virtual void remove(std::string const &name)
Remove all values for a property name (possibly hierarchical).
int64_t getAsInt64(std::string const &name) const
Get the last value for a bool/char/short/int/int64_t property name (possibly hierarchical).
bool exists(std::string const &name) const
Determine if a name (possibly hierarchical) exists.
double getAsDouble(std::string const &name) const
Get the last value for any arithmetic property name (possibly hierarchical).
A class representing an angle.
Point in an unspecified spherical coordinate system.
Reports errors that are due to events beyond the control of the program.
Reports errors from accepting an object of an unexpected or inappropriate type.
int stripVisitInfoKeywords(daf::base::PropertySet &metadata)
Remove VisitInfo-related keywords from the metadata.
void setVisitInfoMetadata(daf::base::PropertyList &metadata, VisitInfo const &visitInfo)
Set FITS metadata from a VisitInfo.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
std::ostream & operator<<(std::ostream &os, Measurement const &measurement)
@ UNKNOWN
Rotation angle is unknown.
FilterProperty & operator=(FilterProperty const &)=default
std::int64_t RecordId
Type used for unique IDs for records.
lsst::geom::SpherePoint SpherePoint
constexpr AngleUnit degrees
constant with units of degrees
constexpr AngleUnit radians
constant with units of radians
double sin(Angle const &a)
double tan(Angle const &a)
double cos(Angle const &a)
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
A base class for image defects.
table::Key< std::string > name
table::Key< lsst::geom::Angle > longitude
table::Key< lsst::geom::Angle > latitude
table::Key< lsst::geom::Angle > boresightAzAlt_az
table::Key< double > exposureTime
table::Key< lsst::geom::Angle > era
table::Key< double > airPressure
table::Key< lsst::geom::Angle > boresightAzAlt_alt
table::Key< int > rotType
table::Key< double > darkTime
table::Key< std::string > instrumentLabel
table::CoordKey boresightRaDec
table::Key< double > boresightAirmass
table::Key< double > airTemperature
table::Key< std::int64_t > tai
table::Key< double > elevation
table::Key< double > humidity
table::Key< int > version
table::Key< lsst::geom::Angle > boresightRotAngle
table::Key< table::RecordId > exposureId