Skip to content

Commit 2093c7e

Browse files
Issue #825 Flip y in docs/faq/how-do-i/modification.rst (#1670)
Fixes #825 # Description I think documenting how to flip y-coords fixes most of the trouble @JaccoHoogewoud had. In my experience, xarray flips y coords quite often, so it is good to have documented somewhere how to workaround this.
1 parent e226f1d commit 2093c7e

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

docs/faq/how-do-i/modification.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,18 @@ integer or float), use ``.item()``:
165165
.. code-block:: python
166166
167167
single_value = da.mean().item()
168-
168+
169+
Flip the y-coordinates
170+
~~~~~~~~~~~~~~~~~~~~~~
171+
172+
Xarray sorts coordinates in ascending order in some methods (see ``align``
173+
example below), which you need to correct afterwards. We want y to be
174+
descending. The most efficient way to do this:
175+
176+
.. code-block:: python
177+
178+
da = da.reindex(y=da.y[::-1])
179+
169180
Increase the extent of a raster
170181
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
171182

@@ -174,6 +185,11 @@ Use another raster with appropriate extent, and use ``align``:
174185
.. code-block:: python
175186
176187
small_aligned, big_aligned = xr.align(small, big, join="outer")
188+
# Flip y-coordinates. Xarray sorts coordinates in ascending order.
189+
# We want y to be descending.
190+
y_descending = big_aligned.y[::-1]
191+
small_aligned = small_aligned.reindex(y=y_descending)
192+
big_aligned = big_aligned.reindex(y=y_descending)
177193
178194
Make sure the cell size is the same, or the result will be non-equidistant.
179195

0 commit comments

Comments
 (0)