From a6c603dd43d98d5569e88b2a95b4a481fc1e02b4 Mon Sep 17 00:00:00 2001 From: ElonOlsson Date: Wed, 7 Dec 2022 15:09:06 -0500 Subject: [PATCH] started making it work --- .../fieldlinessequencemodule.cpp | 2 +- .../tasks/kameleonvolumetofieldlinestask.cpp | 215 ++++++++---------- .../tasks/kameleonvolumetofieldlinestask.h | 4 +- 3 files changed, 92 insertions(+), 129 deletions(-) diff --git a/modules/fieldlinessequence/fieldlinessequencemodule.cpp b/modules/fieldlinessequence/fieldlinessequencemodule.cpp index 8ebbbe8a95..3f4ec67d40 100644 --- a/modules/fieldlinessequence/fieldlinessequencemodule.cpp +++ b/modules/fieldlinessequence/fieldlinessequencemodule.cpp @@ -72,7 +72,7 @@ void FieldlinesSequenceModule::internalInitialize(const ghoul::Dictionary&) { std::vector FieldlinesSequenceModule::documentations() const { return { - KameleonVolumeToFieldlinesTask::Documentation(); + KameleonVolumeToFieldlinesTask::documentation(), RenderableFieldlinesSequence::Documentation() }; } diff --git a/modules/fieldlinessequence/tasks/kameleonvolumetofieldlinestask.cpp b/modules/fieldlinessequence/tasks/kameleonvolumetofieldlinestask.cpp index ac3995d1dd..0031aac770 100644 --- a/modules/fieldlinessequence/tasks/kameleonvolumetofieldlinestask.cpp +++ b/modules/fieldlinessequence/tasks/kameleonvolumetofieldlinestask.cpp @@ -34,8 +34,9 @@ #include #include +#include + namespace { - constexpr const char* _loggerCat = "KameleonVolumeToFieldlinesTask"; constexpr const char* KeyInput = "Input"; constexpr const char* KeyTimeKernel = "TimeKernel"; constexpr const char* KeyOutputFolder = "OutputFolder"; @@ -45,138 +46,100 @@ namespace { constexpr const char* KeyExtraMagnitudeVars = "ExtraMagnitudeVars"; } // namespace +namespace { + constexpr std::string_view _loggerCat = "KameleonVolumeToFieldlinesTask"; + + struct [[codegen::Dictionary(KameleonVolumeToFieldLinesTask)]] Parameters { + // The cdf file to extract data from + std::filesystem::path input; + // A text file with seedpoints with the format x1 y1 z1 x2 y2 z2 ... + // Seedpoints are expressed in the native coordinate system of the model. + std::filesystem::path seedpoints + // The name of the kameleon variable to use for tracing, like b, or u + std::string tracingVar; + // The folder to write the files to + std::filesystem::path outputFolder; + // Output type. Either osfls (OpenSpace FieldLineSequence) or json + std::string outputType; + // A list of vector variables to extract along the fieldlines + std::optional> extraScalarVars; + }; +#include "kameleonvolumetofieldlinestask_codegen.cpp" + +} + namespace openspace { - documentation::Documentation KameleonVolumeToFieldlinesTask::documentation() { - using namespace documentation; - return { - "KameleonVolumeToFieldlinesTask", - "kameleon_metadata_to_fieldlines_task", - { - { - "Type", - new StringEqualVerifier("KameleonVolumeToFieldlinesTask"), - Optional::No, - "The type of this task", - }, - { - KeyInput, - new StringAnnotationVerifier("A file path to a cdf file"), - Optional::No, - "The cdf file to extract data from", - }, - { - KeyTimeKernel, - new StringAnnotationVerifier("A file path to a cdf file"), - Optional::No, - "A file path to a tls spice kernel used for time", - }, - { - KeyTracingVar, - new StringAnnotationVerifier("A kameleon variable name"), - Optional::No, - "The name of the kameleon variable to use for tracing", - }, - { - KeyOutputFolder, - new StringAnnotationVerifier("A valid path to a folder"), - Optional::No, - "The folder to write the osfls file to", - }, - { - KeySeedpoints, - new StringAnnotationVerifier("A valid filepath"), - Optional::No, - "A text file with seedpoints with the format x1 y1 z1 x2 y2 z2 ... " - "Seedpoints are expressed in the native coordinate system of the model." - }, - { - KeyExtraScalarVars, - new StringListVerifier("A list of kameleon variables"), - Optional::Yes, - "A list of scalar variables to extract along the fieldlines", - }, - { - KeyExtraMagnitudeVars, - new StringListVerifier("A list of kameleon variables"), - Optional::Yes, - "A list of vector variables whose magnitude to extract along the " - "fieldlines", - }, - } - }; +documentation::Documentation KameleonVolumeToFieldlinesTask::documentation() { + return codegen::doc("kameleon_volume_to_fieldlines_task") +} + +KameleonVolumeToFieldlinesTask::KameleonVolumeToFieldlinesTask( + const ghoul::Dictionary& dictionary) +{ + + const Parameters p = codegen::bake(dictionary); + + _inputPath = p.input.value(); + _seedpointsPath = p.seepoints.value(); + _outputFolder = p.outputFolder.value(); + _outputType = p.outputType.value(); + _tracingVar = p.tracingVar.value_or(_tractingVar); + + if (dictionary.hasKey(KeyExtraScalarVars)) { + ghoul::Dictionary list = dictionary.value(KeyExtraScalarVars); + for (size_t i = 0; i < list.size(); ++i) { + _extraScalarVars.push_back(list.value(std::to_string(i))); + } + } + if (dictionary.hasKey(KeyExtraMagnitudeVars)) { + ghoul::Dictionary list = + dictionary.value(KeyExtraMagnitudeVars); + + for (size_t i = 0; i < list.size(); ++i) { + _extraMagnitudeVars.push_back(list.value(std::to_string(i))); + } + } +} + +std::string KameleonVolumeToFieldlinesTask::description() { + return fmt::format( + "Extract fieldline data from cdf file {} and seedpoint file {}. " + "Write osfls file into the folder {}.", + _inputPath, _seedpointsPath, _outputFolder + ); +} + +void KameleonVolumeToFieldlinesTask::perform( + const Task::ProgressCallback& progressCallback) +{ + + std::vector seedPoints; + bool readSeedpoints = fls::extractSeedPointsFromFile(_seedpointsPath, seedPoints); + + if (!readSeedpoints) { + LERROR("Falied to read seedpoints"); + return; } - KameleonVolumeToFieldlinesTask::KameleonVolumeToFieldlinesTask( - const ghoul::Dictionary& dictionary) - { - openspace::documentation::testSpecificationAndThrow( - documentation(), - dictionary, - "KameleonVolumeToFieldlinesTask" - ); - _inputPath = absPath(dictionary.value(KeyInput)); - _timeKernelPath = absPath(dictionary.value(KeyTimeKernel)); - _seedpointsPath = absPath(dictionary.value(KeySeedpoints)); - _outputFolder = absPath(dictionary.value(KeyOutputFolder)); - _tracingVar = dictionary.value(KeyTracingVar); + FieldlinesState newState; + bool isSuccessful = fls::convertCdfToFieldlinesState( + newState, + _inputPath, + seedPoints, + _tracingVar, + _extraScalarVars, + _extraMagnitudeVars + ); - if (dictionary.hasKey(KeyExtraScalarVars)) { - ghoul::Dictionary list = dictionary.value(KeyExtraScalarVars); - for (size_t i = 0; i < list.size(); ++i) { - _extraScalarVars.push_back(list.value(std::to_string(i))); - } - } - if (dictionary.hasKey(KeyExtraMagnitudeVars)) { - ghoul::Dictionary list = - dictionary.value(KeyExtraMagnitudeVars); - - for (size_t i = 0; i < list.size(); ++i) { - _extraMagnitudeVars.push_back(list.value(std::to_string(i))); - } - } + if (isSuccessful) { + return newState.saveStateToOsfls(_outputFolder); } - std::string KameleonVolumeToFieldlinesTask::description() { - return fmt::format( - "Extract fieldline data from cdf file {} and seedpoint file {}. " - "Write osfls file into the folder {}.", - _inputPath, _seedpointsPath, _outputFolder - ); - } - - void KameleonVolumeToFieldlinesTask::perform( - const Task::ProgressCallback& progressCallback) - { - - std::vector seedPoints; - bool readSeedpoints = fls::extractSeedPointsFromFile(_seedpointsPath, seedPoints); - - if (!readSeedpoints) { - LERROR("Falied to read seedpoints"); - return; - } - - SpiceManager::ref().loadKernel(_timeKernelPath); - - FieldlinesState newState; - bool isSuccessful = fls::convertCdfToFieldlinesState( - newState, - _inputPath, - seedPoints, - _tracingVar, - _extraScalarVars, - _extraMagnitudeVars - ); - - if (isSuccessful) { - return newState.saveStateToOsfls(_outputFolder); - } - - // Ideally, we would want to signal about progress earlier as well, but - // convertCdfToFieldlinesState does all the work encapsulated in one function call. - progressCallback(1.0f); - } + // Ideally, we would want to signal about progress earlier as well, but + // convertCdfToFieldlinesState does all the work encapsulated in one function call. + progressCallback(1.0f); +} } // namespace openspace diff --git a/modules/fieldlinessequence/tasks/kameleonvolumetofieldlinestask.h b/modules/fieldlinessequence/tasks/kameleonvolumetofieldlinestask.h index 43a11d2bf4..024b103b02 100644 --- a/modules/fieldlinessequence/tasks/kameleonvolumetofieldlinestask.h +++ b/modules/fieldlinessequence/tasks/kameleonvolumetofieldlinestask.h @@ -47,8 +47,8 @@ namespace openspace { std::vector _extraMagnitudeVars; std::filesystem::path _inputPath; //std::string _timeKernelPath; - std::string _seedpointsPath; - std::string _outputFolder; + std::filesystem::path _seedpointsPath; + std::filesystem::path _outputFolder; }; } // namespace openspace