Load radar data asynchronously

This commit is contained in:
Dan Paulat 2021-11-11 23:47:27 -06:00
parent 803a25e884
commit 3625515b8a
6 changed files with 71 additions and 13 deletions

View file

@ -1,5 +1,6 @@
#include <scwx/qt/manager/radar_product_manager.hpp>
#include <scwx/common/constants.hpp>
#include <scwx/util/threads.hpp>
#include <deque>
#include <execution>
@ -182,6 +183,33 @@ void RadarProductManager::LoadLevel2Data(const std::string& filename)
emit Level2DataLoaded();
}
std::unordered_map<uint16_t, std::shared_ptr<wsr88d::rda::DigitalRadarData>>
RadarProductManager::GetLevel2Data(wsr88d::rda::DataBlockType dataBlockType,
uint8_t elevationIndex,
std::chrono::system_clock::time_point time)
{
std::unordered_map<uint16_t, std::shared_ptr<wsr88d::rda::DigitalRadarData>>
radarData;
if (p->level2Data_.size() > 0)
{
// TODO: Pull this from the database
radarData = p->level2Data_[0]->radar_data()[elevationIndex];
}
else
{
scwx::util::async([&]() {
QString filename = qgetenv("AR2V_FILE");
if (!filename.isEmpty())
{
LoadLevel2Data(filename.toUtf8().constData());
}
});
}
return radarData;
}
} // namespace manager
} // namespace qt
} // namespace scwx

View file

@ -33,6 +33,11 @@ public:
void Initialize();
void LoadLevel2Data(const std::string& filename);
std::unordered_map<uint16_t, std::shared_ptr<wsr88d::rda::DigitalRadarData>>
GetLevel2Data(wsr88d::rda::DataBlockType dataBlockType,
uint8_t elevationIndex,
std::chrono::system_clock::time_point time = {});
signals:
void Level2DataLoaded();

View file

@ -77,11 +77,6 @@ MapWidget::MapWidget(const QMapboxGLSettings& settings) :
setFocusPolicy(Qt::StrongFocus);
p->radarProductManager_->Initialize();
QString ar2vFile = qgetenv("AR2V_FILE");
if (!ar2vFile.isEmpty())
{
p->radarProductManager_->LoadLevel2Data(ar2vFile.toUtf8().constData());
}
SelectRadarProduct(common::Level2Product::Reflectivity);
}
@ -110,6 +105,19 @@ void MapWidget::SelectRadarProduct(common::Level2Product product)
p->radarProductView_->LoadColorTable(colorTable);
}
connect(
p->radarProductView_.get(),
&view::RadarProductView::ColorTableUpdated,
this,
[&]() { update(); },
Qt::QueuedConnection);
connect(
p->radarProductView_.get(),
&view::RadarProductView::SweepComputed,
this,
[&]() { update(); },
Qt::QueuedConnection);
if (p->map_ != nullptr)
{
AddLayers();

View file

@ -236,19 +236,19 @@ void Level2ProductView::ComputeSweep()
return;
}
std::shared_ptr<const wsr88d::Ar2vFile> level2Data =
p->radarProductManager_->level2_data();
if (level2Data == nullptr)
// TODO: Pick this based on view settings
auto radarData =
p->radarProductManager_->GetLevel2Data(p->dataBlockType_, 0);
if (radarData.size() == 0)
{
return;
}
// TODO: Pick this based on radar data
const common::RadialSize radialSize = (radarData.size() == 720) ?
common::RadialSize::_0_5Degree :
common::RadialSize::_1Degree;
const std::vector<float>& coordinates =
p->radarProductManager_->coordinates(common::RadialSize::_0_5Degree);
// TODO: Pick this based on view settings
auto radarData = level2Data->radar_data()[0];
p->radarProductManager_->coordinates(radialSize);
auto momentData0 = radarData[0]->moment_data_block(p->dataBlockType_);
p->momentDataBlock0_ = momentData0;