File indexing completed on 2024-04-28 15:11:24

0001 /*
0002     SPDX-FileCopyrightText: 2012 Samikshan Bairagya <samikshan@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "obsconditions.h"
0008 
0009 #include <QDebug>
0010 
0011 #include <cmath>
0012 
0013 ObsConditions::ObsConditions(int bortle, double aperture, Equipment equip, TelescopeType telType)
0014     : m_BortleClass(bortle), m_Equip(equip), m_TelType(telType), m_Aperture(aperture)
0015 {
0016     // 't' parameter
0017     switch (m_TelType)
0018     {
0019         case Reflector:
0020             m_tParam = 0.7;
0021             break;
0022         case Refractor:
0023             m_tParam = 0.9;
0024             break;
0025         case Invalid:
0026             m_tParam = -1; //invalid value
0027             break;
0028     }
0029     setLimMagnitude();
0030 
0031     qDebug() << Q_FUNC_INFO << "Aperture value being used:" << m_Aperture;
0032 }
0033 
0034 QMap<int, double> ObsConditions::setLMMap()
0035 {
0036     QMap<int, double> LMMap;
0037     LMMap.insert(1, 7.8);
0038     LMMap.insert(2, 7.3);
0039     LMMap.insert(3, 6.8);
0040     LMMap.insert(4, 6.3);
0041     LMMap.insert(5, 5.8);
0042     LMMap.insert(6, 5.3);
0043     LMMap.insert(7, 4.8);
0044     LMMap.insert(8, 4.3);
0045     LMMap.insert(9, 3.8);
0046 
0047     return LMMap;
0048 }
0049 
0050 const QMap<int, double> ObsConditions::m_LMMap = setLMMap();
0051 
0052 void ObsConditions::setLimMagnitude()
0053 {
0054     m_LM = m_LMMap[m_BortleClass];
0055 }
0056 
0057 double ObsConditions::getOptimumMAG()
0058 {
0059     double power = (2.81 + 2.814 * m_LM - 0.3694 * pow(m_LM, 2)) / 5;
0060     return 0.1333 * m_Aperture * sqrt(m_tParam) * pow(power, 10);
0061 }
0062 
0063 double ObsConditions::getTrueMagLim()
0064 {
0065     //     qDebug()<< (4.12 + 2.5 * log10( pow(aperture,2)*t ));
0066     //     return 4.12 + 2.5 * log10( pow(aperture,2)*t ); //Taking optimum magnification into consideration
0067 
0068     ///If there is no equipment available then return limiting magnitude for naked-eye
0069     if (m_Equip == None || m_Aperture == -1)
0070         return m_LM;
0071 
0072     /**
0073      * This is a more traditional formula which does not take the
0074      * 't' parameter into account. It also does not take into account
0075      * the magnification being used. The formula used is:
0076      *
0077      * TLM_trad = LM + 5*log10(aperture/7.5)
0078      *
0079      * The calculation is just based on the calculation of the
0080      * telescope's aperture to eye's pupil surface ratio.
0081      */
0082 
0083     return m_LM + 5 * log10(m_Aperture / 7.5);
0084 }
0085 
0086 bool ObsConditions::isVisible(GeoLocation *geo, dms *lst, SkyObject *so)
0087 {
0088     if (so->type() == SkyObject::SATELLITE)
0089     {
0090         return so->alt().Degrees() > 6.0;
0091     }
0092     KStarsDateTime ut = geo->LTtoUT(KStarsDateTime(QDateTime::currentDateTime().toLocalTime()));
0093     SkyPoint sp       = so->recomputeCoords(ut, geo);
0094 
0095     //check altitude of object at this time.
0096     sp.EquatorialToHorizontal(lst, geo->lat());
0097 
0098     return (sp.alt().Degrees() > 6.0 && so->mag() < getTrueMagLim());
0099 }
0100 
0101 void ObsConditions::setObsConditions(int bortle, double aperture, ObsConditions::Equipment equip,
0102                                      ObsConditions::TelescopeType telType)
0103 {
0104     m_BortleClass = bortle;
0105     setLimMagnitude();
0106     m_Aperture = aperture;
0107     m_Equip    = equip;
0108     m_TelType  = telType;
0109 
0110     qDebug() << Q_FUNC_INFO << "Aperture value being used:" << m_Aperture;
0111 }