mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 13:10:04 +00:00 
			
		
		
		
	Add pre-caluclated smoothed coordinates
This commit is contained in:
		
							parent
							
								
									a8132ef9f1
								
							
						
					
					
						commit
						9f7026bf9c
					
				
					 2 changed files with 114 additions and 50 deletions
				
			
		|  | @ -28,6 +28,7 @@ | ||||||
| #include <boost/timer/timer.hpp> | #include <boost/timer/timer.hpp> | ||||||
| #include <fmt/chrono.h> | #include <fmt/chrono.h> | ||||||
| #include <qmaplibre.hpp> | #include <qmaplibre.hpp> | ||||||
|  | #include <units/angle.h> | ||||||
| 
 | 
 | ||||||
| #if defined(_MSC_VER) | #if defined(_MSC_VER) | ||||||
| #   pragma warning(pop) | #   pragma warning(pop) | ||||||
|  | @ -206,6 +207,13 @@ public: | ||||||
| 
 | 
 | ||||||
|    void UpdateAvailableProductsSync(); |    void UpdateAvailableProductsSync(); | ||||||
| 
 | 
 | ||||||
|  |    void | ||||||
|  |    CalculateCoordinates(const boost::integer_range<std::uint32_t>& radialGates, | ||||||
|  |                         const units::angle::degrees<float>         radialAngle, | ||||||
|  |                         const units::angle::degrees<float>         angleOffset, | ||||||
|  |                         const float         gateRangeOffset, | ||||||
|  |                         std::vector<float>& outputCoordinates); | ||||||
|  | 
 | ||||||
|    static void |    static void | ||||||
|    PopulateProductTimes(std::shared_ptr<ProviderManager> providerManager, |    PopulateProductTimes(std::shared_ptr<ProviderManager> providerManager, | ||||||
|                         RadarProductRecordMap&           productRecordMap, |                         RadarProductRecordMap&           productRecordMap, | ||||||
|  | @ -226,7 +234,9 @@ public: | ||||||
|    std::size_t                        cacheLimit_ {6u}; |    std::size_t                        cacheLimit_ {6u}; | ||||||
| 
 | 
 | ||||||
|    std::vector<float> coordinates0_5Degree_ {}; |    std::vector<float> coordinates0_5Degree_ {}; | ||||||
|  |    std::vector<float> coordinates0_5DegreeSmooth_ {}; | ||||||
|    std::vector<float> coordinates1Degree_ {}; |    std::vector<float> coordinates1Degree_ {}; | ||||||
|  |    std::vector<float> coordinates1DegreeSmooth_ {}; | ||||||
| 
 | 
 | ||||||
|    RadarProductRecordMap  level2ProductRecords_ {}; |    RadarProductRecordMap  level2ProductRecords_ {}; | ||||||
|    RadarProductRecordList level2ProductRecentRecords_ {}; |    RadarProductRecordList level2ProductRecentRecords_ {}; | ||||||
|  | @ -361,14 +371,29 @@ void RadarProductManager::DumpRecords() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const std::vector<float>& | const std::vector<float>& | ||||||
| RadarProductManager::coordinates(common::RadialSize radialSize) const | RadarProductManager::coordinates(common::RadialSize radialSize, | ||||||
|  |                                  bool               smoothingEnabled) const | ||||||
| { | { | ||||||
|    switch (radialSize) |    switch (radialSize) | ||||||
|    { |    { | ||||||
|    case common::RadialSize::_0_5Degree: |    case common::RadialSize::_0_5Degree: | ||||||
|  |       if (smoothingEnabled) | ||||||
|  |       { | ||||||
|  |          return p->coordinates0_5DegreeSmooth_; | ||||||
|  |       } | ||||||
|  |       else | ||||||
|  |       { | ||||||
|          return p->coordinates0_5Degree_; |          return p->coordinates0_5Degree_; | ||||||
|  |       } | ||||||
|    case common::RadialSize::_1Degree: |    case common::RadialSize::_1Degree: | ||||||
|  |       if (smoothingEnabled) | ||||||
|  |       { | ||||||
|  |          return p->coordinates1DegreeSmooth_; | ||||||
|  |       } | ||||||
|  |       else | ||||||
|  |       { | ||||||
|          return p->coordinates1Degree_; |          return p->coordinates1Degree_; | ||||||
|  |       } | ||||||
|    default: |    default: | ||||||
|       throw std::invalid_argument("Invalid radial size"); |       throw std::invalid_argument("Invalid radial size"); | ||||||
|    } |    } | ||||||
|  | @ -430,64 +455,107 @@ void RadarProductManager::Initialize() | ||||||
| 
 | 
 | ||||||
|    boost::timer::cpu_timer timer; |    boost::timer::cpu_timer timer; | ||||||
| 
 | 
 | ||||||
|    const GeographicLib::Geodesic& geodesic( |  | ||||||
|       util::GeographicLib::DefaultGeodesic()); |  | ||||||
| 
 |  | ||||||
|    const QMapLibre::Coordinate radar(p->radarSite_->latitude(), |  | ||||||
|                                      p->radarSite_->longitude()); |  | ||||||
| 
 |  | ||||||
|    const float gateSize = gate_size(); |  | ||||||
| 
 |  | ||||||
|    // Calculate half degree azimuth coordinates
 |    // Calculate half degree azimuth coordinates
 | ||||||
|    timer.start(); |    timer.start(); | ||||||
|    std::vector<float>& coordinates0_5Degree = p->coordinates0_5Degree_; |    std::vector<float>& coordinates0_5Degree = p->coordinates0_5Degree_; | ||||||
| 
 | 
 | ||||||
|    coordinates0_5Degree.resize(NUM_COORIDNATES_0_5_DEGREE); |    coordinates0_5Degree.resize(NUM_COORIDNATES_0_5_DEGREE); | ||||||
| 
 | 
 | ||||||
|    auto radialGates0_5Degree = |    const auto radialGates0_5Degree = | ||||||
|       boost::irange<uint32_t>(0, NUM_RADIAL_GATES_0_5_DEGREE); |       boost::irange<uint32_t>(0, NUM_RADIAL_GATES_0_5_DEGREE); | ||||||
| 
 | 
 | ||||||
|    std::for_each( |    p->CalculateCoordinates( | ||||||
|       std::execution::par_unseq, |       radialGates0_5Degree, | ||||||
|       radialGates0_5Degree.begin(), |       units::angle::degrees<float> {0.5f}, // Radial angle
 | ||||||
|       radialGates0_5Degree.end(), |       units::angle::degrees<float> {0.0f}, // Angle offset
 | ||||||
|       [&](uint32_t radialGate) |       // Far end of the first gate is the gate size distance from the radar site
 | ||||||
|       { |       1.0f, | ||||||
|          const uint16_t gate = |       coordinates0_5Degree); | ||||||
|             static_cast<uint16_t>(radialGate % common::MAX_DATA_MOMENT_GATES); |  | ||||||
|          const uint16_t radial = |  | ||||||
|             static_cast<uint16_t>(radialGate / common::MAX_DATA_MOMENT_GATES); |  | ||||||
| 
 | 
 | ||||||
|          const float  angle  = radial * 0.5f; // 0.5 degree radial
 |  | ||||||
|          const float  range  = (gate + 1) * gateSize; |  | ||||||
|          const size_t offset = radialGate * 2; |  | ||||||
| 
 |  | ||||||
|          double latitude; |  | ||||||
|          double longitude; |  | ||||||
| 
 |  | ||||||
|          geodesic.Direct( |  | ||||||
|             radar.first, radar.second, angle, range, latitude, longitude); |  | ||||||
| 
 |  | ||||||
|          coordinates0_5Degree[offset]     = latitude; |  | ||||||
|          coordinates0_5Degree[offset + 1] = longitude; |  | ||||||
|       }); |  | ||||||
|    timer.stop(); |    timer.stop(); | ||||||
|    logger_->debug("Coordinates (0.5 degree) calculated in {}", |    logger_->debug("Coordinates (0.5 degree) calculated in {}", | ||||||
|                   timer.format(6, "%ws")); |                   timer.format(6, "%ws")); | ||||||
| 
 | 
 | ||||||
|  |    // Calculate half degree smooth azimuth coordinates
 | ||||||
|  |    timer.start(); | ||||||
|  |    std::vector<float>& coordinates0_5DegreeSmooth = | ||||||
|  |       p->coordinates0_5DegreeSmooth_; | ||||||
|  | 
 | ||||||
|  |    coordinates0_5DegreeSmooth.resize(NUM_COORIDNATES_0_5_DEGREE); | ||||||
|  | 
 | ||||||
|  |    p->CalculateCoordinates(radialGates0_5Degree, | ||||||
|  |                            units::angle::degrees<float> {0.5f},  // Radial angle
 | ||||||
|  |                            units::angle::degrees<float> {0.25f}, // Angle offset
 | ||||||
|  |                            // Center of the first gate is half the gate size
 | ||||||
|  |                            // distance from the radar site
 | ||||||
|  |                            0.5f, | ||||||
|  |                            coordinates0_5DegreeSmooth); | ||||||
|  | 
 | ||||||
|  |    timer.stop(); | ||||||
|  |    logger_->debug("Coordinates (0.5 degree smooth) calculated in {}", | ||||||
|  |                   timer.format(6, "%ws")); | ||||||
|  | 
 | ||||||
|    // Calculate 1 degree azimuth coordinates
 |    // Calculate 1 degree azimuth coordinates
 | ||||||
|    timer.start(); |    timer.start(); | ||||||
|    std::vector<float>& coordinates1Degree = p->coordinates1Degree_; |    std::vector<float>& coordinates1Degree = p->coordinates1Degree_; | ||||||
| 
 | 
 | ||||||
|    coordinates1Degree.resize(NUM_COORIDNATES_1_DEGREE); |    coordinates1Degree.resize(NUM_COORIDNATES_1_DEGREE); | ||||||
| 
 | 
 | ||||||
|    auto radialGates1Degree = |    const auto radialGates1Degree = | ||||||
|       boost::irange<uint32_t>(0, NUM_RADIAL_GATES_1_DEGREE); |       boost::irange<uint32_t>(0, NUM_RADIAL_GATES_1_DEGREE); | ||||||
| 
 | 
 | ||||||
|  |    p->CalculateCoordinates( | ||||||
|  |       radialGates1Degree, | ||||||
|  |       units::angle::degrees<float> {1.0f}, // Radial angle
 | ||||||
|  |       units::angle::degrees<float> {0.0f}, // Angle offset
 | ||||||
|  |       // Far end of the first gate is the gate size distance from the radar site
 | ||||||
|  |       1.0f, | ||||||
|  |       coordinates1Degree); | ||||||
|  | 
 | ||||||
|  |    timer.stop(); | ||||||
|  |    logger_->debug("Coordinates (1 degree) calculated in {}", | ||||||
|  |                   timer.format(6, "%ws")); | ||||||
|  | 
 | ||||||
|  |    // Calculate 1 degree smooth azimuth coordinates
 | ||||||
|  |    timer.start(); | ||||||
|  |    std::vector<float>& coordinates1DegreeSmooth = p->coordinates1DegreeSmooth_; | ||||||
|  | 
 | ||||||
|  |    coordinates1DegreeSmooth.resize(NUM_COORIDNATES_1_DEGREE); | ||||||
|  | 
 | ||||||
|  |    p->CalculateCoordinates(radialGates1Degree, | ||||||
|  |                            units::angle::degrees<float> {1.0f}, // Radial angle
 | ||||||
|  |                            units::angle::degrees<float> {0.5f}, // Angle offset
 | ||||||
|  |                            // Center of the first gate is twice the gate size
 | ||||||
|  |                            // distance from the radar site
 | ||||||
|  |                            2.0f, | ||||||
|  |                            coordinates1DegreeSmooth); | ||||||
|  | 
 | ||||||
|  |    timer.stop(); | ||||||
|  |    logger_->debug("Coordinates (1 degree smooth) calculated in {}", | ||||||
|  |                   timer.format(6, "%ws")); | ||||||
|  | 
 | ||||||
|  |    p->initialized_ = true; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void RadarProductManagerImpl::CalculateCoordinates( | ||||||
|  |    const boost::integer_range<std::uint32_t>& radialGates, | ||||||
|  |    const units::angle::degrees<float>         radialAngle, | ||||||
|  |    const units::angle::degrees<float>         angleOffset, | ||||||
|  |    const float                                gateRangeOffset, | ||||||
|  |    std::vector<float>&                        outputCoordinates) | ||||||
|  | { | ||||||
|  |    const GeographicLib::Geodesic& geodesic( | ||||||
|  |       util::GeographicLib::DefaultGeodesic()); | ||||||
|  | 
 | ||||||
|  |    const QMapLibre::Coordinate radar(radarSite_->latitude(), | ||||||
|  |                                      radarSite_->longitude()); | ||||||
|  | 
 | ||||||
|  |    const float gateSize = self_->gate_size(); | ||||||
|  | 
 | ||||||
|    std::for_each( |    std::for_each( | ||||||
|       std::execution::par_unseq, |       std::execution::par_unseq, | ||||||
|       radialGates1Degree.begin(), |       radialGates.begin(), | ||||||
|       radialGates1Degree.end(), |       radialGates.end(), | ||||||
|       [&](uint32_t radialGate) |       [&](uint32_t radialGate) | ||||||
|       { |       { | ||||||
|          const uint16_t gate = |          const uint16_t gate = | ||||||
|  | @ -495,8 +563,8 @@ void RadarProductManager::Initialize() | ||||||
|          const uint16_t radial = |          const uint16_t radial = | ||||||
|             static_cast<uint16_t>(radialGate / common::MAX_DATA_MOMENT_GATES); |             static_cast<uint16_t>(radialGate / common::MAX_DATA_MOMENT_GATES); | ||||||
| 
 | 
 | ||||||
|          const float  angle  = radial * 1.0f; // 1 degree radial
 |          const float angle = radial * radialAngle.value() + angleOffset.value(); | ||||||
|          const float  range  = (gate + 1) * gateSize; |          const float range = (gate + gateRangeOffset) * gateSize; | ||||||
|          const size_t offset = radialGate * 2; |          const size_t offset = radialGate * 2; | ||||||
| 
 | 
 | ||||||
|          double latitude; |          double latitude; | ||||||
|  | @ -505,14 +573,9 @@ void RadarProductManager::Initialize() | ||||||
|          geodesic.Direct( |          geodesic.Direct( | ||||||
|             radar.first, radar.second, angle, range, latitude, longitude); |             radar.first, radar.second, angle, range, latitude, longitude); | ||||||
| 
 | 
 | ||||||
|          coordinates1Degree[offset]     = latitude; |          outputCoordinates[offset]     = latitude; | ||||||
|          coordinates1Degree[offset + 1] = longitude; |          outputCoordinates[offset + 1] = longitude; | ||||||
|       }); |       }); | ||||||
|    timer.stop(); |  | ||||||
|    logger_->debug("Coordinates (1 degree) calculated in {}", |  | ||||||
|                   timer.format(6, "%ws")); |  | ||||||
| 
 |  | ||||||
|    p->initialized_ = true; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| std::shared_ptr<ProviderManager> | std::shared_ptr<ProviderManager> | ||||||
|  |  | ||||||
|  | @ -41,7 +41,8 @@ public: | ||||||
|     */ |     */ | ||||||
|    static void DumpRecords(); |    static void DumpRecords(); | ||||||
| 
 | 
 | ||||||
|    const std::vector<float>& coordinates(common::RadialSize radialSize) const; |    const std::vector<float>&          coordinates(common::RadialSize radialSize, | ||||||
|  |                                                   bool smoothingEnabled) const; | ||||||
|    const scwx::util::time_zone*       default_time_zone() const; |    const scwx::util::time_zone*       default_time_zone() const; | ||||||
|    float                              gate_size() const; |    float                              gate_size() const; | ||||||
|    std::string                        radar_id() const; |    std::string                        radar_id() const; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat