Skip to content

Commit

Permalink
created page for data editing
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrss committed Jul 27, 2020
1 parent 88355e7 commit ff6b180
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions doc/source/tutorial-edit.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.. _tutorial-edit:

Editing rasters
===============

Setting 'no data' values
------------------------

The :func:`xarray.DataArray.where` function masks data by setting nans, as demonstrated by the example below.

.. code:: python
import geowombat as gw
from geowombat.data import l8_224078_20200518
# Zeros are replaced with nans
with gw.open(l8_224078_20200518) as src:
data = src.where(src != 0)
Setting 'no data' values with scaling
-------------------------------------

In GeoWombat, we use :func:`xarray.where` and :func:`xarray.DataArray.where` along with optional scaling in the :func:`set_nodata` function. In this example, we set zeros as 65535 and scale all other values from a [0,10000] range to [0,1].

.. code:: python
import geowombat as gw
from geowombat.data import l8_224078_20200518
# Set the 'no data' value and scale all other values
with gw.open(l8_224078_20200518) as src:
data = src.gw.set_nodata(0, 65535, (0, 1), 'float64', scale_factor=0.0001)
Replace values
--------------

The GeoWombat :func:`replace` function mimics :func:`pandas.DataFrame.replace`.

.. code:: python
import geowombat as gw
from geowombat.data import l8_224078_20200518
# Replace 1 with 10
with gw.open(l8_224078_20200518) as src:
data = src.gw.replace({1: 10})
.. note::

The :func:`replace` function is typically used with thematic data.

2 comments on commit ff6b180

@mmann1123
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that looks good. Not sure if you have any control here, but I am thinking that having the accessor class methods hidden in the API reference might make things confusing for nubes like me.
I tried looking it up, maybe .. autosummary:: would do it?

@jgrss
Copy link
Owner

@jgrss jgrss commented on ff6b180 Jul 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will merge this and look into the accessor API.

There are some methods that are accessor-only and not accessible via the geowombat interface. For example, you can do:

import geowombat as gw
with gw.open('image.tif') as src:
    data = src.gw.set_nodata(...)

but you can't do

with gw.open('image.tif') as src:
    data = gw.set_nodata(...)

Please sign in to comment.