CppEphem
CEObserver.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * CEObserver.cpp: CppEphem *
3  * ----------------------------------------------------------------------- *
4  * Copyright © 2016-2019 JCardenzana *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 
36 // C++ HEADERS
37 #include <stdio.h>
38 
39 // CPPEPHEM HEADERS
40 #include "CEObserver.h"
41 
42 
43 /**********************************************************************/
47 {
48  init_members();
49 }
50 
51 
52 /**********************************************************************/
61 CEObserver::CEObserver(const double& longitude,
62  const double& latitude,
63  const double& elevation,
64  const CEAngleType& angle_type)
65 {
66  init_members();
67 
68  // Use the internal methods for setting the values
69  SetLongitude(longitude, angle_type) ;
70  SetLatitude(latitude, angle_type) ;
71  SetElevation(elevation) ;
72 }
73 
74 
75 /**********************************************************************/
81 {
82  init_members();
83  copy_members(other);
84 }
85 
86 
87 /**********************************************************************/
91 {
92  free_members();
93 }
94 
95 
96 /**********************************************************************/
103 {
104  if (this != &other) {
105  free_members();
106  init_members();
107  copy_members(other);
108  }
109  return *this;
110 }
111 
112 
113 /**********************************************************************/
120 std::vector<double> CEObserver::PositionGeo(void) const
121 {
122  // Get the position
123  double xyzm[3];
124  iauGd2gc(1, longitude_, latitude_, elevation_m_, xyzm);
125 
126  return std::vector<double>(&xyzm[0], &xyzm[0]+3);
127 }
128 
129 /**********************************************************************/
134 std::vector<double> CEObserver::PositionCIRS(const CEDate& date) const
135 {
136  UpdatePosVel(date);
137  return pos_cirs_;
138 }
139 
140 
141 /**********************************************************************/
146 std::vector<double> CEObserver::PositionICRS(const CEDate& date) const
147 {
148  UpdatePosVel(date);
149  return pos_icrs_;
150 }
151 
152 
153 /**********************************************************************/
158 std::vector<double> CEObserver::VelocityCIRS(const CEDate& date) const
159 {
160  UpdatePosVel(date);
161  return vel_cirs_;
162 }
163 
164 
165 /**********************************************************************/
170 std::vector<double> CEObserver::VelocityICRS(const CEDate& date) const
171 {
172  UpdatePosVel(date);
173  return vel_icrs_;
174 }
175 
176 
177 /**********************************************************************/
181 std::string CEObserver::print(void) const
182 {
183  // Fill in the returned string with formatted strings
184  std::string msg("Observer:\n");
185  msg += " (Lon,Lat) = (" + std::to_string(Longitude_Deg()) + ", " +
186  std::to_string(Latitude_Deg()) + ") deg\n";
187  msg += " Elevation = " + std::to_string(Elevation_m()) + " m\n";
188  msg += " Temp = " + std::to_string(Temperature_C()) + " C\n";
189  msg += " Pressure = " + std::to_string(Pressure_hPa()) + " hPa\n";
190  msg += " Humidity = " + std::to_string(RelativeHumidity()) + " %%\n";
191  msg += " Wavelength= " + std::to_string(Wavelength_um()) + " um\n";
192  return msg;
193 }
194 
195 
196 /**********************************************************************/
199 void CEObserver::free_members(void)
200 {
201  // Nothing to do here
202 }
203 
204 
205 /**********************************************************************/
210 void CEObserver::copy_members(const CEObserver& other)
211 {
212  longitude_ = other.longitude_;
213  latitude_ = other.latitude_;
214  elevation_m_ = other.elevation_m_;
219  utc_offset_ = other.utc_offset_;
220 
221  // Copy cached parameters
222  cache_date_ = other.cache_date_;
223  pos_cirs_ = other.pos_cirs_;
224  pos_icrs_ = other.pos_icrs_;
225  vel_cirs_ = other.vel_cirs_;
226  vel_icrs_ = other.vel_icrs_;
227 }
228 
229 
230 /**********************************************************************/
233 void CEObserver::init_members(void)
234 {
235  longitude_ = 0.0;
236  latitude_ = 0.0;
237  elevation_m_ = 0.0;
240  relative_humidity_ = 0.0;
241  wavelength_um_ = 0.5;
243 
244  // cached pos/vel parameters
245  cache_date_ = -1.0e30;
246  pos_cirs_ = std::vector<double>(3, 0.0);
247  pos_icrs_ = std::vector<double>(3, 0.0);
248  vel_cirs_ = std::vector<double>(3, 0.0);
249  vel_icrs_ = std::vector<double>(3, 0.0);
250 }
251 
252 
253 /**********************************************************************/
258 void CEObserver::UpdatePosVel(const CEDate& date) const
259 {
260  // Check if the cached date has changed
261  if (date.MJD() != cache_date_) {
262 
263  // Convert UTC to UT1 and TDB
264  double ut11(0.0);
265  double ut12(0.0);
266  double tdb1(0.0);
267  double tdb2(0.0);
268  double tt1(0.0);
269  double tt2(0.0);
270  CEDate::UTC2UT1(date.MJD(), &ut11, &ut12);
271  CEDate::UTC2TDB(date.MJD(), &tdb1, &tdb2);
272  CEDate::UTC2TT(date.MJD(), &tt1, &tt2);
273 
274  // Compute the Earth rotation angle at UT1
275  double theta = iauEra00(ut11, ut12);
276  double sp = iauSp00(tt1, tt2);
277 
278  // Vectors for intermediate position/velocities
279  double pvc[2][3]; // CIRS pos,vel
280 
281  // Get the position and velocity values in CIRS
282  iauPvtob(longitude_,
283  latitude_,
284  elevation_m_,
285  date.xpolar(),
286  date.ypolar(),
287  sp,
288  theta,
289  pvc);
290 
291  // Earth centric distance/velocity in ICRS (AU and AU/day)
292  double ebpv[2][3];
293  double ehpv[2][3];
294  iauEpv00(tdb1, tdb2, ehpv, ebpv);
295 
296  // Get the CIRS and ICRS pos,vel
297  double mps_apd = CppEphem::sec_per_day() / CppEphem::m_per_au();
298  for (int i=0; i<3; i++) {
299  // CIRS
300  pos_cirs_[i] = pvc[0][i] / CppEphem::m_per_au();
301  vel_cirs_[i] = pvc[1][i] * mps_apd;
302 
303  // ICRS (Earth barycenter + CIRS offset)
304  pos_icrs_[i] = ebpv[0][i] + pos_cirs_[i];
305  vel_icrs_[i] = ebpv[1][i] + vel_cirs_[i];
306  }
307  }
308  return;
309 }
CEObserver::Elevation_m
double Elevation_m() const
Return altitude in meters above sea level.
Definition: CEObserver.h:166
CEObserver::cache_date_
double cache_date_
Date used to copute pos/vel vectors.
Definition: CEObserver.h:126
CEObserver::SetLatitude
void SetLatitude(const double &latitude, const CEAngleType &angle_type=CEAngleType::RADIANS)
Set the observer's latitude.
Definition: CEObserver.h:310
CEObserver::free_members
void free_members(void)
Initialize the data members.
Definition: CEObserver.cpp:198
CEDate
Definition: CEDate.h:43
CEObserver::Temperature_C
double Temperature_C() const
Return temperature in degrees Celsius.
Definition: CEObserver.h:186
CEObserver::pos_cirs_
std::vector< double > pos_cirs_
XYZ position (AU) relative to Earth center.
Definition: CEObserver.h:127
CEObserver::copy_members
void copy_members(const CEObserver &other)
Copy data members from another CEObserver object.
Definition: CEObserver.cpp:209
CEObserver.h
CEAngleType
CEAngleType
Definition: CEAngle.h:30
CEObserver::relative_humidity_
double relative_humidity_
Relative humidity (in range 0-1)
Definition: CEObserver.h:122
CEObserver::RelativeHumidity
double RelativeHumidity() const
Return relative humidity.
Definition: CEObserver.h:216
CEObserver::PositionGeo
std::vector< double > PositionGeo(void) const
Returns the observers geocentric position in meters.
Definition: CEObserver.cpp:119
CppEphem::sec_per_day
double sec_per_day()
Seconds per day.
Definition: CENamespace.h:71
CEObserver::SetElevation
void SetElevation(const double &elevation=0.0)
Set elevation in meters above sea level.
Definition: CEObserver.h:285
CEObserver::UpdatePosVel
void UpdatePosVel(const CEDate &date) const
Update cached position/velocity vectors.
Definition: CEObserver.cpp:257
CEObserver::VelocityICRS
std::vector< double > VelocityICRS(const CEDate &date) const
Get the velocity vector for this observer relative to ICRS (solar system barycenter)
Definition: CEObserver.cpp:169
CEDate::UTC2TDB
static void UTC2TDB(const double &mjd, double *tdb1, double *tdb2)
Convert the UTC MJD to TDB JD (useful for planet computations)
Definition: CEDate.cpp:429
CppEphem::SeaLevelTemp_C
double SeaLevelTemp_C()
Definition: CENamespace.h:55
CEObserver::latitude_
double latitude_
Geographic latitude (radians)
Definition: CEObserver.h:116
CEObserver::VelocityCIRS
std::vector< double > VelocityCIRS(const CEDate &date) const
Get the velocity vector for this observer relative to CIRS (solar system barycenter)
Definition: CEObserver.cpp:157
CEDate::ypolar
static double ypolar(const double &date, const CEDateType &date_type=CEDateType::JD)
Polar motion (xy for a given date.
Definition: CEDate.cpp:520
CEObserver::operator=
CEObserver & operator=(const CEObserver &other)
Copy assignment operator.
Definition: CEObserver.cpp:101
CEObserver::PositionICRS
std::vector< double > PositionICRS(const CEDate &date) const
Get the position vector for this observer relative to ICRS (solar system barycenter)
Definition: CEObserver.cpp:145
CEObserver::Pressure_hPa
double Pressure_hPa() const
Return atmospheric pressure in units of hPa.
Definition: CEObserver.h:176
CEObserver::longitude_
double longitude_
Geographic longitude (radians)
Definition: CEObserver.h:115
CEObserver::Wavelength_um
double Wavelength_um() const
Return the wavelength in units of micrometers.
Definition: CEObserver.h:226
CEObserver::print
std::string print(void) const
Returns a string containing information about this object.
Definition: CEObserver.cpp:180
CEObserver::PositionCIRS
std::vector< double > PositionCIRS(const CEDate &date) const
Get the position vector for this observer relative to CIRS (Earth center)
Definition: CEObserver.cpp:133
CEDate::UTC2UT1
static void UTC2UT1(const double &mjd, double *ut11, double *ut12)
Convert the UTC MJD to UT1 JD.
Definition: CEDate.cpp:384
CEObserver::elevation_m_
double elevation_m_
Elevation (in meters) above sea-level.
Definition: CEObserver.h:117
CEObserver::SetLongitude
void SetLongitude(const double &longitude, const CEAngleType &angle_type=CEAngleType::RADIANS)
Set the observer's longitude.
Definition: CEObserver.h:297
CEObserver::wavelength_um_
double wavelength_um_
Observing wavelength (micrometers)
Definition: CEObserver.h:123
CEObserver::vel_cirs_
std::vector< double > vel_cirs_
XYZ velocity (AU) relative to Earth center.
Definition: CEObserver.h:129
CEObserver::Latitude_Deg
double Latitude_Deg() const
Return geographic latitude in degrees.
Definition: CEObserver.h:156
CETime::SystemUTCOffset_hrs
static double SystemUTCOffset_hrs()
Definition: CETime.h:74
CppEphem::EstimatePressure_hPa
double EstimatePressure_hPa(double elevation_m)
Method for estimating atmospheric pressure (in hPa) from altitude (in meters)
Definition: CENamespace.h:100
CEObserver::temperature_celsius_
double temperature_celsius_
Temperature in degrees celsius.
Definition: CEObserver.h:121
CEObserver::CEObserver
CEObserver(void)
Default constructor.
Definition: CEObserver.cpp:45
CEObserver::pressure_hPa_
double pressure_hPa_
Atmospheric pressure (in units of hPa)
Definition: CEObserver.h:120
CEObserver::vel_icrs_
std::vector< double > vel_icrs_
XYZ veloicty (AU) relative to solar system barycenter.
Definition: CEObserver.h:130
CEObserver
Definition: CEObserver.h:28
CEObserver::pos_icrs_
std::vector< double > pos_icrs_
XYZ position (AU) relative to solar system barycenter.
Definition: CEObserver.h:128
CEObserver::utc_offset_
double utc_offset_
UTC offset in hours (set by default to system offset)
Definition: CEObserver.h:133
CEDate::MJD
virtual double MJD() const
Get the Modified Julian date represented by this object.
Definition: CEDate.h:160
CEDate::xpolar
static double xpolar(const double &date, const CEDateType &date_type=CEDateType::JD)
Polar motion (x) for a given date.
Definition: CEDate.cpp:494
CEObserver::Longitude_Deg
double Longitude_Deg() const
Return observer geographic longitude in degrees.
Definition: CEObserver.h:136
CppEphem::m_per_au
double m_per_au()
meters per astronomical unit
Definition: CENamespace.h:70
CEDate::UTC2TT
static void UTC2TT(const double &mjd, double *tt1, double *tt2)
Convert the UTC MJD to TT JD.
Definition: CEDate.cpp:405
CEObserver::init_members
void init_members(void)
Initialize the data members.
Definition: CEObserver.cpp:232
CEObserver::~CEObserver
virtual ~CEObserver(void)
Destructor.
Definition: CEObserver.cpp:89