mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 22:00:05 +00:00
Support selecting level 2 files for display
This commit is contained in:
parent
1655a7c571
commit
95de37cab4
8 changed files with 125 additions and 78 deletions
|
|
@ -63,6 +63,8 @@ public:
|
|||
}
|
||||
~RadarProductManagerImpl() = default;
|
||||
|
||||
std::shared_ptr<types::RadarProductRecord>
|
||||
GetLevel2ProductRecord(std::chrono::system_clock::time_point time);
|
||||
std::shared_ptr<types::RadarProductRecord>
|
||||
StoreRadarProductRecord(std::shared_ptr<types::RadarProductRecord> record);
|
||||
|
||||
|
|
@ -85,10 +87,6 @@ public:
|
|||
std::map<std::chrono::system_clock::time_point,
|
||||
std::shared_ptr<types::RadarProductRecord>>>
|
||||
level3ProductRecords_;
|
||||
|
||||
std::map<std::chrono::system_clock::time_point,
|
||||
std::shared_ptr<wsr88d::Ar2vFile>>
|
||||
level2VolumeScans_;
|
||||
};
|
||||
|
||||
RadarProductManager::RadarProductManager(const std::string& radarId) :
|
||||
|
|
@ -114,18 +112,6 @@ std::shared_ptr<config::RadarSite> RadarProductManager::radar_site() const
|
|||
return p->radarSite_;
|
||||
}
|
||||
|
||||
std::shared_ptr<const wsr88d::Ar2vFile> RadarProductManager::level2_data() const
|
||||
{
|
||||
std::shared_ptr<const wsr88d::Ar2vFile> level2Data = nullptr;
|
||||
|
||||
if (p->level2VolumeScans_.size() > 0)
|
||||
{
|
||||
level2Data = p->level2VolumeScans_.crbegin()->second;
|
||||
}
|
||||
|
||||
return level2Data;
|
||||
}
|
||||
|
||||
void RadarProductManager::Initialize()
|
||||
{
|
||||
if (p->initialized_)
|
||||
|
|
@ -315,25 +301,50 @@ void RadarProductManagerImpl::LoadNexradFile(
|
|||
});
|
||||
}
|
||||
|
||||
void RadarProductManager::LoadLevel2Data(const std::string& filename)
|
||||
std::shared_ptr<types::RadarProductRecord>
|
||||
RadarProductManagerImpl::GetLevel2ProductRecord(
|
||||
std::chrono::system_clock::time_point time)
|
||||
{
|
||||
std::shared_ptr<wsr88d::Ar2vFile> ar2vFile =
|
||||
std::make_shared<wsr88d::Ar2vFile>();
|
||||
std::shared_ptr<types::RadarProductRecord> record = nullptr;
|
||||
|
||||
if (!p->initialized_)
|
||||
// TODO: Round to minutes
|
||||
|
||||
// Find the first product record greater than the time requested
|
||||
auto it = level2ProductRecords_.upper_bound(time);
|
||||
|
||||
// A product record with a time greater was found
|
||||
if (it != level2ProductRecords_.cend())
|
||||
{
|
||||
Initialize();
|
||||
// Are there product records prior to this record?
|
||||
if (it != level2ProductRecords_.cbegin())
|
||||
{
|
||||
// Get the product record immediately preceding, this the record we are
|
||||
// looking for
|
||||
--it;
|
||||
|
||||
// Does the record contain the time we are looking for?
|
||||
if (it->second->level2_file()->start_time() <= time &&
|
||||
time <= it->second->level2_file()->end_time())
|
||||
{
|
||||
record = it->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (level2ProductRecords_.size() > 0)
|
||||
{
|
||||
// A product record with a time greater was not found. If it exists, it
|
||||
// must be the last record.
|
||||
auto rit = level2ProductRecords_.rbegin();
|
||||
|
||||
// Does the record contain the time we are looking for?
|
||||
if (rit->second->level2_file()->start_time() <= time &&
|
||||
time <= rit->second->level2_file()->end_time())
|
||||
{
|
||||
record = rit->second;
|
||||
}
|
||||
}
|
||||
|
||||
bool success = ar2vFile->LoadFile(filename);
|
||||
if (!success)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
p->level2VolumeScans_[ar2vFile->start_time()] = ar2vFile;
|
||||
|
||||
emit Level2DataLoaded();
|
||||
return record;
|
||||
}
|
||||
|
||||
std::shared_ptr<types::RadarProductRecord>
|
||||
|
|
@ -393,30 +404,15 @@ RadarProductManager::GetLevel2Data(wsr88d::rda::DataBlockType dataBlockType,
|
|||
float elevationCut = 0.0f;
|
||||
std::vector<float> elevationCuts;
|
||||
|
||||
if (p->level2VolumeScans_.size() > 0)
|
||||
std::shared_ptr<types::RadarProductRecord> record =
|
||||
p->GetLevel2ProductRecord(time);
|
||||
|
||||
if (record != nullptr)
|
||||
{
|
||||
std::tie(radarData, elevationCut, elevationCuts) =
|
||||
p->level2VolumeScans_.crbegin()->second->GetElevationScan(
|
||||
record->level2_file()->GetElevationScan(
|
||||
dataBlockType, elevation, time);
|
||||
}
|
||||
else
|
||||
{
|
||||
scwx::util::async(
|
||||
[&]()
|
||||
{
|
||||
std::unique_lock lock(fileLoadMutex_);
|
||||
|
||||
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Start load";
|
||||
|
||||
QString filename = qgetenv("AR2V_FILE");
|
||||
if (!filename.isEmpty() && p->level2VolumeScans_.size() == 0)
|
||||
{
|
||||
LoadLevel2Data(filename.toUtf8().constData());
|
||||
}
|
||||
|
||||
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "End load";
|
||||
});
|
||||
}
|
||||
|
||||
return std::tie(radarData, elevationCut, elevationCuts);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,11 +32,7 @@ public:
|
|||
const std::vector<float>& coordinates(common::RadialSize radialSize) const;
|
||||
std::shared_ptr<config::RadarSite> radar_site() const;
|
||||
|
||||
// TODO: Improve this interface
|
||||
std::shared_ptr<const wsr88d::Ar2vFile> level2_data() const;
|
||||
|
||||
void Initialize();
|
||||
void LoadLevel2Data(const std::string& filename);
|
||||
|
||||
std::tuple<std::shared_ptr<wsr88d::rda::ElevationScan>,
|
||||
float,
|
||||
|
|
@ -55,9 +51,6 @@ public:
|
|||
LoadFile(const std::string& filename,
|
||||
std::shared_ptr<request::NexradFileRequest> request = nullptr);
|
||||
|
||||
signals:
|
||||
void Level2DataLoaded();
|
||||
|
||||
private:
|
||||
std::unique_ptr<RadarProductManagerImpl> p;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue