Skip to content

Commit

Permalink
use StarID for getGaia and getHip too
Browse files Browse the repository at this point in the history
  • Loading branch information
henrysky committed Jan 13, 2025
1 parent cbe54bf commit 914b424
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/core/modules/Asterism.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ bool Asterism::read(const QString& record, StarMgr *starMgr)
}
else
{
asterism[i]=starMgr->searchGaia(static_cast<int64_t>(HP));
asterism[i]=starMgr->searchGaia(HP);
}

if (!asterism[i])
Expand Down
2 changes: 1 addition & 1 deletion src/core/modules/Constellation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool Constellation::read(const QString& record, StarMgr *starMgr)
}
else
{
constellation[i]=starMgr->searchGaia(static_cast<int64_t>(HP));
constellation[i]=starMgr->searchGaia(HP);
}

if (!constellation[i])
Expand Down
6 changes: 3 additions & 3 deletions src/core/modules/Star.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ QString Star1::getNameI18n(void) const
StarId star_id;
if (getHip())
{
star_id = static_cast<StarId>(getHip());
star_id = getHip();
}
else
{
Expand All @@ -52,7 +52,7 @@ QString Star1::getScreenNameI18n(void) const
QStringList starNames;
StarId star_id;
if (getHip())
star_id = static_cast<StarId>(getHip());
star_id = getHip();
else
star_id = getGaia();
if (!StarMgr::getDesignationUsage())
Expand All @@ -79,7 +79,7 @@ QString Star1::getDesignation() const
QStringList starNames;
StarId star_id;
if (getHip())
star_id = static_cast<StarId>(getHip());
star_id = getHip();
else
star_id = getGaia();
starNames << StarMgr::getSciName(star_id).split(" - ");
Expand Down
13 changes: 7 additions & 6 deletions src/core/modules/Star.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "StelObjectType.hpp"
#include "StelUtils.hpp"
#include "StarMgr.hpp"
#include "ZoneData.hpp"
#include <QString>
#include <QtEndian>
Expand Down Expand Up @@ -92,7 +93,7 @@ struct Star
// VIP flag is for situation where it can bypass some check (e.g., magnitude display cutoff for Star1 in far
// past/future)
inline bool isVIP() const { return static_cast<const Derived *>(this)->isVIP(); }
inline int64_t getGaia() const { return static_cast<const Derived *>(this)->getGaia(); }
inline StarId getGaia() const { return static_cast<const Derived *>(this)->getGaia(); }
inline bool hasName() const { return static_cast<const Derived *>(this)->hasName(); }
inline QString getNameI18n() const { return static_cast<const Derived *>(this)->getNameI18n(); }
inline QString getScreenNameI18n() const { return static_cast<const Derived *>(this)->getScreenNameI18n(); }
Expand Down Expand Up @@ -287,16 +288,16 @@ struct Star1 : public Star<Star1>
// no point of doing proper propagation if any of them is missing
return (getPlx() || getPlxErr()) && (getPlx() / getPlxErr() > 5) && (getDx0() || getDx1() || getDx2()) && getRV();
}
inline int getHip() const
inline StarId getHip() const
{
// Combine the 3 bytes into a 24-bit integer (little-endian)
quint32 combined_value = d.hip[0] | d.hip[1] << 8 | d.hip[2] << 16;
// Extract the 17-bit ID (shift right by 5 bits)
qint32 hip_id = combined_value >> 5;
quint64 hip_id = combined_value >> 5;
return hip_id;
}

inline int64_t getGaia() const { return d.gaia_id; }
inline StarId getGaia() const { return d.gaia_id; }
inline int getComponentIds() const
{
// Combine the 3 bytes into a 24-bit integer (little-endian)
Expand Down Expand Up @@ -345,7 +346,7 @@ struct Star2 : public Star<Star2>
return sqrt((getDx0() * cos(getX1()) * getDx0() * cos(getX1())) + (getDx1() * getDx1()));
}
StelObjectP createStelObject(const SpecialZoneArray<Star2> * a, const SpecialZoneData<Star2> * z) const;
int64_t getGaia() const { return d.gaia_id; }
StarId getGaia() const { return d.gaia_id; }
float getBV(void) const { return static_cast<float>(d.b_v) / 1000.f; }
QString getNameI18n(void) const { return QString(); }
QString getScreenNameI18n(void) const { return QString(); }
Expand Down Expand Up @@ -398,7 +399,7 @@ struct Star3 : public Star<Star3>
double getRV() const { return 0.; }
double getBV() const { return (0.025 * d.b_v) - 1.; } // in mag
double getMag() const { return d.vmag * 20 + 16000; } // in milli-mag
int64_t getGaia() const { return d.gaia_id; }
StarId getGaia() const { return d.gaia_id; }
QString getNameI18n() const { return QString(); }
QString getScreenNameI18n() const { return QString(); }
QString getDesignation() const { return QString(); }
Expand Down
2 changes: 1 addition & 1 deletion src/core/modules/StarMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ StelObjectP StarMgr::searchHP(int hp) const
}

// Search the star by Gaia source_id
StelObjectP StarMgr::searchGaia(int64_t source_id) const
StelObjectP StarMgr::searchGaia(StarId source_id) const
{
int maxSearchLevel = getMaxSearchLevel();
int matched = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/core/modules/StarMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public slots:
//! @param source_id the Gaia source id of the star which is required.
//! @return the requested StelObjectP or an empty objecy if the requested
//! one was not found.
StelObjectP searchGaia(int64_t source_id) const;
StelObjectP searchGaia(StarId source_id) const;

//! Get the (translated) common name for a star with a specified
//! Hipparcos or Gaia catalogue number.
Expand Down
16 changes: 8 additions & 8 deletions src/core/modules/StarWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ QString StarWrapper1::getObjectType() const
StarId star_id;
if (s->getHip())
{
star_id = static_cast<StarId>(s->getHip());
star_id = s->getHip();
}
else
{
star_id = static_cast<StarId>(s->getGaia());
star_id = s->getGaia();
}

const QString varType = StarMgr::getGcvsVariabilityType(star_id);
Expand Down Expand Up @@ -140,11 +140,11 @@ QString StarWrapper1::getObjectTypeI18n() const
StarId star_id;
if (s->getHip())
{
star_id = static_cast<StarId>(s->getHip());
star_id = s->getHip();
}
else
{
star_id = static_cast<StarId>(s->getGaia());
star_id = s->getGaia();
}
const QString varType = StarMgr::getGcvsVariabilityType(star_id);
if (!varType.isEmpty())
Expand Down Expand Up @@ -174,9 +174,9 @@ QString StarWrapper1::getInfoString(const StelCore *core, const InfoStringGroup&

StarId star_id;
if (s->getHip())
star_id = static_cast<StarId>(s->getHip());
star_id = s->getHip();
else
star_id = static_cast<StarId>(s->getGaia());
star_id = s->getGaia();

const QString varType = StarMgr::getGcvsVariabilityType(star_id);
const QString objType = StarMgr::convertToOjectTypes(s->getObjType());
Expand Down Expand Up @@ -480,11 +480,11 @@ QVariantMap StarWrapper1::getInfoMap(const StelCore *core) const
StarId star_id;
if (s->getHip())
{
star_id = static_cast<StarId>(s->getHip());
star_id = s->getHip();
}
else
{
star_id = static_cast<StarId>(s->getGaia());
star_id = s->getGaia();
}
const QString varType = StarMgr::getGcvsVariabilityType(star_id);
const int wdsObs = StarMgr::getWdsLastObservation(star_id);
Expand Down
4 changes: 2 additions & 2 deletions src/core/modules/ZoneArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ void SpecialZoneArray<Star>::searchAround(const StelCore* core, int index, const
}

template<class Star>
StelObjectP SpecialZoneArray<Star>::searchGaiaID(int index, const int64_t source_id, int &matched) const
StelObjectP SpecialZoneArray<Star>::searchGaiaID(int index, const StarId source_id, int &matched) const
{
const SpecialZoneData<Star> *const z = getZones()+index;
for (const Star* s=z->getStars();s<z->getStars()+z->size;++s)
Expand All @@ -587,7 +587,7 @@ StelObjectP SpecialZoneArray<Star>::searchGaiaID(int index, const int64_t source

template<class Star>
// this class is written for the unit test
void SpecialZoneArray<Star>::searchGaiaIDepochPos(const int64_t source_id,
void SpecialZoneArray<Star>::searchGaiaIDepochPos(const StarId source_id,
float dyrs,
double & RA,
double & DEC,
Expand Down
9 changes: 5 additions & 4 deletions src/core/modules/ZoneArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "ZoneData.hpp"
#include "Star.hpp"
#include "StarMgr.hpp"

#include "StelCore.hpp"
#include "StelSkyDrawer.hpp"
Expand Down Expand Up @@ -96,8 +97,8 @@ class ZoneArray
//! Pure virtual method. See subclass implementation.
virtual void searchAround(const StelCore* core, int index,const Vec3d &v,double cosLimFov,
QList<StelObjectP > &result) = 0;
virtual StelObjectP searchGaiaID(int index, const int64_t source_id, int& matched) const = 0;
virtual void searchGaiaIDepochPos(const int64_t source_id, float dyrs,
virtual StelObjectP searchGaiaID(int index, const StarId source_id, int& matched) const = 0;
virtual void searchGaiaIDepochPos(const StarId source_id, float dyrs,
double & RA,
double & DEC,
double & Plx,
Expand Down Expand Up @@ -186,8 +187,8 @@ class SpecialZoneArray : public ZoneArray

void searchAround(const StelCore* core, int index,const Vec3d &v,double cosLimFov,
QList<StelObjectP > &result) override;
StelObjectP searchGaiaID(int index, const int64_t source_id, int& matched) const override;
void searchGaiaIDepochPos(const int64_t source_id, float dyrs,
StelObjectP searchGaiaID(int index, const StarId source_id, int& matched) const override;
void searchGaiaIDepochPos(const StarId source_id, float dyrs,
double & RA,
double & DEC,
double & Plx,
Expand Down
9 changes: 5 additions & 4 deletions src/tests/testAstrometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "tests/testAstrometry.hpp"
#include "modules/Star.hpp"
#include "modules/StarMgr.hpp"
#include "modules/ZoneArray.hpp"
#include "StelObjectType.hpp"

Expand Down Expand Up @@ -63,7 +64,7 @@ void TestAstrometry::initTestCase()
zoneArrays.append(z);
}
}
void TestAstrometry::test6DAstrometryPropagation(int64_t gaiaID, float depoch_from_catalogs, double expectedRA, double expectedDEC, double expectedPlx, double expectedPMRA, double expectedPMDEC, double expectedRV)
void TestAstrometry::test6DAstrometryPropagation(StarId gaiaID, float depoch_from_catalogs, double expectedRA, double expectedDEC, double expectedPlx, double expectedPMRA, double expectedPMDEC, double expectedRV)
{
double RA = 0, DE = 0, Plx = 0, pmra = 0, pmdec = 0, RV = 0;
for (int i = 0; i < zoneArrays.size(); i++)
Expand All @@ -87,7 +88,7 @@ void TestAstrometry::test6DAstrometryPropagation(int64_t gaiaID, float depoch_fr

void TestAstrometry::testBarnardStar() // test the Barnard's Star
{
int64_t gaiaID = 4472832130942575872;
StarId gaiaID = 4472832130942575872;
// star catalog epoch, to make sure the parameters used to calculate the expected values with astropy are consistent with the catalog
test6DAstrometryPropagation(gaiaID, 0.f, 269.4485025254, 4.7394200511, 546.9759, -801.5510, 10362.3942, -110.1);
// +50,000 years from star catalog epoch
Expand All @@ -102,7 +103,7 @@ void TestAstrometry::testBarnardStar() // test the Barnard's Star

void TestAstrometry::testCrux() // test a random Gaia star within the Crux that has no radial velocity
{
int64_t gaiaID = 6059204728680270080;
StarId gaiaID = 6059204728680270080;
// star catalog epoch, to make sure the parameters used to calculate the expected values with astropy are consistent with the catalog
test6DAstrometryPropagation(gaiaID, 0.f, 187.43783675, -59.02388257, 1000. / 144.35847096, -2.733, -21.946, 0.);
// +50000 years from star catalog epoch
Expand All @@ -117,7 +118,7 @@ void TestAstrometry::testCrux() // test a random Gaia star within the Crux that

void TestAstrometry::testBrightNoPlx() // test a bright Gaia star without parallax but with radial velocity
{
int64_t gaiaID = 1998148532777850880;
StarId gaiaID = 1998148532777850880;
// star catalog epoch, to make sure the parameters used to calculate the expected values with astropy are consistent with the catalog
test6DAstrometryPropagation(gaiaID, 0.f, 358.59593000622834, 57.49936804016163, 0., -4.6991464250248995, -3.1120532783839017, -55.2);
// simply check the case where radial velocity can be inf/nan when there is no parallax for a star
Expand Down

0 comments on commit 914b424

Please sign in to comment.