Skip to content

Conversation

@sebastien-rosset
Copy link
Owner

@sebastien-rosset sebastien-rosset commented Jan 3, 2025

Add Multi-Layer Support to GRIB Plugin

This PR introduces multi-layer support to the GRIB plugin, enabling users to load and manage multiple GRIB files independently. Each file can be toggled on/off and managed separately, while maintaining compatibility with existing functionality.

Key Changes

New Layer Architecture

  1. Added GRIBLayer class to encapsulate individual GRIB files and their settings. Each GribLayer can be associated with one GRIB file. For example, there might be one GRIB file for current and another file for wind. Or one GRIB file with 48 hour high accuracy wind forecast and another GRIB file with 7-day wind forecast at lower accuracy.
  2. Added GRIBLayerSet to manage multiple layers with shared functionality.
    • GRIB layers that can be loaded, unloaded, enabled and disabled independently.
    • Ability to load two different forecast models with the same properties (e.g. "wind"), such as one layer for the HRRR model and another layer for the GFS model.
  3. Refactored GRIBFile from managing multiple files to single file per instance.
  4. Added compatibility layer in GRIBLayerSet to mirror existing GRIBFile interface
  5. Added comprehensive unit tests for new layer functionality

Changes are in the data model and UI.

Code Organization

Split GRIB-related code into separate files for better maintainability:

  • grib_file.[h|cpp]

    • Core GRIB file parsing and data management
    • Single file responsibility
    • Record set organization
  • grib_layer.[h|cpp]

    • Layer state management (enable/disable)
    • Layer-specific settings
    • File ownership and lifecycle
  • grib_layer_set.[h|cpp]

    • Layer coordination and management
    • Data merging across layers
    • Compatibility interface
  • grib_timeline_record_set.h

    • Timeline interpolation functionality
    • Record caching
    • Visualization optimizations

Implementation Details

Migration Strategy

Migrated from single file to multi-layer architecture:

// Old approach
GRIBFile* m_bGRIBActiveFile;  // Managed multiple files

// New approach
GRIBLayerSet m_LayerSet;      // Manages multiple layers

Key Method Updates

Updated core functionality to support layers:

  • Timeline Management

    GribTimelineRecordSet* GetTimeLineRecordSet(wxDateTime time)
    • Interpolates across all enabled layers
    • Maintains temporal consistency
    • Optimizes cache usage
  • Data Access

    double GetTimeInterpolatedValue(int idx, double lon, double lat, wxDateTime time)
    • Accesses data from appropriate layer
    • Handles layer enable/disable state
    • Maintains backward compatibility
  • Index Management

    GRIBFile::GribIdxArray& GetGribIdxArray()
    • Merges indices across enabled layers
    • Eliminates duplicates
    • Updates dynamically with layer state

Testing Infrastructure

Added comprehensive test suite in tests/ directory:

tests/
├── CMakeLists.txt           # Test configuration
├── README.md               # Testing documentation
├── grib_layer_test.cpp    # Layer tests
├── grib_layer_set_test.cpp # Layer set tests
├── mock_defs.cpp          # Mock implementations
└── testdata/              # Test GRIB files

Test coverage includes:

  • Layer creation and management
  • Layer set operations
  • Data merging and access
  • Timeline interpolation
  • Compatibility interface
  • Error handling
  • Memory management

Tasks

Backend

  • Implement Layer Manager (set of layers).
  • Implement Layer.
  • Replace all references to m_bGRIBActiveFile with m_LayerSet which represents layer manager.
    • m_bGRIBActiveFile->m_GribIdxArraym_LayerSet.GetGribIdxArray(). GribIdxArray is a structured array of integers, each representing a unique GRIB parameter and its vertical level information. This array is used to track what meteorological parameters are available in a GRIB file or layer.
    • m_bGRIBActiveFile->GetRecordSetArrayPtr(). ArrayOfGribRecordSets is an array of GribRecordSets in a GRIB file.
    • m_pGDialog->GetTimeLineRecordSet(time)m_pGDialog->m_LayerSet.GetTimeLineRecordSet(time)
  • Integration of Layer Manager with GRIB control bar.
  • Document numerical weather prediction model and data center (HRRR, GFS, ECMWF...)
  • Document functions, MagnitudeRecord

Unit Tests

  • Improve Makefile to support unit tests.

UI Changes

  • Layer management - Add/Remove layers - Load Grib files in layer.
  • Layer visibility controls (enable/disable layer).
  • Layer ordering (ability to reorder layers).
  • Layer-specific settings.
  • Refactor RenderGribIsobar
  • Refactor RenderGribNumbers
  • Refactor RenderGribOverlayMap
  • Refactor RenderGribParticles
  • Refactor RenderGribBarbedArrows

Draft implementation for OpenCPN#4228

@sebastien-rosset sebastien-rosset force-pushed the multi-grib-v2 branch 4 times, most recently from c232d74 to 17920eb Compare January 20, 2025 11:08
@sebastien-rosset sebastien-rosset changed the title Multi-grib support v2 Multi-layer GRIB support Jan 20, 2025
@sebastien-rosset sebastien-rosset force-pushed the multi-grib-v2 branch 7 times, most recently from 8a7e44c to c68b527 Compare January 21, 2025 13:53
@sebastien-rosset
Copy link
Owner Author

sebastien-rosset commented Jan 21, 2025

@rgleason, after quite a bit of code refactor, I'm able to load and show one GRIB layer. There is no interpolation across layers yet, but it's a good milestone. I need to fix the unit test issues on Linux and Windows, do error handling, check memory management.

image

@sebastien-rosset sebastien-rosset force-pushed the multi-grib-v2 branch 7 times, most recently from c376813 to a6f0102 Compare January 22, 2025 14:51
@sebastien-rosset
Copy link
Owner Author

Making some progress towards support for multiple layers of the same parameter types, e.g. both GFS and HRRR at the same time. Though I still have some issues with merging data. The rectangle in the middle contains HRRR data. The outer rectangle contains GFS data.

image

Each GRIB file can be loaded and enabled/disabled independently.
Algorithms to perform data interpolation across GRIB layers.
Merge strategy for combining GRIB records across layers.
Add unit tests for the GRIB plugin.
Add function to return GribRecord editionNumber.
Add enum for HRRR model.
Add code comments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants