We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
WarpedVRT issue when alpha 
In https://github.com/rasterio/rasterio/blob/d008e8aab38afd5d14d98499847754bd0eeaa501/rasterio/_warp.pyx#L978-L979
`dst_alpha` will always be set to `0` when `add_alpha` is False. 

This cause an issue when we already have an alpha band in the data. For some reason the output data will then be totally different.

#### Show image difference 

```python
#### Comparison between rasterio / WarpedVRT and GDALWarpedVRT

```python
import os
import rasterio
from rasterio.vrt import WarpedVRT

# Pure Rasterio Read
with rasterio.open("fake.tif") as src:
    alpha = src.read(out_shape=(1, int(src.height/10), int(src.width/10)), indexes=(6,))
    arr = src.read(out_shape=(1, int(src.height/10), int(src.width/10)), indexes=(1,))
    print("Rasterio - mean: ", arr[alpha > 0].mean())

# Use WarpedVRT but without reprojection
with rasterio.open("fake.tif") as src:
    with WarpedVRT(src, add_alpha=False) as vrt:
        alpha = src.read(out_shape=(1, int(src.height/10), int(src.width/10)), indexes=(6,))
        arr = vrt.read(out_shape=(1, int(src.height/10), int(src.width/10)), indexes=(1,))
        print("WarpedVRT - mean: ", arr[alpha > 0].mean())


# Create a WarpedVRT using GDAL
os.system("gdalwarp -of VRT fake.tif fake.vrt -overwrite")

with rasterio.open("fake.vrt") as src:
    alpha = src.read(out_shape=(1, int(src.height/10), int(src.width/10)), indexes=(6,))
    arr = src.read(out_shape=(1, int(src.height/10), int(src.width/10)), indexes=(1,))
    print("GDAL - mean: ", arr[alpha > 0].mean())
>>> Rasterio - mean:  10000
>>> WarpedVRT - mean:  39
>>> GDAL - mean: 10000
```

First reported in https://github.com/developmentseed/titiler/discussions/629

--- 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/vrt.py`
Content:
```
1 """rasterio.vrt: a module concerned with GDAL VRTs"""
2 
3 import xml.etree.ElementTree as ET
4 
5 import rasterio
6 from rasterio._warp import WarpedVRTReaderBase
7 from rasterio.dtypes import _gdal_typename
8 from rasterio.enums import MaskFlags
9 from rasterio._path import _parse_path
10 from rasterio.transform import TransformMethodsMixin
11 from rasterio.windows import WindowMethodsMixin
12 
13 
14 class WarpedVRT(WarpedVRTReaderBase, WindowMethodsMixin,
15                 TransformMethodsMixin):
16     """A virtual warped dataset.
17 
18     Abstracts the details of raster warping and allows access to data
19     that is reprojected when read.
20 
21     This class is backed by an in-memory GDAL VRTWarpedDataset VRT file.
22 
23     Parameters
24     ----------
25     src_dataset : dataset object
26         The warp source.
27     src_crs : CRS or str, optional
28         Overrides the coordinate reference system of `src_dataset`.
29     src_transfrom : Affine, optional
30         Overrides the transform of `src_dataset`.
31     src_nodata : float, optional
32         Overrides the nodata value of `src_dataset`, which is the
33         default.
34     crs : CRS or str, optional
35         The coordinate reference system at the end of the warp
36         operation.  Default: the crs of `src_dataset`. dst_crs was
37         a deprecated alias for this parameter.
38     transform : Affine, optional
39         The transform for the virtual dataset. Default: will be
40         computed from the attributes of `src_dataset`. dst_transform
41         was a deprecated alias for this parameter.
42     height, width: int, optional
43         The dimensions of the virtual dataset. Defaults: will be
44         computed from the attributes of `src_dataset`. dst_height
45         and dst_width were deprecated alias for these parameters.
46     nodata : float, optional
47         Nodata value for the virtual dataset. Default: the nodata
48         value of `src_dataset` or 0.0. dst_nodata was a deprecated
49         alias for this parameter.
50     resampling : Resampling, optional
51         Warp resampling algorithm. Default: `Resampling.nearest`.
52     tolerance : float, optional
53         The maximum error tolerance in input pixels when
54         approximating the warp transformation. Default: 0.125,
55         or one-eigth of a pixel.
56     src_alpha : int, optional
57         Index of a source band to use as an alpha band for warping.
58     add_alpha : bool, optional
59         Whether to add an alpha masking band to the virtual dataset.
60         Default: False. This option will cause deletion of the VRT
61         nodata value.
62     init_dest_nodata : bool, optional
63         Whether or not to initialize output to `nodata`. Default:
64         True.
65     warp_mem_limit : int, optional
66         The warp operation's memory limit in MB. The default (0)
67         means 64 MB with GDAL 2.2.
68     dtype : str, optional
69         The working data type for warp operation and output.
70     warp_extras : dict
71         GDAL extra warp options. See
72         https://gdal.org/doxygen/structGDALWarpOptions.html.
73 
74     Attributes
75     ----------
76     src_dataset : dataset
77         The dataset object to be virtually warped.
78     resampling : int
79         One of the values from rasterio.enums.Resampling. The default is
80         `Resampling.nearest`.
81     tolerance : float
82         The maximum error tolerance in input pixels when approximating
83         the warp transformation. The default is 0.125.
84     src_nodata: int or float, optional
85         The source nodata value.  Pixels with this value will not be
86         used for interpolation. If not set, it will be default to the
87         nodata value of the source image, if available.
88     dst_nodata: int or float, optional
89         The nodata value used to initialize the destination; it will
90         remain in all areas not covered by the reprojected source.
91         Defaults to the value of src_nodata, or 0 (gdal default).
92     working_dtype : str, optional
93         The working data type for warp operation and output.
94     warp_extras : dict
95         GDAL extra warp options. See
96         https://gdal.org/doxygen/structGDALWarpOptions.html.
97 
98     Examples
99     --------
100 
101     >>> with rasterio.open('tests/data/RGB.byte.tif') as src:
102     ...     with WarpedVRT(src, crs='EPSG:3857') as vrt:
103     ...         data = vrt.read()
104 
105     """
106 
107     def __repr__(self):
108         return "<{} WarpedVRT name='{}' mode='{}'>".format(
109             self.closed and 'closed' or 'open', self.name, self.mode)
110 
111     def __enter__(self):
112         self.start()
113         return self
114 
115     def __exit__(self, *args, **kwargs):
116         if not self._closed:
117             self.close()
118 
119     def __del__(self):
120         if not self._closed:
121             self.close()
122 
123 
124 def _boundless_vrt_doc(
125         src_dataset, nodata=None, background=None, hidenodata=False,
126         width=None, height=None, transform=None, masked=False):
127     """Make a VRT XML document.
128 
129     Parameters
130     ----------
131     src_dataset : Dataset
132         The dataset to wrap.
133     background : int or float, optional
134         The background fill value for the boundless VRT.
135     masked : bool
136         If True, the src_dataset is replaced by its valid data mask.
137 
138     Returns
139     -------
140     str
141         An XML text string.
142     """
143 
144     nodata = nodata or src_dataset.nodata
145     width = width or src_dataset.width
146     height = height or src_dataset.height
147     transform = transform or src_dataset.transform
148 
149     vrtdataset = ET.Element('VRTDataset')
150     vrtdataset.attrib['rasterYSize'] = str(height)
151     vrtdataset.attrib['rasterXSize'] = str(width)
152     srs = ET.SubElement(vrtdataset, 'SRS')
153     srs.text = src_dataset.crs.wkt if src_dataset.crs else ""
154     geotransform = ET.SubElement(vrtdataset, 'GeoTransform')
155     geotransform.text = ','.join([str(v) for v in transform.to_gdal()])
156 
157     for bidx, ci, block_shape, dtype in zip(src_dataset.indexes, src_dataset.colorinterp, src_dataset.block_shapes, src_dataset.dtypes):
158         vrtrasterband = ET.SubElement(vrtdataset, 'VRTRasterBand')
159         vrtrasterband.attrib['dataType'] = _gdal_typename(dtype)
160         vrtrasterband.attrib['band'] = str(bidx)
161 
162         if background is not None or nodata is not None:
163             nodatavalue = ET.SubElement(vrtrasterband, 'NoDataValue')
164             nodatavalue.text = str(background or nodata)
165 
166             if hidenodata:
167                 hidenodatavalue = ET.SubElement(vrtrasterband, 'HideNoDataValue')
168                 hidenodatavalue.text = "1"
169 
170         colorinterp = ET.SubElement(vrtrasterband, 'ColorInterp')
171         colorinterp.text = ci.name.capitalize()
172 
173         complexsource = ET.SubElement(vrtrasterband, 'ComplexSource')
174         sourcefilename = ET.SubElement(complexsource, 'SourceFilename')
175         sourcefilename.attrib['relativeToVRT'] = "0"
176         sourcefilename.attrib["shared"] = "0"
177         sourcefilename.text = _parse_path(src_dataset.name).as_vsi()
178         sourceband = ET.SubElement(complexsource, 'SourceBand')
179         sourceband.text = str(bidx)
180         sourceproperties = ET.SubElement(complexsource, 'SourceProperties')
181         sourceproperties.attrib['RasterXSize'] = str(width)
182         sourceproperties.attrib['RasterYSize'] = str(height)
183         sourceproperties.attrib['dataType'] = _gdal_typename(dtype)
184         sourceproperties.attrib['BlockYSize'] = str(block_shape[0])
185         sourceproperties.attrib['BlockXSize'] = str(block_shape[1])
186         srcrect = ET.SubElement(complexsource, 'SrcRect')
187         srcrect.attrib['xOff'] = '0'
188         srcrect.attrib['yOff'] = '0'
189         srcrect.attrib['xSize'] = str(src_dataset.width)
190         srcrect.attrib['ySize'] = str(src_dataset.height)
191         dstrect = ET.SubElement(complexsource, 'DstRect')
192         dstrect.attrib['xOff'] = str((src_dataset.transform.xoff - transform.xoff) / transform.a)
193         dstrect.attrib['yOff'] = str((src_dataset.transform.yoff - transform.yoff) / transform.e)
194         dstrect.attrib['xSize'] = str(src_dataset.width * src_dataset.transform.a / transform.a)
195         dstrect.attrib['ySize'] = str(src_dataset.height * src_dataset.transform.e / transform.e)
196 
197         if src_dataset.nodata is not None:
198             nodata_elem = ET.SubElement(complexsource, 'NODATA')
199             nodata_elem.text = str(src_dataset.nodata)
200 
201         if src_dataset.options is not None:
202             openoptions = ET.SubElement(complexsource, 'OpenOptions')
203             for ookey, oovalue in src_dataset.options.items():
204                 ooi = ET.SubElement(openoptions, 'OOI')
205                 ooi.attrib['key'] = str(ookey)
206                 ooi.text = str(oovalue)
207 
208         # Effectively replaces all values of the source dataset with
209         # 255.  Due to GDAL optimizations, the source dataset will not
210         # be read, so we get a performance improvement.
211         if masked:
212             scaleratio = ET.SubElement(complexsource, 'ScaleRatio')
213             scaleratio.text = '0'
214             scaleoffset = ET.SubElement(complexsource, 'ScaleOffset')
215             scaleoffset.text = '255'
216 
217     if all(MaskFlags.per_dataset in flags for flags in src_dataset.mask_flag_enums):
218         maskband = ET.SubElement(vrtdataset, 'MaskBand')
219         vrtrasterband = ET.SubElement(maskband, 'VRTRasterBand')
220         vrtrasterband.attrib['dataType'] = 'Byte'
221 
222         simplesource = ET.SubElement(vrtrasterband, 'SimpleSource')
223         sourcefilename = ET.SubElement(simplesource, 'SourceFilename')
224         sourcefilename.attrib['relativeToVRT'] = "0"
225         sourcefilename.attrib["shared"] = "0"
226         sourcefilename.text = _parse_path(src_dataset.name).as_vsi()
227 
228         sourceband = ET.SubElement(simplesource, 'SourceBand')
229         sourceband.text = 'mask,1'
230         sourceproperties = ET.SubElement(simplesource, 'SourceProperties')
231         sourceproperties.attrib['RasterXSize'] = str(width)
232         sourceproperties.attrib['RasterYSize'] = str(height)
233         sourceproperties.attrib['dataType'] = 'Byte'
234         sourceproperties.attrib['BlockYSize'] = str(block_shape[0])
235         sourceproperties.attrib['BlockXSize'] = str(block_shape[1])
236         srcrect = ET.SubElement(simplesource, 'SrcRect')
237         srcrect.attrib['xOff'] = '0'
238         srcrect.attrib['yOff'] = '0'
239         srcrect.attrib['xSize'] = str(src_dataset.width)
240         srcrect.attrib['ySize'] = str(src_dataset.height)
241         dstrect = ET.SubElement(simplesource, 'DstRect')
242         dstrect.attrib['xOff'] = str((src_dataset.transform.xoff - transform.xoff) / transform.a)
243         dstrect.attrib['yOff'] = str((src_dataset.transform.yoff - transform.yoff) / transform.e)
244         dstrect.attrib['xSize'] = str(src_dataset.width)
245         dstrect.attrib['ySize'] = str(src_dataset.height)
246 
247     return ET.tostring(vrtdataset).decode('ascii')
248
```
--- 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/vrt.py b/rasterio/vrt.py
--- a/rasterio/vrt.py
+++ b/rasterio/vrt.py
@@ -55,6 +55,8 @@
         or one-eigth of a pixel.
     src_alpha : int, optional
         Index of a source band to use as an alpha band for warping.
+    dst_alpha : int, optional
+        Index of a destination band to use as an alpha band for warping.
     add_alpha : bool, optional
         Whether to add an alpha masking band to the virtual dataset.
         Default: False. This option will cause deletion of the VRT

{"golden_diff": "diff --git a/rasterio/vrt.py b/rasterio/vrt.py\n--- a/rasterio/vrt.py\n+++ b/rasterio/vrt.py\n@@ -55,6 +55,8 @@\n         or one-eigth of a pixel.\n     src_alpha : int, optional\n         Index of a source band to use as an alpha band for warping.\n+    dst_alpha : int, optional\n+        Index of a destination band to use as an alpha band for warping.\n     add_alpha : bool, optional\n         Whether to add an alpha masking band to the virtual dataset.\n         Default: False. This option will cause deletion of the VRT\n", "issue": "WarpedVRT issue when alpha \nIn https://github.com/rasterio/rasterio/blob/d008e8aab38afd5d14d98499847754bd0eeaa501/rasterio/_warp.pyx#L978-L979\r\n`dst_alpha` will always be set to `0` when `add_alpha` is False. \r\n\r\nThis cause an issue when we already have an alpha band in the data. For some reason the output data will then be totally different.\r\n\r\n#### Show image difference \r\n\r\n```python\r\n#### Comparison between rasterio / WarpedVRT and GDALWarpedVRT\r\n\r\n```python\r\nimport os\r\nimport rasterio\r\nfrom rasterio.vrt import WarpedVRT\r\n\r\n# Pure Rasterio Read\r\nwith rasterio.open(\"fake.tif\") as src:\r\n    alpha = src.read(out_shape=(1, int(src.height/10), int(src.width/10)), indexes=(6,))\r\n    arr = src.read(out_shape=(1, int(src.height/10), int(src.width/10)), indexes=(1,))\r\n    print(\"Rasterio - mean: \", arr[alpha > 0].mean())\r\n\r\n# Use WarpedVRT but without reprojection\r\nwith rasterio.open(\"fake.tif\") as src:\r\n    with WarpedVRT(src, add_alpha=False) as vrt:\r\n        alpha = src.read(out_shape=(1, int(src.height/10), int(src.width/10)), indexes=(6,))\r\n        arr = vrt.read(out_shape=(1, int(src.height/10), int(src.width/10)), indexes=(1,))\r\n        print(\"WarpedVRT - mean: \", arr[alpha > 0].mean())\r\n\r\n\r\n# Create a WarpedVRT using GDAL\r\nos.system(\"gdalwarp -of VRT fake.tif fake.vrt -overwrite\")\r\n\r\nwith rasterio.open(\"fake.vrt\") as src:\r\n    alpha = src.read(out_shape=(1, int(src.height/10), int(src.width/10)), indexes=(6,))\r\n    arr = src.read(out_shape=(1, int(src.height/10), int(src.width/10)), indexes=(1,))\r\n    print(\"GDAL - mean: \", arr[alpha > 0].mean())\r\n>>> Rasterio - mean:  10000\r\n>>> WarpedVRT - mean:  39\r\n>>> GDAL - mean: 10000\r\n```\r\n\r\nFirst reported in https://github.com/developmentseed/titiler/discussions/629\n", "before_files": [{"content": "\"\"\"rasterio.vrt: a module concerned with GDAL VRTs\"\"\"\n\nimport xml.etree.ElementTree as ET\n\nimport rasterio\nfrom rasterio._warp import WarpedVRTReaderBase\nfrom rasterio.dtypes import _gdal_typename\nfrom rasterio.enums import MaskFlags\nfrom rasterio._path import _parse_path\nfrom rasterio.transform import TransformMethodsMixin\nfrom rasterio.windows import WindowMethodsMixin\n\n\nclass WarpedVRT(WarpedVRTReaderBase, WindowMethodsMixin,\n                TransformMethodsMixin):\n    \"\"\"A virtual warped dataset.\n\n    Abstracts the details of raster warping and allows access to data\n    that is reprojected when read.\n\n    This class is backed by an in-memory GDAL VRTWarpedDataset VRT file.\n\n    Parameters\n    ----------\n    src_dataset : dataset object\n        The warp source.\n    src_crs : CRS or str, optional\n        Overrides the coordinate reference system of `src_dataset`.\n    src_transfrom : Affine, optional\n        Overrides the transform of `src_dataset`.\n    src_nodata : float, optional\n        Overrides the nodata value of `src_dataset`, which is the\n        default.\n    crs : CRS or str, optional\n        The coordinate reference system at the end of the warp\n        operation.  Default: the crs of `src_dataset`. dst_crs was\n        a deprecated alias for this parameter.\n    transform : Affine, optional\n        The transform for the virtual dataset. Default: will be\n        computed from the attributes of `src_dataset`. dst_transform\n        was a deprecated alias for this parameter.\n    height, width: int, optional\n        The dimensions of the virtual dataset. Defaults: will be\n        computed from the attributes of `src_dataset`. dst_height\n        and dst_width were deprecated alias for these parameters.\n    nodata : float, optional\n        Nodata value for the virtual dataset. Default: the nodata\n        value of `src_dataset` or 0.0. dst_nodata was a deprecated\n        alias for this parameter.\n    resampling : Resampling, optional\n        Warp resampling algorithm. Default: `Resampling.nearest`.\n    tolerance : float, optional\n        The maximum error tolerance in input pixels when\n        approximating the warp transformation. Default: 0.125,\n        or one-eigth of a pixel.\n    src_alpha : int, optional\n        Index of a source band to use as an alpha band for warping.\n    add_alpha : bool, optional\n        Whether to add an alpha masking band to the virtual dataset.\n        Default: False. This option will cause deletion of the VRT\n        nodata value.\n    init_dest_nodata : bool, optional\n        Whether or not to initialize output to `nodata`. Default:\n        True.\n    warp_mem_limit : int, optional\n        The warp operation's memory limit in MB. The default (0)\n        means 64 MB with GDAL 2.2.\n    dtype : str, optional\n        The working data type for warp operation and output.\n    warp_extras : dict\n        GDAL extra warp options. See\n        https://gdal.org/doxygen/structGDALWarpOptions.html.\n\n    Attributes\n    ----------\n    src_dataset : dataset\n        The dataset object to be virtually warped.\n    resampling : int\n        One of the values from rasterio.enums.Resampling. The default is\n        `Resampling.nearest`.\n    tolerance : float\n        The maximum error tolerance in input pixels when approximating\n        the warp transformation. The default is 0.125.\n    src_nodata: int or float, optional\n        The source nodata value.  Pixels with this value will not be\n        used for interpolation. If not set, it will be default to the\n        nodata value of the source image, if available.\n    dst_nodata: int or float, optional\n        The nodata value used to initialize the destination; it will\n        remain in all areas not covered by the reprojected source.\n        Defaults to the value of src_nodata, or 0 (gdal default).\n    working_dtype : str, optional\n        The working data type for warp operation and output.\n    warp_extras : dict\n        GDAL extra warp options. See\n        https://gdal.org/doxygen/structGDALWarpOptions.html.\n\n    Examples\n    --------\n\n    >>> with rasterio.open('tests/data/RGB.byte.tif') as src:\n    ...     with WarpedVRT(src, crs='EPSG:3857') as vrt:\n    ...         data = vrt.read()\n\n    \"\"\"\n\n    def __repr__(self):\n        return \"<{} WarpedVRT name='{}' mode='{}'>\".format(\n            self.closed and 'closed' or 'open', self.name, self.mode)\n\n    def __enter__(self):\n        self.start()\n        return self\n\n    def __exit__(self, *args, **kwargs):\n        if not self._closed:\n            self.close()\n\n    def __del__(self):\n        if not self._closed:\n            self.close()\n\n\ndef _boundless_vrt_doc(\n        src_dataset, nodata=None, background=None, hidenodata=False,\n        width=None, height=None, transform=None, masked=False):\n    \"\"\"Make a VRT XML document.\n\n    Parameters\n    ----------\n    src_dataset : Dataset\n        The dataset to wrap.\n    background : int or float, optional\n        The background fill value for the boundless VRT.\n    masked : bool\n        If True, the src_dataset is replaced by its valid data mask.\n\n    Returns\n    -------\n    str\n        An XML text string.\n    \"\"\"\n\n    nodata = nodata or src_dataset.nodata\n    width = width or src_dataset.width\n    height = height or src_dataset.height\n    transform = transform or src_dataset.transform\n\n    vrtdataset = ET.Element('VRTDataset')\n    vrtdataset.attrib['rasterYSize'] = str(height)\n    vrtdataset.attrib['rasterXSize'] = str(width)\n    srs = ET.SubElement(vrtdataset, 'SRS')\n    srs.text = src_dataset.crs.wkt if src_dataset.crs else \"\"\n    geotransform = ET.SubElement(vrtdataset, 'GeoTransform')\n    geotransform.text = ','.join([str(v) for v in transform.to_gdal()])\n\n    for bidx, ci, block_shape, dtype in zip(src_dataset.indexes, src_dataset.colorinterp, src_dataset.block_shapes, src_dataset.dtypes):\n        vrtrasterband = ET.SubElement(vrtdataset, 'VRTRasterBand')\n        vrtrasterband.attrib['dataType'] = _gdal_typename(dtype)\n        vrtrasterband.attrib['band'] = str(bidx)\n\n        if background is not None or nodata is not None:\n            nodatavalue = ET.SubElement(vrtrasterband, 'NoDataValue')\n            nodatavalue.text = str(background or nodata)\n\n            if hidenodata:\n                hidenodatavalue = ET.SubElement(vrtrasterband, 'HideNoDataValue')\n                hidenodatavalue.text = \"1\"\n\n        colorinterp = ET.SubElement(vrtrasterband, 'ColorInterp')\n        colorinterp.text = ci.name.capitalize()\n\n        complexsource = ET.SubElement(vrtrasterband, 'ComplexSource')\n        sourcefilename = ET.SubElement(complexsource, 'SourceFilename')\n        sourcefilename.attrib['relativeToVRT'] = \"0\"\n        sourcefilename.attrib[\"shared\"] = \"0\"\n        sourcefilename.text = _parse_path(src_dataset.name).as_vsi()\n        sourceband = ET.SubElement(complexsource, 'SourceBand')\n        sourceband.text = str(bidx)\n        sourceproperties = ET.SubElement(complexsource, 'SourceProperties')\n        sourceproperties.attrib['RasterXSize'] = str(width)\n        sourceproperties.attrib['RasterYSize'] = str(height)\n        sourceproperties.attrib['dataType'] = _gdal_typename(dtype)\n        sourceproperties.attrib['BlockYSize'] = str(block_shape[0])\n        sourceproperties.attrib['BlockXSize'] = str(block_shape[1])\n        srcrect = ET.SubElement(complexsource, 'SrcRect')\n        srcrect.attrib['xOff'] = '0'\n        srcrect.attrib['yOff'] = '0'\n        srcrect.attrib['xSize'] = str(src_dataset.width)\n        srcrect.attrib['ySize'] = str(src_dataset.height)\n        dstrect = ET.SubElement(complexsource, 'DstRect')\n        dstrect.attrib['xOff'] = str((src_dataset.transform.xoff - transform.xoff) / transform.a)\n        dstrect.attrib['yOff'] = str((src_dataset.transform.yoff - transform.yoff) / transform.e)\n        dstrect.attrib['xSize'] = str(src_dataset.width * src_dataset.transform.a / transform.a)\n        dstrect.attrib['ySize'] = str(src_dataset.height * src_dataset.transform.e / transform.e)\n\n        if src_dataset.nodata is not None:\n            nodata_elem = ET.SubElement(complexsource, 'NODATA')\n            nodata_elem.text = str(src_dataset.nodata)\n\n        if src_dataset.options is not None:\n            openoptions = ET.SubElement(complexsource, 'OpenOptions')\n            for ookey, oovalue in src_dataset.options.items():\n                ooi = ET.SubElement(openoptions, 'OOI')\n                ooi.attrib['key'] = str(ookey)\n                ooi.text = str(oovalue)\n\n        # Effectively replaces all values of the source dataset with\n        # 255.  Due to GDAL optimizations, the source dataset will not\n        # be read, so we get a performance improvement.\n        if masked:\n            scaleratio = ET.SubElement(complexsource, 'ScaleRatio')\n            scaleratio.text = '0'\n            scaleoffset = ET.SubElement(complexsource, 'ScaleOffset')\n            scaleoffset.text = '255'\n\n    if all(MaskFlags.per_dataset in flags for flags in src_dataset.mask_flag_enums):\n        maskband = ET.SubElement(vrtdataset, 'MaskBand')\n        vrtrasterband = ET.SubElement(maskband, 'VRTRasterBand')\n        vrtrasterband.attrib['dataType'] = 'Byte'\n\n        simplesource = ET.SubElement(vrtrasterband, 'SimpleSource')\n        sourcefilename = ET.SubElement(simplesource, 'SourceFilename')\n        sourcefilename.attrib['relativeToVRT'] = \"0\"\n        sourcefilename.attrib[\"shared\"] = \"0\"\n        sourcefilename.text = _parse_path(src_dataset.name).as_vsi()\n\n        sourceband = ET.SubElement(simplesource, 'SourceBand')\n        sourceband.text = 'mask,1'\n        sourceproperties = ET.SubElement(simplesource, 'SourceProperties')\n        sourceproperties.attrib['RasterXSize'] = str(width)\n        sourceproperties.attrib['RasterYSize'] = str(height)\n        sourceproperties.attrib['dataType'] = 'Byte'\n        sourceproperties.attrib['BlockYSize'] = str(block_shape[0])\n        sourceproperties.attrib['BlockXSize'] = str(block_shape[1])\n        srcrect = ET.SubElement(simplesource, 'SrcRect')\n        srcrect.attrib['xOff'] = '0'\n        srcrect.attrib['yOff'] = '0'\n        srcrect.attrib['xSize'] = str(src_dataset.width)\n        srcrect.attrib['ySize'] = str(src_dataset.height)\n        dstrect = ET.SubElement(simplesource, 'DstRect')\n        dstrect.attrib['xOff'] = str((src_dataset.transform.xoff - transform.xoff) / transform.a)\n        dstrect.attrib['yOff'] = str((src_dataset.transform.yoff - transform.yoff) / transform.e)\n        dstrect.attrib['xSize'] = str(src_dataset.width)\n        dstrect.attrib['ySize'] = str(src_dataset.height)\n\n    return ET.tostring(vrtdataset).decode('ascii')\n", "path": "rasterio/vrt.py"}], "after_files": [{"content": "\"\"\"rasterio.vrt: a module concerned with GDAL VRTs\"\"\"\n\nimport xml.etree.ElementTree as ET\n\nimport rasterio\nfrom rasterio._warp import WarpedVRTReaderBase\nfrom rasterio.dtypes import _gdal_typename\nfrom rasterio.enums import MaskFlags\nfrom rasterio._path import _parse_path\nfrom rasterio.transform import TransformMethodsMixin\nfrom rasterio.windows import WindowMethodsMixin\n\n\nclass WarpedVRT(WarpedVRTReaderBase, WindowMethodsMixin,\n                TransformMethodsMixin):\n    \"\"\"A virtual warped dataset.\n\n    Abstracts the details of raster warping and allows access to data\n    that is reprojected when read.\n\n    This class is backed by an in-memory GDAL VRTWarpedDataset VRT file.\n\n    Parameters\n    ----------\n    src_dataset : dataset object\n        The warp source.\n    src_crs : CRS or str, optional\n        Overrides the coordinate reference system of `src_dataset`.\n    src_transfrom : Affine, optional\n        Overrides the transform of `src_dataset`.\n    src_nodata : float, optional\n        Overrides the nodata value of `src_dataset`, which is the\n        default.\n    crs : CRS or str, optional\n        The coordinate reference system at the end of the warp\n        operation.  Default: the crs of `src_dataset`. dst_crs was\n        a deprecated alias for this parameter.\n    transform : Affine, optional\n        The transform for the virtual dataset. Default: will be\n        computed from the attributes of `src_dataset`. dst_transform\n        was a deprecated alias for this parameter.\n    height, width: int, optional\n        The dimensions of the virtual dataset. Defaults: will be\n        computed from the attributes of `src_dataset`. dst_height\n        and dst_width were deprecated alias for these parameters.\n    nodata : float, optional\n        Nodata value for the virtual dataset. Default: the nodata\n        value of `src_dataset` or 0.0. dst_nodata was a deprecated\n        alias for this parameter.\n    resampling : Resampling, optional\n        Warp resampling algorithm. Default: `Resampling.nearest`.\n    tolerance : float, optional\n        The maximum error tolerance in input pixels when\n        approximating the warp transformation. Default: 0.125,\n        or one-eigth of a pixel.\n    src_alpha : int, optional\n        Index of a source band to use as an alpha band for warping.\n    dst_alpha : int, optional\n        Index of a destination band to use as an alpha band for warping.\n    add_alpha : bool, optional\n        Whether to add an alpha masking band to the virtual dataset.\n        Default: False. This option will cause deletion of the VRT\n        nodata value.\n    init_dest_nodata : bool, optional\n        Whether or not to initialize output to `nodata`. Default:\n        True.\n    warp_mem_limit : int, optional\n        The warp operation's memory limit in MB. The default (0)\n        means 64 MB with GDAL 2.2.\n    dtype : str, optional\n        The working data type for warp operation and output.\n    warp_extras : dict\n        GDAL extra warp options. See\n        https://gdal.org/doxygen/structGDALWarpOptions.html.\n\n    Attributes\n    ----------\n    src_dataset : dataset\n        The dataset object to be virtually warped.\n    resampling : int\n        One of the values from rasterio.enums.Resampling. The default is\n        `Resampling.nearest`.\n    tolerance : float\n        The maximum error tolerance in input pixels when approximating\n        the warp transformation. The default is 0.125.\n    src_nodata: int or float, optional\n        The source nodata value.  Pixels with this value will not be\n        used for interpolation. If not set, it will be default to the\n        nodata value of the source image, if available.\n    dst_nodata: int or float, optional\n        The nodata value used to initialize the destination; it will\n        remain in all areas not covered by the reprojected source.\n        Defaults to the value of src_nodata, or 0 (gdal default).\n    working_dtype : str, optional\n        The working data type for warp operation and output.\n    warp_extras : dict\n        GDAL extra warp options. See\n        https://gdal.org/doxygen/structGDALWarpOptions.html.\n\n    Examples\n    --------\n\n    >>> with rasterio.open('tests/data/RGB.byte.tif') as src:\n    ...     with WarpedVRT(src, crs='EPSG:3857') as vrt:\n    ...         data = vrt.read()\n\n    \"\"\"\n\n    def __repr__(self):\n        return \"<{} WarpedVRT name='{}' mode='{}'>\".format(\n            self.closed and 'closed' or 'open', self.name, self.mode)\n\n    def __enter__(self):\n        self.start()\n        return self\n\n    def __exit__(self, *args, **kwargs):\n        if not self._closed:\n            self.close()\n\n    def __del__(self):\n        if not self._closed:\n            self.close()\n\n\ndef _boundless_vrt_doc(\n        src_dataset, nodata=None, background=None, hidenodata=False,\n        width=None, height=None, transform=None, masked=False):\n    \"\"\"Make a VRT XML document.\n\n    Parameters\n    ----------\n    src_dataset : Dataset\n        The dataset to wrap.\n    background : int or float, optional\n        The background fill value for the boundless VRT.\n    masked : bool\n        If True, the src_dataset is replaced by its valid data mask.\n\n    Returns\n    -------\n    str\n        An XML text string.\n    \"\"\"\n\n    nodata = nodata or src_dataset.nodata\n    width = width or src_dataset.width\n    height = height or src_dataset.height\n    transform = transform or src_dataset.transform\n\n    vrtdataset = ET.Element('VRTDataset')\n    vrtdataset.attrib['rasterYSize'] = str(height)\n    vrtdataset.attrib['rasterXSize'] = str(width)\n    srs = ET.SubElement(vrtdataset, 'SRS')\n    srs.text = src_dataset.crs.wkt if src_dataset.crs else \"\"\n    geotransform = ET.SubElement(vrtdataset, 'GeoTransform')\n    geotransform.text = ','.join([str(v) for v in transform.to_gdal()])\n\n    for bidx, ci, block_shape, dtype in zip(src_dataset.indexes, src_dataset.colorinterp, src_dataset.block_shapes, src_dataset.dtypes):\n        vrtrasterband = ET.SubElement(vrtdataset, 'VRTRasterBand')\n        vrtrasterband.attrib['dataType'] = _gdal_typename(dtype)\n        vrtrasterband.attrib['band'] = str(bidx)\n\n        if background is not None or nodata is not None:\n            nodatavalue = ET.SubElement(vrtrasterband, 'NoDataValue')\n            nodatavalue.text = str(background or nodata)\n\n            if hidenodata:\n                hidenodatavalue = ET.SubElement(vrtrasterband, 'HideNoDataValue')\n                hidenodatavalue.text = \"1\"\n\n        colorinterp = ET.SubElement(vrtrasterband, 'ColorInterp')\n        colorinterp.text = ci.name.capitalize()\n\n        complexsource = ET.SubElement(vrtrasterband, 'ComplexSource')\n        sourcefilename = ET.SubElement(complexsource, 'SourceFilename')\n        sourcefilename.attrib['relativeToVRT'] = \"0\"\n        sourcefilename.attrib[\"shared\"] = \"0\"\n        sourcefilename.text = _parse_path(src_dataset.name).as_vsi()\n        sourceband = ET.SubElement(complexsource, 'SourceBand')\n        sourceband.text = str(bidx)\n        sourceproperties = ET.SubElement(complexsource, 'SourceProperties')\n        sourceproperties.attrib['RasterXSize'] = str(width)\n        sourceproperties.attrib['RasterYSize'] = str(height)\n        sourceproperties.attrib['dataType'] = _gdal_typename(dtype)\n        sourceproperties.attrib['BlockYSize'] = str(block_shape[0])\n        sourceproperties.attrib['BlockXSize'] = str(block_shape[1])\n        srcrect = ET.SubElement(complexsource, 'SrcRect')\n        srcrect.attrib['xOff'] = '0'\n        srcrect.attrib['yOff'] = '0'\n        srcrect.attrib['xSize'] = str(src_dataset.width)\n        srcrect.attrib['ySize'] = str(src_dataset.height)\n        dstrect = ET.SubElement(complexsource, 'DstRect')\n        dstrect.attrib['xOff'] = str((src_dataset.transform.xoff - transform.xoff) / transform.a)\n        dstrect.attrib['yOff'] = str((src_dataset.transform.yoff - transform.yoff) / transform.e)\n        dstrect.attrib['xSize'] = str(src_dataset.width * src_dataset.transform.a / transform.a)\n        dstrect.attrib['ySize'] = str(src_dataset.height * src_dataset.transform.e / transform.e)\n\n        if src_dataset.nodata is not None:\n            nodata_elem = ET.SubElement(complexsource, 'NODATA')\n            nodata_elem.text = str(src_dataset.nodata)\n\n        if src_dataset.options is not None:\n            openoptions = ET.SubElement(complexsource, 'OpenOptions')\n            for ookey, oovalue in src_dataset.options.items():\n                ooi = ET.SubElement(openoptions, 'OOI')\n                ooi.attrib['key'] = str(ookey)\n                ooi.text = str(oovalue)\n\n        # Effectively replaces all values of the source dataset with\n        # 255.  Due to GDAL optimizations, the source dataset will not\n        # be read, so we get a performance improvement.\n        if masked:\n            scaleratio = ET.SubElement(complexsource, 'ScaleRatio')\n            scaleratio.text = '0'\n            scaleoffset = ET.SubElement(complexsource, 'ScaleOffset')\n            scaleoffset.text = '255'\n\n    if all(MaskFlags.per_dataset in flags for flags in src_dataset.mask_flag_enums):\n        maskband = ET.SubElement(vrtdataset, 'MaskBand')\n        vrtrasterband = ET.SubElement(maskband, 'VRTRasterBand')\n        vrtrasterband.attrib['dataType'] = 'Byte'\n\n        simplesource = ET.SubElement(vrtrasterband, 'SimpleSource')\n        sourcefilename = ET.SubElement(simplesource, 'SourceFilename')\n        sourcefilename.attrib['relativeToVRT'] = \"0\"\n        sourcefilename.attrib[\"shared\"] = \"0\"\n        sourcefilename.text = _parse_path(src_dataset.name).as_vsi()\n\n        sourceband = ET.SubElement(simplesource, 'SourceBand')\n        sourceband.text = 'mask,1'\n        sourceproperties = ET.SubElement(simplesource, 'SourceProperties')\n        sourceproperties.attrib['RasterXSize'] = str(width)\n        sourceproperties.attrib['RasterYSize'] = str(height)\n        sourceproperties.attrib['dataType'] = 'Byte'\n        sourceproperties.attrib['BlockYSize'] = str(block_shape[0])\n        sourceproperties.attrib['BlockXSize'] = str(block_shape[1])\n        srcrect = ET.SubElement(simplesource, 'SrcRect')\n        srcrect.attrib['xOff'] = '0'\n        srcrect.attrib['yOff'] = '0'\n        srcrect.attrib['xSize'] = str(src_dataset.width)\n        srcrect.attrib['ySize'] = str(src_dataset.height)\n        dstrect = ET.SubElement(simplesource, 'DstRect')\n        dstrect.attrib['xOff'] = str((src_dataset.transform.xoff - transform.xoff) / transform.a)\n        dstrect.attrib['yOff'] = str((src_dataset.transform.yoff - transform.yoff) / transform.e)\n        dstrect.attrib['xSize'] = str(src_dataset.width)\n        dstrect.attrib['ySize'] = str(src_dataset.height)\n\n    return ET.tostring(vrtdataset).decode('ascii')\n", "path": "rasterio/vrt.py"}]}