Skip to content

Commit

Permalink
Rename rename findPlanetsPrecise to findPlanets, remove old findPlane…
Browse files Browse the repository at this point in the history
…ts method, new FindPlanet argument
  • Loading branch information
AlexanderJCS committed Oct 26, 2022
1 parent c383c10 commit 033fce8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 94 deletions.
3 changes: 2 additions & 1 deletion docs/find_planet_class.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ To create the FindPlanet class, we need to pass in the six required input variab
- `float sizeThreshold`: The range that the flux can vary and be considered the same planet
- `float maxTransitDurationDays`: The maximum amount of time, in days, that the transit can take. **It is recommended this value is under the minimum orbital period expected, but as close to 1.0 as possible.**
- `float TTVRange`: The amount of variation the period of a planet can have, in days, to be considered the same planet. The recommended value for this is around 0.5.
- `int allowedMissedTransits = 2`: optional parameter which defaults to 2. This is the number of transits that cna be missed and still be counted as an exoplanet. This is made to reduce false positives in noisy data. Unless you have a specific reasion, it is recommended to keep this at 2.
- `int allowedMissedTransits = 2`: parameter which defaults to 2 unless otherwise specified. This is the number of transits that cna be missed and still be counted as an exoplanet. This is made to reduce false positives in noisy data. Unless you have a specific reasion, it is recommended to keep this at 2.
- `float minimumConfidence = 0.4`: parameter which defaults ot 0.4 unless otherwise specified. This is the minimum confidence the program can have in an exoplanet and still include it in the final list of planets.

Using this information, we can create the planet class:

Expand Down
66 changes: 7 additions & 59 deletions include/exoSpotter/exoSpotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,34 +239,7 @@ std::vector<ExoSpotter::Lightcurve> ExoSpotter::FindPlanet::splitDatapoints(Ligh


/*
Returns -1 if a planet is not found. Otherwise returns the Julian date of the first transit.
WARNING: This algorithm may give a false negative when two planets are in the same dataset.
This would happen if two planets are similar size, it wouldn't get
picked up by the grouping algorithm.
*/
std::optional<ExoSpotter::Exoplanet> ExoSpotter::FindPlanet::planetInData(Lightcurve data)
{
if (data.size() < 3) {
return { }; // not enough datapoints
}

for (int i = 0; i < data.size() - 2; i++) {
float transitTime1 = data.date()[i + 1] - data.date()[i];
float transitTime2 = data.date()[i + 2] - data.date()[i + 1];

if (abs(transitTime2 - transitTime1) < TTVRange) {
return Exoplanet{ data.slice(i, i + 2), 1};
}
}

return {};
}


/*
This method is to provide a more sophisticated algorithm which counteracts the
warning in the planetInData method, at the cost of time.
Returns a vector of all detected planets in a dataset splitted, grouped.
*/
std::vector<ExoSpotter::Exoplanet> ExoSpotter::FindPlanet::planetInDataPrecise(Lightcurve data)
{
Expand Down Expand Up @@ -317,7 +290,8 @@ std::vector<ExoSpotter::Exoplanet> ExoSpotter::FindPlanet::planetInDataPrecise(L

// If more than allowedMissedTransits were missed, exclude this planet. This is to
// prevent noise data from being considered a real planet.
if ((data.date()[i] - data.date()[0]) / candidate.averagePeriod < allowedMissedTransits) {
if ((data.date()[i] - data.date()[0]) / candidate.averagePeriod < allowedMissedTransits &&
candidate.confidence >= minimumConfidence) {
bool broken = false;

for (Exoplanet exoplanet : detectedExoplanets) {
Expand Down Expand Up @@ -379,38 +353,10 @@ void ExoSpotter::FindPlanet::printVerbose(
}


/*
Calls other methods necessary to find planets
*/
std::vector<ExoSpotter::Exoplanet> ExoSpotter::FindPlanet::findPlanets(bool verbose)
{
auto candidates = findPlanetCandidates();
auto grouped = groupDatapoints(candidates);
auto splitted = splitDatapoints(grouped);

std::vector<Exoplanet> planets;

for (auto& group : splitted) {
std::optional<Exoplanet> planetInfo = planetInData(group);

if (planetInfo) {
planets.push_back(planetInfo.value());
}
}

// Print additional info if verbose is enabled, mainly used for debugging
if (verbose) {
printVerbose(candidates, grouped, splitted, planets);
}

return planets;
}


/*
Uses a different algorithm to find more exoplanets at the expense of time
*/
std::vector<ExoSpotter::Exoplanet> ExoSpotter::FindPlanet::findPlanetsPrecise(bool verbose)
std::vector<ExoSpotter::Exoplanet> ExoSpotter::FindPlanet::findPlanets(bool verbose)
{
auto candidates = findPlanetCandidates();
auto grouped = groupDatapoints(candidates);
Expand Down Expand Up @@ -445,7 +391,8 @@ maxTransitDurationDays: Used for grouping data. The amount of time, in days, tha
TTVRange: The amount of variation the period of a planet can have, in days, to be considered the same planet.
*/
ExoSpotter::FindPlanet::FindPlanet(Lightcurve data, float planetThreshold,
float sizeThreshold, float maxTransitDurationDays, float TTVRange, int allowedMissedTransits)
float sizeThreshold, float maxTransitDurationDays, float TTVRange, float minimumConfidence,
int allowedMissedTransits)
{
this->rawData = data;

Expand All @@ -454,4 +401,5 @@ ExoSpotter::FindPlanet::FindPlanet(Lightcurve data, float planetThreshold,
this->maxTransitDurationDays = maxTransitDurationDays;
this->TTVRange = TTVRange;
this->allowedMissedTransits = allowedMissedTransits;
this->minimumConfidence = minimumConfidence;
}
18 changes: 3 additions & 15 deletions include/exoSpotter/exoSpotter.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace ExoSpotter
float maxTransitDurationDays;
float TTVRange;
int allowedMissedTransits;
float minimumConfidence;

int findClosestIndex(Lightcurve data, int startIndex, float targetDate);

Expand All @@ -81,15 +82,6 @@ namespace ExoSpotter
*/
std::vector<Lightcurve> splitDatapoints(Lightcurve data);

/*
Returns a planet struct of the planet identified.
WARNING: This algorithm may give a false negative when two planets are in the same dataset.
This would happen if two planets are similar size, it wouldn't get
picked up by the grouping algorithm.
*/
std::optional<Exoplanet> planetInData(Lightcurve data);

/*
Returns a vector of all the planets found.
Expand All @@ -102,15 +94,11 @@ namespace ExoSpotter
Lightcurve candidates, Lightcurve grouped, std::vector<Lightcurve> splitted, std::vector<Exoplanet> planets);

public:
/*
Calls other methods necessary to find planets
*/
std::vector<Exoplanet> findPlanets(bool verbose);

/*
Uses a different algorithm to find more exoplanets at the expense of time
*/
std::vector<Exoplanet> findPlanetsPrecise(bool verbose = false);
std::vector<Exoplanet> findPlanets(bool verbose = false);

/*
data: The data from the observed star's brightness. It will have two key values of "flux" and "date".
Expand All @@ -125,6 +113,6 @@ namespace ExoSpotter
TTVRange: The amount of variation the period of a planet can have, in days, to be considered the same planet.
*/
FindPlanet(Lightcurve data, float planetThreshold, float sizeThreshold,
float maxTransitDurationDays, float TTVRange, int allowedMissedTransits = 2);
float maxTransitDurationDays, float TTVRange, float minimumConfidence = 0.4, int allowedMissedTransits = 2);
};
}
22 changes: 3 additions & 19 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,19 @@ using namespace std::chrono;
int main()
{
ExoSpotter::FindPlanet planetFinder{
readData("test/data.csv"), 0.9999, 0.005, 1.5, 0.1, 2
readData("test/wasp-126_data.csv"), 0.9999, 0.005, 1.5, 0.1, 0.5, 2
};

auto start = high_resolution_clock::now();
auto planets = planetFinder.findPlanets(false);
auto stop = high_resolution_clock::now();

std::cout << "*** FAST ALGORITHM ***\n";

for (int i = 0; i < planets.size(); i++) {
std::cout << "Planet " << i + 1 << ":\n" << planets[i];
std::cout << "Radius percent: " << planets[i].findRadiusRatio() * 100 << "%\n\n";
}

auto duration = duration_cast<microseconds>(stop - start);
std::cout << "\nCompleted in " << duration.count() << " microseconds\n";

start = high_resolution_clock::now();
planets = planetFinder.findPlanetsPrecise(false);
stop = high_resolution_clock::now();

std::cout << "\n*** PRECISE ALGORITHM ***\n";


for (int i = 0; i < planets.size(); i++) {
std::cout << "Planet " << i + 1 << ":\n" << planets[i];
std::cout << "Radius percent: " << planets[i].findRadiusRatio() * 100 << "%\n";
std::cout << "Confidence: " << planets[i].confidence * 100 << "%\n\n";
}

duration = duration_cast<microseconds>(stop - start);
auto duration = duration_cast<microseconds>(stop - start);
std::cout << "\nCompleted in " << duration.count() << " microseconds\n";
}

0 comments on commit 033fce8

Please sign in to comment.