mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-07 03:49:43 -05:00
Read ionosphere data from json file
This commit is contained in:
@@ -35,13 +35,13 @@ function postInitialization()
|
||||
--openspace.iswa.addCygnet("-2,Data,1");
|
||||
--openspace.iswa.addCygnet("-3,Data,1");
|
||||
|
||||
--[[
|
||||
openspace.iswa.addScreenSpaceCygnet(
|
||||
{
|
||||
CygnetId = 2,
|
||||
Position = {-0.8, 0.3},
|
||||
Scale = 0.2
|
||||
});
|
||||
--[[
|
||||
{
|
||||
Type = "ScreenSpaceCygnet",
|
||||
CygnetId = 7,
|
||||
|
||||
@@ -37,7 +37,7 @@ CygnetSphere::CygnetSphere(const ghoul::Dictionary& dictionary)
|
||||
CygnetSphere::~CygnetSphere(){}
|
||||
|
||||
bool CygnetSphere::createGeometry(){
|
||||
PowerScaledScalar radius = PowerScaledScalar(3*6.371f, 6.0);
|
||||
PowerScaledScalar radius = PowerScaledScalar(6.371f, 6.01);
|
||||
int segments = 100;
|
||||
_sphere = std::make_shared<PowerScaledSphere>(radius, segments);
|
||||
_sphere->initialize();
|
||||
|
||||
@@ -128,7 +128,6 @@ bool DataPlane::loadTexture() {
|
||||
_dataBuffer.append(dataFile.buffer, dataFile.size);
|
||||
}
|
||||
|
||||
|
||||
// if the buffer in the datafile is empty, do not proceed
|
||||
if(_dataBuffer.empty())
|
||||
return false;
|
||||
|
||||
@@ -94,6 +94,8 @@ DataSphere::DataSphere(const ghoul::Dictionary& dictionary)
|
||||
|
||||
|
||||
_type = IswaManager::CygnetType::Data;
|
||||
_dataBuffer = "";
|
||||
_data->frame = "SM";
|
||||
}
|
||||
|
||||
DataSphere::~DataSphere(){}
|
||||
@@ -108,15 +110,15 @@ void DataSphere::backgroundValues(glm::vec2 backgroundValues){ _backgroundValues
|
||||
bool DataSphere::loadTexture(){
|
||||
|
||||
// if The future is done then get the new dataFile
|
||||
if(_futureObject.valid() && DownloadManager::futureReady(_futureObject)){
|
||||
DownloadManager::MemoryFile dataFile = _futureObject.get();
|
||||
// if(_futureObject.valid() && DownloadManager::futureReady(_futureObject)){
|
||||
// DownloadManager::MemoryFile dataFile = _futureObject.get();
|
||||
|
||||
if(dataFile.corrupted)
|
||||
return false;
|
||||
// if(dataFile.corrupted)
|
||||
// return false;
|
||||
|
||||
_dataBuffer = "";
|
||||
_dataBuffer.append(dataFile.buffer, dataFile.size);
|
||||
}
|
||||
// _dataBuffer = "";
|
||||
// _dataBuffer.append(dataFile.buffer, dataFile.size);
|
||||
// }
|
||||
|
||||
|
||||
// if the buffer in the datafile is empty, do not proceed
|
||||
@@ -124,9 +126,9 @@ bool DataSphere::loadTexture(){
|
||||
return false;
|
||||
|
||||
if(!_dataOptions.options().size()){ // load options for value selection
|
||||
std::vector<std::string> options = _dataProcessor->readHeader(_dataBuffer);
|
||||
std::vector<std::string> options = _dataProcessor->readJSONHeader(_dataBuffer);
|
||||
for(int i=0; i<options.size(); i++){
|
||||
_dataOptions.addOption({i, name()+"_"+options[i]});
|
||||
_dataOptions.addOption({i, name()+"/"+options[i]});
|
||||
_textures.push_back(nullptr);
|
||||
}
|
||||
_dataOptions.setValue(std::vector<int>(1,0));
|
||||
@@ -134,7 +136,7 @@ bool DataSphere::loadTexture(){
|
||||
IswaManager::ref().registerOptionsToGroup(_data->groupId, _dataOptions.options());
|
||||
}
|
||||
|
||||
std::vector<float*> data = _dataProcessor->readData(_dataBuffer, _dataOptions);
|
||||
std::vector<float*> data = _dataProcessor->readJSONData(_dataBuffer, _dataOptions);
|
||||
|
||||
if(data.empty())
|
||||
return false;
|
||||
@@ -169,19 +171,29 @@ bool DataSphere::loadTexture(){
|
||||
texturesReady = true;
|
||||
}
|
||||
|
||||
return texturesReady;
|
||||
// _dataBuffer = "";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DataSphere::updateTexture(){
|
||||
if(_futureObject.valid())
|
||||
return false;
|
||||
|
||||
std::future<DownloadManager::MemoryFile> future = IswaManager::ref().fetchDataCygnet(_data->id);
|
||||
|
||||
if(future.valid()){
|
||||
_futureObject = std::move(future);
|
||||
if(_dataBuffer == ""){
|
||||
std::ifstream data(absPath("${OPENSPACE_DATA}/ionosphere_variables.json"));
|
||||
std::stringstream buffer;
|
||||
buffer << data.rdbuf();
|
||||
_dataBuffer = buffer.str();
|
||||
std::cout << "data in buffer" << std::endl;
|
||||
// loadTexture();
|
||||
return true;
|
||||
}
|
||||
// if(_futureObject.valid())
|
||||
// return false;
|
||||
|
||||
// std::future<DownloadManager::MemoryFile> future = IswaManager::ref().fetchDataCygnet(_data->id);
|
||||
|
||||
// if(future.valid()){
|
||||
// _futureObject = std::move(future);
|
||||
// return true;
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ Fragment getFragment() {
|
||||
|
||||
if((numTransferFunctions == 1) || (numTextures > numTransferFunctions)){
|
||||
for(int i=0; i<numTextures; i++){
|
||||
v += texture(textures[i], vec2(vs_st.s, 1-vs_st.t)).r;
|
||||
v += texture(textures[i], vec2(vs_st.t, vs_st.s)).r;
|
||||
}
|
||||
v /= numTextures;
|
||||
|
||||
@@ -64,7 +64,7 @@ Fragment getFragment() {
|
||||
diffuse = color;
|
||||
}else{
|
||||
for(int i=0; i<numTextures; i++){
|
||||
v = texture(textures[i], vec2(vs_st.s, 1-vs_st.t)).r;
|
||||
v = texture(textures[i], vec2(vs_st.t, vs_st.s)).r;
|
||||
vec4 color = texture(transferFunctions[i], vec2(v,0));
|
||||
diffuse += color;
|
||||
}
|
||||
@@ -73,6 +73,7 @@ Fragment getFragment() {
|
||||
if (diffuse.a <= backgroundValues.y)
|
||||
discard;
|
||||
|
||||
// diffuse = vec4(vs_st.s, 0,0,1);
|
||||
Fragment frag;
|
||||
frag.color = diffuse;
|
||||
frag.depth = depth;
|
||||
|
||||
@@ -34,9 +34,11 @@
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <modules/iswa/util/iswamanager.h>
|
||||
#include <modules/iswa/ext/json/json.hpp>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "DataPlane";
|
||||
using json = nlohmann::json;
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
@@ -88,6 +90,27 @@ std::vector<std::string> DataProcessor::readHeader(std::string& dataBuffer){
|
||||
return options;
|
||||
}
|
||||
|
||||
std::vector<std::string> DataProcessor::readJSONHeader(std::string& dataBuffer){
|
||||
std::vector<std::string> options = std::vector<std::string>();
|
||||
if(!dataBuffer.empty()){
|
||||
json j = json::parse(dataBuffer);
|
||||
json var = j["variables"];
|
||||
for (json::iterator it = var.begin(); it != var.end(); ++it) {
|
||||
std::string option = it.key();
|
||||
if(option == "x"){
|
||||
json lon = it.value();
|
||||
json lat = lon.at(0);
|
||||
|
||||
_dimensions = glm::size3_t(lon.size(), lat.size(), 1);
|
||||
}
|
||||
if(option != "x" && option != "y" && option != "z"){
|
||||
options.push_back(option);
|
||||
}
|
||||
}
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
std::vector<float*> DataProcessor::readData(std::string& dataBuffer, properties::SelectionProperty dataOptions){
|
||||
if(!dataBuffer.empty()){
|
||||
// if(!_dataOptions.options().size()) // load options for value selection
|
||||
@@ -182,6 +205,145 @@ std::vector<float*> DataProcessor::readData(std::string& dataBuffer, properties:
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<float*> DataProcessor::readJSONData(std::string& dataBuffer, properties::SelectionProperty dataOptions){
|
||||
std::cout << "Reading JSON Data" << std::endl;
|
||||
if(!dataBuffer.empty()){
|
||||
json j = json::parse(dataBuffer);
|
||||
json var = j["variables"];
|
||||
|
||||
|
||||
// if(!_dataOptions.options().size()) // load options for value selection
|
||||
// readHeader(dataBuffer);
|
||||
|
||||
// std::stringstream memorystream(dataBuffer);
|
||||
// std::string line;
|
||||
|
||||
std::vector<int> selectedOptions = dataOptions.value();
|
||||
int numSelected = selectedOptions.size();
|
||||
|
||||
std::vector<float> min(numSelected, std::numeric_limits<float>::max());
|
||||
std::vector<float> max(numSelected, std::numeric_limits<float>::min());
|
||||
|
||||
std::vector<float> sum(numSelected, 0.0f);
|
||||
std::vector<std::vector<float>> optionValues(numSelected, std::vector<float>());
|
||||
|
||||
auto options = dataOptions.options();
|
||||
|
||||
std::vector<float*> data(options.size(), nullptr);
|
||||
int i = 0;
|
||||
for(int option : selectedOptions){
|
||||
std::cout << option << " " << options[option].description << std::endl;
|
||||
data[option] = new float[_dimensions.x*_dimensions.y]{0.0f};
|
||||
|
||||
std::stringstream memorystream(options[option].description);
|
||||
std::string optionName;
|
||||
getline(memorystream, optionName, '/');
|
||||
getline(memorystream, optionName, '/');
|
||||
std::cout << optionName << std::endl;
|
||||
|
||||
json valueArray = var[optionName];
|
||||
int ySize = valueArray.size();
|
||||
|
||||
for(int y=0; y<valueArray.size(); y++){
|
||||
json values = valueArray.at(y);
|
||||
for(int x=0; x<values.size(); x++){
|
||||
float v = values.at(x);
|
||||
// std::cout << v << std::endl;
|
||||
if(_useLog){
|
||||
int sign = (v>0)? 1:-1;
|
||||
if(v != 0){
|
||||
v = sign*log(fabs(v));
|
||||
}
|
||||
}
|
||||
|
||||
optionValues[i].push_back(v);
|
||||
|
||||
min[i] = std::min(min[i], v);
|
||||
max[i] = std::max(max[i], v);
|
||||
|
||||
sum[i] += v;
|
||||
}
|
||||
// break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
for(int i=0; i<numSelected; i++){
|
||||
processData(data[ selectedOptions[i] ], optionValues[i], min[i], max[i], sum[i]);
|
||||
}
|
||||
|
||||
return data;
|
||||
// int numValues = 0;
|
||||
// while(getline(memorystream, line)){
|
||||
// if(line.find("#") == 0){ //part of the header
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// std::stringstream ss(line);
|
||||
// std::vector<float> value;
|
||||
// float v;
|
||||
// while(ss >> v){
|
||||
// value.push_back(v);
|
||||
// }
|
||||
|
||||
// if(value.size()){
|
||||
// for(int i=0; i<numSelected; i++){
|
||||
|
||||
// float v = value[selectedOptions[i]+3]; //+3 because "options" x, y and z.
|
||||
|
||||
// if(_useLog){
|
||||
// int sign = (v>0)? 1:-1;
|
||||
// if(v != 0){
|
||||
// v = sign*log(fabs(v));
|
||||
// }
|
||||
// }
|
||||
|
||||
// optionValues[i].push_back(v);
|
||||
|
||||
// min[i] = std::min(min[i], v);
|
||||
// max[i] = std::max(max[i], v);
|
||||
|
||||
// sum[i] += v;
|
||||
// }
|
||||
// numValues++;
|
||||
// }
|
||||
// }
|
||||
// // std::cout << "Actual size: " << numValues << " Expected: " << _dimensions.x*_dimensions.y << std::endl;
|
||||
// if(numValues != _dimensions.x*_dimensions.y){
|
||||
// LWARNING("Number of values read and expected are not the same");
|
||||
// return std::vector<float*>();
|
||||
// }
|
||||
|
||||
// // FOR TESTING
|
||||
// // ===========
|
||||
// // std::chrono::time_point<std::chrono::system_clock> start, end;
|
||||
// // start = std::chrono::system_clock::now();
|
||||
// // ===========
|
||||
|
||||
// for(int i=0; i<numSelected; i++){
|
||||
// processData(data[ selectedOptions[i] ], optionValues[i], min[i], max[i], sum[i]);
|
||||
// }
|
||||
|
||||
// FOR TESTING
|
||||
// ===========
|
||||
// end = std::chrono::system_clock::now();
|
||||
// _numOfBenchmarks++;
|
||||
// std::chrono::duration<double> elapsed_seconds = end-start;
|
||||
// _avgBenchmarkTime = ( (_avgBenchmarkTime * (_numOfBenchmarks-1)) + elapsed_seconds.count() ) / _numOfBenchmarks;
|
||||
// std::cout << " readData():" << std::endl;
|
||||
// std::cout << "avg elapsed time: " << _avgBenchmarkTime << "s\n";
|
||||
// std::cout << "num Benchmarks: " << _numOfBenchmarks << "\n";
|
||||
// ===========
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
// LWARNING("Nothing in memory buffer, are you connected to the information super highway?");
|
||||
return std::vector<float*>();
|
||||
}
|
||||
// return std::vector<float*>();
|
||||
}
|
||||
|
||||
void DataProcessor::processData(float* outputData, std::vector<float>& inputData, float min, float max,float sum){
|
||||
|
||||
// HISTOGRAM
|
||||
|
||||
@@ -57,6 +57,10 @@ public:
|
||||
|
||||
std::vector<std::string> readHeader(std::string& dataBuffer);
|
||||
std::vector<float*> readData(std::string& dataBuffer, properties::SelectionProperty dataOptions);
|
||||
|
||||
std::vector<std::string> readJSONHeader(std::string& dataBuffer);
|
||||
std::vector<float*> readJSONData(std::string& dataBuffer, properties::SelectionProperty dataOptions);
|
||||
|
||||
|
||||
private:
|
||||
void processData(
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
_kameleonFrames = { "J2000", "GEI", "GEO", "MAG", "GSE", "GSM", "SM", "RTN", "GSEQ", //geocentric
|
||||
"HEE", "HAE", "HEEQ" //heliocentric
|
||||
};
|
||||
_dipoleFrames = {"GSM", "SM", "MAG"};
|
||||
// _dipoleFrames = {"GSM", "MAG"};
|
||||
}
|
||||
|
||||
TransformationManager::~TransformationManager(){
|
||||
@@ -55,9 +55,9 @@
|
||||
auto fromit = _dipoleFrames.find(from);
|
||||
auto toit = _dipoleFrames.find(to);
|
||||
|
||||
//diopole frame to J200 makes the frame rotate.
|
||||
if(fromit != _dipoleFrames.end()) from = "GSE";
|
||||
if(toit != _dipoleFrames.end()) to = "GSE";
|
||||
// //diopole frame to J200 makes the frame rotate.
|
||||
// if(fromit != _dipoleFrames.end()) from = "GSE";
|
||||
// if(toit != _dipoleFrames.end()) to = "GSE";
|
||||
|
||||
fromit = _kameleonFrames.find(from);
|
||||
toit = _kameleonFrames.find(to);
|
||||
|
||||
Reference in New Issue
Block a user