Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: execute the jupyter-sphinx cells #383

Merged
merged 5 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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