Skip to content

Commit

Permalink
Perform level 3 data moment remapping when smoothing
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaulat committed Dec 8, 2024
1 parent c492f11 commit b7970bb
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 14 deletions.
44 changes: 44 additions & 0 deletions scwx-qt/source/scwx/qt/view/level3_product_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,50 @@ void Level3ProductView::UpdateColorTableLut()
Q_EMIT ColorTableLutUpdated();
}

std::uint8_t Level3ProductView::ComputeEdgeValue() const
{
std::uint8_t edgeValue = 0;

std::shared_ptr<wsr88d::rpg::ProductDescriptionBlock> descriptionBlock =
p->graphicMessage_->description_block();

const float offset = descriptionBlock->offset();
const float scale = descriptionBlock->scale();

switch (p->category_)
{
case common::Level3ProductCategory::Velocity:
edgeValue = (scale > 0.0f) ? (-offset / scale) : -offset;
break;

case common::Level3ProductCategory::DifferentialReflectivity:
edgeValue = -offset;
break;

case common::Level3ProductCategory::SpectrumWidth:
case common::Level3ProductCategory::SpecificDifferentialPhase:
edgeValue = 2;
break;

case common::Level3ProductCategory::CorrelationCoefficient:
edgeValue = static_cast<std::uint8_t>(
std::max<std::uint16_t>(255, descriptionBlock->number_of_levels()));
break;

case common::Level3ProductCategory::Reflectivity:
case common::Level3ProductCategory::StormRelativeVelocity:
case common::Level3ProductCategory::VerticallyIntegratedLiquid:
case common::Level3ProductCategory::EchoTops:
case common::Level3ProductCategory::HydrometeorClassification:
case common::Level3ProductCategory::PrecipitationAccumulation:
default:
edgeValue = 0;
break;
}

return edgeValue;
}

std::optional<wsr88d::DataLevelCode>
Level3ProductView::GetDataLevelCode(std::uint16_t level) const
{
Expand Down
2 changes: 2 additions & 0 deletions scwx-qt/source/scwx/qt/view/level3_product_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class Level3ProductView : public RadarProductView
void DisconnectRadarProductManager() override;
void UpdateColorTableLut() override;

std::uint8_t ComputeEdgeValue() const;

private:
class Impl;
std::unique_ptr<Impl> p;
Expand Down
32 changes: 26 additions & 6 deletions scwx-qt/source/scwx/qt/view/level3_radial_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ class Level3RadialView::Impl
const std::shared_ptr<wsr88d::rpg::GenericRadialDataPacket>& radialData,
bool smoothingEnabled);

inline std::uint8_t RemapDataMoment(std::uint8_t dataMoment) const;

Level3RadialView* self_;

boost::asio::thread_pool threadPool_ {1u};

std::vector<float> coordinates_ {};
std::vector<float> vertices_ {};
std::vector<std::uint8_t> dataMoments8_ {};
std::uint8_t edgeValue_ {};

std::shared_ptr<wsr88d::rpg::GenericRadialDataPacket> lastRadialData_ {};
bool lastSmoothingEnabled_ {false};
Expand Down Expand Up @@ -347,6 +350,10 @@ void Level3RadialView::ComputeSweep()
// are skipping the radar site origin. The end gate is unaffected, as
// we need to draw one less data point.
++startGate;

// For most products other than reflectivity, the edge should not go to
// the bottom of the color table
p->edgeValue_ = ComputeEdgeValue();
}

for (std::uint16_t radial = 0; radial < radialData->number_of_radials();
Expand Down Expand Up @@ -401,12 +408,12 @@ void Level3RadialView::ComputeSweep()
}

// The order must match the store vertices section below
dataMoments8[mIndex++] = dm1;
dataMoments8[mIndex++] = dm2;
dataMoments8[mIndex++] = dm4;
dataMoments8[mIndex++] = dm1;
dataMoments8[mIndex++] = dm3;
dataMoments8[mIndex++] = dm4;
dataMoments8[mIndex++] = p->RemapDataMoment(dm1);
dataMoments8[mIndex++] = p->RemapDataMoment(dm2);
dataMoments8[mIndex++] = p->RemapDataMoment(dm4);
dataMoments8[mIndex++] = p->RemapDataMoment(dm1);
dataMoments8[mIndex++] = p->RemapDataMoment(dm3);
dataMoments8[mIndex++] = p->RemapDataMoment(dm4);
}
else
{
Expand Down Expand Up @@ -492,6 +499,19 @@ void Level3RadialView::ComputeSweep()
Q_EMIT SweepComputed();
}

std::uint8_t
Level3RadialView::Impl::RemapDataMoment(std::uint8_t dataMoment) const
{
if (dataMoment != 0)
{
return dataMoment;
}
else
{
return edgeValue_;
}
}

void Level3RadialView::Impl::ComputeCoordinates(
const std::shared_ptr<wsr88d::rpg::GenericRadialDataPacket>& radialData,
bool smoothingEnabled)
Expand Down
39 changes: 31 additions & 8 deletions scwx-qt/source/scwx/qt/view/level3_raster_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ class Level3RasterViewImpl
}
~Level3RasterViewImpl() { threadPool_.join(); };

inline std::uint8_t RemapDataMoment(std::uint8_t dataMoment) const;

boost::asio::thread_pool threadPool_ {1u};

std::vector<float> vertices_;
std::vector<uint8_t> dataMoments8_;
std::vector<float> vertices_ {};
std::vector<std::uint8_t> dataMoments8_ {};
std::uint8_t edgeValue_ {};

std::shared_ptr<wsr88d::rpg::RasterDataPacket> lastRasterData_ {};
bool lastSmoothingEnabled_ {false};
Expand Down Expand Up @@ -310,6 +313,13 @@ void Level3RasterView::ComputeSweep()
rasterData->number_of_rows() - 1 :
rasterData->number_of_rows();

if (smoothingEnabled)
{
// For most products other than reflectivity, the edge should not go to
// the bottom of the color table
p->edgeValue_ = ComputeEdgeValue();
}

for (std::size_t row = 0; row < rowCount; ++row)
{
const std::size_t nextRow =
Expand Down Expand Up @@ -364,12 +374,12 @@ void Level3RasterView::ComputeSweep()
}

// The order must match the store vertices section below
dataMoments8[mIndex++] = dm1;
dataMoments8[mIndex++] = dm2;
dataMoments8[mIndex++] = dm4;
dataMoments8[mIndex++] = dm1;
dataMoments8[mIndex++] = dm3;
dataMoments8[mIndex++] = dm4;
dataMoments8[mIndex++] = p->RemapDataMoment(dm1);
dataMoments8[mIndex++] = p->RemapDataMoment(dm2);
dataMoments8[mIndex++] = p->RemapDataMoment(dm4);
dataMoments8[mIndex++] = p->RemapDataMoment(dm1);
dataMoments8[mIndex++] = p->RemapDataMoment(dm3);
dataMoments8[mIndex++] = p->RemapDataMoment(dm4);
}

// Store vertices
Expand Down Expand Up @@ -411,6 +421,19 @@ void Level3RasterView::ComputeSweep()
Q_EMIT SweepComputed();
}

std::uint8_t
Level3RasterViewImpl::RemapDataMoment(std::uint8_t dataMoment) const
{
if (dataMoment != 0)
{
return dataMoment;
}
else
{
return edgeValue_;
}
}

std::optional<std::uint16_t>
Level3RasterView::GetBinLevel(const common::Coordinate& coordinate) const
{
Expand Down

0 comments on commit b7970bb

Please sign in to comment.