Add task for reading the new exoplanet data in csv format

Also cleanup old exoplanet code a bit based on that new data
This commit is contained in:
Emma Broman
2020-10-05 08:56:34 +02:00
parent 3310d954b3
commit 250dbcc3f1
8 changed files with 518 additions and 125 deletions
+2
View File
@@ -29,6 +29,7 @@ set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableorbitdisc.h
${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetscsvtobintask.h
${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetsdatapreparationtask.h
)
source_group("Header Files" FILES ${HEADER_FILES})
@@ -38,6 +39,7 @@ set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule_lua.inl
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableorbitdisc.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetscsvtobintask.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetsdatapreparationtask.cpp
)
source_group("Source Files" FILES ${SOURCE_FILES})
+12 -68
View File
@@ -29,98 +29,42 @@
namespace openspace::exoplanets {
std::string_view speckStarName(std::string_view csvName) {
if (csvName == "HD 1237") { return "GJ 3021"; }
if (csvName == "MOA-2009-BLG-387L") { return "MOA 2009-BLG-387L"; }
if (csvName == "HD 126614 A") { return "HD 126614"; }
if (csvName == "epsilon Ret") { return "HD 27442"; }
if (csvName == "PH-1") { return "PH1"; }
if (csvName == "gamma Leo A") { return "gam 1 Leo"; }
if (csvName == "OGLE-2007-BLG-368L") { return "OGLE 2007-BLG-368L"; }
if (csvName == "alpha Ari") { return "alf Ari"; }
if (csvName == "mu Ara") { return "HD 160691"; }
if (csvName == "OGLE-05-169L") { return "OGLE 2005-BLG-169L"; }
if (csvName == "tau Gru") { return "HD 216435"; }
if (csvName == "iota Hor") { return "HR 810"; }
if (csvName == "OGLE-05-071L") { return "OGLE 2005-BLG-71L"; }
if (csvName == "OGLE235-MOA53") { return "OGLE 2003-BLG-235L"; }
if (csvName == "OGLE-2005-BLG-169L") { return "OGLE 2005-BLG-169L"; }
if (csvName == "OGLE-2005-BLG-071L") { return "OGLE 2005-BLG-71L"; }
if (csvName == "OGLE-2003-BLG-235L") { return "OGLE 2003-BLG-235L"; }
if (csvName == "MOA-2008-BLG-310L") { return "MOA 2008-BLG-310L"; }
if (csvName == "KIC 11442793") { return "KOI-351"; }
if (csvName == "OGLE-2006-BLG-109L") { return "OGLE 2006-BLG-109L"; }
if (csvName == "HD 137388") { return "HD 137388 A"; }
if (csvName == "kappa CrB") { return "kap CrB"; }
if (csvName == "XO-2") { return "XO-2 N"; }
if (csvName == "epsilon Tau") { return "eps Tau"; }
if (csvName == "epsilon Eri") { return "eps Eri"; }
if (csvName == "Kepler-448") { return "KOI-12"; }
if (csvName == "omega Ser") { return "ome Ser"; }
if (csvName == "MOA-2010-BLG-477L") { return "MOA 2010-BLG-477L"; }
if (csvName == "GJ 176") { return "HD 285968"; }
if (csvName == "HIP 2247") { return "BD-17 63"; }
if (csvName == "MOA-2009-BLG-266L") { return "MOA 2009-BLG-266L"; }
if (csvName == "Kepler-89") { return "KOI-94"; }
if (csvName == "iota Dra") { return "HIP 75458"; }
if (csvName == "iot Dra") { return "HIP 75458"; }
if (csvName == "MOA-2007-BLG-400L") { return "MOA 2007-BLG-400L"; }
if (csvName == "upsilon And") { return "ups And"; }
if (csvName == "OGLE-2011-BLG-0251") { return "OGLE 2011-BLG-251L"; }
if (csvName == "OGLE-05-390L") { return "OGLE 2005-BLG-390L"; }
if (csvName == "Kepler-420") { return "KOI-1257"; }
if (csvName == "beta Pic") { return "bet Pic"; }
if (csvName == "gamma Cep") { return "gam Cep"; }
if (csvName == "OGLE-2011-BLG-0251L") { return "OGLE 2011-BLG-251L"; }
if (csvName == "OGLE-2005-BLG-390L") { return "OGLE 2005-BLG-390L"; }
if (csvName == "MOA-2007-BLG-192L") { return "MOA 2007-BLG-192L"; }
if (csvName == "MOA-2009-BLG-319L") { return "MOA 2009-BLG-319L"; }
if (csvName == "omicron CrB") { return "omi CrB"; }
if (csvName == "beta Gem") { return "HD 62509"; }
if (csvName == "epsilon CrB") { return "eps CrB"; }
if (csvName == "omicron UMa") { return "omi UMa"; }
if (csvName == "HD 142022") { return "HD 142022 A"; }
return csvName;
}
std::string_view csvStarName(std::string_view name) {
if (name == "GJ 3021") { return "HD 1237"; }
if (name == "MOA 2009-BLG-387L") { return "MOA-2009-BLG-387L"; }
if (name == "HD 126614") { return "HD 126614 A"; }
if (name == "HD 27442") { return "epsilon Ret"; }
if (name == "PH1") { return "PH-1"; }
if (name == "gam 1 Leo") { return "gamma Leo A"; }
if (name == "OGLE 2007-BLG-368L") { return "OGLE-2007-BLG-368L"; }
if (name == "alf Ari") { return "alpha Ari"; }
if (name == "HD 160691") { return "mu Ara"; }
if (name == "OGLE 2005-BLG-169L") { return "OGLE-05-169L"; }
if (name == "HD 216435") { return "tau Gru"; }
if (name == "HR 810") { return "iota Hor"; }
if (name == "OGLE 2005-BLG-71L") { return "OGLE-05-071L"; }
if (name == "OGLE 2003-BLG-235L") { return "OGLE235-MOA53"; }
if (name == "OGLE 2005-BLG-169L") { return "OGLE-2005-BLG-169L"; }
if (name == "OGLE 2005-BLG-71L") { return "OGLE-2005-BLG-071L"; }
if (name == "OGLE 2003-BLG-235L") { return "OGLE-2003-BLG-235L"; }
if (name == "MOA 2008-BLG-310L") { return "MOA-2008-BLG-310L"; }
if (name == "KOI-351") { return "KIC 11442793"; }
if (name == "OGLE 2006-BLG-109L") { return "OGLE-2006-BLG-109L"; }
if (name == "HD 137388 A") { return "HD 137388"; }
if (name == "kap CrB") { return "kappa CrB"; }
if (name == "XO-2 N") { return "XO-2"; }
if (name == "eps Tau") { return "epsilon Tau"; }
if (name == "eps Eri") { return "epsilon Eri"; }
if (name == "KOI-12") { return "Kepler-448"; }
if (name == "ome Ser") { return "omega Ser"; }
if (name == "MOA 2010-BLG-477L") { return "MOA-2010-BLG-477L"; }
if (name == "HD 285968") { return "GJ 176"; }
if (name == "BD-17 63") { return "HIP 2247"; }
if (name == "MOA 2009-BLG-266L") { return "MOA-2009-BLG-266L"; }
if (name == "KOI-94") { return "Kepler-89"; }
if (name == "HIP 75458") { return "iota Dra"; }
if (name == "HIP 75458") { return "iot Dra"; }
if (name == "MOA 2007-BLG-400L") { return "MOA-2007-BLG-400L"; }
if (name == "ups And") { return "upsilon And"; }
if (name == "OGLE 2011-BLG-251L") { return "OGLE-2011-BLG-0251"; }
if (name == "OGLE 2005-BLG-390L") { return "OGLE-05-390L"; }
if (name == "KOI-1257") { return "Kepler-420"; }
if (name == "bet Pic") { return "beta Pic"; }
if (name == "gam Cep") { return "gamma Cep"; }
if (name == "OGLE 2011-BLG-251L") { return "OGLE-2011-BLG-0251L"; }
if (name == "OGLE 2005-BLG-390L") { return "OGLE-2005-BLG-390L"; }
if (name == "MOA 2007-BLG-192L") { return "MOA-2007-BLG-192L"; }
if (name == "MOA 2009-BLG-319L") { return "MOA-2009-BLG-319L"; }
if (name == "omi CrB") { return "omicron CrB"; }
if (name == "HD 62509") { return "beta Gem"; }
if (name == "eps CrB") { return "epsilon CrB"; }
if (name == "omi UMa") { return "omicron UMa"; }
if (name == "HD 142022 A") { return "HD 142022"; }
return name;
}
+6 -15
View File
@@ -33,42 +33,33 @@ struct Exoplanet {
float a; // Orbital semi-major axis in AU
double aUpper; // Upper uncertainty of orbital semi-major axis
double aLower; // Lower uncertainty of orbital semi-major axis
double ua; // Uncertainty of orbital semi-major axis
float bigOm; // Longitude of ascending node in degrees
float bigOmUpper; // Upper uncertainty of longitude of ascending node
float bigOmLower; // Lower uncertainty of longitude of ascending node
float uBigOm; // Uncertainty of longitude of ascending node
float bigOmega; // Longitude of ascending node in degrees
float bigOmegaUpper;// Upper uncertainty of longitude of ascending node
float bigOmegaLower;// Lower uncertainty of longitude of ascending node
bool binary; // Star known to be binary?
float bmv; // B V color
float ecc; // Orbital eccentricity
float eccUpper; // Upper uncertainty of orbital eccentricity
float eccLower; // Lower uncertainty of orbital eccentricity
float uEcc; // Uncertainty of orbital eccentricity
float i; // Orbital inclination in degrees (for transiting systems only)
float iUpper; // Upper uncertainty of orbital inclination
float iLower; // Lower uncertainty of orbital inclination
float ui; // Uncertainty of orbital inclination
int nComp; // Number of planetary companions known
float om; // Argument of periastron in degrees
float omUpper; // Upper uncertainty of argument of periastron
float omLower; // Lower uncertainty of argument of periastron
float uOm; // Uncertainty of argument of periastron
float omega; // Argument of periastron in degrees
float omegaUpper; // Upper uncertainty of argument of periastron
float omegaLower; // Lower uncertainty of argument of periastron
double per; // Orbital period in days
float perUpper; // Upper uncertainty of period
float perLower; // Lower uncertainty of period
float uPer; // Uncertainty of period
double r; // Radius of the planet in Jupiter radii
double rUpper; // Upper uncertainty of radius of the planet
double rLower; // Lower uncertainty of radius of the planet
double ur; // Uncertainty of radius of the planet
float rStar; // Estimated radius of the star in solar radii
float rStarUpper; // Upper uncertainty of estimated star radius
float rStarLower; // Lower uncertainty of estimated star radius
float urStar; // Uncertainty of estimated star radius
double tt; // Epoch of transit center in HJD-2440000
float ttUpper; // Upper uncertainty of epoch of transit center
float ttLower; // Lower uncertainty of epoch of transit center
float uTt; // Uncertainty of epoch of transit center
float positionX; // Star position's X-coordinate in parsec
float positionY; // Star position's Y-coordinate in parsec
float positionZ; // Star position's Z-coordinate in parsec
+4 -1
View File
@@ -26,6 +26,7 @@
#include <modules/exoplanets/rendering/renderableorbitdisc.h>
#include <modules/exoplanets/tasks/exoplanetscsvtobintask.h>
#include <modules/exoplanets/tasks/exoplanetsdatapreparationtask.h>
#include <openspace/engine/globals.h>
#include <openspace/engine/globalscallbacks.h>
#include <openspace/interaction/navigationhandler.h>
@@ -81,12 +82,14 @@ void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) {
auto fRenderable = FactoryManager::ref().factory<Renderable>();
ghoul_assert(fTask, "No task factory existed");
fTask->registerClass<ExoplanetsCsvToBinTask>("ExoplanetsCsvToBinTask");
fTask->registerClass<ExoplanetsDataPreparationTask>("ExoplanetsDataPreparationTask");
fRenderable->registerClass<RenderableOrbitDisc>("RenderableOrbitDisc");
}
std::vector<documentation::Documentation> ExoplanetsModule::documentations() const {
return {
ExoplanetsCsvToBinTask::documentation()
ExoplanetsCsvToBinTask::documentation(),
ExoplanetsDataPreparationTask::documentation()
};
}
+10 -10
View File
@@ -79,7 +79,7 @@ std::string starColor(float bv, std::ifstream& colormap) {
return fmt::format("{{ {}, {}, {} }}", r, g, b);
}
glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om) {
glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float omega) {
// Exoplanet defined inclination changed to be used as Kepler defined inclination
const glm::dvec3 ascendingNodeAxisRot = glm::dvec3(0.0, 0.0, 1.0);
const glm::dvec3 inclinationAxisRot = glm::dvec3(1.0, 0.0, 0.0);
@@ -87,7 +87,7 @@ glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om) {
const double asc = glm::radians(bigom);
const double inc = glm::radians(i);
const double per = glm::radians(om);
const double per = glm::radians(omega);
const glm::dmat4 orbitPlaneRotation =
glm::rotate(asc, glm::dvec3(ascendingNodeAxisRot)) *
@@ -335,11 +335,11 @@ int addExoplanetSystem(lua_State* L) {
if (isnan(planet.i)) {
planet.i = 90.f;
}
if (isnan(planet.bigOm)) {
planet.bigOm = 180.f;
if (isnan(planet.bigOmega)) {
planet.bigOmega = 180.f;
}
if (isnan(planet.om)) {
planet.om = 90.f;
if (isnan(planet.omega)) {
planet.omega = 90.f;
}
Time epoch;
std::string sEpoch;
@@ -383,8 +383,8 @@ int addExoplanetSystem(lua_State* L) {
"Eccentricity = " + std::to_string(planet.ecc) + "," //ECC
"SemiMajorAxis = " + std::to_string(semiMajorAxisInKm) + ","
"Inclination = " + std::to_string(planet.i) + "," //I
"AscendingNode = " + std::to_string(planet.bigOm) + "," //BIGOM
"ArgumentOfPeriapsis = " + std::to_string(planet.om) + "," //OM
"AscendingNode = " + std::to_string(planet.bigOmega) + "," //BIGOM
"ArgumentOfPeriapsis = " + std::to_string(planet.omega) + "," //OM
"MeanAnomaly = 0.0,"
"Epoch = '" + sEpoch + "'," //TT. JD to YYYY MM DD hh:mm:ss
"Period = " + std::to_string(period) + ""
@@ -453,8 +453,8 @@ int addExoplanetSystem(lua_State* L) {
// Get the orbit plane of the planet trail orbit from the KeplerTranslation
const glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(
planet.i,
planet.bigOm,
planet.om
planet.bigOmega,
planet.omega
);
const glm::dmat3 rotation = orbitPlaneRotationMatrix;
@@ -140,8 +140,6 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb
p.aLower = readDoubleData(data);
getline(lineStream, data, ','); // UA
p.ua = readDoubleData(data);
getline(lineStream, data, ','); // AREF
getline(lineStream, data, ','); // AURL
getline(lineStream, data, ','); // AR
@@ -158,17 +156,15 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb
getline(lineStream, data, ','); // BREF
getline(lineStream, data, ','); // BURL
getline(lineStream, data, ','); // BIGOM
p.bigOm = readFloatData(data);
p.bigOmega = readFloatData(data);
getline(lineStream, data, ','); // BIGOMUPPER
p.bigOmUpper = readFloatData(data);
p.bigOmegaUpper = readFloatData(data);
getline(lineStream, data, ','); // BIGOMLOWER
p.bigOmLower = readFloatData(data);
p.bigOmegaLower = readFloatData(data);
getline(lineStream, data, ','); // UBIGOM
p.uBigOm = readFloatData(data);
getline(lineStream, data, ','); // BIGOMREF
getline(lineStream, data, ','); // BIGOMURL
getline(lineStream, data, ','); // BINARY
@@ -228,8 +224,6 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb
p.eccLower = readFloatData(data);
getline(lineStream, data, ','); // UECC
p.uEcc = readFloatData(data);
getline(lineStream, data, ','); // ECCREF
getline(lineStream, data, ','); // ECCURL
getline(lineStream, data, ','); // EOD
@@ -271,8 +265,6 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb
p.iLower = readFloatData(data);
getline(lineStream, data, ','); // UI
p.ui = readFloatData(data);
getline(lineStream, data, ','); // IREF
getline(lineStream, data, ','); // IURL
getline(lineStream, data, ','); // IMAGING
@@ -326,17 +318,15 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb
getline(lineStream, data, ','); // NOBS
getline(lineStream, data, ','); // OM
p.om = readFloatData(data);
p.omega = readFloatData(data);
getline(lineStream, data, ','); // OMUPPER
p.omUpper = readFloatData(data);
p.omegaUpper = readFloatData(data);
getline(lineStream, data, ','); // OMLOWER
p.omLower = readFloatData(data);
p.omegaLower = readFloatData(data);
getline(lineStream, data, ','); // UOM
p.uOm = readFloatData(data);
getline(lineStream, data, ','); // OMREF
getline(lineStream, data, ','); // OMURL
getline(lineStream, data, ','); // ORBREF
@@ -356,8 +346,6 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb
p.perLower = readFloatData(data);
getline(lineStream, data, ','); // UPER
p.uPer = readFloatData(data);
getline(lineStream, data, ','); // PERREF
getline(lineStream, data, ','); // PERURL
getline(lineStream, data, ','); // PLANETDISCMETH
@@ -371,8 +359,6 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb
p.rLower = readDoubleData(data);
getline(lineStream, data, ','); //UR
p.ur = readDoubleData(data);
getline(lineStream, data, ','); // RREF
getline(lineStream, data, ','); // RURL
getline(lineStream, data, ','); // RA
@@ -401,8 +387,6 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb
p.rStarLower = readFloatData(data);
getline(lineStream, data, ','); // URSTAR
p.urStar = readFloatData(data);
getline(lineStream, data, ','); // RSTARREF
getline(lineStream, data, ','); // RSTARURL
getline(lineStream, data, ','); // SAO
@@ -517,8 +501,6 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb
p.ttLower = readFloatData(data);
getline(lineStream, data, ','); // UTT
p.uTt = readFloatData(data);
getline(lineStream, data, ','); // TTREF
getline(lineStream, data, ','); // TTURL
getline(lineStream, data, ','); // V
@@ -593,13 +575,7 @@ glm::vec3 ExoplanetsCsvToBinTask::starPosition(const std::string& starName) {
}
}
// Apply transformation matrix to pos
glm::dmat4 _transformationMatrix = glm::dmat4(1.0);
glm::vec3 transformedPosition = glm::vec3(
_transformationMatrix * glm::dvec4(position, 1.0)
);
return transformedPosition;
return position;
}
float ExoplanetsCsvToBinTask::bvFromTeff(float teff) {
@@ -0,0 +1,421 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2020 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/exoplanets/tasks/exoplanetsdatapreparationtask.h>
#include <modules/exoplanets/exoplanetshelper.h>
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
#include <openspace/json.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/fmt.h>
#include <ghoul/glm.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/dictionary.h>
#include <charconv>
#include <fstream>
// TEST: do not optimise for now
#pragma optimize("", off)
namespace {
constexpr const char* KeyInputDataFile = "InputDataFile";
constexpr const char* KeyInputSpeck = "InputSPECK";
constexpr const char* KeyOutputBin = "OutputBIN";
constexpr const char* KeyOutputLut = "OutputLUT";
constexpr const char* KeyTeffToBv = "TeffToBvFile";
constexpr const char* _loggerCat = "ExoplanetsDataPreparationTask";
} // namespace
namespace openspace::exoplanets {
using json = nlohmann::json;
ExoplanetsDataPreparationTask::ExoplanetsDataPreparationTask(const ghoul::Dictionary& dictionary) {
openspace::documentation::testSpecificationAndThrow(
documentation(),
dictionary,
"ExoplanetsDataPreparationTask"
);
_inputDataPath = absPath(dictionary.value<std::string>(KeyInputDataFile));
_inputSpeckPath = absPath(dictionary.value<std::string>(KeyInputSpeck));
_outputBinPath = absPath(dictionary.value<std::string>(KeyOutputBin));
_outputLutPath = absPath(dictionary.value<std::string>(KeyOutputLut));
_teffToBvFilePath = absPath(dictionary.value<std::string>(KeyTeffToBv));
}
std::string ExoplanetsDataPreparationTask::description() {
return fmt::format(
"Extract metadata from file '{}' and write as bin to '{}'", // TODO: update description
_inputDataPath,
_outputBinPath
);
}
void ExoplanetsDataPreparationTask::perform(const Task::ProgressCallback& progressCallback) {
std::ifstream inputDataFile(_inputDataPath);
if (!inputDataFile.good()) {
LERROR(fmt::format("Failed to open input file '{}'", _inputDataPath));
return;
}
std::ofstream binFile(_outputBinPath, std::ios::out | std::ios::binary);
std::ofstream lutFile(_outputLutPath);
int version = 1;
binFile.write(reinterpret_cast<char*>(&version), sizeof(int));
std::string planetRow;
getline(inputDataFile, planetRow); // The first line, containing the data names
// read column names into a vector, for access later
std::vector<std::string> columnNames;
std::stringstream sStream(planetRow);
std::string colName;
while (getline(sStream, colName, ',')) {
columnNames.push_back(colName);
}
// read total number of items
int total = 0;
while (getline(inputDataFile, planetRow)) {
++total;
}
inputDataFile.clear();
inputDataFile.seekg(0);
getline(inputDataFile, planetRow); // The first line, containing the data names
LINFO(fmt::format("Loading {} exoplanets", total));
auto readFloatData = [](const std::string& str) -> float {
float result;
auto [p, ec] = std::from_chars(str.data(), str.data() + str.size(), result);
if (ec == std::errc()) {
return result;
}
return NAN;
};
auto readDoubleData = [](const std::string& str) -> double {
double result;
auto [p, ec] = std::from_chars(str.data(), str.data() + str.size(), result);
if (ec == std::errc()) {
return result;
}
return NAN;
};
auto readIntegerData = [](const std::string& str) -> int {
int result;
auto [p, ec] = std::from_chars(str.data(), str.data() + str.size(), result);
if (ec == std::errc()) {
return result;
}
return -1;
};
auto readStringData = [](const std::string& str) -> std::string {
std::string result = str;
// remove quotes, if any
result.erase(std::remove(result.begin(), result.end(), '\"'), result.end());
return result;
};
Exoplanet p;
std::string data;
int exoplanetCount = 0;
while (getline(inputDataFile, planetRow)) {
++exoplanetCount;
progressCallback(static_cast<float>(exoplanetCount) / static_cast<float>(total));
std::string component;
std::string speckStarname;
std::istringstream lineStream(planetRow);
int columnIndex = 0;
while (getline(lineStream, data, ',')) {
const std::string& column = columnNames[columnIndex];
columnIndex++;
if (column == "pl_letter") {
component = readStringData(data);
}
// Orbital semi-major axis
else if (column == "pl_orbsmax") {
p.a = readFloatData(data);
}
else if (column == "pl_orbsmaxerr1") {
p.aUpper = readDoubleData(data);
}
else if (column == "pl_orbsmaxerr2") {
p.aLower = -readDoubleData(data);
}
// Orbital eccentricity
else if (column == "pl_orbeccen") {
p.ecc = readFloatData(data);
}
else if (column == "pl_orbeccenerr1") {
p.eccUpper = readFloatData(data);
}
else if (column == "pl_orbeccenerr2") {
p.eccLower = -readFloatData(data);
}
// Orbital inclination
else if (column == "pl_orbincl") {
p.i = readFloatData(data);
}
else if (column == "pl_orbinclerr1") {
p.iUpper = readFloatData(data);
}
else if (column == "pl_orbinclerr2") {
p.iLower = -readFloatData(data);
}
// Argument of periastron
else if (column == "pl_orblper") {
p.omega = readFloatData(data);
}
else if (column == "pl_orblpererr1") {
p.omegaUpper = readFloatData(data);
}
else if (column == "pl_orblpererr2") {
p.omegaLower = -readFloatData(data);
}
// Orbital period
else if (column == "pl_orbper") {
p.per = readDoubleData(data);
}
else if (column == "pl_orbpererr1") {
p.perUpper = readFloatData(data);
}
else if (column == "pl_orbpererr2") {
p.perLower = -readFloatData(data);
}
// Radius of the planet (Jupiter radii)
else if (column == "pl_radj") {
p.r = readDoubleData(data);
}
else if (column == "pl_radjerr1") {
p.rUpper = readDoubleData(data);
}
else if (column == "pl_radjerr2") {
p.rLower = -readDoubleData(data);
}
// Time of transit midpoint
else if (column == "pl_tranmid") {
p.tt = readDoubleData(data);
}
else if (column == "pl_tranmiderr1") {
p.ttUpper = readFloatData(data);
}
else if (column == "pl_tranmiderr2") {
p.ttLower = -readFloatData(data);
}
// Star - name and position
else if (column == "hostname") {
std::string name = readStringData(data);
speckStarname = std::string(speckStarName(name));
glm::vec3 position = starPosition(speckStarname);
p.positionX = position[0];
p.positionY = position[1];
p.positionZ = position[2];
}
// Star radius
else if (column == "st_rad") {
p.rStar = readFloatData(data);
}
else if (column == "st_raderr1") {
p.rStarUpper = readFloatData(data);
}
else if (column == "st_raderr2") {
p.rStarLower = -readFloatData(data);
}
// Color of star (B-V color index computed from star's effective temperature)
else if (column == "st_teff") {
float teff = readFloatData(data);
p.bmv = bvFromTeff(teff);
}
// Is the planet orbiting a binary system?
else if (column == "cb_flag") {
p.binary = static_cast<bool>(readIntegerData(data));
}
// Number of planets in the system
else if (column == "sy_pnum") {
p.nComp = readIntegerData(data);
}
}
// @TODO (emmbr 2020-10-05) Currently, the dataset has no information about the
// longitude of the ascending node, but maybe it might in the future
p.bigOmega = NAN;
p.bigOmegaUpper = NAN;
p.bigOmegaLower = NAN;
// create look-up table
long pos = static_cast<long>(binFile.tellp());
std::string planetName = speckStarname + " " + component;
lutFile << planetName << "," << pos << std::endl;
// Write to binary data file
binFile.write(reinterpret_cast<char*>(&p), sizeof(Exoplanet));
}
progressCallback(1.f);
}
glm::vec3 ExoplanetsDataPreparationTask::starPosition(const std::string& starName) {
std::ifstream exoplanetsFile(_inputSpeckPath);
if (!exoplanetsFile) {
LERROR(fmt::format("Error opening file expl.speck"));
}
glm::vec3 position{ NAN };
std::string line;
while (getline(exoplanetsFile, line)) {
bool shouldSkipLine = (
line.empty() || line[0] == '#' || line.substr(0, 7) == "datavar" ||
line.substr(0, 10) == "texturevar" || line.substr(0, 7) == "texture"
);
if (shouldSkipLine) {
continue;
}
std::string data;
std::string name;
std::istringstream linestream(line);
getline(linestream, data, '#');
getline(linestream, name);
name.erase(0, 1);
std::string coord;
if (name == starName) {
std::stringstream dataStream(data);
getline(dataStream, coord, ' ');
position[0] = std::stof(coord.c_str(), nullptr);
getline(dataStream, coord, ' ');
position[1] = std::stof(coord.c_str(), nullptr);
getline(dataStream, coord, ' ');
position[2] = std::stof(coord.c_str(), nullptr);
break;
}
}
return position;
}
float ExoplanetsDataPreparationTask::bvFromTeff(float teff) {
if (std::isnan(teff)) {
return NAN;
}
std::ifstream teffToBvFile(_teffToBvFilePath);
if (!teffToBvFile.good()) {
LERROR(fmt::format("Failed to open teff_bv.txt file"));
return NAN;
}
float bv = 0.f;
float bvUpper = 0.f;
float bvLower = 0.f;
float teffLower, teffUpper;
std::string row, teffString, bvString;
while (getline(teffToBvFile, row)) {
std::istringstream lineStream(row);
getline(lineStream, teffString, ',');
getline(lineStream, bvString);
float teffCurrent = std::stof(teffString.c_str(), nullptr);
float bvCurrent = std::stof(bvString.c_str(), nullptr);
if (teff > teffCurrent) {
teffLower = teffCurrent;
bvLower = bvCurrent;
}
else {
teffUpper = teffCurrent;
bvUpper = bvCurrent;
if (bvLower == 0.f) {
bv = 2.f;
}
else {
float bvDiff = (bvUpper - bvLower);
float teffDiff = (teffUpper - teffLower);
bv = ((bvDiff * (teff - teffLower)) / teffDiff) + bvLower;
}
break;
}
}
return bv;
}
documentation::Documentation ExoplanetsDataPreparationTask::documentation() {
using namespace documentation;
return {
"ExoplanetsDataPreparationTask",
"exoplanets_data_preparation_task",
{
{
"Type",
new StringEqualVerifier("ExoplanetsDataPreparationTask"),
Optional::No,
""
},
{
KeyInputDataFile,
new StringAnnotationVerifier("A valid filepath"),
Optional::No,
"The csv file to extract data from"
},
{
KeyInputSpeck,
new StringAnnotationVerifier("A file path to a speck file"),
Optional::No,
"The speck file with star locations"
},
{
KeyOutputBin,
new StringAnnotationVerifier("A valid filepath"),
Optional::No,
"The bin file to export data into"
},
{
KeyOutputLut,
new StringAnnotationVerifier("A valid filepath"),
Optional::No,
"The txt file to write look-up table into"
},
{
KeyTeffToBv,
new StringAnnotationVerifier("A valid filepath"),
Optional::No,
"The path to a teff to bv conversion file"
}
}
};
}
} // namespace openspace::exoplanets
@@ -0,0 +1,56 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2020 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSDATAPREPARATIONTASK___H__
#define __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSDATAPREPARATIONTASK___H__
#include <openspace/properties/vector/vec3property.h>
#include <openspace/util/task.h>
#include <string>
namespace openspace::exoplanets {
class ExoplanetsDataPreparationTask : public Task {
public:
ExoplanetsDataPreparationTask(const ghoul::Dictionary& dictionary);
std::string description() override;
void perform(const Task::ProgressCallback& progressCallback) override;
static documentation::Documentation documentation();
private:
std::string _inputDataPath;
std::string _inputSpeckPath;
std::string _outputBinPath;
std::string _outputLutPath;
std::string _teffToBvFilePath;
glm::vec3 starPosition(const std::string& starName);
// Compute b-v color from teff value using a conversion file
float bvFromTeff(float teff);
};
} // namespace openspace::exoplanets
#endif // __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSDATAPREPARATIONTASK___H__