Skip to content

Commit

Permalink
Deploying to gh-pages from @ 33c0059 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 committed May 26, 2023
1 parent 8e2b271 commit 1f7efeb
Show file tree
Hide file tree
Showing 19 changed files with 989 additions and 103 deletions.
Binary file modified latest/.doctrees/environment.pickle
Binary file not shown.
Binary file modified latest/.doctrees/examples/transform_bounds.doctree
Binary file not shown.
289 changes: 264 additions & 25 deletions latest/.doctrees/nbsphinx/examples/transform_bounds.ipynb

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added latest/_images/examples_transform_bounds_12_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added latest/_images/examples_transform_bounds_15_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added latest/_images/examples_transform_bounds_18_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added latest/_images/examples_transform_bounds_4_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added latest/_images/examples_transform_bounds_9_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
289 changes: 264 additions & 25 deletions latest/_sources/examples/transform_bounds.ipynb.txt

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions latest/_static/nbsphinx-code-cells.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ div.nblast.container {
}

/* input prompt */
div.nbinput.container div.prompt pre {
div.nbinput.container div.prompt pre,
/* for sphinx_immaterial theme: */
div.nbinput.container div.prompt pre > code {
color: #307FC1;
}

/* output prompt */
div.nboutput.container div.prompt pre {
div.nboutput.container div.prompt pre,
/* for sphinx_immaterial theme: */
div.nboutput.container div.prompt pre > code {
color: #BF5B3D;
}

Expand Down Expand Up @@ -204,8 +208,10 @@ div.nboutput.container div.output_area > div[class^='highlight']{
overflow-y: hidden;
}

/* hide copybtn icon on prompts (needed for 'sphinx_copybutton') */
.prompt .copybtn {
/* hide copy button on prompts for 'sphinx_copybutton' extension ... */
.prompt .copybtn,
/* ... and 'sphinx_immaterial' theme */
.prompt .md-clipboard.md-icon {
display: none;
}

Expand Down
209 changes: 186 additions & 23 deletions latest/examples/transform_bounds.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,16 @@
<li class="toctree-l2"><a class="reference internal" href="reproject_match.html">Example - Reproject Match (For Raster Calculations/Stacking)</a></li>
<li class="toctree-l2"><a class="reference internal" href="merge.html">Example - Merge</a></li>
<li class="toctree-l2"><a class="reference internal" href="interpolate_na.html">Example - Interpolate Missing Data</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Example - Transform Bounds</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Example - Transform Bounds</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#Original-Raster-&amp;-Bounds">Original Raster &amp; Bounds</a></li>
<li class="toctree-l3"><a class="reference internal" href="#Determine-bounds-of-re-projected-raster">Determine bounds of re-projected raster</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#Boundary-calculated-from-the-re-projected-raster-(inefficient)">Boundary calculated from the re-projected raster (inefficient)</a></li>
<li class="toctree-l4"><a class="reference internal" href="#Boundary-calculated-from-original-corners-(incorrect)">Boundary calculated from original corners (incorrect)</a></li>
<li class="toctree-l4"><a class="reference internal" href="#Boundary-calculates-using-transform_bounds">Boundary calculates using transform_bounds</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="COG.html">Example - Cloud Optimized GeoTiff (COG)</a></li>
<li class="toctree-l2"><a class="reference internal" href="dask_read_write.html">Example - Reading and Writing with Dask</a></li>
<li class="toctree-l2"><a class="reference external" href="https://corteva.github.io/geocube/html/examples/zonal_statistics.html">Example - Zonal Statistics</a></li>
Expand Down Expand Up @@ -111,12 +120,17 @@

<section id="Example---Transform-Bounds">
<h1>Example - Transform Bounds<a class="headerlink" href="#Example---Transform-Bounds" title="Permalink to this heading"></a></h1>
<p>The <a class="reference internal" href="../rioxarray.html#rioxarray.rioxarray.XRasterBase.transform_bounds"><span class="std std-ref">rio.transform_bounds()</span></a> method allows you to correctly estimate the bounds of your raster in a different CRS without needing to re-project it. If you simply calculate the bounds by transforming the bounds, there are often situations when this is incorrect due to nonlinear transformations.</p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[1]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>import rioxarray # for the extension to load
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>import pyproj
import rioxarray # for the extension to load
import xarray
from shapely.geometry import box

import matplotlib.pyplot as plt

%matplotlib inline
</pre></div>
Expand All @@ -126,72 +140,221 @@ <h1>Example - Transform Bounds<a class="headerlink" href="#Example---Transform-B
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[2]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>xds = xarray.open_dataarray(&quot;MODIS_ARRAY.nc&quot;)
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>xds = xarray.open_dataarray(&quot;../../test/test_data/input/MODIS_ARRAY.nc&quot;)
transformer = pyproj.Transformer.from_crs(xds.rio.crs, &quot;EPSG:4326&quot;, always_xy=True)
</pre></div>
</div>
</div>
<section id="Original-Raster-&amp;-Bounds">
<h2>Original Raster &amp; Bounds<a class="headerlink" href="#Original-Raster-&-Bounds" title="Permalink to this heading"></a></h2>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[3]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>xds.rio.bounds()
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>ax = plt.subplot()
xds.plot(ax=ax)
ax.plot(
*box(*xds.rio.bounds()).exterior.xy,
color=&quot;red&quot;,
linewidth=3,
)
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="nboutput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[3]:
</pre></div>
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
(-7274009.649486291, 5003777.3385, -7227678.3778335, 5050108.61015275)
[&lt;matplotlib.lines.Line2D at 0x7f324f4456c0&gt;]
</pre></div></div>
</div>
<p>API Reference: <a class="reference internal" href="../rioxarray.html#rioxarray.rioxarray.XRasterBase.transform_bounds"><span class="std std-ref">rio.transform_bounds()</span></a></p>
<div class="nbinput docutils container">
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="../_images/examples_transform_bounds_4_1.png" src="../_images/examples_transform_bounds_4_1.png" />
</div>
</div>
</section>
<section id="Determine-bounds-of-re-projected-raster">
<h2>Determine bounds of re-projected raster<a class="headerlink" href="#Determine-bounds-of-re-projected-raster" title="Permalink to this heading"></a></h2>
<p>The <a class="reference internal" href="../rioxarray.html#rioxarray.rioxarray.XRasterBase.transform_bounds"><span class="std std-ref">rio.transform_bounds()</span></a> method allows you to safely convert a bounding box into another projection taking into account the effects of nonlinear transformations.</p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[4]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>xds.rio.transform_bounds(
&quot;+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +ellps=WGS84&quot;
&quot; +datum=WGS84 +units=m +no_defs&quot;,
densify_pts=100,
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>reprojected_raster = xds.rio.reproject(&quot;EPSG:4326&quot;)
</pre></div>
</div>
</div>
<section id="Boundary-calculated-from-the-re-projected-raster-(inefficient)">
<h3>Boundary calculated from the re-projected raster (inefficient)<a class="headerlink" href="#Boundary-calculated-from-the-re-projected-raster-(inefficient)" title="Permalink to this heading"></a></h3>
<p>This is the benchmark. However, this method is computationally inefficient. So, if you don’t need to re-project, <a class="reference internal" href="../rioxarray.html#rioxarray.rioxarray.XRasterBase.transform_bounds"><span class="std std-ref">rio.transform_bounds()</span></a> is a more efficent method.</p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[5]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>reprojected_raster_box = box(*reprojected_raster.rio.bounds())
</pre></div>
</div>
</div>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[6]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>ax = plt.subplot()
reprojected_raster.plot(ax=ax)
ax.plot(
*reprojected_raster_box.exterior.xy,
color=&quot;red&quot;,
linewidth=3,
)
</pre></div>
</div>
</div>
<div class="nboutput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[6]:
</pre></div>
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
[&lt;matplotlib.lines.Line2D at 0x7f324735e4d0&gt;]
</pre></div></div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[4]:
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="../_images/examples_transform_bounds_9_1.png" src="../_images/examples_transform_bounds_9_1.png" />
</div>
</div>
</section>
<section id="Boundary-calculated-from-original-corners-(incorrect)">
<h3>Boundary calculated from original corners (incorrect)<a class="headerlink" href="#Boundary-calculated-from-original-corners-(incorrect)" title="Permalink to this heading"></a></h3>
<p>Directly transforming the corners is an incorrect method to calculate the new boundary.</p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[7]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>transform_box = box(*transformer.transform(*xds.rio.bounds()))
</pre></div>
</div>
</div>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[8]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>ax = plt.subplot()
reprojected_raster.plot(ax=ax)
ax.plot(
*transform_box.exterior.xy,
color=&quot;red&quot;,
linewidth=3,
)
</pre></div>
</div>
</div>
<div class="nboutput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[8]:
</pre></div>
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
(-10374232.525903117,
5591295.917919335,
-10232919.684719983,
5656912.314724255)
[&lt;matplotlib.lines.Line2D at 0x7f3245a3bee0&gt;]
</pre></div></div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="../_images/examples_transform_bounds_12_1.png" src="../_images/examples_transform_bounds_12_1.png" />
</div>
</div>
</section>
<section id="Boundary-calculates-using-transform_bounds">
<h3>Boundary calculates using transform_bounds<a class="headerlink" href="#Boundary-calculates-using-transform_bounds" title="Permalink to this heading"></a></h3>
<p><a class="reference internal" href="../rioxarray.html#rioxarray.rioxarray.XRasterBase.transform_bounds"><span class="std std-ref">rio.transform_bounds()</span></a> is both computationally efficient and a correct method for calculating the bounds of your raster in the new projection.</p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[9]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>transform_bounds_box = box(*xds.rio.transform_bounds(&quot;EPSG:4326&quot;))
</pre></div>
</div>
</div>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[5]:
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[10]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>xds.rio.transform_bounds(
&quot;+init=epsg:4326&quot;,
densify_pts=1,
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>ax = plt.subplot()
reprojected_raster.plot(ax=ax)
ax.plot(
*transform_bounds_box.exterior.xy,
color=&quot;red&quot;,
linewidth=3,
)
</pre></div>
</div>
</div>
<div class="nboutput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[10]:
</pre></div>
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
[&lt;matplotlib.lines.Line2D at 0x7f32459316c0&gt;]
</pre></div></div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[5]:
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="../_images/examples_transform_bounds_15_1.png" src="../_images/examples_transform_bounds_15_1.png" />
</div>
</div>
<p>As seen below, this is equivalent to the <a class="reference external" href="https://pyproj4.github.io/pyproj/stable/api/transformer.html#pyproj.transformer.Transformer.transform_bounds">Transformer.transform_bounds</a> method in pyproj:</p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[11]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>pyproj_transform_bounds_box = box(*transformer.transform_bounds(*xds.rio.bounds()))
</pre></div>
</div>
</div>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[12]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>ax = plt.subplot()
reprojected_raster.plot(ax=ax)
ax.plot(
*transform_bounds_box.exterior.xy,
color=&quot;red&quot;,
linewidth=3,
)
</pre></div>
</div>
</div>
<div class="nboutput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[12]:
</pre></div>
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
(-93.19331639028637, 44.99999999595885, -91.92388153951472, 45.41666666258786)
[&lt;matplotlib.lines.Line2D at 0x7f324580d120&gt;]
</pre></div></div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="../_images/examples_transform_bounds_18_1.png" src="../_images/examples_transform_bounds_18_1.png" />
</div>
</div>
</section>
</section>
</section>


Expand Down
289 changes: 264 additions & 25 deletions latest/examples/transform_bounds.ipynb

Large diffs are not rendered by default.

Binary file modified latest/objects.inv
Binary file not shown.
2 changes: 1 addition & 1 deletion latest/searchindex.js

Large diffs are not rendered by default.

0 comments on commit 1f7efeb

Please sign in to comment.