Add mesh_layout='triangular' for regular triangular mesh generation#92
Open
prajwal-tech07 wants to merge 7 commits intomllam:mainfrom
Open
Add mesh_layout='triangular' for regular triangular mesh generation#92prajwal-tech07 wants to merge 7 commits intomllam:mainfrom
prajwal-tech07 wants to merge 7 commits intomllam:mainfrom
Conversation
…ivity architecture Implement the mesh_layout parameter and refactor mesh graph creation into a two-step process as discussed in mllam#78: 1. Coordinate creation (mesh_layout + mesh_layout_kwargs): - create_single_level_2d_mesh_coordinates() returns nx.Graph with spatial adjacency edges annotated as 'cardinal' or 'diagonal' - create_multirange_2d_mesh_coordinates() returns list of nx.Graph for multi-level meshes with interlevel_refinement_factor stored as graph attr 2. Connectivity creation (m2m_connectivity + m2m_connectivity_kwargs): - create_directed_mesh_graph() converts nx.Graph to nx.DiGraph based on pattern ('4-star' or '8-star') - create_flat_singlescale_from_coordinates() for flat single-scale - create_flat_multiscale_from_coordinates() with intra_level/inter_level sub-dicts for explicit connectivity control - create_hierarchical_from_coordinates() with intra_level/inter_level sub-dicts supporting 'nearest' pattern with k parameter Parameter restructuring: - grid_spacing replaces mesh_node_distance in mesh_layout_kwargs - interlevel_refinement_factor replaces level_refinement_factor - max_num_levels moves to mesh_layout_kwargs - m2m_connectivity_kwargs restructured with intra_level/inter_level sub-dicts Backward compatibility: - Old-style kwargs (mesh_node_distance, level_refinement_factor, max_num_levels in m2m_connectivity_kwargs) are auto-migrated with deprecation warnings - All existing wrapper functions preserved - All existing tests pass unchanged Archetype functions updated to use new parameter scheme: - create_keisler_graph: pattern='8-star' - create_graphcast_graph: intra_level=8-star, inter_level=coincident - create_oskarsson_hierarchical_graph: intra_level=8-star, inter_level=nearest(k=1) Closes mllam#78
Add 46 new tests in test_mesh_layout.py covering: - Coordinate creation (nx.Graph with adjacency_type annotations) - Connectivity creation (4-star vs 8-star pattern filtering) - New API via create_all_graph_components (flat, flat_multiscale, hierarchical) - Backward compatibility with deprecation warnings - Caller dict non-mutation safety - Error handling (unsupported layouts, missing grid_spacing, etc.) - Equivalence between archetype functions and new API Also remove unused imports from base.py (old wrapper functions no longer called directly from the dispatch logic).
… flat_multiscale kwargs - Rename interlevel_refinement_factor → refinement_factor, max_num_levels → max_num_refinement_levels - flat_multiscale uses simple pattern='8-star' (not intra_level/inter_level sub-dicts) - Only hierarchical uses intra_level/inter_level sub-dicts - Update archetypes and backward compat migration messages - Add 36 comprehensive edge case tests (81 total mesh layout tests pass)
- Rename mesh.py -> coords.py to reflect coordinate/primitive focus - Split mesh creation into two steps: primitive creation (nx.Graph) and directed connectivity creation (nx.DiGraph) - Add create_single_level_2d_mesh_primitive and create_directed_mesh_graph as new public API - Make mesh_layout a required parameter (no default) to force explicit choice - Extract _migrate_deprecated_kwargs() as a separate module-private helper function for planned removal - Use dict-based interface for intra_level/inter_level kwargs in hierarchical mesh creation - Remove redundant default values in base.py, let each mesh kind handle its own defaults - Add _check_required_graph_attributes() validation in flat.py - Group method+kwargs arguments together in archetype functions - Add comprehensive docstrings explaining 4-star/8-star patterns - Preserve backward compatibility with deprecation warnings - Update all tests to pass mesh_layout explicitly - All 81 mesh layout tests passing, 177/179 full suite passing (2 pre-existing Windows PermissionError on temp PNG files)
…tion Implements Issue mllam#80: adds triangular lattice mesh support using networkx.triangular_lattice_graph, providing 6-connectivity (vs 8 for rectilinear) for more isotropic message passing. New module: triangular.py - create_single_level_2d_triangular_mesh_primitive: coordinate creation - create_multirange_2d_triangular_mesh_primitives: multi-level primitives - create_single_level_2d_triangular_mesh_graph: convenience wrapper - create_flat_singlescale_triangular_mesh_graph: flat single-scale - create_flat_multiscale_from_triangular_coordinates: position-based node merging (KDTree) for flat multiscale, replacing index-based approach that only works with rectilinear grids - create_flat_multiscale_triangular_mesh_graph: flat multiscale wrapper - create_hierarchical_triangular_mesh_graph: hierarchical wrapper Dispatch in base.py: - All 3 m2m_connectivity modes (flat, hierarchical, flat_multiscale) now support mesh_layout='triangular' - Default pattern is '4-star' for triangular (all edges are cardinal) - CRS geographic coordinate warning added Tests: 48 new tests covering primitives, directed graphs, multirange, flat/hierarchical/flat_multiscale, integration, numerical correctness, pattern equivalence (4-star==8-star), and rectilinear regressions.
Comprehensive edge cases added to every test class: - Primitive: minimal lattice, large lattice, asymmetric nx/ny, offset domain, wide domain, numpy array type checks, no self-loops - Directed graph: edge count = 2x undirected, no self-loops, pos preserved, interior node degree=12 (6-connectivity), minimal lattice directed - Multirange: single level, refinement factor 2, domain coverage consistency, refinement factor preserved, all levels have edges - Single-level wrapper: edge attrs, rectangular domain, minimal grid - Flat singlescale: bidirectional edges, smaller spacing = more nodes, rectangular domain, no NaN, spacing-just-fits - Flat multiscale: bidirectional, pos attrs, single-level fallback, refinement factor 2, no self-loops, more nodes than coarsest level - Hierarchical: pos attrs, custom intra_level/inter_level configs, no self-loops, inter-level edge count, direction attrs (up/down) - Integration: within_radius connectivity, nearest_neighbour (singular), missing mesh_node_spacing raises for all 3 modes, all components have nodes, large domain - Numerical: no NaN/Inf, no zero-length edges, roughly uniform lengths, scaled domain = scaled lengths, positions are finite numpy arrays Total: 97 tests (up from 48)
20 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your changes
Adds support for
mesh_layout="triangular"increate_all_graph_components, usingnetworkx.triangular_lattice_graphto produce an equilateral-triangle lattice with 6-connectivity (vs 8 for rectilinear). This provides more isotropic message passing for weather model graph neural networks.New module:
triangular.py(428 lines)create_single_level_2d_triangular_mesh_primitive— coordinate creation usingtriangular_lattice_graph, scales/offsets positions to cover the coordinate domaincreate_multirange_2d_triangular_mesh_primitives— multi-level triangular primitives at progressively coarser resolutionscreate_single_level_2d_triangular_mesh_graph— convenience wrapper (primitive → directed)create_flat_singlescale_triangular_mesh_graph— flat single-scale wrappercreate_flat_multiscale_from_triangular_coordinates— position-based (KDTree) node merging for flat multiscale (replaces the index-based reshaping approach from rectilinear which is incompatible with triangular lattice node labeling)create_flat_multiscale_triangular_mesh_graph— flat multiscale wrappercreate_hierarchical_triangular_mesh_graph— hierarchical wrapperDispatch in
base.py:m2m_connectivitymodes (flat,hierarchical,flat_multiscale) now supportmesh_layout="triangular""4-star"for triangular (all edges are cardinal;"4-star"=="8-star")Tests: 97 tests in
test_triangular_mesh.pycovering:create_all_graph_componentsfor all 3 modesThis is part of the flexible graph construction effort for Issue #80.
No new dependencies — uses existing
networkx,numpy,scipy.spatial.Issue Link
closes #80
Type of change
Checklist before requesting a review
pullwith--rebaseoption if possible).Checklist for reviewers
Each PR comes with its own improvements and flaws. The reviewer should check the following:
Author checklist after completed review
reflecting type of change (add section where missing):
Checklist for assignee