Repository: rasterio/rasterio

Issue:
Surface TIFF compression in rio-info
Because when you need to know, you need to know.



Discussion:
It's there now, but obscured:

### CLI

``` bash
rio info /tmp/rgb.tif --tags --namespace IMAGE_STRUCTURE
{"COMPRESSION": "JPEG", "INTERLEAVE": "PIXEL"}
```

### API

``` python
$ rio insp /tmp/rgb.tif
Rasterio 0.26.0 Interactive Inspector (Python 3.4.2)
Type "src.meta", "src.read(1)", or "help(src)" for more information.
>>> src.tags()
{'AREA_OR_POINT': 'Area'}
>>> src.tags(ns='IMAGE_STRUCTURE')
{'COMPRESSION': 'JPEG', 'INTERLEAVE': 'PIXEL'}
```

I propose extending `meta` with values taken from this tag namespace.

@sgillies at the root level, or nested under a key like `image_structure`?  Does it make sense to do this for the other namespaces SUBDATASETS and RPC while you're at it, each nested under the appropriate key?

@sgillies @brendan-ward I think adding them to the root level will re-introduce problems https://github.com/mapbox/rasterio/issues/405 solved.  What about adding to `src.profile`?


Resolving patch:
diff --git a/rasterio/enums.py b/rasterio/enums.py
--- a/rasterio/enums.py
+++ b/rasterio/enums.py
@@ -28,3 +28,20 @@ class Resampling(Enum):
     mode='MODE'
     average_magphase='AVERAGE_MAGPHASE'
     none='NONE'
+
+
+class Compression(Enum):
+    jpeg='JPEG'
+    lzw='LZW'
+    packbits='PACKBITS'
+    deflate='DEFLATE'
+    ccittrle='CCITTRLE'
+    ccittfax3='CCITTFAX3'
+    ccittfax4='CCITTFAX4'
+    lzma='LZMA'
+    none='NONE'
+
+
+class Interleaving(Enum):
+    pixel='PIXEL'
+    band='BAND'
diff --git a/rasterio/rio/info.py b/rasterio/rio/info.py
--- a/rasterio/rio/info.py
+++ b/rasterio/rio/info.py
@@ -278,7 +278,7 @@ def info(ctx, input, aspect, indent, namespace, meta_member, verbose, bidx,
     try:
         with rasterio.drivers(CPL_DEBUG=(verbosity > 2)):
             with rasterio.open(input, mode) as src:
-                info = src.meta
+                info = src.profile
                 info['transform'] = info['affine'][:6]
                 del info['affine']
                 info['shape'] = info['height'], info['width']


Test patch:
diff --git a/tests/data/rgb_deflate.tif b/tests/data/rgb_deflate.tif
new file mode 100644
Binary files /dev/null and b/tests/data/rgb_deflate.tif differ
diff --git a/tests/test_image_structure.py b/tests/test_image_structure.py
new file mode 100644
--- /dev/null
+++ b/tests/test_image_structure.py
@@ -0,0 +1,74 @@
+import rasterio
+
+from rasterio.enums import Compression, Interleaving
+
+
+def test_enum_compression_JPEG():
+    assert Compression('JPEG').name == 'jpeg'
+
+
+def test_enum_compression_LZW():
+    assert Compression('LZW').name == 'lzw'
+
+
+def test_enum_compression_PACKBITS():
+    assert Compression('PACKBITS').name == 'packbits'
+
+
+def test_enum_compression_DEFLATE():
+    assert Compression('DEFLATE').name == 'deflate'
+
+
+def test_enum_compression_CCITTRLE():
+    assert Compression('CCITTRLE').name == 'ccittrle'
+
+
+def test_enum_compression_CCITTFAX3():
+    assert Compression('CCITTFAX3').name == 'ccittfax3'
+
+
+def test_enum_compression_CCITTFAX4():
+    assert Compression('CCITTFAX4').name == 'ccittfax4'
+
+
+def test_enum_compression_LZMA():
+    assert Compression('LZMA').name == 'lzma'
+
+
+def test_enum_compression_NONE():
+    assert Compression('NONE').name == 'none'
+
+
+def test_compression_none():
+    with rasterio.open('tests/data/RGB.byte.tif') as src:
+        assert src.compression is None
+        assert 'compress' not in src.profile
+
+
+def test_compression_deflate():
+    with rasterio.open('tests/data/rgb_deflate.tif') as src:
+        assert src.compression.name == 'deflate'
+        assert src.compression.value == 'DEFLATE'
+        assert src.profile['compress'] == 'deflate'
+
+
+def test_enum_interleaving_BAND():
+    assert Interleaving('BAND').name == 'band'
+
+
+def test_enum_interleaving_PIXEL():
+    assert Interleaving('PIXEL').name == 'pixel'
+
+
+def test_interleaving_pixel():
+    with rasterio.open('tests/data/RGB.byte.tif') as src:
+        assert src.interleaving.name == 'pixel'
+        assert src.interleaving.value == 'PIXEL'
+        assert src.profile['interleave'] == 'pixel'
+
+
+def test_interleaving_pixel():
+    with rasterio.open('tests/data/rgb_deflate.tif') as src:
+        assert src.interleaving.name == 'band'
+        assert src.interleaving.value == 'BAND'
+        assert src.profile['interleave'] == 'band'