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 b1d117f
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 76 deletions.
172 changes: 96 additions & 76 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
72 changes: 72 additions & 0 deletions src/gui/astroCalcDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2987,6 +2987,78 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_27">
<item row="0" column="0">
<widget class="QCheckBox" name="seFilterTotal">
<property name="toolTip">
<string>Include total eclipses</string>
</property>
<property name="text">
<string extracomment="This is a filter checkbox meaning &quot;include total solar eclipses&quot;, so the adjective should be in plural (if applicable)">Total</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="seFilterPartial">
<property name="toolTip">
<string>Include partial eclipses</string>
</property>
<property name="text">
<string extracomment="This is a filter checkbox meaning &quot;include partial solar eclipses&quot;, so the adjective should be in plural (if applicable)">Partial</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="seFilterAnnular">
<property name="toolTip">
<string>Include annular eclipses</string>
</property>
<property name="text">
<string extracomment="This is a filter checkbox meaning &quot;include annular solar eclipses&quot;, so the adjective should be in plural (if applicable)">Annular</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="seFilterHybrid">
<property name="toolTip">
<string>Include hybrid eclipses</string>
</property>
<property name="text">
<string extracomment="This is a filter checkbox meaning &quot;include hybrid solar eclipses&quot;, so the adjective should be in plural (if applicable)">Hybrid</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
Expand Down

0 comments on commit b1d117f

Please sign in to comment.