Skip to content

Commit

Permalink
AstroCalc: Add a filter by eclipse type
Browse files Browse the repository at this point in the history
  • Loading branch information
10110111 committed Jan 5, 2025
1 parent 59de1f6 commit b51cbe8
Show file tree
Hide file tree
Showing 3 changed files with 267 additions and 125 deletions.
4 changes: 4 additions & 0 deletions data/gui/normalStyle.css
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,10 @@ QLabel#monthlyElevationTimeInfo {
color: rgb(238, 238, 238);
font-size: 18pt;
}

QWidget#seFilterWidget {
background: transparent;
}
/**************************************************************************************************************
* searchDialog
*************************************************************************************************************/
Expand Down
296 changes: 171 additions & 125 deletions src/gui/AstroCalcDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3159,124 +3159,144 @@ void AstroCalcDialog::generateSolarEclipses()
// Source: Astronomical Algorithms (1991), Jean Meeus
if (abs(gamma) <= (1.5433 + L2))
{
bool add = false;
if (abs(gamma) > 0.9972 && abs(gamma) < (1.5433 + L2))
{
if (abs(gamma) < 0.9972 + abs(L2) && dRatio > 1.)
{
eclipseTypeStr = qc_("Total", "eclipse type"); // Non-central total eclipse
if (ui->seFilterTotal->isChecked())
add = true;
}
else if (abs(gamma) < 0.9972 + abs(L2) && dRatio < 1.)
{
eclipseTypeStr = qc_("Annular", "eclipse type"); // Non-central annular eclipse
if (ui->seFilterAnnular->isChecked())
add = true;
}
else
{
eclipseTypeStr = qc_("Partial", "eclipse type");
if (ui->seFilterPartial->isChecked())
add = true;
}
noncentraleclipse = true;
}
else
{
if (L2 < 0.)
{
eclipseTypeStr = qc_("Total", "eclipse type");
if (ui->seFilterTotal->isChecked())
add = true;
}
else if (L2 > 0.0047)
{
eclipseTypeStr = qc_("Annular", "eclipse type");
if (ui->seFilterAnnular->isChecked())
add = true;
}
else if (L2 > 0. && L2 < 0.0047)
{
if (L2 < (0.00464 * sqrt(1. - gamma * gamma)))
{
eclipseTypeStr = qc_("Hybrid", "eclipse type");
if (ui->seFilterHybrid->isChecked())
add = true;
}
else
{
eclipseTypeStr = qc_("Annular", "eclipse type");
if (ui->seFilterAnnular->isChecked())
add = true;
}
}
}

// Saros series calculations - useful to search for eclipses in the same Saros
// Adapted from Saros calculations for solar eclipses in Sky & Telescope (October 1985)
// Saros numbers calculated here are matching well with NASA's Five Millennium Catalog of Solar Eclipses

// ln = Brown Lunation number : = 1 at the first New Moon of 1923
const double q = round ((JD-2423436.40347)/29.530588);
const int ln = int(q) + 1 - 953;
const int nd = ln + 105;
const int s = 136 + 38 * nd;
const int nx = -61 * nd;
const int nc = qFloor(nx / 358. + 0.5 - nd / (12. * 358 * 358));
int saros = 1 + ((s + nc * 223 - 1) % 223);
if ((s + nc * 223 - 1) < 0) saros -= 223;
if (saros < -223) saros += 223;

sarosStr = QString("%1").arg(QString::number(saros));
gammaStr = QString("%1").arg(QString::number(gamma, 'f', 3));
double eclipseLatitude = 0.;
double eclipseLongitude = 0.;
double eclipseAltitude = 0.;

if (noncentraleclipse)
if (add)
{
magStr = QString("%1").arg(QString::number(magnitude, 'f', 3));
eclipseLatitude = latDeg;
eclipseLongitude = lngDeg;
altitudeStr = "";
durationStr = dash;
pathWidthStr = dash;
}
else
{
magStr = QString("%1").arg(QString::number(dRatio, 'f', 3));
eclipseAltitude = altitude;
altitudeStr = QString("%1°").arg(QString::number(round(eclipseAltitude)));
pathWidthStr = QString("%1 %2").arg(QString::number(round(pathWidth)), km);
eclipseLatitude = latDeg;
eclipseLongitude = lngDeg;
double centralDuration = abs(duration);
int durationMinute = int(centralDuration);
int durationSecond = qRound((centralDuration - durationMinute) * 60.);
if (durationSecond>59)
// Saros series calculations - useful to search for eclipses in the same Saros
// Adapted from Saros calculations for solar eclipses in Sky & Telescope (October 1985)
// Saros numbers calculated here are matching well with NASA's Five Millennium Catalog of Solar Eclipses

// ln = Brown Lunation number : = 1 at the first New Moon of 1923
const double q = round ((JD-2423436.40347)/29.530588);
const int ln = int(q) + 1 - 953;
const int nd = ln + 105;
const int s = 136 + 38 * nd;
const int nx = -61 * nd;
const int nc = qFloor(nx / 358. + 0.5 - nd / (12. * 358 * 358));
int saros = 1 + ((s + nc * 223 - 1) % 223);
if ((s + nc * 223 - 1) < 0) saros -= 223;
if (saros < -223) saros += 223;

sarosStr = QString("%1").arg(QString::number(saros));
gammaStr = QString("%1").arg(QString::number(gamma, 'f', 3));
double eclipseLatitude = 0.;
double eclipseLongitude = 0.;
double eclipseAltitude = 0.;

if (noncentraleclipse)
{
durationMinute += 1;
durationSecond = 0;
magStr = QString("%1").arg(QString::number(magnitude, 'f', 3));
eclipseLatitude = latDeg;
eclipseLongitude = lngDeg;
altitudeStr = "";
durationStr = dash;
pathWidthStr = dash;
}
if (durationSecond>9)
durationStr = QString("%1m %2s").arg(QString::number(durationMinute), QString::number(durationSecond));
else
durationStr = QString("%1m 0%2s").arg(QString::number(durationMinute), QString::number(durationSecond));
}

latitudeStr = StelUtils::decDegToLatitudeStr(eclipseLatitude, !withDecimalDegree);
longitudeStr = StelUtils::decDegToLongitudeStr(eclipseLongitude, true, false, !withDecimalDegree);
{
magStr = QString("%1").arg(QString::number(dRatio, 'f', 3));
eclipseAltitude = altitude;
altitudeStr = QString("%1°").arg(QString::number(round(eclipseAltitude)));
pathWidthStr = QString("%1 %2").arg(QString::number(round(pathWidth)), km);
eclipseLatitude = latDeg;
eclipseLongitude = lngDeg;
double centralDuration = abs(duration);
int durationMinute = int(centralDuration);
int durationSecond = qRound((centralDuration - durationMinute) * 60.);
if (durationSecond>59)
{
durationMinute += 1;
durationSecond = 0;
}
if (durationSecond>9)
durationStr = QString("%1m %2s").arg(QString::number(durationMinute), QString::number(durationSecond));
else
durationStr = QString("%1m 0%2s").arg(QString::number(durationMinute), QString::number(durationSecond));
}

ACSolarEclipseTreeWidgetItem* treeItem = new ACSolarEclipseTreeWidgetItem(ui->solareclipseTreeWidget);
const double utcOffsetHrs = core->getUTCOffset(JD);
treeItem->setText(SolarEclipseDate, QString("%1 %2").arg(localeMgr->getPrintableDateLocal(JD, utcOffsetHrs), localeMgr->getPrintableTimeLocal(JD, utcOffsetHrs))); // local date and time
treeItem->setData(SolarEclipseDate, Qt::UserRole, JD);
treeItem->setText(SolarEclipseSaros, sarosStr);
treeItem->setToolTip(SolarEclipseSaros, q_("Saros series number of eclipse (each eclipse in a Saros is separated by an interval of 18 years 11.3 days)"));
treeItem->setText(SolarEclipseType, eclipseTypeStr);
treeItem->setText(SolarEclipseGamma, gammaStr);
treeItem->setText(SolarEclipseMag, magStr);
treeItem->setToolTip(SolarEclipseMag, q_("Eclipse magnitude is the fraction of the Sun's diameter obscured by the Moon"));
treeItem->setText(SolarEclipseLatitude, latitudeStr);
treeItem->setData(SolarEclipseLatitude, Qt::UserRole, eclipseLatitude);
treeItem->setText(SolarEclipseLongitude, longitudeStr);
treeItem->setData(SolarEclipseLongitude, Qt::UserRole, eclipseLongitude);
treeItem->setText(SolarEclipseAltitude, altitudeStr);
treeItem->setData(SolarEclipseAltitude, Qt::UserRole, eclipseAltitude);
treeItem->setToolTip(SolarEclipseAltitude, q_("Sun's altitude at greatest eclipse"));
treeItem->setText(SolarEclipsePathwidth, pathWidthStr);
treeItem->setData(SolarEclipsePathwidth, Qt::UserRole, pathWidth);
treeItem->setToolTip(SolarEclipsePathwidth, q_("Width of the path of totality or annularity at greatest eclipse"));
treeItem->setText(SolarEclipseDuration, durationStr);
treeItem->setData(SolarEclipseDuration, Qt::UserRole, abs(duration));
treeItem->setToolTip(SolarEclipseDuration, q_("Duration of total or annular phase at greatest eclipse"));
for (auto column: {SolarEclipseDate, SolarEclipseSaros, SolarEclipseGamma, SolarEclipseMag, SolarEclipseLatitude,
SolarEclipseLongitude, SolarEclipseAltitude, SolarEclipsePathwidth, SolarEclipseDuration})
treeItem->setTextAlignment(column, Qt::AlignRight);
latitudeStr = StelUtils::decDegToLatitudeStr(eclipseLatitude, !withDecimalDegree);
longitudeStr = StelUtils::decDegToLongitudeStr(eclipseLongitude, true, false, !withDecimalDegree);

ACSolarEclipseTreeWidgetItem* treeItem = new ACSolarEclipseTreeWidgetItem(ui->solareclipseTreeWidget);
const double utcOffsetHrs = core->getUTCOffset(JD);
treeItem->setText(SolarEclipseDate, QString("%1 %2").arg(localeMgr->getPrintableDateLocal(JD, utcOffsetHrs), localeMgr->getPrintableTimeLocal(JD, utcOffsetHrs))); // local date and time
treeItem->setData(SolarEclipseDate, Qt::UserRole, JD);
treeItem->setText(SolarEclipseSaros, sarosStr);
treeItem->setToolTip(SolarEclipseSaros, q_("Saros series number of eclipse (each eclipse in a Saros is separated by an interval of 18 years 11.3 days)"));
treeItem->setText(SolarEclipseType, eclipseTypeStr);
treeItem->setText(SolarEclipseGamma, gammaStr);
treeItem->setText(SolarEclipseMag, magStr);
treeItem->setToolTip(SolarEclipseMag, q_("Eclipse magnitude is the fraction of the Sun's diameter obscured by the Moon"));
treeItem->setText(SolarEclipseLatitude, latitudeStr);
treeItem->setData(SolarEclipseLatitude, Qt::UserRole, eclipseLatitude);
treeItem->setText(SolarEclipseLongitude, longitudeStr);
treeItem->setData(SolarEclipseLongitude, Qt::UserRole, eclipseLongitude);
treeItem->setText(SolarEclipseAltitude, altitudeStr);
treeItem->setData(SolarEclipseAltitude, Qt::UserRole, eclipseAltitude);
treeItem->setToolTip(SolarEclipseAltitude, q_("Sun's altitude at greatest eclipse"));
treeItem->setText(SolarEclipsePathwidth, pathWidthStr);
treeItem->setData(SolarEclipsePathwidth, Qt::UserRole, pathWidth);
treeItem->setToolTip(SolarEclipsePathwidth, q_("Width of the path of totality or annularity at greatest eclipse"));
treeItem->setText(SolarEclipseDuration, durationStr);
treeItem->setData(SolarEclipseDuration, Qt::UserRole, abs(duration));
treeItem->setToolTip(SolarEclipseDuration, q_("Duration of total or annular phase at greatest eclipse"));
for (auto column: {SolarEclipseDate, SolarEclipseSaros, SolarEclipseGamma, SolarEclipseMag, SolarEclipseLatitude,
SolarEclipseLongitude, SolarEclipseAltitude, SolarEclipsePathwidth, SolarEclipseDuration})
treeItem->setTextAlignment(column, Qt::AlignRight);
}
}
}
}
Expand Down Expand Up @@ -3515,73 +3535,85 @@ void AstroCalcDialog::generateSolarEclipsesLocal()
}
double C3altitude = eclipseData.altitude;

bool add = false;
if (eclipseData.ce > 0. && ((C2altitude > -.3) || (C3altitude > -.3))) // Central eclipse occurs
{
centraleclipse = true;
if (eclipseData.L2 < 0.)
{
eclipseTypeStr = qc_("Total", "eclipse type");
qSwap(JD2, JD3);
if (ui->seFilterTotal->isChecked())
add = true;
}
else
{
eclipseTypeStr = qc_("Annular", "eclipse type");
if (ui->seFilterAnnular->isChecked())
add = true;
}
}
else
{
eclipseTypeStr = qc_("Partial", "eclipse type");
centraleclipse = false;
}
{
eclipseTypeStr = qc_("Partial", "eclipse type");
centraleclipse = false;
if (ui->seFilterPartial->isChecked())
add = true;
}

if (centraleclipse)
if (add)
{
double duration = abs(JD3-JD2)*1440.;
int durationMinute = int(duration);
int durationSecond = qRound((duration - durationMinute) * 60.);
if (durationSecond>59)
if (centraleclipse)
{
durationMinute += 1;
durationSecond = 0;
double duration = abs(JD3-JD2)*1440.;
int durationMinute = int(duration);
int durationSecond = qRound((duration - durationMinute) * 60.);
if (durationSecond>59)
{
durationMinute += 1;
durationSecond = 0;
}
if (durationSecond>9)
durationStr = QString("%1m %2s").arg(QString::number(durationMinute), QString::number(durationSecond));
else
durationStr = QString("%1m 0%2s").arg(QString::number(durationMinute), QString::number(durationSecond));
}
if (durationSecond>9)
durationStr = QString("%1m %2s").arg(QString::number(durationMinute), QString::number(durationSecond));

ACSolarEclipseLocalTreeWidgetItem* treeItem = new ACSolarEclipseLocalTreeWidgetItem(ui->solareclipselocalTreeWidget);
treeItem->setText(SolarEclipseLocalDate, QString("%1").arg(localeMgr->getPrintableDateLocal(JDmax, core->getUTCOffset(JDmax)))); // local date
treeItem->setData(SolarEclipseLocalDate, Qt::UserRole, JDmax);
treeItem->setText(SolarEclipseLocalType, eclipseTypeStr);
treeItem->setText(SolarEclipseLocalFirstContact, QString("%1").arg(localeMgr->getPrintableTimeLocal(JD1, core->getUTCOffset(JD1))));
if (centraleclipse && JD2<JD1) // central eclipse in progress at Sunrise
treeItem->setText(SolarEclipseLocalFirstContact, dash);
treeItem->setToolTip(SolarEclipseLocalFirstContact, q_("The time of first contact"));

if (centraleclipse)
treeItem->setText(SolarEclipseLocal2ndContact, QString("%1").arg(localeMgr->getPrintableTimeLocal(JD2, core->getUTCOffset(JD2))));
else
treeItem->setText(SolarEclipseLocal2ndContact, dash);
treeItem->setToolTip(SolarEclipseLocal2ndContact, q_("The time of second contact"));
treeItem->setText(SolarEclipseLocalMaximum, QString("%1").arg(localeMgr->getPrintableTimeLocal(JDmax, core->getUTCOffset(JDmax))));
treeItem->setToolTip(SolarEclipseLocalMaximum, q_("The time of greatest eclipse"));
treeItem->setText(SolarEclipseLocalMagnitude, magStr);
if (centraleclipse)
treeItem->setText(SolarEclipseLocal3rdContact, QString("%1").arg(localeMgr->getPrintableTimeLocal(JD3, core->getUTCOffset(JD3))));
else
durationStr = QString("%1m 0%2s").arg(QString::number(durationMinute), QString::number(durationSecond));
treeItem->setText(SolarEclipseLocal3rdContact, dash);
treeItem->setToolTip(SolarEclipseLocal3rdContact, q_("The time of third contact"));
treeItem->setText(SolarEclipseLocalLastContact, QString("%1").arg(localeMgr->getPrintableTimeLocal(JD4, core->getUTCOffset(JD4))));
if (centraleclipse && JD3>JD4) // central eclipse in progress at Sunset
treeItem->setText(SolarEclipseLocalLastContact, dash);
treeItem->setToolTip(SolarEclipseLocalLastContact, q_("The time of fourth contact"));
if (centraleclipse)
treeItem->setText(SolarEclipseLocalDuration, durationStr);
else
treeItem->setText(SolarEclipseLocalDuration, dash);
treeItem->setToolTip(SolarEclipseLocalDuration, q_("Duration of total or annular eclipse"));
for (auto column: {SolarEclipseLocalDate, SolarEclipseLocalMagnitude, SolarEclipseLocalFirstContact, SolarEclipseLocal2ndContact,
SolarEclipseLocalMaximum, SolarEclipseLocal3rdContact, SolarEclipseLocalLastContact, SolarEclipseLocalDuration})
treeItem->setTextAlignment(column, Qt::AlignRight);
}

ACSolarEclipseLocalTreeWidgetItem* treeItem = new ACSolarEclipseLocalTreeWidgetItem(ui->solareclipselocalTreeWidget);
treeItem->setText(SolarEclipseLocalDate, QString("%1").arg(localeMgr->getPrintableDateLocal(JDmax, core->getUTCOffset(JDmax)))); // local date
treeItem->setData(SolarEclipseLocalDate, Qt::UserRole, JDmax);
treeItem->setText(SolarEclipseLocalType, eclipseTypeStr);
treeItem->setText(SolarEclipseLocalFirstContact, QString("%1").arg(localeMgr->getPrintableTimeLocal(JD1, core->getUTCOffset(JD1))));
if (centraleclipse && JD2<JD1) // central eclipse in progress at Sunrise
treeItem->setText(SolarEclipseLocalFirstContact, dash);
treeItem->setToolTip(SolarEclipseLocalFirstContact, q_("The time of first contact"));

if (centraleclipse)
treeItem->setText(SolarEclipseLocal2ndContact, QString("%1").arg(localeMgr->getPrintableTimeLocal(JD2, core->getUTCOffset(JD2))));
else
treeItem->setText(SolarEclipseLocal2ndContact, dash);
treeItem->setToolTip(SolarEclipseLocal2ndContact, q_("The time of second contact"));
treeItem->setText(SolarEclipseLocalMaximum, QString("%1").arg(localeMgr->getPrintableTimeLocal(JDmax, core->getUTCOffset(JDmax))));
treeItem->setToolTip(SolarEclipseLocalMaximum, q_("The time of greatest eclipse"));
treeItem->setText(SolarEclipseLocalMagnitude, magStr);
if (centraleclipse)
treeItem->setText(SolarEclipseLocal3rdContact, QString("%1").arg(localeMgr->getPrintableTimeLocal(JD3, core->getUTCOffset(JD3))));
else
treeItem->setText(SolarEclipseLocal3rdContact, dash);
treeItem->setToolTip(SolarEclipseLocal3rdContact, q_("The time of third contact"));
treeItem->setText(SolarEclipseLocalLastContact, QString("%1").arg(localeMgr->getPrintableTimeLocal(JD4, core->getUTCOffset(JD4))));
if (centraleclipse && JD3>JD4) // central eclipse in progress at Sunset
treeItem->setText(SolarEclipseLocalLastContact, dash);
treeItem->setToolTip(SolarEclipseLocalLastContact, q_("The time of fourth contact"));
if (centraleclipse)
treeItem->setText(SolarEclipseLocalDuration, durationStr);
else
treeItem->setText(SolarEclipseLocalDuration, dash);
treeItem->setToolTip(SolarEclipseLocalDuration, q_("Duration of total or annular eclipse"));
for (auto column: {SolarEclipseLocalDate, SolarEclipseLocalMagnitude, SolarEclipseLocalFirstContact, SolarEclipseLocal2ndContact,
SolarEclipseLocalMaximum, SolarEclipseLocal3rdContact, SolarEclipseLocalLastContact, SolarEclipseLocalDuration})
treeItem->setTextAlignment(column, Qt::AlignRight);
}
}
}
Expand Down Expand Up @@ -7194,6 +7226,20 @@ void AstroCalcDialog::changeEclipsesTab(int index)
{3, q_("Transits of Mercury and Venus across the Sun")}
};
ui->eclipseHeaderLabel->setText(headermap.value(index, q_("Table of solar eclipses")));
switch(index)
{
case 0: // Solar eclipses
ui->seFilterWidget->setVisible(true);
ui->seFilterHybrid->setVisible(true);
break;
case 1: // Local solar eclipses
ui->seFilterWidget->setVisible(true);
ui->seFilterHybrid->setVisible(false);
break;
default:
ui->seFilterWidget->setVisible(false);
break;
}
}

void AstroCalcDialog::updateTabBarListWidgetWidth()
Expand Down
Loading

0 comments on commit b51cbe8

Please sign in to comment.