You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add JPEG 2000 codec with optional nvJPEG2000 GPU acceleration (#1049)
* Add JPEG 2000 codec with optional nvJPEG2000 GPU acceleration (#1048)
CPU path via glymur (same pattern as JPEG/Pillow and ZSTD/zstandard).
GPU path via nvJPEG2000 ctypes bindings (same pattern as nvCOMP).
Both are optional -- graceful fallback if libraries aren't installed.
* Add JPEG 2000 test coverage and fix glymur numres constraint (#1048)
- 14 new tests: codec roundtrip, TIFF write/read roundtrip, public API,
availability checks, and ImportError fallback
- Fix jpeg2000_compress: calculate numres from tile dimensions, remove
pre-existing temp file before glymur write
- Update test_edge_cases: use 'webp' as unsupported compression example
since 'jpeg2000' is now supported
* Add JPEG 2000 compression user guide notebook (#1048)
Covers write/read roundtrip, file size comparison with deflate,
multi-band RGB example, and GPU acceleration notes.
* Update README: add JPEG 2000 / nvJPEG2000 to codec lists (#1048)
@@ -540,7 +540,7 @@ Check out the user guide [here](/examples/user_guide/).
540
540
541
541
-**Zero GDAL installation hassle.**`pip install xarray-spatial` gets you everything needed to read and write GeoTIFFs, COGs, and VRT files.
542
542
-**Pure Python, fully extensible.** All codec, header parsing, and metadata code is readable Python/Numba, not wrapped C/C++.
543
-
-**GPU-accelerated reads.** With optional nvCOMP, compressed tiles decompress directly on the GPU via CUDA -- something GDAL cannot do.
543
+
-**GPU-accelerated reads.** With optional nvCOMP and nvJPEG2000, compressed tiles decompress directly on the GPU via CUDA -- something GDAL cannot do.
544
544
545
545
The native reader is pixel-exact against rasterio/GDAL across Landsat 8, Copernicus DEM, USGS 1-arc-second, and USGS 1-meter DEMs. For uncompressed files it reads 5-7x faster than rioxarray; for compressed COGs it is comparable or faster with GPU acceleration.
"source": "# JPEG 2000 compression for GeoTIFFs\n\nThe geotiff package supports JPEG 2000 (J2K) as a compression codec for both reading and writing. This is useful for satellite imagery workflows where J2K is common (Sentinel-2, Landsat, etc.).\n\nTwo acceleration tiers are available:\n- **CPU** via `glymur` (pip install glymur) -- works anywhere OpenJPEG is installed\n- **GPU** via NVIDIA's nvJPEG2000 library -- same optional pattern as nvCOMP for deflate/ZSTD\n\nThis notebook demonstrates write/read roundtrips with JPEG 2000 compression.",
7
+
"metadata": {}
8
+
},
9
+
{
10
+
"cell_type": "code",
11
+
"id": "kamu534xsm",
12
+
"source": "import numpy as np\nimport xarray as xr\nimport matplotlib.pyplot as plt\nimport tempfile\nimport os\n\nfrom xrspatial.geotiff import read_geotiff, write_geotiff",
13
+
"metadata": {},
14
+
"execution_count": null,
15
+
"outputs": []
16
+
},
17
+
{
18
+
"cell_type": "markdown",
19
+
"id": "w7tlml1cyqj",
20
+
"source": "## Generate synthetic elevation data\n\nWe'll create a small terrain-like raster to use as test data.",
"source": "## Read it back and verify lossless roundtrip\n\n`read_geotiff` auto-detects the compression from the TIFF header. No special arguments needed.",
"source": "## GPU acceleration\n\nOn systems with nvJPEG2000 installed (CUDA toolkit, RAPIDS environments), pass `gpu=True` to use GPU-accelerated J2K encode/decode. The API is the same -- it falls back to CPU automatically if the library isn't found.\n\n```python\n# GPU write (nvJPEG2000 if available, else CPU fallback)\nwrite_geotiff(cupy_data, \"output.tif\", compression=\"jpeg2000\", gpu=True)\n\n# GPU read (nvJPEG2000 decode if available)\nda = read_geotiff(\"satellite.tif\", gpu=True)\n```",
0 commit comments