Skip to content

Commit

Permalink
Fixed displaying the proper motion data (fix Stellarium#1787)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-w committed Sep 7, 2021
1 parent 6cdfd4d commit 7d34689
Show file tree
Hide file tree
Showing 4 changed files with 118,048 additions and 5 deletions.
74 changes: 74 additions & 0 deletions src/core/modules/StarMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ QMap<int, int> StarMgr::hdStarsIndex;
QMap<int, int> StarMgr::hrStarsIndex;
QHash<int, QString> StarMgr::referenceMap;
QHash<int, float> StarMgr::hipParallaxErrors;
QHash<int, PMData> StarMgr::hipPMData;

QStringList initStringListFromFile(const QString& file_name)
{
Expand Down Expand Up @@ -360,6 +361,14 @@ float StarMgr::getPlxError(int hip)
return 0.f;
}

PMData StarMgr::getProperMotion(int hip)
{
auto it = hipPMData.find(hip);
if (it!=hipPMData.end())
return it.value();
return QPair<float, float>(NAN, NAN);
}

void StarMgr::copyDefaultConfigFile()
{
try
Expand Down Expand Up @@ -1143,6 +1152,65 @@ void StarMgr::loadPlxErr(const QString& plxErrFile)
qDebug() << "Loaded" << readOk << "/" << totalRecords << "parallax error data records for stars";
}

void StarMgr::loadPMData(const QString &pmDataFile)
{
// TODO: This is temporary solution for display parallax errors until format of stars catalogs will not be changed!
hipPMData.clear();

qDebug() << "Loading proper motion data from" << QDir::toNativeSeparators(pmDataFile);
QFile ciFile(pmDataFile);
if (!ciFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
qWarning() << "WARNING - could not open" << QDir::toNativeSeparators(pmDataFile);
return;
}
const QStringList& allRecords = QString::fromUtf8(ciFile.readAll()).split('\n');
ciFile.close();

int readOk=0;
int totalRecords=0;
int lineNumber=0;
// record structure is delimited with a 'tab' character. Example record strings:
// "1 -4.58 -1.61"
// "2 179.70 1.40"
for (const auto& record : allRecords)
{
++lineNumber;
// skip comments and empty lines
if (record.startsWith("//") || record.startsWith("#") || record.isEmpty())
continue;

++totalRecords;
const QStringList& fields = record.split('\t');
if (fields.size()!=3)
{
qWarning() << "WARNING - parse error at line" << lineNumber << "in" << QDir::toNativeSeparators(pmDataFile)
<< " - record does not match record pattern";
continue;
}
else
{
// The record is the right format. Extract the fields
bool ok;
int hip = fields.at(0).toInt(&ok);
if (!ok)
{
qWarning() << "WARNING - parse error at line" << lineNumber << "in" << QDir::toNativeSeparators(pmDataFile)
<< " - failed to convert " << fields.at(0) << "to a number";
continue;
}
PMData properMotion;
properMotion.first = fields.at(1).toFloat(&ok);
properMotion.second = fields.at(2).toFloat(&ok);
hipPMData[hip] = properMotion;

++readOk;
}
}

qDebug() << "Loaded" << readOk << "/" << totalRecords << "proper motion data records for stars";
}

int StarMgr::getMaxSearchLevel() const
{
int rval = -1;
Expand Down Expand Up @@ -1806,6 +1874,12 @@ void StarMgr::populateStarsDesignations()
qWarning() << "WARNING: could not load parallax errors data file: stars/default/hip_plx_err.dat";
else
loadPlxErr(fic);

fic = StelFileMgr::findFile("stars/default/hip_pm.dat");
if (fic.isEmpty())
qWarning() << "WARNING: could not load proper motion data file: stars/default/hip_pm.dat";
else
loadPMData(fic);
}

QStringList StarMgr::listAllObjects(bool inEnglish) const
Expand Down
11 changes: 11 additions & 0 deletions src/core/modules/StarMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ typedef struct
} crossid;

typedef QMap<StelObjectP, float> StelACStarData;
typedef QPair<float, float> PMData;

//! @class StarMgr
//! Stores the star catalogue data.
Expand Down Expand Up @@ -340,6 +341,11 @@ public slots:
//! @return the parallax error (mas)
static float getPlxError(int hip);

//! Get the proper motion data for star with a Hipparcos catalogue number.
//! @param hip The Hipparcos number of star
//! @return the proper motion (mas/yr for RA and Dec)
static PMData getProperMotion(int hip);

static QString convertToSpectralType(int index);
static QString convertToComponentIds(int index);

Expand Down Expand Up @@ -412,6 +418,10 @@ private slots:
//! @param the path to a file containing the parallax error data.
void loadPlxErr(const QString& plxErrFile);

//! Loads proper motion data from a file.
//! @param the path to a file containing the proper motion data.
void loadPMData(const QString& pmDataFile);

//! Gets the maximum search level.
// TODO: add a non-lame description - what is the purpose of the max search level?
int getMaxSearchLevel() const;
Expand Down Expand Up @@ -482,6 +492,7 @@ private slots:
static QMap<int, int> hrStarsIndex;

static QHash<int, float> hipParallaxErrors;
static QHash<int, PMData> hipPMData;

static QHash<int, QString> referenceMap;

Expand Down
11 changes: 6 additions & 5 deletions src/core/modules/StarWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ QString StarWrapper1::getInfoString(const StelCore *core, const InfoStringGroup&
const double vPeriod = StarMgr::getGcvsPeriod(s->getHip());
const int vMm = StarMgr::getGcvsMM(s->getHip());
const float plxErr = StarMgr::getPlxError(s->getHip());
const PMData properMotion = StarMgr::getProperMotion(s->getHip());
if (s->getHip())
{
if ((flags&Name) || (flags&CatalogNumber))
Expand Down Expand Up @@ -316,17 +317,17 @@ QString StarWrapper1::getInfoString(const StelCore *core, const InfoStringGroup&
oss << getExtraInfoStrings(Distance).join("");
}

if (flags&ProperMotion)
if (flags&ProperMotion && (!isNan(properMotion.first) && !isNan(properMotion.second)))
{
float dx = 0.1f*s->getDx0();
float dy = 0.1f*s->getDx1();
float dx = properMotion.first;
float dy = properMotion.second;
float pa = std::atan2(dx, dy)*M_180_PIf;
if (pa<0)
pa += 360.f;
oss << QString("%1: %2 %3 %4 %5%6").arg(q_("Proper motion"))
.arg(QString::number(std::sqrt(dx*dx + dy*dy), 'f', 1)).arg(qc_("mas/yr", "milliarc second per year"))
.arg(QString::number(std::sqrt(dx*dx + dy*dy), 'f', 2)).arg(qc_("mas/yr", "milliarc second per year"))
.arg(qc_("towards", "into the direction of")).arg(QString::number(pa, 'f', 1)).arg(QChar(0x00B0)) << "<br />";
oss << QString("%1: %2 %3 (%4)").arg(q_("Proper motions by axes")).arg(QString::number(dx, 'f', 1)).arg(QString::number(dy, 'f', 1)).arg(qc_("mas/yr", "milliarc second per year")) << "<br />";
oss << QString("%1: %2 %3 (%4)").arg(q_("Proper motions by axes")).arg(QString::number(dx, 'f', 2)).arg(QString::number(dy, 'f', 2)).arg(qc_("mas/yr", "milliarc second per year")) << "<br />";
}

if (flags&Extra)
Expand Down
Loading

0 comments on commit 7d34689

Please sign in to comment.