Skip to content

Add regional templates to from_template (Africa, Asia, the Americas, Oceania)#3553

Merged
brendancol merged 8 commits into
mainfrom
issue-3552
Jun 27, 2026
Merged

Add regional templates to from_template (Africa, Asia, the Americas, Oceania)#3553
brendancol merged 8 commits into
mainfrom
issue-3552

Conversation

@brendancol

@brendancol brendancol commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Closes #3552

Adds curated continental and subcontinental regions to from_template, covering every continent. Each is in an EPSG-coded GLANCE continental Lambert azimuthal equal-area projection (the equal-area analog of the existing europe LAEA region), except Antarctica, which uses the de-facto standard Antarctic Polar Stereographic. attrs['crs'] stays a real EPSG int throughout.

  • North America (GLANCE North America, EPSG:10598): central_america, caribbean, greenland, canada, mexico, great_lakes, pacific_northwest, gulf_coast, new_england, great_plains, american_southwest
  • South America (GLANCE South America, EPSG:10603): south_america, amazon_basin, andes, southern_cone
  • Europe (GLANCE Europe, EPSG:10596): western_europe, eastern_europe, northern_europe, southern_europe
  • Africa (GLANCE Africa, EPSG:10592): west_africa, north_africa, east_africa, southern_africa, central_africa
  • Asia (GLANCE Asia, EPSG:10594): southeast_asia, south_asia, east_asia, central_asia, middle_east, north_asia
  • Oceania (GLANCE Oceania, EPSG:10601): oceania, australia, new_zealand
  • Antarctica (Antarctic Polar Stereographic, EPSG:3031): antarctica — conformal, so preserve='area' returns the south-polar LAEA (EPSG:6932) instead of claiming 3031 is equal-area

The new names are plain _REGIONS entries, so they ride the existing region dispatch with no logic change; numpy, cupy, dask+numpy, and dask+cupy all work, and the dask path stays lazy.

Note: the original request spelled it carribean; the template uses the correct caribbean.

Test plan

  • pytest xrspatial/tests/test_templates.py (249 passed, including the cupy and dask backends that run on this box)
  • Every GLANCE region is parametrized over: contract, pixel centers within bounds, case-insensitive lookup, bounds-match-reprojected-lonlat (within 2 m), and LAEA CF grid-mapping
  • Antarctica has its own contract test plus a grid-mapping/preserve test (polar_stereographic; preserve='area' -> 6932, preserve='shape' -> 3031)

Add southeast_asia (EPSG:10594), central_america/caribbean (EPSG:10598),
and west_africa (EPSG:10592), each in its GLANCE continental Lambert
azimuthal equal-area projection. Real EPSG codes keep attrs['crs'] an int.
Reuses the existing region dispatch, so all four backends work.

@brendancol brendancol left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review: Add regional templates to from_template

Blockers (must fix before merge)

None.

Suggestions (should fix, not blocking)

  • xrspatial/_template_data.py: the four bounds tuples are hand-maintained numbers, each one the lonlat box projected into its GLANCE CRS. I recomputed them and they match to sub-metre, so they are right today, but nothing stops a future edit or regeneration from drifting the two apart, and a wrong bounds value silently misgeoreferences the grid. A registry-integrity test (like the cities have) that reprojects each region's lonlat and checks it against the stored bounds within a tolerance would catch that.

Nits (optional improvements)

  • xrspatial/_template_data.py: none of the four regions set shape_epsg, so from_template(name, preserve='shape') falls back to the centroid's UTM zone, which only covers a slice of a continental extent. That is the expected EPSG-clean fallback (there is no EPSG conformal continental code, unlike Europe's curated LCC 3034), but a one-line comment would save the next reader a double-take.
  • xrspatial/_template_data.py: the southeast_asia box reaches lat -11 and central_america reaches lat 7, each roughly 0.2 to 1 degree past the southern edge of its GLANCE projection's official area of use. LAEA still projects those points finitely (verified), so the grid is valid, just slightly outside the projection's nominal extent.

What looks good

  • Real EPSG codes throughout (GLANCE 10592/10594/10598), so attrs['crs'] stays an int, matching the convention and the europe LAEA precedent.
  • Pure data addition: the new names are plain _REGIONS entries that ride the existing region dispatch, so all four backends and the preserve path work with no logic change.
  • Tests cover the contract, bounds containment, case-insensitive lookup, and the LAEA CF grid-mapping for each region; test_registry_codes_resolve and test_list_templates_grouped pick the new regions up on their own.
  • Stored bounds verified against the reprojected lonlat boxes to sub-metre.

Checklist

  • Algorithm matches reference (EPSG codes and projected bounds verified with pyproj)
  • All implemented backends produce consistent results (shared region dispatch)
  • NaN handling correct (NaN-filled, asserted)
  • Edge cases covered (case-insensitive, bounds containment)
  • Dask chunk boundaries handled (lazy da.full, no overlap)
  • No premature materialization
  • Benchmark not needed (no compute kernel)
  • Docstrings updated (name list extended)
  • README left as-is (open-ended row already covers the new regions; avoids a conflict with #3550)

@brendancol brendancol left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up review (after commit 4bca7b9)

All three items from the first pass are handled.

  • Suggestion (bounds drift): added test_regional_bounds_match_reprojected_lonlat, which reprojects each region's lonlat and asserts it matches the stored bounds within 2 m. A future edit that desyncs the two now fails the test instead of shipping a misgeoreferenced grid.
  • Nit (shape_epsg fallback): documented in the _REGIONS comment that these regions intentionally omit shape_epsg, so preserve='shape' falls back to the centroid UTM zone.
  • Nit (area-of-use overshoot): no code change. The lon/lat boxes follow the real region extent (e.g. Timor at -11, Panama at 7), and LAEA projects those points finitely; the comment now records this.

No new findings. Tests: 87 passed locally (numpy, cupy, dask backends).

# Conflicts:
#	docs/source/reference/templates.rst
#	xrspatial/templates.py
#	xrspatial/tests/test_templates.py
Add north_africa/east_africa/southern_africa (GLANCE Africa 10592),
south_asia/east_asia/central_asia/middle_east (GLANCE Asia 10594),
south_america (GLANCE S. America 10603), and oceania (GLANCE Oceania
10601). Same EPSG-coded continental LAEA pattern as the first batch;
covered by the existing parametrized regional tests.
@brendancol brendancol changed the title Add regional templates to from_template (southeast_asia, central_america, caribbean, west_africa) Add regional templates to from_template (Africa, Asia, the Americas, Oceania) Jun 27, 2026

@brendancol brendancol left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up review (after commit 8335d54): additional regions

Added nine more regions at the same level, each on its GLANCE continental LAEA EPSG code:

  • Africa (10592): north_africa, east_africa, southern_africa
  • Asia (10594): south_asia, east_asia, central_asia, middle_east
  • South America (10603): south_america
  • Oceania (10601): oceania

Each lon/lat box was reprojected into its GLANCE CRS to derive the stored bounds, and the test_regional_bounds_match_reprojected_lonlat check confirms they match to within 2 m. oceania is bounded west of the antimeridian (110-179E: Australia, New Guinea, New Zealand) so the box does not wrap 180. The existing parametrized regional tests cover all of them through the extended _REGIONAL list.

No new findings. Tests: 147 passed locally (numpy, cupy, dask backends).

Add Europe subregions (western/eastern/northern/southern_europe, GLANCE
Europe 10596), central_africa, north_asia, greenland, South America
subregions (amazon_basin/andes/southern_cone), australia, new_zealand,
and antarctica (Antarctic Polar Stereographic 3031, with area_epsg=6932
S-polar LAEA for preserve='area'). Every continent now has a few regions.

@brendancol brendancol left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up review (after commit 05cf9fa): full continent coverage

Filled out every continent:

  • Europe (GLANCE Europe 10596): western_europe, eastern_europe, northern_europe, southern_europe
  • South America (10603): amazon_basin, andes, southern_cone
  • Africa (10592): central_africa
  • Asia (10594): north_asia
  • North America (10598): greenland
  • Oceania (10601): australia, new_zealand
  • Antarctica (3031): antarctica

Antarctica is the one non-GLANCE region: it uses Antarctic Polar Stereographic (the standard there), which is conformal, so area_epsg points at the south-polar LAEA EPSG:6932 and preserve='area' returns a real equal-area code rather than mislabeling 3031. It has dedicated tests (test_antarctica_contract, test_antarctica_grid_mapping_and_preserve); the GLANCE regions stay covered by the parametrized _REGIONAL suite, including the bounds-integrity check.

No new findings. Tests: 209 passed locally (numpy, cupy, dask backends).

Add canada, mexico, great_lakes, pacific_northwest, gulf_coast,
new_england, great_plains, and american_southwest, all in GLANCE North
America LAEA (EPSG:10598). Covered by the parametrized regional tests.

@brendancol brendancol left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up review (after commit bbab5ec): more North America regions

Added the common North America gaps, all on GLANCE North America (EPSG:10598):

  • canada, mexico — the two missing neighbors of the existing CONUS/Alaska
  • great_lakes — cross-border, common in hydrology
  • pacific_northwest, gulf_coast, new_england, great_plains, american_southwest — standard US macro-regions

All ride the parametrized _REGIONAL suite (contract, bounds containment, case-insensitive, bounds-match-reprojected-lonlat within 2 m, GLANCE grid-mapping). North America now has 11 curated regions.

No new findings. Tests: 249 passed locally (numpy, cupy, dask backends).

Add 'pacific' (alias 'pdc') global template in EPSG:3832 (WGS 84 / PDC
Mercator), the Pacific Disaster Center projection centered on lon_0=150
so the Pacific Ocean is continuous (map seam in the Atlantic). Conformal,
so preserve='area' falls back to Equal Earth.

@brendancol brendancol left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up review (after commit a66d19e): Pacific-centered template

Added pacific (alias pdc): the Pacific Disaster Center projection, EPSG:3832 (WGS 84 / PDC Mercator). It is a Mercator with lon_0=150, so the Pacific Ocean is drawn continuously and the map seam falls in the Atlantic (~30 W). Native bounds are the full longitude extent (x = +/-a*pi = +/-20037508 m) and the ellipsoidal Mercator y at the conventional +/-85.0511287798 latitude limit.

A real EPSG code, so attrs['crs'] stays an int (and 3832 has a CF grid_mapping_name='mercator', unlike 3857). It is conformal, so area_epsg points at Equal Earth (8857) for preserve='area'. Covered by test_global_projection_contract/test_global_projection_case_insensitive and a dedicated test_pacific_pdc_mercator (grid mapping, PDC WKT, pdc alias identity, preserve fallback).

No new findings. Tests: 253 passed locally (numpy, cupy, dask backends).

@brendancol brendancol merged commit 9be1f25 into main Jun 27, 2026
12 checks passed
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.

Add regional templates to from_template (southeast_asia, central_america, caribbean, west_africa)

1 participant