Skip to content

Commit

Permalink
docs: execute the jupyter-sphinx cells (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau authored Nov 26, 2024
2 parents c83e92f + 566210d commit c80b804
Show file tree
Hide file tree
Showing 36 changed files with 494 additions and 328 deletions.
14 changes: 3 additions & 11 deletions docs/usage/asset.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@
},
"outputs": [],
"source": [
"import ee, geetools, os, re, httplib2\n",
"import ee, geetools\n",
"from geetools.utils import initialize_documentation\n",
"\n",
"if \"EARTHENGINE_SERVICE_ACCOUNT\" in os.environ:\n",
" private_key = os.environ[\"EARTHENGINE_SERVICE_ACCOUNT\"]\n",
" private_key = private_key[1:-1] if re.compile(r\"^'[^']*'$\").match(private_key) else private_key\n",
" ee.Initialize.geetools.from_service_account(private_key)\n",
"\n",
"elif \"EARTHENGINE_PROJECT\" in os.environ:\n",
" ee.Initialize(project=os.environ[\"EARTHENGINE_PROJECT\"], http_transport=httplib2.Http())\n",
"\n",
"else:\n",
" raise ValueError(\"EARTHENGINE_SERVICE_ACCOUNT or EARTHENGINE_PROJECT environment variable is missing\")"
"initialize_documentation()"
]
},
{
Expand Down
14 changes: 3 additions & 11 deletions docs/usage/export.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,10 @@
},
"outputs": [],
"source": [
"import ee, geetools, os, re, httplib2\n",
"import ee, geetools\n",
"from geetools.utils import initialize_documentation\n",
"\n",
"if \"EARTHENGINE_SERVICE_ACCOUNT\" in os.environ:\n",
" private_key = os.environ[\"EARTHENGINE_SERVICE_ACCOUNT\"]\n",
" private_key = private_key[1:-1] if re.compile(r\"^'[^']*'$\").match(private_key) else private_key\n",
" ee.Initialize.geetools.from_service_account(private_key)\n",
"\n",
"elif \"EARTHENGINE_PROJECT\" in os.environ:\n",
" ee.Initialize(project=os.environ[\"EARTHENGINE_PROJECT\"], http_transport=httplib2.Http())\n",
"\n",
"else:\n",
" raise ValueError(\"EARTHENGINE_SERVICE_ACCOUNT or EARTHENGINE_PROJECT environment variable is missing\")"
"initialize_documentation()"
]
},
{
Expand Down
14 changes: 3 additions & 11 deletions docs/usage/plot/map-featurecollection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,10 @@
},
"outputs": [],
"source": [
"import ee, geetools, os, re, httplib2\n",
"import ee, geetools\n",
"from geetools.utils import initialize_documentation\n",
"\n",
"if \"EARTHENGINE_SERVICE_ACCOUNT\" in os.environ:\n",
" private_key = os.environ[\"EARTHENGINE_SERVICE_ACCOUNT\"]\n",
" private_key = private_key[1:-1] if re.compile(r\"^'[^']*'$\").match(private_key) else private_key\n",
" ee.Initialize.geetools.from_service_account(private_key)\n",
"\n",
"elif \"EARTHENGINE_PROJECT\" in os.environ:\n",
" ee.Initialize(project=os.environ[\"EARTHENGINE_PROJECT\"], http_transport=httplib2.Http())\n",
"\n",
"else:\n",
" raise ValueError(\"EARTHENGINE_SERVICE_ACCOUNT or EARTHENGINE_PROJECT environment variable is missing\")"
"initialize_documentation()"
]
},
{
Expand Down
14 changes: 3 additions & 11 deletions docs/usage/plot/map-image.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,10 @@
},
"outputs": [],
"source": [
"import ee, geetools, os, re, httplib2\n",
"import ee, geetools\n",
"from geetools.utils import initialize_documentation\n",
"\n",
"if \"EARTHENGINE_SERVICE_ACCOUNT\" in os.environ:\n",
" private_key = os.environ[\"EARTHENGINE_SERVICE_ACCOUNT\"]\n",
" private_key = private_key[1:-1] if re.compile(r\"^'[^']*'$\").match(private_key) else private_key\n",
" ee.Initialize.geetools.from_service_account(private_key)\n",
"\n",
"elif \"EARTHENGINE_PROJECT\" in os.environ:\n",
" ee.Initialize(project=os.environ[\"EARTHENGINE_PROJECT\"], http_transport=httplib2.Http())\n",
"\n",
"else:\n",
" raise ValueError(\"EARTHENGINE_SERVICE_ACCOUNT or EARTHENGINE_PROJECT environment variable is missing\")"
"initialize_documentation()"
]
},
{
Expand Down
14 changes: 3 additions & 11 deletions docs/usage/plot/plot-featurecollection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,10 @@
},
"outputs": [],
"source": [
"import ee, geetools, os, re, httplib2\n",
"import ee, geetools\n",
"from geetools.utils import initialize_documentation\n",
"\n",
"if \"EARTHENGINE_SERVICE_ACCOUNT\" in os.environ:\n",
" private_key = os.environ[\"EARTHENGINE_SERVICE_ACCOUNT\"]\n",
" private_key = private_key[1:-1] if re.compile(r\"^'[^']*'$\").match(private_key) else private_key\n",
" ee.Initialize.geetools.from_service_account(private_key)\n",
"\n",
"elif \"EARTHENGINE_PROJECT\" in os.environ:\n",
" ee.Initialize(project=os.environ[\"EARTHENGINE_PROJECT\"], http_transport=httplib2.Http())\n",
"\n",
"else:\n",
" raise ValueError(\"EARTHENGINE_SERVICE_ACCOUNT or EARTHENGINE_PROJECT environment variable is missing\")"
"initialize_documentation()"
]
},
{
Expand Down
14 changes: 3 additions & 11 deletions docs/usage/plot/plot-image.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,10 @@
},
"outputs": [],
"source": [
"import ee, geetools, os, re, httplib2\n",
"import ee, geetools\n",
"from geetools.utils import initialize_documentation\n",
"\n",
"if \"EARTHENGINE_SERVICE_ACCOUNT\" in os.environ:\n",
" private_key = os.environ[\"EARTHENGINE_SERVICE_ACCOUNT\"]\n",
" private_key = private_key[1:-1] if re.compile(r\"^'[^']*'$\").match(private_key) else private_key\n",
" ee.Initialize.geetools.from_service_account(private_key)\n",
"\n",
"elif \"EARTHENGINE_PROJECT\" in os.environ:\n",
" ee.Initialize(project=os.environ[\"EARTHENGINE_PROJECT\"], http_transport=httplib2.Http())\n",
"\n",
"else:\n",
" raise ValueError(\"EARTHENGINE_SERVICE_ACCOUNT or EARTHENGINE_PROJECT environment variable is missing\")"
"initialize_documentation()"
]
},
{
Expand Down
14 changes: 3 additions & 11 deletions docs/usage/plot/plot-imagecollection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,10 @@
},
"outputs": [],
"source": [
"import ee, geetools, os, re, httplib2\n",
"import ee, geetools\n",
"from geetools.utils import initialize_documentation\n",
"\n",
"if \"EARTHENGINE_SERVICE_ACCOUNT\" in os.environ:\n",
" private_key = os.environ[\"EARTHENGINE_SERVICE_ACCOUNT\"]\n",
" private_key = private_key[1:-1] if re.compile(r\"^'[^']*'$\").match(private_key) else private_key\n",
" ee.Initialize.geetools.from_service_account(private_key)\n",
"\n",
"elif \"EARTHENGINE_PROJECT\" in os.environ:\n",
" ee.Initialize(project=os.environ[\"EARTHENGINE_PROJECT\"], http_transport=httplib2.Http())\n",
"\n",
"else:\n",
" raise ValueError(\"EARTHENGINE_SERVICE_ACCOUNT or EARTHENGINE_PROJECT environment variable is missing\")"
"initialize_documentation()"
]
},
{
Expand Down
14 changes: 3 additions & 11 deletions docs/usage/profile.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,10 @@
},
"outputs": [],
"source": [
"import ee, geetools, os, re, httplib2\n",
"import ee, geetools\n",
"from geetools.utils import initialize_documentation\n",
"\n",
"if \"EARTHENGINE_SERVICE_ACCOUNT\" in os.environ:\n",
" private_key = os.environ[\"EARTHENGINE_SERVICE_ACCOUNT\"]\n",
" private_key = private_key[1:-1] if re.compile(r\"^'[^']*'$\").match(private_key) else private_key\n",
" ee.Initialize.geetools.from_service_account(private_key)\n",
"\n",
"elif \"EARTHENGINE_PROJECT\" in os.environ:\n",
" ee.Initialize(project=os.environ[\"EARTHENGINE_PROJECT\"], http_transport=httplib2.Http())\n",
"\n",
"else:\n",
" raise ValueError(\"EARTHENGINE_SERVICE_ACCOUNT or EARTHENGINE_PROJECT environment variable is missing\")"
"initialize_documentation()"
]
},
{
Expand Down
14 changes: 3 additions & 11 deletions docs/usage/reduce.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@
},
"outputs": [],
"source": [
"import ee, geetools, os, re, httplib2\n",
"import ee, geetools\n",
"from geetools.utils import initialize_documentation\n",
"\n",
"if \"EARTHENGINE_SERVICE_ACCOUNT\" in os.environ:\n",
" private_key = os.environ[\"EARTHENGINE_SERVICE_ACCOUNT\"]\n",
" private_key = private_key[1:-1] if re.compile(r\"^'[^']*'$\").match(private_key) else private_key\n",
" ee.Initialize.geetools.from_service_account(private_key)\n",
"\n",
"elif \"EARTHENGINE_PROJECT\" in os.environ:\n",
" ee.Initialize(project=os.environ[\"EARTHENGINE_PROJECT\"], http_transport=httplib2.Http())\n",
"\n",
"else:\n",
" raise ValueError(\"EARTHENGINE_SERVICE_ACCOUNT or EARTHENGINE_PROJECT environment variable is missing\")"
"initialize_documentation()"
]
},
{
Expand Down
14 changes: 3 additions & 11 deletions docs/usage/template.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@
},
"outputs": [],
"source": [
"import ee, geetools, os, re, httplib2\n",
"import ee, geetools\n",
"from geetools.utils import initialize_documentation\n",
"\n",
"if \"EARTHENGINE_SERVICE_ACCOUNT\" in os.environ:\n",
" private_key = os.environ[\"EARTHENGINE_SERVICE_ACCOUNT\"]\n",
" private_key = private_key[1:-1] if re.compile(r\"^'[^']*'$\").match(private_key) else private_key\n",
" ee.Initialize.geetools.from_service_account(private_key)\n",
"\n",
"elif \"EARTHENGINE_PROJECT\" in os.environ:\n",
" ee.Initialize(project=os.environ[\"EARTHENGINE_PROJECT\"], http_transport=httplib2.Http())\n",
"\n",
"else:\n",
" raise ValueError(\"EARTHENGINE_SERVICE_ACCOUNT or EARTHENGINE_PROJECT environment variable is missing\")"
"initialize_documentation()"
]
},
{
Expand Down
23 changes: 12 additions & 11 deletions geetools/ee_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ def __init__(self, obj: ee.Array):
"""Initialize the Array class."""
self._obj = obj

# -- alternative constructor -----------------------------------------------
def full(
self,
width: float | int | ee.Number,
height: float | int | ee.Number,
value: float | int | ee.Number,
) -> ee.Array:
"""Create an array with the given dimensions, initialized to the given value.
"""Create an :py:class:`ee.Array` with the given dimensions, initialized to the given value.
Parameters:
width: The width of the array.
Expand All @@ -32,19 +31,19 @@ def full(
An array with the given dimensions, initialized to the given value.
Examples:
.. code-block:: python
.. jupyter-execute::
import ee, geetools
from geetools.utils import initialize_documentation
ee.Initialize()
initialize_documentation()
arr = ee.Array.geetools.full(3, 3, 1)
arr.getInfo()
array = ee.Array.geetools.full(3, 3, 1)
array.getInfo()
"""
width, height = ee.Number(width).toInt(), ee.Number(height).toInt()
return ee.Array(ee.List.repeat(ee.List.repeat(value, width), height))

# -- data maniputlation ----------------------------------------------------
def set(
self,
x: int | ee.Number,
Expand All @@ -62,14 +61,16 @@ def set(
The array with the cell set to the given value.
Examples:
.. code-block:: python
.. jupyter-execute::
import ee, geetools
from geetools.utils import initialize_documentation
ee.Initialize()
initialize_documentation()
arr = ee.Array.geetools.full(3, 3, 1)
arr.geetools.set(1, 1, 0).getInfo()
array = ee.Array.geetools.full(3, 3, 1)
array = array.geetools.set(1, 1, 0)
array.getInfo()
"""
xPos, yPos = ee.Number(x).toInt(), ee.Number(y).toInt()
row = ee.List(self._obj.toList().get(yPos)).set(xPos, ee.Number(value))
Expand Down
25 changes: 11 additions & 14 deletions geetools/ee_authenticate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AuthenticateAccessor:
def new_user(name: str = "", credential_pathname: str = "") -> None:
"""Authenticate the user and save the credentials in a specific folder.
Equivalent to ee.Authenticate but where the registered user will not be the default one (the one you get when running ee.initialize())
Equivalent to ee.Authenticate but where the registered user will not be the default one (the one you get when running :py:meth:`ee.Initialize`)
Args:
name: The name of the user. If not set, it will reauthenticate default.
Expand All @@ -33,10 +33,9 @@ def new_user(name: str = "", credential_pathname: str = "") -> None:
# cannot be displayed in the documentation as the creation
# of a new user requires user interaction
# geetools.User.create("secondary")
# geetools.User.set("secondary")
# ee.Number(1).getInfo()
ee.Authenticate.geetools.new_user("secondary")
ee.Initialize.geetools.from_user("secondary")
ee.Number(1).getInfo()
"""
name = f"credentials{name}"
credential_pathname = credential_pathname or ee.oauth.get_credentials_path()
Expand Down Expand Up @@ -71,11 +70,8 @@ def delete_user(name: str = "", credential_pathname: str = "") -> None:
# cannot be displayed in the documentation as the creation
# of a new user requires user interaction
# geetools.User.create("secondary")
# geetools.User.delete("secondary")
# geetools.User.set("secondary")
# will raise an error as the user does not exist anymore
ee.Authenticate.geetools.new_user("secondary")
ee.Authenticate.geetools.delete_user("secondary")
"""
name = f"credentials{name}"
credential_pathname = credential_pathname or ee.oauth.get_credentials_path()
Expand All @@ -101,7 +97,7 @@ def list_user(credential_pathname: str = "") -> list:
import ee
import geetools
geetools.User.list(
ee.Authenticate.geetools.list_user()
"""
credential_pathname = credential_pathname or ee.oauth.get_credentials_path()
credential_path = Path(credential_pathname).parent
Expand All @@ -123,9 +119,10 @@ def rename_user(new: str, old: str = "", credential_pathname: str = "") -> None:
import ee
import geetools
geetools.user.create("secondary")
geetools.User.rename("secondary", "new_default")
geetools.User.list()
ee.Authenticate.geetools.new_user("old")
ee.Authenticate.geetools.rename_user("new", "old")
ee.Initialize.geetools.from_user("new")
ee.Number(1).getInfo()
"""
old = f"credentials{old}"
new = f"credentials{new}"
Expand Down
Loading

0 comments on commit c80b804

Please sign in to comment.