Repository: rasterio/rasterio

Issue:
RGB shortcut for rio stack
Making an RGB image is by far my most common use for `rio stack`, and I suspect this is true for many others. It would be convenient to have `--rgb` as a shortcut for `--photometric rgb`. Depending, of course, on the consensus feeling about special cases.



Discussion:
I'm in favor since you're (to my knowledge) the #1 user of this feature. @geowurster, this would let us remove the generic `--photometric`, which can be done using `--co photometic=rgb` now.

@sgillies :+1: I don't think I have ever generated an image with `rio stack` that I didn't intend to view as RGB.


Resolving patch:
diff --git a/rasterio/rio/bands.py b/rasterio/rio/bands.py
--- a/rasterio/rio/bands.py
+++ b/rasterio/rio/bands.py
@@ -9,26 +9,13 @@
 from rasterio.five import zip_longest
 
 
-PHOTOMETRIC_CHOICES = [val.lower() for val in [
-    'MINISBLACK',
-    'MINISWHITE',
-    'RGB',
-    'CMYK',
-    'YCBCR',
-    'CIELAB',
-    'ICCLAB',
-    'ITULAB']]
-
-
 # Stack command.
 @click.command(short_help="Stack a number of bands into a multiband dataset.")
 @files_inout_arg
 @options.output_opt
 @format_opt
 @options.bidx_mult_opt
-@click.option('--photometric', default=None,
-              type=click.Choice(PHOTOMETRIC_CHOICES),
-              help="Photometric interpretation")
+@options.rgb_opt
 @options.creation_options
 @click.pass_context
 def stack(ctx, files, output, driver, bidx, photometric, creation_options):
diff --git a/rasterio/rio/convert.py b/rasterio/rio/convert.py
--- a/rasterio/rio/convert.py
+++ b/rasterio/rio/convert.py
@@ -29,11 +29,12 @@
               help="Source to destination scaling ratio.")
 @click.option('--scale-offset', type=float, default=None,
               help="Source to destination scaling offset.")
+@options.rgb_opt
 @options.creation_options
 @click.pass_context
 def convert(
         ctx, files, output, driver, dtype, scale_ratio, scale_offset,
-        creation_options):
+        photometric, creation_options):
     """Copy and convert raster datasets to other data types and formats.
 
     Data values may be linearly scaled when copying by using the
@@ -83,6 +84,9 @@ def convert(
 
             profile.update(**creation_options)
 
+            if photometric:
+                kwargs['photometric'] = photometric
+
             with rasterio.open(outputfile, 'w', **profile) as dst:
 
                 data = src.read()
diff --git a/rasterio/rio/options.py b/rasterio/rio/options.py
--- a/rasterio/rio/options.py
+++ b/rasterio/rio/options.py
@@ -153,4 +153,10 @@ def _cb_key_val(ctx, param, value):
     callback=_cb_key_val,
     help="Driver specific creation options."
          "See the documentation for the selected output driver for "
-         "more information.")
\ No newline at end of file
+         "more information.")
+
+rgb_opt = click.option(
+    '--rgb', 'photometric', 
+    flag_value='rgb',
+    default=False,
+    help="Set RGB photometric interpretation")


Test patch:
diff --git a/tests/test_rio_bands.py b/tests/test_rio_bands.py
--- a/tests/test_rio_bands.py
+++ b/tests/test_rio_bands.py
@@ -5,10 +5,6 @@
 from rasterio.rio import bands
 
 
-def test_photometic_choices():
-    assert len(bands.PHOTOMETRIC_CHOICES) == 8
-
-
 def test_stack(tmpdir):
     outputname = str(tmpdir.join('stacked.tif'))
     runner = CliRunner()
@@ -54,7 +50,7 @@ def test_stack_single_slice(tmpdir):
         [
             'tests/data/RGB.byte.tif', '--bidx', '1',
             'tests/data/RGB.byte.tif', '--bidx', '2..',
-            '--photometric', 'rgb',
+            '--rgb',
             outputname])
     assert result.exit_code == 0
     with rasterio.open(outputname) as out: