We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Missing `RMS` support in build_overviews
https://github.com/mapbox/rasterio/blob/3c630f8a30d31ceb61aa52ad3ab96f4fc25f2ecd/rasterio/_io.pyx#L1794-L1801

>  @param pszResampling one of "AVERAGE", "AVERAGE_MAGPHASE", "RMS", "BILINEAR", "CUBIC", "CUBICSPLINE", "GAUSS", "LANCZOS", "MODE", "NEAREST", "NONE"
 
https://github.com/OSGeo/gdal/blob/3d32de21b79ab7e09024f55a0e6740f00318dd3e/gdal/gcore/gdaldataset.cpp#L1908-L1909

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `rasterio/enums.py`
Content:
```
1 """Enumerations."""
2 
3 from enum import Enum, IntEnum
4 
5 
6 class ColorInterp(IntEnum):
7     """Raster band color interpretation."""
8     undefined = 0
9     gray = 1
10     grey = 1
11     palette = 2
12     red = 3
13     green = 4
14     blue = 5
15     alpha = 6
16     hue = 7
17     saturation = 8
18     lightness = 9
19     cyan = 10
20     magenta = 11
21     yellow = 12
22     black = 13
23     Y = 14
24     Cb = 15
25     Cr = 16
26 
27 
28 class Resampling(IntEnum):
29     """Available warp resampling algorithms.
30 
31     The first 8, 'nearest', 'bilinear', 'cubic', 'cubic_spline',
32     'lanczos', 'average', 'mode', and 'gauss', are available for making
33     dataset overviews.
34 
35     'max', 'min', 'med', 'q1', 'q3' are only supported in GDAL >= 2.0.0.
36 
37     'nearest', 'bilinear', 'cubic', 'cubic_spline', 'lanczos',
38     'average', 'mode' are always available (GDAL >= 1.10).
39 
40     'sum' is only supported in GDAL >= 3.1.
41 
42     'rms' is only supported in GDAL >= 3.3.
43 
44     Note: 'gauss' is not available to the functions in rio.warp.
45     """
46     nearest = 0
47     bilinear = 1
48     cubic = 2
49     cubic_spline = 3
50     lanczos = 4
51     average = 5
52     mode = 6
53     gauss = 7
54     max = 8
55     min = 9
56     med = 10
57     q1 = 11
58     q3 = 12
59     sum = 13
60     rms = 14
61 
62 
63 class Compression(Enum):
64     """Available compression algorithms."""
65     jpeg = 'JPEG'
66     lzw = 'LZW'
67     packbits = 'PACKBITS'
68     deflate = 'DEFLATE'
69     ccittrle = 'CCITTRLE'
70     ccittfax3 = 'CCITTFAX3'
71     ccittfax4 = 'CCITTFAX4'
72     lzma = 'LZMA'
73     none = 'NONE'
74     zstd = 'ZSTD'
75     lerc = 'LERC'
76     webp = 'WEBP'
77     jpeg2000 = 'JPEG2000'
78 
79 
80 class Interleaving(Enum):
81     pixel = 'PIXEL'
82     line = 'LINE'
83     band = 'BAND'
84 
85 
86 class MaskFlags(IntEnum):
87     all_valid = 1
88     per_dataset = 2
89     alpha = 4
90     nodata = 8
91 
92 
93 class PhotometricInterp(Enum):
94     black = 'MINISBLACK'
95     white = 'MINISWHITE'
96     rgb = 'RGB'
97     cmyk = 'CMYK'
98     ycbcr = 'YCbCr'
99     cielab = 'CIELAB'
100     icclab = 'ICCLAB'
101     itulab = 'ITULAB'
102 
103 class MergeAlg(Enum):
104     """Available rasterization algorithms"""
105     replace = 'REPLACE'
106     add = 'ADD'
107
```

Path: `rasterio/rio/overview.py`
Content:
```
1 # coding: utf-8
2 """Manage overviews of a dataset."""
3 
4 from functools import reduce
5 import logging
6 import operator
7 
8 import click
9 
10 from . import options
11 import rasterio
12 from rasterio.enums import Resampling
13 
14 
15 def build_handler(ctx, param, value):
16     if value:
17         try:
18             if '^' in value:
19                 base, exp_range = value.split('^')
20                 exp_min, exp_max = (int(v) for v in exp_range.split('..'))
21                 value = [pow(int(base), k) for k in range(exp_min, exp_max + 1)]
22             elif ',' in value:
23                 value = [int(v) for v in value.split(',')]
24             elif value == "auto":
25                 pass
26             else:
27                 raise Exception
28         except Exception:
29             raise click.BadParameter(u"must match 'n,n,n,…', 'n^n..n', or 'auto'.")
30     return value
31 
32 
33 def get_maximum_overview_level(width, height, minsize=256):
34     """
35     Calculate the maximum overview level of a dataset at which
36     the smallest overview is smaller than `minsize`.
37 
38     Attributes
39     ----------
40     width : int
41         Width of the dataset.
42     height : int
43         Height of the dataset.
44     minsize : int (default: 256)
45         Minimum overview size.
46 
47     Returns
48     -------
49     overview_level: int
50         overview level.
51 
52     """
53     overview_level = 0
54     overview_factor = 1
55     while min(width // overview_factor, height // overview_factor) > minsize:
56         overview_factor *= 2
57         overview_level += 1
58 
59     return overview_level
60 
61 
62 @click.command('overview', short_help="Construct overviews in an existing dataset.")
63 @options.file_in_arg
64 @click.option('--build', callback=build_handler, metavar=u"f1,f2,…|b^min..max|auto",
65               help="A sequence of decimation factors specified as "
66                    "comma-separated list of numbers or a base and range of "
67                    "exponents, or 'auto' to automatically determine the maximum factor.")
68 @click.option('--ls', help="Print the overviews for each band.",
69               is_flag=True, default=False)
70 @click.option('--rebuild', help="Reconstruct existing overviews.",
71               is_flag=True, default=False)
72 @click.option('--resampling', help="Resampling algorithm.",
73               type=click.Choice(
74                   [it.name for it in Resampling if it.value in [0, 1, 2, 3, 4, 5, 6, 7]]),
75               default='nearest', show_default=True)
76 @click.pass_context
77 def overview(ctx, input, build, ls, rebuild, resampling):
78     """Construct overviews in an existing dataset.
79 
80     A pyramid of overviews computed once and stored in the dataset can
81     improve performance in some applications.
82 
83     The decimation levels at which to build overviews can be specified as
84     a comma separated list
85 
86       rio overview --build 2,4,8,16
87 
88     or a base and range of exponents
89 
90       rio overview --build 2^1..4
91 
92     or 'auto' to automatically determine the maximum decimation level at
93     which the smallest overview is smaller than 256 pixels in size.
94 
95       rio overview --build auto
96 
97     Note that overviews can not currently be removed and are not
98     automatically updated when the dataset's primary bands are
99     modified.
100 
101     Information about existing overviews can be printed using the --ls
102     option.
103 
104       rio overview --ls
105 
106     """
107     with ctx.obj['env']:
108         if ls:
109             with rasterio.open(input, 'r') as dst:
110                 resampling_method = dst.tags(
111                     ns='rio_overview').get('resampling') or 'unknown'
112 
113                 click.echo("Overview factors:")
114                 for idx in dst.indexes:
115                     click.echo("  Band %d: %s (method: '%s')" % (
116                         idx, dst.overviews(idx) or 'None', resampling_method))
117         elif rebuild:
118             with rasterio.open(input, 'r+') as dst:
119                 # Build the same overviews for all bands.
120                 factors = reduce(
121                     operator.or_,
122                     [set(dst.overviews(i)) for i in dst.indexes])
123 
124                 # Attempt to recover the resampling method from dataset tags.
125                 resampling_method = dst.tags(
126                     ns='rio_overview').get('resampling') or resampling
127 
128                 dst.build_overviews(
129                     list(factors), Resampling[resampling_method])
130 
131         elif build:
132             with rasterio.open(input, 'r+') as dst:
133                 if build == "auto":
134                     overview_level = get_maximum_overview_level(dst.width, dst.height)
135                     build = [2 ** j for j in range(1, overview_level + 1)]
136                 dst.build_overviews(build, Resampling[resampling])
137 
138                 # Save the resampling method to a tag.
139                 dst.update_tags(ns='rio_overview', resampling=resampling)
140 
141         else:
142             raise click.UsageError(
143                 "Please specify --ls, --rebuild, or --build ...")
144
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/rasterio/enums.py b/rasterio/enums.py
--- a/rasterio/enums.py
+++ b/rasterio/enums.py
@@ -60,6 +60,30 @@
     rms = 14
 
 
+class OverviewResampling(IntEnum):
+    """Available Overview resampling algorithms.
+
+    The first 8, 'nearest', 'bilinear', 'cubic', 'cubic_spline',
+    'lanczos', 'average', 'mode', and 'gauss', are available for making
+    dataset overviews.
+
+    'nearest', 'bilinear', 'cubic', 'cubic_spline', 'lanczos',
+    'average', 'mode' are always available (GDAL >= 1.10).
+
+    'rms' is only supported in GDAL >= 3.3.
+
+    """
+    nearest = 0
+    bilinear = 1
+    cubic = 2
+    cubic_spline = 3
+    lanczos = 4
+    average = 5
+    mode = 6
+    gauss = 7
+    rms = 14
+
+
 class Compression(Enum):
     """Available compression algorithms."""
     jpeg = 'JPEG'
diff --git a/rasterio/rio/overview.py b/rasterio/rio/overview.py
--- a/rasterio/rio/overview.py
+++ b/rasterio/rio/overview.py
@@ -9,7 +9,7 @@
 
 from . import options
 import rasterio
-from rasterio.enums import Resampling
+from rasterio.enums import OverviewResampling
 
 
 def build_handler(ctx, param, value):
@@ -70,8 +70,7 @@
 @click.option('--rebuild', help="Reconstruct existing overviews.",
               is_flag=True, default=False)
 @click.option('--resampling', help="Resampling algorithm.",
-              type=click.Choice(
-                  [it.name for it in Resampling if it.value in [0, 1, 2, 3, 4, 5, 6, 7]]),
+              type=click.Choice([it.name for it in OverviewResampling]),
               default='nearest', show_default=True)
 @click.pass_context
 def overview(ctx, input, build, ls, rebuild, resampling):
@@ -126,14 +125,14 @@
                     ns='rio_overview').get('resampling') or resampling
 
                 dst.build_overviews(
-                    list(factors), Resampling[resampling_method])
+                    list(factors), OverviewResampling[resampling_method])
 
         elif build:
             with rasterio.open(input, 'r+') as dst:
                 if build == "auto":
                     overview_level = get_maximum_overview_level(dst.width, dst.height)
                     build = [2 ** j for j in range(1, overview_level + 1)]
-                dst.build_overviews(build, Resampling[resampling])
+                dst.build_overviews(build, OverviewResampling[resampling])
 
                 # Save the resampling method to a tag.
                 dst.update_tags(ns='rio_overview', resampling=resampling)

{"golden_diff": "diff --git a/rasterio/enums.py b/rasterio/enums.py\n--- a/rasterio/enums.py\n+++ b/rasterio/enums.py\n@@ -60,6 +60,30 @@\n     rms = 14\n \n \n+class OverviewResampling(IntEnum):\n+    \"\"\"Available Overview resampling algorithms.\n+\n+    The first 8, 'nearest', 'bilinear', 'cubic', 'cubic_spline',\n+    'lanczos', 'average', 'mode', and 'gauss', are available for making\n+    dataset overviews.\n+\n+    'nearest', 'bilinear', 'cubic', 'cubic_spline', 'lanczos',\n+    'average', 'mode' are always available (GDAL >= 1.10).\n+\n+    'rms' is only supported in GDAL >= 3.3.\n+\n+    \"\"\"\n+    nearest = 0\n+    bilinear = 1\n+    cubic = 2\n+    cubic_spline = 3\n+    lanczos = 4\n+    average = 5\n+    mode = 6\n+    gauss = 7\n+    rms = 14\n+\n+\n class Compression(Enum):\n     \"\"\"Available compression algorithms.\"\"\"\n     jpeg = 'JPEG'\ndiff --git a/rasterio/rio/overview.py b/rasterio/rio/overview.py\n--- a/rasterio/rio/overview.py\n+++ b/rasterio/rio/overview.py\n@@ -9,7 +9,7 @@\n \n from . import options\n import rasterio\n-from rasterio.enums import Resampling\n+from rasterio.enums import OverviewResampling\n \n \n def build_handler(ctx, param, value):\n@@ -70,8 +70,7 @@\n @click.option('--rebuild', help=\"Reconstruct existing overviews.\",\n               is_flag=True, default=False)\n @click.option('--resampling', help=\"Resampling algorithm.\",\n-              type=click.Choice(\n-                  [it.name for it in Resampling if it.value in [0, 1, 2, 3, 4, 5, 6, 7]]),\n+              type=click.Choice([it.name for it in OverviewResampling]),\n               default='nearest', show_default=True)\n @click.pass_context\n def overview(ctx, input, build, ls, rebuild, resampling):\n@@ -126,14 +125,14 @@\n                     ns='rio_overview').get('resampling') or resampling\n \n                 dst.build_overviews(\n-                    list(factors), Resampling[resampling_method])\n+                    list(factors), OverviewResampling[resampling_method])\n \n         elif build:\n             with rasterio.open(input, 'r+') as dst:\n                 if build == \"auto\":\n                     overview_level = get_maximum_overview_level(dst.width, dst.height)\n                     build = [2 ** j for j in range(1, overview_level + 1)]\n-                dst.build_overviews(build, Resampling[resampling])\n+                dst.build_overviews(build, OverviewResampling[resampling])\n \n                 # Save the resampling method to a tag.\n                 dst.update_tags(ns='rio_overview', resampling=resampling)\n", "issue": "Missing `RMS` support in build_overviews\nhttps://github.com/mapbox/rasterio/blob/3c630f8a30d31ceb61aa52ad3ab96f4fc25f2ecd/rasterio/_io.pyx#L1794-L1801\r\n\r\n>  @param pszResampling one of \"AVERAGE\", \"AVERAGE_MAGPHASE\", \"RMS\", \"BILINEAR\", \"CUBIC\", \"CUBICSPLINE\", \"GAUSS\", \"LANCZOS\", \"MODE\", \"NEAREST\", \"NONE\"\r\n \r\nhttps://github.com/OSGeo/gdal/blob/3d32de21b79ab7e09024f55a0e6740f00318dd3e/gdal/gcore/gdaldataset.cpp#L1908-L1909\n", "before_files": [{"content": "\"\"\"Enumerations.\"\"\"\n\nfrom enum import Enum, IntEnum\n\n\nclass ColorInterp(IntEnum):\n    \"\"\"Raster band color interpretation.\"\"\"\n    undefined = 0\n    gray = 1\n    grey = 1\n    palette = 2\n    red = 3\n    green = 4\n    blue = 5\n    alpha = 6\n    hue = 7\n    saturation = 8\n    lightness = 9\n    cyan = 10\n    magenta = 11\n    yellow = 12\n    black = 13\n    Y = 14\n    Cb = 15\n    Cr = 16\n\n\nclass Resampling(IntEnum):\n    \"\"\"Available warp resampling algorithms.\n\n    The first 8, 'nearest', 'bilinear', 'cubic', 'cubic_spline',\n    'lanczos', 'average', 'mode', and 'gauss', are available for making\n    dataset overviews.\n\n    'max', 'min', 'med', 'q1', 'q3' are only supported in GDAL >= 2.0.0.\n\n    'nearest', 'bilinear', 'cubic', 'cubic_spline', 'lanczos',\n    'average', 'mode' are always available (GDAL >= 1.10).\n\n    'sum' is only supported in GDAL >= 3.1.\n\n    'rms' is only supported in GDAL >= 3.3.\n\n    Note: 'gauss' is not available to the functions in rio.warp.\n    \"\"\"\n    nearest = 0\n    bilinear = 1\n    cubic = 2\n    cubic_spline = 3\n    lanczos = 4\n    average = 5\n    mode = 6\n    gauss = 7\n    max = 8\n    min = 9\n    med = 10\n    q1 = 11\n    q3 = 12\n    sum = 13\n    rms = 14\n\n\nclass Compression(Enum):\n    \"\"\"Available compression algorithms.\"\"\"\n    jpeg = 'JPEG'\n    lzw = 'LZW'\n    packbits = 'PACKBITS'\n    deflate = 'DEFLATE'\n    ccittrle = 'CCITTRLE'\n    ccittfax3 = 'CCITTFAX3'\n    ccittfax4 = 'CCITTFAX4'\n    lzma = 'LZMA'\n    none = 'NONE'\n    zstd = 'ZSTD'\n    lerc = 'LERC'\n    webp = 'WEBP'\n    jpeg2000 = 'JPEG2000'\n\n\nclass Interleaving(Enum):\n    pixel = 'PIXEL'\n    line = 'LINE'\n    band = 'BAND'\n\n\nclass MaskFlags(IntEnum):\n    all_valid = 1\n    per_dataset = 2\n    alpha = 4\n    nodata = 8\n\n\nclass PhotometricInterp(Enum):\n    black = 'MINISBLACK'\n    white = 'MINISWHITE'\n    rgb = 'RGB'\n    cmyk = 'CMYK'\n    ycbcr = 'YCbCr'\n    cielab = 'CIELAB'\n    icclab = 'ICCLAB'\n    itulab = 'ITULAB'\n\nclass MergeAlg(Enum):\n    \"\"\"Available rasterization algorithms\"\"\"\n    replace = 'REPLACE'\n    add = 'ADD'\n", "path": "rasterio/enums.py"}, {"content": "# coding: utf-8\n\"\"\"Manage overviews of a dataset.\"\"\"\n\nfrom functools import reduce\nimport logging\nimport operator\n\nimport click\n\nfrom . import options\nimport rasterio\nfrom rasterio.enums import Resampling\n\n\ndef build_handler(ctx, param, value):\n    if value:\n        try:\n            if '^' in value:\n                base, exp_range = value.split('^')\n                exp_min, exp_max = (int(v) for v in exp_range.split('..'))\n                value = [pow(int(base), k) for k in range(exp_min, exp_max + 1)]\n            elif ',' in value:\n                value = [int(v) for v in value.split(',')]\n            elif value == \"auto\":\n                pass\n            else:\n                raise Exception\n        except Exception:\n            raise click.BadParameter(u\"must match 'n,n,n,\u2026', 'n^n..n', or 'auto'.\")\n    return value\n\n\ndef get_maximum_overview_level(width, height, minsize=256):\n    \"\"\"\n    Calculate the maximum overview level of a dataset at which\n    the smallest overview is smaller than `minsize`.\n\n    Attributes\n    ----------\n    width : int\n        Width of the dataset.\n    height : int\n        Height of the dataset.\n    minsize : int (default: 256)\n        Minimum overview size.\n\n    Returns\n    -------\n    overview_level: int\n        overview level.\n\n    \"\"\"\n    overview_level = 0\n    overview_factor = 1\n    while min(width // overview_factor, height // overview_factor) > minsize:\n        overview_factor *= 2\n        overview_level += 1\n\n    return overview_level\n\n\n@click.command('overview', short_help=\"Construct overviews in an existing dataset.\")\n@options.file_in_arg\n@click.option('--build', callback=build_handler, metavar=u\"f1,f2,\u2026|b^min..max|auto\",\n              help=\"A sequence of decimation factors specified as \"\n                   \"comma-separated list of numbers or a base and range of \"\n                   \"exponents, or 'auto' to automatically determine the maximum factor.\")\n@click.option('--ls', help=\"Print the overviews for each band.\",\n              is_flag=True, default=False)\n@click.option('--rebuild', help=\"Reconstruct existing overviews.\",\n              is_flag=True, default=False)\n@click.option('--resampling', help=\"Resampling algorithm.\",\n              type=click.Choice(\n                  [it.name for it in Resampling if it.value in [0, 1, 2, 3, 4, 5, 6, 7]]),\n              default='nearest', show_default=True)\n@click.pass_context\ndef overview(ctx, input, build, ls, rebuild, resampling):\n    \"\"\"Construct overviews in an existing dataset.\n\n    A pyramid of overviews computed once and stored in the dataset can\n    improve performance in some applications.\n\n    The decimation levels at which to build overviews can be specified as\n    a comma separated list\n\n      rio overview --build 2,4,8,16\n\n    or a base and range of exponents\n\n      rio overview --build 2^1..4\n\n    or 'auto' to automatically determine the maximum decimation level at\n    which the smallest overview is smaller than 256 pixels in size.\n\n      rio overview --build auto\n\n    Note that overviews can not currently be removed and are not\n    automatically updated when the dataset's primary bands are\n    modified.\n\n    Information about existing overviews can be printed using the --ls\n    option.\n\n      rio overview --ls\n\n    \"\"\"\n    with ctx.obj['env']:\n        if ls:\n            with rasterio.open(input, 'r') as dst:\n                resampling_method = dst.tags(\n                    ns='rio_overview').get('resampling') or 'unknown'\n\n                click.echo(\"Overview factors:\")\n                for idx in dst.indexes:\n                    click.echo(\"  Band %d: %s (method: '%s')\" % (\n                        idx, dst.overviews(idx) or 'None', resampling_method))\n        elif rebuild:\n            with rasterio.open(input, 'r+') as dst:\n                # Build the same overviews for all bands.\n                factors = reduce(\n                    operator.or_,\n                    [set(dst.overviews(i)) for i in dst.indexes])\n\n                # Attempt to recover the resampling method from dataset tags.\n                resampling_method = dst.tags(\n                    ns='rio_overview').get('resampling') or resampling\n\n                dst.build_overviews(\n                    list(factors), Resampling[resampling_method])\n\n        elif build:\n            with rasterio.open(input, 'r+') as dst:\n                if build == \"auto\":\n                    overview_level = get_maximum_overview_level(dst.width, dst.height)\n                    build = [2 ** j for j in range(1, overview_level + 1)]\n                dst.build_overviews(build, Resampling[resampling])\n\n                # Save the resampling method to a tag.\n                dst.update_tags(ns='rio_overview', resampling=resampling)\n\n        else:\n            raise click.UsageError(\n                \"Please specify --ls, --rebuild, or --build ...\")\n", "path": "rasterio/rio/overview.py"}], "after_files": [{"content": "\"\"\"Enumerations.\"\"\"\n\nfrom enum import Enum, IntEnum\n\n\nclass ColorInterp(IntEnum):\n    \"\"\"Raster band color interpretation.\"\"\"\n    undefined = 0\n    gray = 1\n    grey = 1\n    palette = 2\n    red = 3\n    green = 4\n    blue = 5\n    alpha = 6\n    hue = 7\n    saturation = 8\n    lightness = 9\n    cyan = 10\n    magenta = 11\n    yellow = 12\n    black = 13\n    Y = 14\n    Cb = 15\n    Cr = 16\n\n\nclass Resampling(IntEnum):\n    \"\"\"Available warp resampling algorithms.\n\n    The first 8, 'nearest', 'bilinear', 'cubic', 'cubic_spline',\n    'lanczos', 'average', 'mode', and 'gauss', are available for making\n    dataset overviews.\n\n    'max', 'min', 'med', 'q1', 'q3' are only supported in GDAL >= 2.0.0.\n\n    'nearest', 'bilinear', 'cubic', 'cubic_spline', 'lanczos',\n    'average', 'mode' are always available (GDAL >= 1.10).\n\n    'sum' is only supported in GDAL >= 3.1.\n\n    'rms' is only supported in GDAL >= 3.3.\n\n    Note: 'gauss' is not available to the functions in rio.warp.\n    \"\"\"\n    nearest = 0\n    bilinear = 1\n    cubic = 2\n    cubic_spline = 3\n    lanczos = 4\n    average = 5\n    mode = 6\n    gauss = 7\n    max = 8\n    min = 9\n    med = 10\n    q1 = 11\n    q3 = 12\n    sum = 13\n    rms = 14\n\n\nclass OverviewResampling(IntEnum):\n    \"\"\"Available Overview resampling algorithms.\n\n    The first 8, 'nearest', 'bilinear', 'cubic', 'cubic_spline',\n    'lanczos', 'average', 'mode', and 'gauss', are available for making\n    dataset overviews.\n\n    'nearest', 'bilinear', 'cubic', 'cubic_spline', 'lanczos',\n    'average', 'mode' are always available (GDAL >= 1.10).\n\n    'rms' is only supported in GDAL >= 3.3.\n\n    \"\"\"\n    nearest = 0\n    bilinear = 1\n    cubic = 2\n    cubic_spline = 3\n    lanczos = 4\n    average = 5\n    mode = 6\n    gauss = 7\n    rms = 14\n\n\nclass Compression(Enum):\n    \"\"\"Available compression algorithms.\"\"\"\n    jpeg = 'JPEG'\n    lzw = 'LZW'\n    packbits = 'PACKBITS'\n    deflate = 'DEFLATE'\n    ccittrle = 'CCITTRLE'\n    ccittfax3 = 'CCITTFAX3'\n    ccittfax4 = 'CCITTFAX4'\n    lzma = 'LZMA'\n    none = 'NONE'\n    zstd = 'ZSTD'\n    lerc = 'LERC'\n    webp = 'WEBP'\n    jpeg2000 = 'JPEG2000'\n\n\nclass Interleaving(Enum):\n    pixel = 'PIXEL'\n    line = 'LINE'\n    band = 'BAND'\n\n\nclass MaskFlags(IntEnum):\n    all_valid = 1\n    per_dataset = 2\n    alpha = 4\n    nodata = 8\n\n\nclass PhotometricInterp(Enum):\n    black = 'MINISBLACK'\n    white = 'MINISWHITE'\n    rgb = 'RGB'\n    cmyk = 'CMYK'\n    ycbcr = 'YCbCr'\n    cielab = 'CIELAB'\n    icclab = 'ICCLAB'\n    itulab = 'ITULAB'\n\nclass MergeAlg(Enum):\n    \"\"\"Available rasterization algorithms\"\"\"\n    replace = 'REPLACE'\n    add = 'ADD'\n", "path": "rasterio/enums.py"}, {"content": "# coding: utf-8\n\"\"\"Manage overviews of a dataset.\"\"\"\n\nfrom functools import reduce\nimport logging\nimport operator\n\nimport click\n\nfrom . import options\nimport rasterio\nfrom rasterio.enums import OverviewResampling\n\n\ndef build_handler(ctx, param, value):\n    if value:\n        try:\n            if '^' in value:\n                base, exp_range = value.split('^')\n                exp_min, exp_max = (int(v) for v in exp_range.split('..'))\n                value = [pow(int(base), k) for k in range(exp_min, exp_max + 1)]\n            elif ',' in value:\n                value = [int(v) for v in value.split(',')]\n            elif value == \"auto\":\n                pass\n            else:\n                raise Exception\n        except Exception:\n            raise click.BadParameter(u\"must match 'n,n,n,\u2026', 'n^n..n', or 'auto'.\")\n    return value\n\n\ndef get_maximum_overview_level(width, height, minsize=256):\n    \"\"\"\n    Calculate the maximum overview level of a dataset at which\n    the smallest overview is smaller than `minsize`.\n\n    Attributes\n    ----------\n    width : int\n        Width of the dataset.\n    height : int\n        Height of the dataset.\n    minsize : int (default: 256)\n        Minimum overview size.\n\n    Returns\n    -------\n    overview_level: int\n        overview level.\n\n    \"\"\"\n    overview_level = 0\n    overview_factor = 1\n    while min(width // overview_factor, height // overview_factor) > minsize:\n        overview_factor *= 2\n        overview_level += 1\n\n    return overview_level\n\n\n@click.command('overview', short_help=\"Construct overviews in an existing dataset.\")\n@options.file_in_arg\n@click.option('--build', callback=build_handler, metavar=u\"f1,f2,\u2026|b^min..max|auto\",\n              help=\"A sequence of decimation factors specified as \"\n                   \"comma-separated list of numbers or a base and range of \"\n                   \"exponents, or 'auto' to automatically determine the maximum factor.\")\n@click.option('--ls', help=\"Print the overviews for each band.\",\n              is_flag=True, default=False)\n@click.option('--rebuild', help=\"Reconstruct existing overviews.\",\n              is_flag=True, default=False)\n@click.option('--resampling', help=\"Resampling algorithm.\",\n              type=click.Choice([it.name for it in OverviewResampling]),\n              default='nearest', show_default=True)\n@click.pass_context\ndef overview(ctx, input, build, ls, rebuild, resampling):\n    \"\"\"Construct overviews in an existing dataset.\n\n    A pyramid of overviews computed once and stored in the dataset can\n    improve performance in some applications.\n\n    The decimation levels at which to build overviews can be specified as\n    a comma separated list\n\n      rio overview --build 2,4,8,16\n\n    or a base and range of exponents\n\n      rio overview --build 2^1..4\n\n    or 'auto' to automatically determine the maximum decimation level at\n    which the smallest overview is smaller than 256 pixels in size.\n\n      rio overview --build auto\n\n    Note that overviews can not currently be removed and are not\n    automatically updated when the dataset's primary bands are\n    modified.\n\n    Information about existing overviews can be printed using the --ls\n    option.\n\n      rio overview --ls\n\n    \"\"\"\n    with ctx.obj['env']:\n        if ls:\n            with rasterio.open(input, 'r') as dst:\n                resampling_method = dst.tags(\n                    ns='rio_overview').get('resampling') or 'unknown'\n\n                click.echo(\"Overview factors:\")\n                for idx in dst.indexes:\n                    click.echo(\"  Band %d: %s (method: '%s')\" % (\n                        idx, dst.overviews(idx) or 'None', resampling_method))\n        elif rebuild:\n            with rasterio.open(input, 'r+') as dst:\n                # Build the same overviews for all bands.\n                factors = reduce(\n                    operator.or_,\n                    [set(dst.overviews(i)) for i in dst.indexes])\n\n                # Attempt to recover the resampling method from dataset tags.\n                resampling_method = dst.tags(\n                    ns='rio_overview').get('resampling') or resampling\n\n                dst.build_overviews(\n                    list(factors), OverviewResampling[resampling_method])\n\n        elif build:\n            with rasterio.open(input, 'r+') as dst:\n                if build == \"auto\":\n                    overview_level = get_maximum_overview_level(dst.width, dst.height)\n                    build = [2 ** j for j in range(1, overview_level + 1)]\n                dst.build_overviews(build, OverviewResampling[resampling])\n\n                # Save the resampling method to a tag.\n                dst.update_tags(ns='rio_overview', resampling=resampling)\n\n        else:\n            raise click.UsageError(\n                \"Please specify --ls, --rebuild, or --build ...\")\n", "path": "rasterio/rio/overview.py"}]}