Merge remote-tracking branch 'origin/thesis/2019/spaceweather-stream' into thesis/2019/spaceweather-stream

This commit is contained in:
Sovanny Huy
2019-08-29 14:55:12 -04:00
10 changed files with 75 additions and 59 deletions
+2 -2
View File
@@ -31,13 +31,13 @@ local earthRadius = 6371
-- Selected field lines + some additional field lines
asset.require('./testwsa/scs_oi')
asset.require('./testwsa/pfss_oi')
asset.require('./testwsa/pfss_io')
--asset.require('./testwsa/pfss_io')
-- Parker Solar Probe
-- asset.require('scene/solarsystem/missions/parkersolarprobe/parker_solar_probe_trail')
-- Sun earth connection
asset.require('./testwsa/sub_earth')
--asset.require('./testwsa/sub_earth')
-- Every N:th WSA field line
-- asset.require('./testwsa/pfss_io_25')
+2 -1
View File
@@ -14,7 +14,8 @@ local fieldlines = {
Renderable = {
Type = "RenderableFieldlinesSequence",
SourceFolder = fieldlinesDirectory,
WebFieldlines = true,
-- Dynamic web content wants a url with a unique id where the data may be fetched.
DynamicWebContent = "https://iswa.gsfc.nasa.gov/IswaSystemWebApp/FilesInRangeServlet?dataID=1178",
FlowEnabled = false,
AlphaBlendlingEnabled = false,
InputFileType = "osfls",
+2 -1
View File
@@ -15,7 +15,8 @@ local fieldlines = {
Renderable = {
Type = "RenderableFieldlinesSequence",
SourceFolder = fieldlinesDirectory,
WebFieldlines = true,
-- Dynamic web content wants a url with a unique id where the data may be fetched.
DynamicWebContent = "https://iswa.gsfc.nasa.gov/IswaSystemWebApp/FilesInRangeServlet?dataID=1179",
FlowEnabled = false,
AlphaBlendlingEnabled = false,
InputFileType = "osfls",
+2 -1
View File
@@ -15,7 +15,8 @@ local fieldlines = {
Renderable = {
Type = "RenderableFieldlinesSequence",
SourceFolder = fieldlinesDirectory,
WebFieldlines = true,
-- Dynamic web content wants a url with a unique id where the data may be fetched.
DynamicWebContent = "https://iswa.gsfc.nasa.gov/IswaSystemWebApp/FilesInRangeServlet?dataID=1177",
FlowEnabled = false,
AlphaBlendlingEnabled = false,
InputFileType = "osfls",
+5 -3
View File
@@ -2,7 +2,7 @@ local assetHelper = asset.require('util/asset_helper')
local transforms = asset.require('./transforms')
local transferFunctions = asset.localResource("transferfunctions")
local fieldlinesDirectory = asset.localResource("fl_sun_earth")
local fieldlinesDirectory = asset.localResource("fl_sub_earth")
local polarityColorTable = transferFunctions .. "/polarity_spec.txt"
local subEarthLevelColorTable = transferFunctions .. "/subearth_spec.txt"
@@ -11,11 +11,13 @@ local sunRadius = 695508000
-- Fieldlies from json
local fieldlines = {
Identifier = "WSA_Fieldlines_Sun_Earth_Connection",
Identifier = "WSA_Fieldlines_Sub_Earth_Track",
Parent = transforms.HNMReferenceFrame.Identifier,
Renderable = {
Type = "RenderableFieldlinesSequence",
SourceFolder = fieldlinesDirectory,
-- Dynamic web content wants a url with a unique id where the data may be fetched.
DynamicWebContent = "https://iswa.gsfc.nasa.gov/IswaSystemWebApp/FilesInRangeServlet?dataID=1176",
FlowEnabled = false,
AlphaBlendlingEnabled = false,
InputFileType = "osfls",
@@ -39,7 +41,7 @@ local fieldlines = {
},
GUI = {
Path = "/Solar System/Heliosphere",
Name = "WSA Sub-Satellite Points"
Name = "WSA Sub-Earth track"
},
Transform = {
Scale = {
@@ -55,7 +55,7 @@ namespace {
// [STRING] should be path to folder containing the input files
constexpr const char* KeySourceFolder = "SourceFolder";
// [BOOLEAN] should specify whether field line data should be fetched online or not
constexpr const char* KeyWebFieldlines = "WebFieldlines";
constexpr const char* KeyDynamicWebContent = "DynamicWebContent";
// ---------------------- MANDATORY INPUT TYPE SPECIFIC KEYS ---------------------- //
// [STRING] Path to a .txt file containing seed points
@@ -326,7 +326,7 @@ namespace openspace {
if (!prepareForOsflsStreaming()) {
return;
}
if (_webFieldlines) {
if (_dynamicWebContent) {
LERROR("initializing webmanager");
initializeWebManager();
}
@@ -425,18 +425,24 @@ namespace openspace {
std::string sourceFolderPath;
// try to get webfield setting, if not try to get sourcefolder setting
if (!_dictionary->getValue(KeyWebFieldlines, _webFieldlines)) {
// Try to get dynamicwebcontent setting, if not try to get sourcefolder setting
if (!_dictionary->getValue(KeyDynamicWebContent, _dynWebContentUrl)) {
if (!_dictionary->getValue(KeySourceFolder, sourceFolderPath)) {
LERROR(fmt::format("{}: The field {} or {} is missing.", _identifier, KeySourceFolder, KeyWebFieldlines));
LERROR(fmt::format("{}: The field {} or {} is missing.", _identifier, KeySourceFolder, KeyDynamicWebContent));
return false;
}
}
else {
LERROR("initializing sync-dir and downloading startset webFLman");
sourceFolderPath = _webFieldlinesManager.initializeSyncDirectory(_identifier);
_webFieldlinesManager.preDownload();
if (!_dynWebContentUrl.empty()) {
_dynamicWebContent = true;
LINFO("Initializing sync-directory and downloading a startset");
sourceFolderPath = _webFieldlinesManager.initializeSyncDirectory(_identifier);
_webFieldlinesManager.preDownload(_dynWebContentUrl);
}
else {
LERROR(fmt::format("{}: The field {} is missing a url", _identifier, KeyDynamicWebContent));
return false;
}
}
// Ensure that the source folder exists and then extract
@@ -1193,7 +1199,7 @@ namespace openspace {
const double currentTime = data.time.j2000Seconds();
if (_webFieldlines) {
if (_dynamicWebContent) {
if (!_webFieldlinesManager.hasUpdated && _webFieldlinesManager.checkIfWindowIsReadyToLoad()) {
_startTimes.clear();
@@ -1247,7 +1253,7 @@ namespace openspace {
_needsUpdate = false;
}
if (_webFieldlines && _webFieldlinesManager.notifyUpdate) {
if (_dynamicWebContent && _webFieldlinesManager.notifyUpdate) {
updateActiveTriggerTimeIndex(currentTime);
computeSequenceEndTime();
_webFieldlinesManager.notifyUpdate = false;
@@ -87,9 +87,11 @@ private:
// True when new state is loaded or user change which quantity used for masking out
// line segments
bool _shouldUpdateMaskingBuffer = false;
// Stated weather the field lines are fetched on demand from the web or not, default
// is false.
bool _webFieldlines = false;
// Stated weather the asset is fetching dynamic web content,
// The URL to the content is specifiec in the string below,
bool _dynamicWebContent = false;
// URL to the dynamic web content.
std::string _dynWebContentUrl = "";
// --------------------------------- NUMERICALS ----------------------------------- //
// Active index of _states. If(==-1)=>no state available for current time. Always the
@@ -41,9 +41,6 @@ namespace {
namespace openspace{
// --------------------------- PUBLIC FUNCTIONS --------------------------- //
void WebFieldlinesManager::initializeWebFieldlinesManager(std::string identifier, size_t& _nStates, std::vector<std::string>& _sourceFiles,
std::vector<double>& _startTimes)
@@ -55,24 +52,6 @@ namespace openspace{
}
bool WebFieldlinesManager::checkConnectionToServer() {
SyncHttpMemoryDownload mmryDld = SyncHttpMemoryDownload("http://localhost:3000/");
HttpRequest::RequestOptions opt = {};
opt.requestTimeoutSeconds = 0;
mmryDld.download(opt);
std::string s = "";
std::transform(mmryDld.downloadedData().begin(), mmryDld.downloadedData().end(), std::back_inserter(s),
[](char c) {
return c;
});
if (s == "You are at ROOT") {
_connected = true;
return true;
}
else
return false;
}
bool WebFieldlinesManager::isConnected() {
return _connected;
}
@@ -97,10 +76,28 @@ namespace openspace{
// Temporary function - this should be moved to the worker. It's to download
// the start latest line
// this could be used to test the connection too
void WebFieldlinesManager::preDownload(){
void WebFieldlinesManager::preDownload(std::string dUrl){
// Download a dataset that we know exists, hopefully the API could send the latest entry of that dataset
// TODO(Axel): Change this endpoint to be dynamic for each dataset
std::string url = "https://iswa.ccmc.gsfc.nasa.gov/iswa_data_tree/model/solar/WSA4.5/WSA4.5_fieldlines/trace_pfss_intoout/2017/09/2017-09-28T00-23-22.000.osfls";
int ID = std::stoi(dUrl.substr(dUrl.size() - 4));
std::string type = "";
switch (ID)
{
case 1176:
type = "trace_sun_earth";
break;
case 1177:
type = "trace_scs_outtoin";
break;
case 1178:
type = "trace_pfss_intoout";
break;
case 1179:
type = "trace_pfss_outtoin";
break;
}
std::string url = "https://iswa.ccmc.gsfc.nasa.gov/iswa_data_tree/model/solar/WSA4.5/WSA4.5_fieldlines/" + type + "/2017/09/2017-09-28T00-23-22.000.osfls";
std::string destinationpath = absPath(_syncDir + ghoul::filesystem::FileSystem::PathSeparator + "2017-09-28T00-23-22.000.osfls"); // what the downloaded filename is to be
AsyncHttpFileDownload ashd = AsyncHttpFileDownload(url, destinationpath, HttpFileDownload::Overwrite::Yes);
HttpRequest::RequestOptions opt = {};
@@ -112,6 +109,7 @@ namespace openspace{
}
if(ashd.hasFailed() == true ){
LERROR("failed: " + destinationpath);
}
}
@@ -50,8 +50,6 @@ public:
// These may in the future be the same.
void initializeWebFieldlinesManager(std::string identifier, size_t& _nStates, std::vector<std::string>& _sourceFiles, std::vector<double>& _startTimes);
bool checkConnectionToServer();
// Returns true or false, wether a successful connection to the field line-providing server has been establish
bool isConnected();
@@ -59,7 +57,7 @@ public:
// Temporary function - this should be moved to the worker. It's to download
// the start lines if the directory is empty or launching for the first time
void preDownload();
void preDownload(std::string dUrl);
// Returns the sync directory
std::string getDirectory();
@@ -41,20 +41,24 @@ namespace {
namespace openspace{
// CONSTRUCTOR
WebFieldlinesWorker::WebFieldlinesWorker(std::string syncDir, std::string serverUrl)
: _serverUrl(serverUrl)
, _syncDir(syncDir){
: _syncDir(syncDir), _serverUrl(serverUrl) {
_endpointSingleDownload = _serverUrl + "WSA/fieldline/"; // should be set by argument to be more general [DEPRICATED FOR NOW, DO WE NEED THIS?]
}
// Destructor, deleting all files that were downloaded during the run.
WebFieldlinesWorker::~WebFieldlinesWorker() {
// Cancel any potential download
if(_downloading && _downloading->hasStarted())
_downloading->cancel();
// Remova all files
std::for_each(_downloadedTriggerTimes.begin(), _downloadedTriggerTimes.end(), [&](auto it) {
FileSys.deleteFile(_syncDir + FileSys.PathSeparator + it.second);
});
if (_downloading && _downloading->hasStarted())
_downloading->wait();
// Remove all files
std::vector<std::string> temp = ghoul::filesystem::Directory(_syncDir).readFiles();
// Sneaky check, just want to make sure it is only deleting fieldlines for now
if (temp.back().substr(temp.back().size() - 5) == "osfls" && temp.front().substr(temp.front().size() - 5) == "osfls") {
std::for_each(temp.begin(), temp.end(), [&](auto it) {
FileSys.deleteFile(it);
});
}
}
// PUBLIC FUNCTIONS
@@ -111,7 +115,7 @@ namespace openspace{
if (_triggerTimesWeb.size() == 0) // We got an empty response
_strikes++;
if (_strikes % 3 == 0){ // We have got 3 strikes, no more requests for you, Mr.Sir.
if (_strikes % 2 == 0){ // We have got 2 strikes, no more requests for you, Mr.Sir.
_noEmptyResponses = false;
acceptableToStartRequestingAgain = std::make_pair(minTime.j2000Seconds(), maxTime.j2000Seconds());
}
@@ -132,6 +136,8 @@ namespace openspace{
bool downloaded = false;
bool oneUpdate = false;
// May be interesting to keep something like this, if it will be possible to use a list of
// AsyncHttpFileDownloads
/*if (auto index = std::find_if(_downloadList.begin(), _downloadList.end(), [](auto element) {
return element.first->hasSucceeded();
}); index != _downloadList.end()) {
@@ -176,10 +182,11 @@ namespace openspace{
}
if (!downloaded && !_doneUpdating && _newWindow && _readyToDownload || oneUpdate) {
if ((!downloaded && !_doneUpdating && _newWindow && _readyToDownload) || oneUpdate) {
// If reach this point, we now know that we have downloaded all the sets
_readyToUpdateSourceFiles = true;
_newWindow = false;
if(!oneUpdate)
_newWindow = false;
oneUpdate = false;
}