1 /*
2     SPDX-FileCopyrightText: 2012 Samikshan Bairagya <samikshan@gmail.com>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "obsconditions.h"
8 
9 #include <QDebug>
10 
11 #include <cmath>
12 
ObsConditions(int bortle,double aperture,Equipment equip,TelescopeType telType)13 ObsConditions::ObsConditions(int bortle, double aperture, Equipment equip, TelescopeType telType)
14     : m_BortleClass(bortle), m_Equip(equip), m_TelType(telType), m_Aperture(aperture)
15 {
16     // 't' parameter
17     switch (m_TelType)
18     {
19         case Reflector:
20             m_tParam = 0.7;
21             break;
22         case Refractor:
23             m_tParam = 0.9;
24             break;
25         case Invalid:
26             m_tParam = -1; //invalid value
27             break;
28     }
29     setLimMagnitude();
30 
31     qDebug() << "Aperture value being used:" << m_Aperture;
32 }
33 
setLMMap()34 QMap<int, double> ObsConditions::setLMMap()
35 {
36     QMap<int, double> LMMap;
37     LMMap.insert(1, 7.8);
38     LMMap.insert(2, 7.3);
39     LMMap.insert(3, 6.8);
40     LMMap.insert(4, 6.3);
41     LMMap.insert(5, 5.8);
42     LMMap.insert(6, 5.3);
43     LMMap.insert(7, 4.8);
44     LMMap.insert(8, 4.3);
45     LMMap.insert(9, 3.8);
46 
47     return LMMap;
48 }
49 
50 const QMap<int, double> ObsConditions::m_LMMap = setLMMap();
51 
setLimMagnitude()52 void ObsConditions::setLimMagnitude()
53 {
54     m_LM = m_LMMap[m_BortleClass];
55 }
56 
getOptimumMAG()57 double ObsConditions::getOptimumMAG()
58 {
59     double power = (2.81 + 2.814 * m_LM - 0.3694 * pow(m_LM, 2)) / 5;
60     return 0.1333 * m_Aperture * sqrt(m_tParam) * pow(power, 10);
61 }
62 
getTrueMagLim()63 double ObsConditions::getTrueMagLim()
64 {
65     //     qDebug()<< (4.12 + 2.5 * log10( pow(aperture,2)*t ));
66     //     return 4.12 + 2.5 * log10( pow(aperture,2)*t ); //Taking optimum magnification into consideration
67 
68     ///If there is no equipment available then return limiting magnitude for naked-eye
69     if (m_Equip == None || m_Aperture == -1)
70         return m_LM;
71 
72     /**
73      * This is a more traditional formula which does not take the
74      * 't' parameter into account. It also does not take into account
75      * the magnification being used. The formula used is:
76      *
77      * TLM_trad = LM + 5*log10(aperture/7.5)
78      *
79      * The calculation is just based on the calculation of the
80      * telescope's aperture to eye's pupil surface ratio.
81      */
82 
83     return m_LM + 5 * log10(m_Aperture / 7.5);
84 }
85 
isVisible(GeoLocation * geo,dms * lst,SkyObject * so)86 bool ObsConditions::isVisible(GeoLocation *geo, dms *lst, SkyObject *so)
87 {
88     if (so->type() == SkyObject::SATELLITE)
89     {
90         return so->alt().Degrees() > 6.0;
91     }
92     KStarsDateTime ut = geo->LTtoUT(KStarsDateTime(QDateTime::currentDateTime().toLocalTime()));
93     SkyPoint sp       = so->recomputeCoords(ut, geo);
94 
95     //check altitude of object at this time.
96     sp.EquatorialToHorizontal(lst, geo->lat());
97 
98     return (sp.alt().Degrees() > 6.0 && so->mag() < getTrueMagLim());
99 }
100 
setObsConditions(int bortle,double aperture,ObsConditions::Equipment equip,ObsConditions::TelescopeType telType)101 void ObsConditions::setObsConditions(int bortle, double aperture, ObsConditions::Equipment equip,
102                                      ObsConditions::TelescopeType telType)
103 {
104     m_BortleClass = bortle;
105     setLimMagnitude();
106     m_Aperture = aperture;
107     m_Equip    = equip;
108     m_TelType  = telType;
109 
110     qDebug() << "Aperture value being used:" << m_Aperture;
111 }
112