directory of seedpoint files instead of just one seedpoint file

This commit is contained in:
ElonOlsson
2021-05-03 10:24:34 -04:00
parent b600df4187
commit 5c143da954
8 changed files with 110 additions and 67 deletions
@@ -75,7 +75,7 @@ local EarthIAU = {
local GSMReferenceFrame = {
Identifier = "GSMReferenceFrame",
Parent = EarthBarycenter.Identifier,
Parent = EarthCenter.Identifier,
Transform = {
Rotation = {
Type = "SpiceRotation",
@@ -6,8 +6,10 @@ local transferFunctions = asset.localResource("transferfunctions")
local masVelocityColorTable = transferFunctions .. "/velocity_fieldlines.txt"
local masDensityColorTable = transferFunctions .. "/density_fieldlines.txt"
local fieldlinesDirectory = 'D:/data/2000_01_01_event/cdf'
local seedPointFile = 'D:/data/2000_01_01_event/seedpoints/mp_position_257532008271_20000101_040000.txt'
local fieldlinesDirectory = 'D:/data/2000_01_01_event/cdf/GM_CDF'
local fieldlinesDirectory = 'C:/Users/eolsson/Documents/openspace/data/20000101/osfls'
--local seedPointDirectory = 'D:/data/2000_01_01_event/seedpoints'
local seedPointDirectory = 'D:/data/2000_01_01_event/seedpoints/Masha_Kuznetsova_030106_2_data_257970025845'
--local sunRadius = 6.957E8
local earthRadius = 6378137
@@ -16,18 +18,18 @@ local earthRadius = 6378137
-- Fieldlies from binaries
local fieldlines = {
Identifier = "MAS_MHD_Fieldlines",
--wrong Parent = sunTransforms.HNMReferenceFrame.Identifier,
Parent = transforms.GSMReferenceFrame.Identifier,
Renderable = {
Type = "RenderableFieldlinesSequence",
SourceFolder = fieldlinesDirectory,
SeedPointFile = seedPointFile,
SeedPointDirectory = seedPointDirectory,
TracingVariable = 'b',
--OutputFolder = "C:/Users/eolsson/Documents/openspace/data/20000101/osfls/",
-- FlowEnabled = false,
-- LineWidth = 1.0;
AlphaBlendlingEnabled = false,
InputFileType = "cdf",
InputFileType = "osfls",
ColorTablePaths = {
masDensityColorTable,
@@ -24,6 +24,7 @@
#include <modules/fieldlinessequence/rendering/renderablefieldlinessequence.h>
#include <map>
#include <modules/fieldlinessequence/fieldlinessequencemodule.h>
#include <modules/fieldlinessequence/util/kameleonfieldlinehelper.h>
#include <openspace/engine/globals.h>
@@ -57,7 +58,7 @@ namespace {
// ---------------------- MANDATORY INPUT TYPE SPECIFIC KEYS ---------------------- //
// [STRING] Path to a .txt file containing seed points
constexpr const char* KeyCdfSeedPointFile = "SeedPointFile";
constexpr const char* KeyCdfSeedPointDirectory = "SeedPointDirectory";
// [STRING] Currently supports: "batsrus", "enlil" & "pfss"
constexpr const char* KeyJsonSimulationModel = "SimulationModel";
@@ -315,6 +316,7 @@ void RenderableFieldlinesSequence::initializeGL() {
// SOURCE
switch (sourceFileType) {
case SourceFileType::Cdf:
if (!getStatesFromCdfFiles(outputFolderPath)) {
return;
}
@@ -484,15 +486,15 @@ void RenderableFieldlinesSequence::extractOptionalInfoFromDictionary(
_pFlowEnabled = _dictionary->value<bool>(KeyFlowEnabled);
}
float lineWidthValue;
if (_dictionary->hasValue<std::string>(KeyLineWidth)) {
_pLineWidth = stringToFloat(_dictionary->value<std::string>(KeyLineWidth));
}
if (_dictionary->hasValue<std::string>(KeyOutputFolder)) {
ghoul::filesystem::Directory outputFolder(outputFolderPath);
std::string temp = _dictionary->value<std::string>(KeyOutputFolder);
ghoul::filesystem::Directory outputFolder(temp);
if (FileSys.directoryExists(outputFolder)) {
outputFolderPath = absPath(outputFolderPath);
outputFolderPath = absPath(outputFolder);
}
else {
LERROR(fmt::format(
@@ -890,28 +892,28 @@ void RenderableFieldlinesSequence::addStateToSequence(FieldlinesState& state) {
bool RenderableFieldlinesSequence::getStatesFromCdfFiles(const std::string& outputFolder)
{
std::string seedFilePath;
std::string tracingVar;
std::vector<std::string> extraVars;
if (!extractCdfInfoFromDictionary(seedFilePath, tracingVar, extraVars)) {
return false;
}
std::vector<glm::vec3> seedPoints;
if (!extractSeedPointsFromFile(seedFilePath, seedPoints)) {
if (!extractCdfInfoFromDictionary(tracingVar, extraVars)) {
return false;
}
std::vector<std::string> extraMagVars;
extractMagnitudeVarsFromStrings(extraVars, extraMagVars);
std::unordered_map<std::string, std::vector<glm::vec3>> seedsPerFiles;
std::string seedDirectoryPath;
if (!extractSeedPointsFromFiles(seedDirectoryPath, seedsPerFiles)) {
return false;
}
// Load states into RAM!
for (const std::string& cdfPath : _sourceFiles) {
FieldlinesState newState;
bool isSuccessful = fls::convertCdfToFieldlinesState(
newState,
cdfPath,
seedPoints,
seedsPerFiles,
tracingVar,
extraVars,
extraMagVars
@@ -930,28 +932,9 @@ bool RenderableFieldlinesSequence::getStatesFromCdfFiles(const std::string& outp
/*
* Returns false if it fails to extract mandatory information!
*/
bool RenderableFieldlinesSequence::extractCdfInfoFromDictionary(std::string& seedFilePath,
std::string& tracingVar,
bool RenderableFieldlinesSequence::extractCdfInfoFromDictionary(std::string& tracingVar,
std::vector<std::string>& extraVars)
{
if (_dictionary->hasValue<std::string>(KeyCdfSeedPointFile)) {
seedFilePath = _dictionary->value<std::string>(KeyCdfSeedPointFile);
ghoul::filesystem::File seedPointFile(seedFilePath);
if (FileSys.fileExists(seedPointFile)) {
seedFilePath = absPath(seedFilePath);
}
else {
LERROR(fmt::format(
"{}: The specified seed poitn file: '{}' does not exist",
_identifier, seedFilePath
));
return false;
}
}
else {
LERROR(fmt::format("{}: Must specify '{}'", _identifier, KeyCdfSeedPointFile));
return false;
}
if (_dictionary->hasValue<std::string>(KeyCdfTracingVariable)) {
tracingVar = _dictionary->value<std::string>(KeyCdfTracingVariable);
@@ -978,30 +961,75 @@ bool RenderableFieldlinesSequence::extractCdfInfoFromDictionary(std::string& see
return true;
}
bool RenderableFieldlinesSequence::extractSeedPointsFromFile(const std::string& path,
std::vector<glm::vec3>& outVec)
bool RenderableFieldlinesSequence::extractSeedPointsFromFiles( std::string& path,
std::unordered_map<std::string,
std::vector<glm::vec3>>& outMap)
{
std::vector<std::string> files;
std::ifstream seedFile(FileSys.relativePath(path));
if (!seedFile.good()) {
LERROR(fmt::format("Could not open seed points file '{}'", path));
if (_dictionary->hasValue<std::string>(KeyCdfSeedPointDirectory)) {
path = _dictionary->value<std::string>(KeyCdfSeedPointDirectory);
ghoul::filesystem::Directory seedPointDir(path);
if (FileSys.directoryExists(seedPointDir)) {
path = absPath(path);
files = seedPointDir.readFiles(
ghoul::filesystem::Directory::Recursive::No,
ghoul::filesystem::Directory::Sort::Yes);
}
else {
LERROR(fmt::format(
"{}: The specified seed point directory: '{}' does not exist",
_identifier, path
));
return false;
}
}
else {
LERROR(fmt::format("{}: Must specify '{}'",
_identifier, KeyCdfSeedPointDirectory));
return false;
}
LDEBUG(fmt::format("Reading seed points from file '{}'", path));
std::string line;
while (std::getline(seedFile, line)) {
std::stringstream ss(line);
glm::vec3 point;
ss >> point.x;
ss >> point.y;
ss >> point.z;
outVec.push_back(std::move(point));
}
for (const std::string& seedFilePath : files) {
if (seedFilePath.find("mp_position") == std::string::npos) {
continue;
}
size_t lastIndex = seedFilePath.find_last_of('.');
std::string name = seedFilePath.substr(0, lastIndex); // remove file extention
size_t dateAndTimeSeperator = name.find_last_of('_');
std::string time = name.substr(dateAndTimeSeperator+1, name.length());
std::string date = name.substr(dateAndTimeSeperator - 8, 8); //8 for yyyymmdd
std::string dateAndTime = date + time;
std::ifstream seedFile(FileSys.relativePath(seedFilePath));
if (!seedFile.good()) {
LERROR(fmt::format("Could not open seed points file '{}'", seedFilePath));
return false;
}
LDEBUG(fmt::format("Reading seed points from file '{}'", seedFilePath));
std::string line;
std::vector<glm::vec3> outVec;
while (std::getline(seedFile, line)) {
std::stringstream ss(line);
glm::vec3 point;
ss >> point.x;
ss >> point.y;
ss >> point.z;
outVec.push_back(std::move(point));
}
if (outVec.size() == 0) {
LERROR(fmt::format("Found no seed points in: {}", seedFilePath));
return false;
}
// add outVec as value and time stamp as int as key
outMap[dateAndTime] = outVec;
if (outVec.size() == 0) {
LERROR(fmt::format("Found no seed points in: {}", path));
return false;
}
return true;
@@ -204,7 +204,7 @@ private:
void addStateToSequence(FieldlinesState& STATE);
void computeSequenceEndTime();
void definePropertyCallbackFunctions();
bool extractCdfInfoFromDictionary(std::string& seedFilePath, std::string& tracingVar,
bool extractCdfInfoFromDictionary(std::string& tracingVar,
std::vector<std::string>& extraVars);
bool extractJsonInfoFromDictionary(fls::Model& model);
void extractMagnitudeVarsFromStrings(std::vector<std::string>& extraVars,
@@ -212,8 +212,8 @@ private:
bool extractMandatoryInfoFromDictionary(SourceFileType& sourceFileType);
void extractOptionalInfoFromDictionary(std::string& outputFolderPath);
void extractOsflsInfoFromDictionary();
bool extractSeedPointsFromFile(const std::string& path,
std::vector<glm::vec3>& outVec);
bool extractSeedPointsFromFiles(std::string& path,
std::unordered_map<std::string, std::vector<glm::vec3>>& outVec);
void extractTriggerTimesFromFileNames();
bool loadJsonStatesIntoRAM(const std::string& outputFolder);
void loadOsflsStatesIntoRAM(const std::string& outputFolder);
@@ -296,6 +296,8 @@ void FieldlinesState::saveStateToOsfls(const std::string& absPath) {
ofs.write(reinterpret_cast<char*>(vec.data()), sizeof(float) * nPoints);
}
ofs.write(allExtraQuantityNamesInOne.c_str(), nStringBytes);
ofs.close();
}
// TODO: This should probably be rewritten, but this is the way the files were structured
@@ -26,6 +26,7 @@
#include <modules/fieldlinessequence/util/commons.h>
#include <modules/fieldlinessequence/util/fieldlinesstate.h>
#include <openspace/util/spicemanager.h>
#include <ghoul/fmt.h>
#include <ghoul/logging/logmanager.h>
#include <memory>
@@ -88,10 +89,11 @@ namespace openspace::fls {
* vector at each line vertex
*/
bool convertCdfToFieldlinesState(FieldlinesState& state, const std::string& cdfPath,
const std::vector<glm::vec3>& seedPoints,
const std::string& tracingVar,
std::vector<std::string>& extraVars,
std::vector<std::string>& extraMagVars)
const std::unordered_map<std::string,
std::vector<glm::vec3>>& seedMap,
const std::string& tracingVar,
std::vector<std::string>& extraVars,
std::vector<std::string>& extraMagVars)
{
#ifndef OPENSPACE_MODULE_KAMELEON_ENABLED
@@ -104,7 +106,15 @@ bool convertCdfToFieldlinesState(FieldlinesState& state, const std::string& cdfP
);
state.setModel(fls::stringToModel(kameleon->getModelName()));
state.setTriggerTime(kameleonHelper::getTime(kameleon.get()));
double cdfDoubleTime = kameleonHelper::getTime(kameleon.get());
state.setTriggerTime(cdfDoubleTime);
//get time as string.
std::string cdfStringTime = SpiceManager::ref().dateFromEphemerisTime(cdfDoubleTime,
"YYYYMMDDHRMNSC::RND"); //YYYY MM DD HOUR MIN SEC ROUNDED
// use time as string for picking seedpoints from seedm
std::vector<glm::vec3> seedPoints = seedMap.at(cdfStringTime);
if (addLinesToState(kameleon.get(), seedPoints, tracingVar, state)) {
// The line points are in their RAW format (unscaled & maybe spherical)
@@ -36,8 +36,9 @@ class FieldlinesState;
namespace fls {
bool convertCdfToFieldlinesState(FieldlinesState& state, const std::string& cdfPath,
const std::vector<glm::vec3>& seedPoints, const std::string& tracingVar,
std::vector<std::string>& extraVars, std::vector<std::string>& extraMagVars);
const std::unordered_map<std::string, std::vector<glm::vec3>>& seedMap,
const std::string& tracingVar, std::vector<std::string>& extraVars,
std::vector<std::string>& extraMagVars);
} // namespace fls
} // namespace openspace
+1 -1
View File
@@ -159,7 +159,7 @@ double getTime(ccmc::Kameleon* kameleon) {
"The current state starts the same time as the sequence!");
}
return seqStartDbl + stateStartOffset;
return seqStartDbl + stateStartOffset - 14400;
}
} // namespace openspace::kameleonHelper {