The observatory
table defines basic observatory metadata.
Several tables store reference information for each observatory including:
pier
mark
instrument
Observatory baseline observations are stored in the observation
table,
and refer to reference information using database ids. Each observation has
one or more readings, stored in the reading
table. Each reading has one or
more measurements, stored in the measurement
table.
Records in reference tables represent time intervals for the associated information, and multiple records may refer to the same physical instrument, pier, or mark.
All reference tables (pier
, mark
, and instrument
) use
begin
and end
unix epoch timestamps to identify the time interval for which
information is considered valid.
The interval is closed for begin
(includes the begin time)
and open for end
(excludes the end time),
which can be written as [begin, end)
.
-
begin
- (int) unix epoch timestamp.When
begin
is null that indicates no start time, or that the information can be used for any time beforeend
-
end
- (int) unix epoch timestamp.When
end
is null that indicates no end time, or that the information can be used for any time afterbegin
.
NOTE: Because observations refer to information in reference tables using ids, do not modify existing reference data. Instead, close the epoch for an existing records by setting the
end
time and insert a new record to represent a new epoch.
The instrument
table describes hardware used to create baseline observations.
id
- (int) primary keyobservatory_id
- (int) foreign key toobservatory.id
serial_number
- (text) serial number of instrumentname
- (text) name of instrumenttype
- (text) but usuallytheodolite
orelectronics
begin
,end
- (int) time when instrument is valid
The logical key for this table is the combination of
(observatory_id
, serial_number
, type
, begin
).
If an instrument is both
theodolite
andelectronics
, it should have one record in this table for each type. Similarly, if an instrument is repaired, multiple records may be used to identify the instrument before and after its repair.
The pier
table describes a pier correction value for a specific time period,
rather than a physical pier, so there may be multiple records for the same
physical pier.
id
- (int) primary keyobservatory_id
- (int) foreign key toobservatory.id
name
- (text) name of piercorrection
- (float) pier correction valuedefault_mark_id
- (int) foreign key tomark.id
default_electronics_id
- (int) foreign key toinstrument.id
default_theodolite_id
- (int) foreign key toinstrument.id
begin
,end
- (int) time when pier correction is valid
The unique constraint for this table is the combination of
(observatory_id
, name
, correction
, begin
).
The mark
table describes the azimuth to a given mark, for a specific pier
.
id
- (int) primary keypier_id
- (int) foreign key topier.id
name
- (text) name of azimuthazimuth
- (float) azimuth from pier to markbegin
,end
- time when mark azimuth is valid.
Piers may have multiple marks associated, with different names or azimuths, but mark records are always associated to a specific pier correction epoch.
NOTE: these examples are specific to mysql.
-- define pier to insert
SET @observatory = 'BOU';
SET @pier_begin = UNIX_TIMESTAMP('2016-01-01T00:00:00Z');
SET @pier_correction = -22.0;
SET @pier_name = 'MainPCDCP';
SET @mark_name = 'AZ';
SET @mark_azimuth = 199.1383;
-- end define pier, remaining SQL should not require modification
-- look up observatory id
SET @observatory_id = (SELECT id FROM observatory WHERE code=@observatory);
-- close existing pier and mark epoch
UPDATE pier p
SET p.end = @pier_begin
WHERE observatory_id = @observatory_id
AND p.end is NULL;
-- add new pier epoch
INSERT INTO pier (observatory_id, name, begin, end, correction)
VALUES (
@observatory_id,
@pier_name,
@pier_begin,
null,
@pier_correction
);
SET @pier_id = LAST_INSERT_ID();
-- add new mark epoch associated to new pier epoch
INSERT INTO mark (pier_id, name, begin, end, azimuth)
VALUES (
@pier_id,
@mark_name,
@pier_begin,
null,
@mark_azimuth
);
SET @mark_id = LAST_INSERT_ID();
-- set new mark as default for new pier
UPDATE pier
SET default_mark_id = @mark_id
WHERE id = @pier_id;
-- set new pier as default for observatory
UPDATE observatory
SET default_pier_id = @pier_id
WHERE id = @observatory_id;