diff --git a/.copier-answers.yml b/.copier-answers.yml new file mode 100644 index 00000000..a57ccd37 --- /dev/null +++ b/.copier-answers.yml @@ -0,0 +1,13 @@ +# Changes here will be overwritten by Copier +_commit: 0.1.16 +_src_path: gh:12rambau/pypackage +author_email: pierrick.rambaud49@gmail.com +author_first_name: Pierrick +author_last_name: Rambaud +author_orcid: 0000-0001-8764-5749 +creation_year: "2017" +github_repo_name: geetools +github_user: gee-community +project_name: geetools +project_slug: geetools +short_description: A collection of tools to work with Google Earth Engine Python API diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d21f0b86..0288d0c1 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,8 +3,7 @@ "image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye", "features": { "ghcr.io/devcontainers-contrib/features/nox:2": {}, - "ghcr.io/devcontainers-contrib/features/pre-commit:2": {}, - "ghcr.io/rocker-org/devcontainer-features/pandoc:1": {} + "ghcr.io/devcontainers-contrib/features/pre-commit:2": {} }, - "postCreateCommand": "pre-commit install" + "postCreateCommand": "python -m pip install commitizen uv && pre-commit install" } diff --git a/.github/ISSUE_TEMPLATE/PULL_REQUEST_TEMPLATE/pr_template.md b/.github/ISSUE_TEMPLATE/PULL_REQUEST_TEMPLATE/pr_template.md new file mode 100644 index 00000000..f9c309e0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/PULL_REQUEST_TEMPLATE/pr_template.md @@ -0,0 +1,23 @@ +--- +name: Pull request template +about: Create a pull request +title: "" +labels: "" +assignees: "" +--- + +## reference the related issue + +PR should answer problem stated in the issue tracker. please open one before starting a PR + +## description of the changes + +Describe the changes you propose + +## mention + +@mentions of the person or team responsible for reviewing proposed changes + +## comments + +any other comments we should pay attention to diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..25ea0037 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,24 @@ +--- +name: Bug report +about: Create a report to help us improve +title: "" +labels: "" +assignees: "" +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: + +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..2bc5d5f7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,19 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: "" +labels: "" +assignees: "" +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/workflows/pypackage_check.yaml b/.github/workflows/pypackage_check.yaml new file mode 100644 index 00000000..d9dd5891 --- /dev/null +++ b/.github/workflows/pypackage_check.yaml @@ -0,0 +1,53 @@ +name: template update check + +on: + workflow_dispatch: + +env: + PIP_ROOT_USER_ACTION: ignore + +jobs: + check_version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: install dependencies + run: pip install requests + - name: get latest pypackage release + id: get_latest_release + run: | + RELEASE=$(curl -s https://api.github.com/repos/12rambau/pypackage/releases | jq -r '.[0].tag_name') + echo "latest=$RELEASE" >> $GITHUB_OUTPUT + echo "latest release: $RELEASE" + - name: get current pypackage version + id: get_current_version + run: | + RELEASE=$(yq -r "._commit" .copier-answers.yml) + echo "current=$RELEASE" >> $GITHUB_OUTPUT + echo "current release: $RELEASE" + - name: open issue + if: steps.get_current_version.outputs.current != steps.get_latest_release.outputs.latest + uses: rishabhgupta/git-action-issue@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + title: "Update template to ${{ steps.get_latest_release.outputs.latest }}" + body: | + The package is based on the ${{ steps.get_current_version.outputs.current }} version of [@12rambau/pypackage](https://github.com/12rambau/pypackage). + + The latest version of the template is ${{ steps.get_latest_release.outputs.latest }}. + + Please consider updating the template to the latest version to include all the latest developments. + + Run the following code in your project directory to update the template: + + ``` + copier update --trust --defaults --vcs-ref ${{ steps.get_latest_release.outputs.latest }} + ``` + + > **Note** + > You may need to reinstall ``copier`` and ``jinja2-time`` if they are not available in your environment. + + After solving the merging issues you can push back the changes to your main branch. diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e053807f..75830dde 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,26 +1,30 @@ -name: Release +name: Upload Python Package on: - workflow_dispatch: release: types: [created] +env: + PIP_ROOT_USER_ACTION: ignore + jobs: + tests: + uses: ./.github/workflows/unit.yaml + deploy: + needs: [tests] runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - #- uses: ./.github/workflows/unit.yaml - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: - python-version: "3.10" + python-version: "3.11" - name: Install dependencies - run: pip install twine build nox + run: pip install twine build nox[uv] + - name: update citation date + run: nox -s release-date - name: Build and publish env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - python -m build - twine upload dist/* + run: python -m build && twine upload dist/* diff --git a/.github/workflows/unit.yaml b/.github/workflows/unit.yaml index 2e6e2b2a..7e12e6ae 100644 --- a/.github/workflows/unit.yaml +++ b/.github/workflows/unit.yaml @@ -1,15 +1,17 @@ -name: Unit +name: Unit tests on: + workflow_call: push: branches: - main pull_request: - workflow_dispatch: env: EARTHENGINE_SERVICE_ACCOUNT: ${{ secrets.EARTHENGINE_SERVICE_ACCOUNT }} EARTHENGINE_PROJECT: ${{ secrets.EARTHENGINE_PROJECT }} + FORCE_COLOR: 1 + PIP_ROOT_USER_ACTION: ignore jobs: lint: @@ -18,8 +20,8 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: "3.10" - - uses: pre-commit/action@v3.0.1 + python-version: "3.11" + - uses: pre-commit/action@v3.0.0 mypy: runs-on: ubuntu-latest @@ -27,23 +29,22 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: "3.10" + python-version: "3.11" - name: Install nox - run: pip install nox + run: pip install nox[uv] - name: run mypy checks run: nox -s mypy docs: - needs: [lint] + needs: [lint, mypy] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: 12rambau/setup-pandoc@test - uses: actions/setup-python@v5 with: - python-version: "3.10" + python-version: "3.11" - name: Install nox - run: pip install nox + run: pip install nox[uv] - name: build static docs run: nox -s docs @@ -53,7 +54,6 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - # dropping 3.12 for now because of https://github.com/r-earthengine/ee_extra/issues/56 python-version: ["3.9", "3.10", "3.11"] include: - os: macos-latest # macos test @@ -68,7 +68,7 @@ jobs: with: python-version: ${{ matrix.python-version }} - name: Install nox - run: pip install nox + run: pip install nox[uv] - name: test with pytest run: nox -s ci-test - name: assess dead fixtures @@ -88,6 +88,7 @@ jobs: - uses: actions/download-artifact@v4 with: name: coverage + path: coverage.xml - name: codecov uses: codecov/codecov-action@v4 with: diff --git a/.gitignore b/.gitignore index 511f0094..d8b224aa 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ parts/ sdist/ var/ wheels/ +pip-wheel-metadata/ share/python-wheels/ *.egg-info/ .installed.cfg @@ -49,7 +50,7 @@ coverage.xml *.py,cover .hypothesis/ .pytest_cache/ -cover/ +.ruff_cache/ # Translations *.mo @@ -70,10 +71,9 @@ instance/ # Sphinx documentation docs/_build/ -warnings.txt +docs/api/ # PyBuilder -.pybuilder/ target/ # Jupyter Notebook @@ -84,9 +84,7 @@ profile_default/ ipython_config.py # pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version +.python-version # pipenv # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. @@ -95,7 +93,7 @@ ipython_config.py # install all needed dependencies. #Pipfile.lock -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +# PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff @@ -132,15 +130,11 @@ dmypy.json # Pyre type checker .pyre/ -# pytype static type analyzer -.pytype/ - -# Cython debug symbols -cython_debug/ - -# vscode config +# system IDE .vscode/ -# sandbox Notebook -sandbox.ipynb +# image tmp file +*Zone.Identifier + +# debugging notebooks test.ipynb diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6136f96c..c4a21ce4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,36 +1,38 @@ default_install_hook_types: [pre-commit, commit-msg] repos: - - repo: "https://github.com/psf/black" - rev: "22.3.0" - hooks: - - id: black - stages: [pre-commit] - - repo: "https://github.com/commitizen-tools/commitizen" rev: "v2.18.0" hooks: - id: commitizen stages: [commit-msg] - - repo: "https://github.com/pre-commit/mirrors-prettier" - rev: "v2.7.1" + - repo: "https://github.com/kynan/nbstripout" + rev: "0.5.0" + hooks: + - id: nbstripout + stages: [pre-commit] + + - repo: "https://github.com/pycontribs/mirrors-prettier" + rev: "v3.4.2" hooks: - id: prettier stages: [pre-commit] exclude: tests\/test_.+\. - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: "v0.0.215" + rev: "v0.7.0" hooks: - id: ruff stages: [pre-commit] + - id: ruff-format + stages: [pre-commit] - # - repo: https://github.com/PyCQA/doc8 - # rev: "v1.1.1" - # hooks: - # - id: doc8 - # stages: [pre-commit] + - repo: https://github.com/sphinx-contrib/sphinx-lint + rev: "v1.0.0" + hooks: + - id: sphinx-lint + stages: [pre-commit] - repo: https://github.com/codespell-project/codespell rev: v2.2.4 @@ -40,10 +42,10 @@ repos: additional_dependencies: - tomli - # waiting for https://github.com/gee-community/geetools/issues/337 - # so notebooks can again be executed from the documentation - - repo: "https://github.com/kynan/nbstripout" - rev: "0.5.0" + # Prevent committing inline conflict markers + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 hooks: - - id: nbstripout + - id: check-merge-conflict stages: [pre-commit] + args: [--assume-in-merge] diff --git a/CHANGELOG.rst b/CHANGELOG.rst deleted file mode 100644 index 12208ffc..00000000 --- a/CHANGELOG.rst +++ /dev/null @@ -1,19 +0,0 @@ -Changelog -========= - -This is an old legacy changelog system, for newer versions, please refer to the changelog associated with github releases. - -New version 0.3.0 ------------------ - -I have split this package in two. This ``geetools`` will contain functions and methods related to Google Earth Engine exclusively, so you can use this module in any python environment you like. For working in Jupyter I have made another package called ``ipygee`` available `here `__. - -New version 0.5.0 (breaking changes) ------------------------------------- - -I have split this package in two (again). Now the functions to make a strip of images using Pillow is available as a different package called `geepillow `__. - -New version 0.6.0 (breaking changes) ------------------------------------- - -I have split this package in two (again x2). The module ``geetools.collection`` in an independent package called `geedataset `__. \ No newline at end of file diff --git a/CITATION.cff b/CITATION.cff new file mode 100644 index 00000000..07722944 --- /dev/null +++ b/CITATION.cff @@ -0,0 +1,13 @@ +cff-version: "1.2.0" +message: "If you use this software, please cite it as below." +authors: + - family-names: "Esteban Principe" + given-names: "Rodrigo" + - family-names: "Rambaud" + given-names: "Pierrick" + orcid: "https://orcid.org/0000-0001-8764-5749" +title: "geetools" +version: "1.9.1" +doi: "" +date-released: "2017-11-15" +url: "https://github.com/gee-community/geetools" diff --git a/CODE_OF_CONDUCT.rst b/CODE_OF_CONDUCT.rst new file mode 100644 index 00000000..8d623501 --- /dev/null +++ b/CODE_OF_CONDUCT.rst @@ -0,0 +1,140 @@ +Contributor Covenant Code of Conduct +==================================== + +Our Pledge +---------- + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +Our Standards +------------- + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +Enforcement Responsibilities +---------------------------- + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +Scope +----- + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +Enforcement +----------- + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the FAO team responsible for enforcement at +pierrick.rambaud49@gmail.com. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +Enforcement Guidelines +---------------------- + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +Correction +^^^^^^^^^^ + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +Warning +^^^^^^^ + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +Temporary Ban +^^^^^^^^^^^^^ + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +Permanent Ban +^^^^^^^^^^^^^ + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +Attribution +----------- + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. diff --git a/LICENSE b/LICENSE index 148be08d..8127d6ff 100644 --- a/LICENSE +++ b/LICENSE @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/README.rst b/README.rst index d207fa06..e86823ac 100644 --- a/README.rst +++ b/README.rst @@ -1,18 +1,22 @@ + +geetools +======== + .. |license| image:: https://img.shields.io/badge/License-MIT-yellow.svg?logo=opensourceinitiative&logoColor=white :target: LICENSE :alt: License: MIT .. |commit| image:: https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?logo=git&logoColor=white - :target: https://conventionalcommits.org - :alt: conventional commit + :target: https://conventionalcommits.org + :alt: conventional commit -.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg - :target: https://github.com/psf/black - :alt: Black badge +.. |ruff| image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json + :target: https://github.com/astral-sh/ruff + :alt: ruff badge .. |prettier| image:: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?logo=prettier&logoColor=white - :target: https://github.com/prettier/prettier - :alt: prettier badge + :target: https://github.com/prettier/prettier + :alt: prettier badge .. |pre-commit| image:: https://img.shields.io/badge/pre--commit-active-yellow?logo=pre-commit&logoColor=white :target: https://pre-commit.com/ @@ -38,13 +42,7 @@ :target: https://app.readthedocs.org/projects/geetools/ :alt: Documentation Status - - -geetools -======== - -|license| |commit| |black| |prettier| |pre-commit| |pypi| |conda| |build| |coverage| |docs| - +|license| |commit| |ruff| |prettier| |pre-commit| |pypi| |conda| |build| |coverage| |docs| Google Earth Engine tools ------------------------- @@ -94,3 +92,8 @@ This small example wrapping of the excellent ``ee_extra`` package functionalitie .geetools.maskClouds(prob = 70) # Extended (pre-processing) .geetools.scaleAndOffset() # Extended (pre-processing) .geetools.spectralIndices(['NDVI','NDWI','BAIS2'])) # Extended (processing) + +Credits +------- + +This package was created with `Copier `__ and the `@12rambau/pypackage `__ 0.1.16 project template. diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000..de09d048 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,2 @@ +# disable the treemap comment and report in PRs +comment: false diff --git a/docs/_extension/api_admonition.py b/docs/_extension/api_admonition.py index 7e096053..88800204 100644 --- a/docs/_extension/api_admonition.py +++ b/docs/_extension/api_admonition.py @@ -1,6 +1,9 @@ """A directive to generate an API admonition.""" + from __future__ import annotations +from typing import ClassVar + from docutils import nodes from docutils.parsers.rst import directives from docutils.parsers.rst.directives.admonitions import BaseAdmonition @@ -17,10 +20,12 @@ class api_node(nodes.Admonition, nodes.Element): def visit_api_node(self: HTML5Translator, node: api_node) -> None: + """Visit the api node.""" self.visit_admonition(node) def depart_api_node(self: HTML5Translator, node: api_node) -> None: + """Depart from the api node.""" self.depart_admonition(node) @@ -32,12 +37,13 @@ class APIAdmonitionDirective(BaseAdmonition, SphinxDirective): required_arguments = 0 optional_arguments = 0 final_argument_whitespace = False - option_spec = { + option_spec: ClassVar = { "class": directives.class_option, "name": directives.unchanged, } def run(self) -> list[nodes.Node]: + """Run the directive.""" if not self.options.get("class"): self.options["class"] = ["admonition-api"] diff --git a/docs/_extension/docstring.py b/docs/_extension/docstring.py index 50d01ade..f6de3127 100644 --- a/docs/_extension/docstring.py +++ b/docs/_extension/docstring.py @@ -1,4 +1,5 @@ """A docstring role to read the docstring from a Python method.""" + from __future__ import annotations import inspect diff --git a/docs/_static/custom-icon.js b/docs/_static/custom-icon.js index e080c65d..d947d8a5 100644 --- a/docs/_static/custom-icon.js +++ b/docs/_static/custom-icon.js @@ -12,5 +12,5 @@ FontAwesome.library.add( "e001", // unicode codepoint - private use area "M12.045.033a12.181 12.182 0 00-1.361.078 17.512 17.513 0 011.813 1.433l.48.438-.465.45a15.047 15.048 0 00-1.126 1.205l-.178.215a8.527 8.527 0 01.86-.05 8.154 8.155 0 11-4.286 15.149 15.764 15.765 0 01-1.841.106h-.86a21.847 21.848 0 00.264 2.866 11.966 11.967 0 106.7-21.89zM8.17.678a12.181 12.182 0 00-2.624 1.275 15.506 15.507 0 011.813.43A18.551 18.552 0 018.17.678zM9.423.75a16.237 16.238 0 00-.995 1.998 16.15 16.152 0 011.605.66 6.98 6.98 0 01.43-.509c.234-.286.472-.559.716-.817A15.047 15.048 0 009.423.75zM4.68 2.949a14.969 14.97 0 000 2.336c.587-.065 1.196-.1 1.812-.107a16.617 16.617 0 01.48-1.748 16.48 16.481 0 00-2.292-.481zM3.62 3.5A11.938 11.938 0 001.762 5.88a17.004 17.004 0 011.877-.444A17.39 17.391 0 013.62 3.5zm4.406.287c-.143.437-.265.888-.38 1.347a8.255 8.255 0 011.67-.803c-.423-.2-.845-.38-1.29-.544zM6.3 6.216a14.051 14.052 0 00-1.555.108c.064.523.157 1.038.272 1.554a8.39 8.391 0 011.283-1.662zm-2.55.137a15.313 15.313 0 00-2.602.716h-.078v.079a17.104 17.105 0 001.267 2.544l.043.071.072-.049a16.309 16.31 0 011.734-1.083l.057-.035V8.54a16.867 16.868 0 01-.408-2.094v-.092zM.644 8.095l-.063.2A11.844 11.845 0 000 11.655v.209l.143-.152a17.706 17.707 0 011.584-1.447l.057-.043-.043-.064a16.18 16.18 0 01-1.025-1.87zm3.77 1.253l-.18.1c-.465.273-.93.573-1.375.889l-.065.05.05.064c.309.437.645.867.996 1.276l.137.165v-.208a8.176 8.176 0 01.364-2.15zM2.2 10.853l-.072.05a16.574 16.574 0 00-1.813 1.734l-.058.058.066.057a15.449 15.45 0 001.991 1.483l.072.05.043-.08a16.738 16.74 0 011.053-1.64v-.05l-.043-.05a16.99 16.99 0 01-1.19-1.54zm1.855 2.071l-.121.172a15.363 15.363 0 00-.917 1.433l-.043.072.071.043a16.61 16.61 0 001.562.766l.193.086-.086-.193a8.04 8.04 0 01-.66-2.172zm-3.976.48v.2a11.758 11.759 0 00.946 3.326l.078.186.072-.194a16.215 16.216 0 01.845-2l.057-.063-.064-.043a17.197 17.198 0 01-1.776-1.284zm2.543 1.805l-.035.08a15.764 15.765 0 00-.983 2.479v.08h.086a16.15 16.152 0 002.688.5l.072.007v-.086a17.562 17.563 0 01.164-2.056v-.065H4.55a16.266 16.266 0 01-1.849-.896zm2.544 1.169v.114a17.254 17.255 0 00-.151 1.828v.078h.931c.287 0 .624.014.946 0h.209l-.166-.129a8.011 8.011 0 01-1.64-1.834zm-3.29 2.1l.115.172a11.988 11.988 0 002.502 2.737l.157.129v-.201a22.578 22.58 0 01-.2-2.336v-.071h-.072a16.23 16.23 0 01-2.3-.387z", // svg path (https://simpleicons.org/icons/anaconda.svg) ], - }) + }), ); diff --git a/docs/_template/pypackage-credits.html b/docs/_template/pypackage-credits.html new file mode 100644 index 00000000..2a399da3 --- /dev/null +++ b/docs/_template/pypackage-credits.html @@ -0,0 +1,5 @@ +

+ From + @12rambau/pypackage + 0.1.16 Copier project. +

diff --git a/docs/_templates/python/class.rst b/docs/_template/python/class.rst similarity index 99% rename from docs/_templates/python/class.rst rename to docs/_template/python/class.rst index 77963fbc..057e8232 100644 --- a/docs/_templates/python/class.rst +++ b/docs/_template/python/class.rst @@ -103,4 +103,4 @@ Methods {% endif %} {% endif %} -{% endif %} \ No newline at end of file +{% endif %} diff --git a/docs/_templates/python/function.rst b/docs/_template/python/function.rst similarity index 98% rename from docs/_templates/python/function.rst rename to docs/_template/python/function.rst index 3381ee4f..2895d1da 100644 --- a/docs/_templates/python/function.rst +++ b/docs/_template/python/function.rst @@ -20,4 +20,4 @@ {{ obj.docstring|indent(3) }} {% endif %} -{% endif %} \ No newline at end of file +{% endif %} diff --git a/docs/_templates/python/method.rst b/docs/_template/python/method.rst similarity index 98% rename from docs/_templates/python/method.rst rename to docs/_template/python/method.rst index b7cc9721..0b31a378 100644 --- a/docs/_templates/python/method.rst +++ b/docs/_template/python/method.rst @@ -20,4 +20,4 @@ {{ obj.docstring|indent(3) }} {% endif %} -{% endif %} \ No newline at end of file +{% endif %} diff --git a/docs/_templates/python/module.rst b/docs/_template/python/module.rst similarity index 99% rename from docs/_templates/python/module.rst rename to docs/_template/python/module.rst index d45d1945..73d6194f 100644 --- a/docs/_templates/python/module.rst +++ b/docs/_template/python/module.rst @@ -177,4 +177,4 @@ Functions {{obj_item.render()|indent(3)}} {% endfor %} {% endif %} -{% endif %} \ No newline at end of file +{% endif %} diff --git a/docs/conf.py b/docs/conf.py index 0514089f..e4095c39 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -57,6 +57,7 @@ html_theme = "pydata_sphinx_theme" html_static_path = ["_static"] +templates_path = ["_template"] html_logo = "_static/logo.png" html_favicon = "_static/logo.png" html_theme_options = { @@ -90,11 +91,7 @@ "edit-this-page.html", ], "article_footer_items": ["last-updated"], - # remove the switcher for now as the version management is not satisfying - # "switcher": { - # "json_url": json_url, - # "version_match": version_match, - # }, + "footer_end": ["theme-version", "pypackage-credit"], "show_toc_level": 2, } html_context = { @@ -111,7 +108,7 @@ autoapi_dirs = ["../geetools"] autoapi_python_class_content = "both" autoapi_member_order = "groupwise" -autoapi_template_dir = "_templates" +autoapi_template_dir = "_template" autoapi_options = [ "members", "undoc-members", diff --git a/docs/setup/author.rst b/docs/setup/author.rst index f3e97086..c3b0c9f9 100644 --- a/docs/setup/author.rst +++ b/docs/setup/author.rst @@ -1,4 +1,4 @@ Authors -======= +======== -.. include:: ../../AUTHORS.rst \ No newline at end of file +.. include:: ../../AUTHORS.rst diff --git a/docs/setup/license.rst b/docs/setup/license.rst index 01f3963c..f4954d17 100644 --- a/docs/setup/license.rst +++ b/docs/setup/license.rst @@ -1,4 +1,4 @@ License -======= +======== -.. include:: ../../LICENSE \ No newline at end of file +.. include:: ../../LICENSE diff --git a/docs/setup/pattern.rst b/docs/setup/pattern.rst index a7c7a17b..28df4393 100644 --- a/docs/setup/pattern.rst +++ b/docs/setup/pattern.rst @@ -67,4 +67,4 @@ However, using the register accessor decorators is preferable to simply adding y Accessors are created once per object instance. New instances, like those created from mapping operations or when accessing a ``ee.Feature`` from a ``ee.FeatureCollection`` (ex. ``fc.first()``), will have new accessors created. -The intent here is that libraries that extend ``earthengine-api`` could add such an accessor to implement subclass specific functionality rather than using actual subclasses or patching in a large number of domain specific methods. For further reading on ways to write new accessors and the philosophy behind the approach, see https://github.com/pydata/xarray/issues/1080. \ No newline at end of file +The intent here is that libraries that extend ``earthengine-api`` could add such an accessor to implement subclass specific functionality rather than using actual subclasses or patching in a large number of domain specific methods. For further reading on ways to write new accessors and the philosophy behind the approach, see https://github.com/pydata/xarray/issues/1080. diff --git a/docs/usage/asset.ipynb b/docs/usage/asset.ipynb index b69ebefc..25c157da 100644 --- a/docs/usage/asset.ipynb +++ b/docs/usage/asset.ipynb @@ -17,7 +17,8 @@ }, "outputs": [], "source": [ - "import ee, geetools\n", + "import ee\n", + "\n", "from geetools.utils import initialize_documentation\n", "\n", "initialize_documentation()" @@ -56,8 +57,7 @@ "metadata": {}, "outputs": [], "source": [ - "import ee\n", - "import geetools #noqa: F401" + "import geetools # noqa: F401" ] }, { @@ -109,9 +109,7 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "import ee, geetools" - ] + "source": [] }, { "cell_type": "markdown", @@ -299,7 +297,7 @@ "metadata": {}, "outputs": [], "source": [ - "folder in { ee.Asset(\"projects/ee-geetools/assets/documentation\")}" + "folder in {ee.Asset(\"projects/ee-geetools/assets/documentation\")}" ] }, { diff --git a/docs/usage/export.ipynb b/docs/usage/export.ipynb index 617eb720..e4cea9ae 100644 --- a/docs/usage/export.ipynb +++ b/docs/usage/export.ipynb @@ -21,7 +21,8 @@ }, "outputs": [], "source": [ - "import ee, geetools\n", + "import ee\n", + "\n", "from geetools.utils import initialize_documentation\n", "\n", "initialize_documentation()" @@ -50,7 +51,7 @@ "metadata": {}, "outputs": [], "source": [ - "import ee, geetools" + "import geetools # noqa: F401" ] }, { @@ -62,8 +63,8 @@ "# Load a landsat image and select three bands over the whole mont of january 2023\n", "landsat = (\n", " ee.ImageCollection(\"LANDSAT/LC08/C02/T1_TOA\")\n", - " .select(['B4', 'B3', 'B2'])\n", - " .filterDate('2023-01-01', '2023-01-31')\n", + " .select([\"B4\", \"B3\", \"B2\"])\n", + " .filterDate(\"2023-01-01\", \"2023-01-31\")\n", ")\n", "\n", "# Create a geometry representing an export region.\n", diff --git a/docs/usage/index.rst b/docs/usage/index.rst index 5246df20..f12729be 100644 --- a/docs/usage/index.rst +++ b/docs/usage/index.rst @@ -44,4 +44,4 @@ Then you can open a PR with the new file and it will be reviewed and merged. plot/index asset profile - reduce \ No newline at end of file + reduce diff --git a/docs/usage/plot/index.rst b/docs/usage/plot/index.rst index 6d244b4f..bdd057d5 100644 --- a/docs/usage/plot/index.rst +++ b/docs/usage/plot/index.rst @@ -96,4 +96,4 @@ If you are used to the :py:mod:`pyplot ` interface of matplot .. image:: ../../_static/usage/plot/index/hydroshed.png :alt: HydroATLAS basins of level4 - :align: center \ No newline at end of file + :align: center diff --git a/docs/usage/plot/map-featurecollection.ipynb b/docs/usage/plot/map-featurecollection.ipynb index 816e9954..3f5b7817 100644 --- a/docs/usage/plot/map-featurecollection.ipynb +++ b/docs/usage/plot/map-featurecollection.ipynb @@ -19,7 +19,8 @@ }, "outputs": [], "source": [ - "import ee, geetools\n", + "import ee\n", + "\n", "from geetools.utils import initialize_documentation\n", "\n", "initialize_documentation()" @@ -58,11 +59,9 @@ "metadata": {}, "outputs": [], "source": [ - "from IPython.display import display\n", "from matplotlib import pyplot as plt\n", "\n", - "import ee\n", - "import geetools #noqa: F401" + "import geetools # noqa: F401" ] }, { @@ -91,8 +90,8 @@ "metadata": {}, "outputs": [], "source": [ - "region = ee.Geometry.BBox(-80, -60, -20, 20);\n", - "fc = ee.FeatureCollection('WWF/HydroATLAS/v1/Basins/level04').filterBounds(region)" + "region = ee.Geometry.BBox(-80, -60, -20, 20)\n", + "fc = ee.FeatureCollection(\"WWF/HydroATLAS/v1/Basins/level04\").filterBounds(region)" ] }, { @@ -152,7 +151,7 @@ "metadata": {}, "outputs": [], "source": [ - "plt.ioff() # remove interactive for the sake of the example\n", + "plt.ioff() # remove interactive for the sake of the example\n", "fig, ax = plt.subplots(figsize=(10, 10))\n", "\n", "# create the graph\n", diff --git a/docs/usage/plot/map-image.ipynb b/docs/usage/plot/map-image.ipynb index 6d060079..122e5c55 100644 --- a/docs/usage/plot/map-image.ipynb +++ b/docs/usage/plot/map-image.ipynb @@ -19,7 +19,8 @@ }, "outputs": [], "source": [ - "import ee, geetools\n", + "import ee\n", + "\n", "from geetools.utils import initialize_documentation\n", "\n", "initialize_documentation()" @@ -58,11 +59,9 @@ "metadata": {}, "outputs": [], "source": [ - "from IPython.display import display\n", "from matplotlib import pyplot as plt\n", "\n", - "import ee\n", - "import geetools #noqa: F401" + "import geetools # noqa: F401" ] }, { @@ -97,8 +96,8 @@ "\n", "# pre-process the imagecollection and mosaic the month of June 2022\n", "image = (\n", - " ee.ImageCollection('COPERNICUS/S2_HARMONIZED')\n", - " .filterDate('2022-06-01', '2022-06-30')\n", + " ee.ImageCollection(\"COPERNICUS/S2_HARMONIZED\")\n", + " .filterDate(\"2022-06-01\", \"2022-06-30\")\n", " .filterBounds(vatican)\n", " .geetools.maskClouds()\n", " .geetools.spectralIndices(\"NDVI\")\n", @@ -136,14 +135,14 @@ "fig, ax = plt.subplots()\n", "\n", "image.geetools.plot(\n", - " bands = [\"NDVI\"],\n", + " bands=[\"NDVI\"],\n", " ax=ax,\n", " region=vatican.geometry(),\n", " crs=\"EPSG:3857\",\n", " scale=10,\n", " fc=vatican,\n", " cmap=\"viridis\",\n", - " color=\"k\"\n", + " color=\"k\",\n", ")\n", "\n", "# as it's a figure you can then edit the information as you see fit\n", @@ -178,11 +177,7 @@ "\n", "# Create the graph\n", "image.geetools.plot(\n", - " bands = [\"B4\", \"B3\", \"B2\"],\n", - " ax=ax,\n", - " region=vatican.geometry(),\n", - " fc=vatican,\n", - " color=\"k\"\n", + " bands=[\"B4\", \"B3\", \"B2\"], ax=ax, region=vatican.geometry(), fc=vatican, color=\"k\"\n", ")\n", "\n", "# as it's a figure you can then edit the information as you see fit\n", @@ -190,7 +185,7 @@ "ax.set_xlabel(\"longitude (°)\")\n", "ax.set_ylabel(\"latitude (°)\")\n", "\n", - "plt.show()\n" + "plt.show()" ] } ], diff --git a/docs/usage/plot/plot-featurecollection.ipynb b/docs/usage/plot/plot-featurecollection.ipynb index c612083a..3760a0cc 100644 --- a/docs/usage/plot/plot-featurecollection.ipynb +++ b/docs/usage/plot/plot-featurecollection.ipynb @@ -19,7 +19,8 @@ }, "outputs": [], "source": [ - "import ee, geetools\n", + "import ee\n", + "\n", "from geetools.utils import initialize_documentation\n", "\n", "initialize_documentation()" @@ -58,10 +59,11 @@ "metadata": {}, "outputs": [], "source": [ + "from datetime import datetime as dt\n", + "\n", "from matplotlib import pyplot as plt\n", "\n", - "import ee\n", - "import geetools #noqa: F401" + "import geetools # noqa: F401" ] }, { @@ -91,7 +93,7 @@ "outputs": [], "source": [ "# Import the example feature collection.\n", - "ecoregions = ee.FeatureCollection('projects/google/charts_feature_example')" + "ecoregions = ee.FeatureCollection(\"projects/google/charts_feature_example\")" ] }, { @@ -115,11 +117,10 @@ }, "outputs": [], "source": [ - "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "# Data for the chart\n", - "features = ['f1', 'f2', 'f3']\n", + "features = [\"f1\", \"f2\", \"f3\"]\n", "p1_values = [0.5, 2.5, 4.5]\n", "p2_values = [1.5, 3.5, 5.5]\n", "p3_values = [2.5, 4.0, 6.5]\n", @@ -133,18 +134,18 @@ "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", "# Plotting the bars\n", - "rects1 = ax.bar(index, p1_values, bar_width, label='p1', color='#1d6b99')\n", - "rects2 = ax.bar(index + (bar_width + offset), p2_values, bar_width, label='p2', color='#cf513e')\n", - "rects3 = ax.bar(index + 2 * (bar_width + offset), p3_values, bar_width, label='p3', color='#f0af07')\n", + "rects1 = ax.bar(index, p1_values, bar_width, label=\"p1\", color=\"#1d6b99\")\n", + "rects2 = ax.bar(index + (bar_width + offset), p2_values, bar_width, label=\"p2\", color=\"#cf513e\")\n", + "rects3 = ax.bar(index + 2 * (bar_width + offset), p3_values, bar_width, label=\"p3\", color=\"#f0af07\")\n", "\n", "# Add labels, title, and custom x-axis tick labels\n", - "ax.set_xlabel('Features by property value')\n", - "ax.set_ylabel('Series property value')\n", + "ax.set_xlabel(\"Features by property value\")\n", + "ax.set_ylabel(\"Series property value\")\n", "ax.set_xticks(index + bar_width)\n", "ax.set_xticklabels(features)\n", "\n", "# Add a legend\n", - "ax.legend(loc='upper center', bbox_to_anchor=(0.85, 1.15), ncol=3, title='Property names')\n", + "ax.legend(loc=\"upper center\", bbox_to_anchor=(0.85, 1.15), ncol=3, title=\"Property names\")\n", "\n", "# set the grid display\n", "ax.grid(axis=\"y\")\n", @@ -184,14 +185,22 @@ "source": [ "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", + "# define the colors for to use in the display\n", + "# fmt: off\n", + "colors = [\n", + " \"#604791\", \"#1d6b99\", \"#39a8a7\", \"#0f8755\",\n", + " \"#76b349\", \"#f0af07\", \"#e37d05\", \"#cf513e\",\n", + " \"#96356f\", \"#724173\", \"#9c4f97\", \"#696969\",\n", + "]\n", + "\n", "# initialize the plot with the ecoregions data\n", "ecoregions.geetools.plot_by_features(\n", - " type = \"bar\",\n", - " featureId = \"label\",\n", - " properties = ['01_tmean', '02_tmean', '03_tmean', '04_tmean', '05_tmean', '06_tmean', '07_tmean', '08_tmean', '09_tmean', '10_tmean', '11_tmean', '12_tmean'],\n", - " labels = [\"jan\", \"feb\", \"mar\", \"apr\", \"may\", \"jun\", \"jul\", \"aug\", \"sep\", \"oct\", \"nov\", \"dec\"],\n", - " colors = ['#604791', '#1d6b99', '#39a8a7', '#0f8755', '#76b349', '#f0af07', '#e37d05', '#cf513e', '#96356f', '#724173', '#9c4f97', '#696969'],\n", - " ax = ax\n", + " type=\"bar\",\n", + " featureId=\"label\",\n", + " properties=[f\"0{i}_tmean\" for i in range(1, 13)],\n", + " labels=[dt(2000, m, 1).strftime(\"%b\").lower() for m in range(1, 13)],\n", + " colors=colors,\n", + " ax=ax,\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -218,14 +227,23 @@ "source": [ "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", + "# define the colors for to use in the display\n", + "# fmt: off\n", + "colors = [\n", + " \"#604791\", \"#1d6b99\", \"#39a8a7\", \"#0f8755\",\n", + " \"#76b349\", \"#f0af07\", \"#e37d05\", \"#cf513e\",\n", + " \"#96356f\", \"#724173\", \"#9c4f97\", \"#696969\",\n", + "]\n", + "# fmt: on\n", + "\n", "# initialize theplot with the ecoregions data\n", "ecoregions.geetools.plot_by_features(\n", - " type = \"stacked\",\n", - " featureId = \"label\",\n", - " properties = ['01_ppt', '02_ppt', '03_ppt', '04_ppt', '05_ppt', '06_ppt', '07_ppt', '08_ppt', '09_ppt', '10_ppt', '11_ppt', '12_ppt'],\n", - " labels = [\"jan\", \"feb\", \"mar\", \"apr\", \"may\", \"jun\", \"jul\", \"aug\", \"sep\", \"oct\", \"nov\", \"dec\"],\n", - " colors = ['#604791', '#1d6b99', '#39a8a7', '#0f8755', '#76b349', '#f0af07', '#e37d05', '#cf513e', '#96356f', '#724173', '#9c4f97', '#696969'],\n", - " ax = ax\n", + " type=\"stacked\",\n", + " featureId=\"label\",\n", + " properties=[f\"0{i}_ppt\" for i in range(1, 13)],\n", + " labels=[dt(2000, m, 1).strftime(\"%b\").lower() for m in range(1, 13)],\n", + " colors=colors,\n", + " ax=ax,\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -254,11 +272,11 @@ "\n", "# initialize theplot with the ecoregions data\n", "ecoregions.geetools.plot_by_features(\n", - " type = \"scatter\",\n", - " featureId = \"label\",\n", - " properties = ['01_ppt', '06_ppt', '09_ppt'],\n", - " labels = [\"jan\", \"jun\", \"sep\"],\n", - " ax = ax\n", + " type=\"scatter\",\n", + " featureId=\"label\",\n", + " properties=[\"01_ppt\", \"06_ppt\", \"09_ppt\"],\n", + " labels=[\"jan\", \"jun\", \"sep\"],\n", + " ax=ax,\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -287,11 +305,11 @@ "\n", "# initialize theplot with the ecoregions data\n", "ecoregions.geetools.plot_by_features(\n", - " type = \"pie\",\n", - " featureId = \"label\",\n", - " properties = ['06_ppt'],\n", - " colors = [\"#f0af07\", \"#0f8755\", \"#76b349\"],\n", - " ax = ax\n", + " type=\"pie\",\n", + " featureId=\"label\",\n", + " properties=[\"06_ppt\"],\n", + " colors=[\"#f0af07\", \"#0f8755\", \"#76b349\"],\n", + " ax=ax,\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -318,11 +336,11 @@ "\n", "# initialize theplot with the ecoregions data\n", "ecoregions.geetools.plot_by_features(\n", - " type = \"donut\",\n", - " featureId = \"label\",\n", - " properties = ['07_ppt'],\n", - " colors = [\"#f0af07\", \"#0f8755\", \"#76b349\"],\n", - " ax = ax\n", + " type=\"donut\",\n", + " featureId=\"label\",\n", + " properties=[\"07_ppt\"],\n", + " colors=[\"#f0af07\", \"#0f8755\", \"#76b349\"],\n", + " ax=ax,\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -353,7 +371,7 @@ "import numpy as np\n", "\n", "# Data for the chart\n", - "features = ['p1', 'p2', 'p3']\n", + "features = [\"p1\", \"p2\", \"p3\"]\n", "p1_values = [0.5, 2.5, 4.5]\n", "p2_values = [1.5, 3.5, 5.5]\n", "p3_values = [2.5, 4.0, 6.5]\n", @@ -367,18 +385,20 @@ "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", "# Plotting the bars\n", - "rects1 = ax.bar(index, p1_values, bar_width, label='f1', color='#1d6b99')\n", - "rects2 = ax.bar(index + (bar_width + offset), p2_values, bar_width, label='f2', color='#cf513e')\n", - "rects3 = ax.bar(index + 2 * (bar_width + offset), p3_values, bar_width, label='f3', color='#f0af07')\n", + "rects1 = ax.bar(index, p1_values, bar_width, label=\"f1\", color=\"#1d6b99\")\n", + "rects2 = ax.bar(index + (bar_width + offset), p2_values, bar_width, label=\"f2\", color=\"#cf513e\")\n", + "rects3 = ax.bar(index + 2 * (bar_width + offset), p3_values, bar_width, label=\"f3\", color=\"#f0af07\")\n", "\n", "# Add labels, title, and custom x-axis tick labels\n", - "ax.set_xlabel('Property names')\n", - "ax.set_ylabel('Series property value')\n", + "ax.set_xlabel(\"Property names\")\n", + "ax.set_ylabel(\"Series property value\")\n", "ax.set_xticks(index + bar_width)\n", "ax.set_xticklabels(features)\n", "\n", "# Add a legend\n", - "ax.legend(loc='upper center', bbox_to_anchor=(0.85, 1.15), ncol=3, title='Features by property value')\n", + "ax.legend(\n", + " loc=\"upper center\", bbox_to_anchor=(0.85, 1.15), ncol=3, title=\"Features by property value\"\n", + ")\n", "\n", "# set the grid display\n", "ax.grid(axis=\"y\")\n", @@ -421,12 +441,12 @@ "\n", "# initialize theplot with the ecoregions data\n", "ax = ecoregions.geetools.plot_by_properties(\n", - " type = \"bar\",\n", - " properties = ['01_ppt', '02_ppt', '03_ppt', '04_ppt', '05_ppt', '06_ppt', '07_ppt', '08_ppt', '09_ppt', '10_ppt', '11_ppt', '12_ppt'],\n", - " labels = [\"jan\", \"feb\", \"mar\", \"apr\", \"may\", \"jun\", \"jul\", \"aug\", \"sep\", \"oct\", \"nov\", \"dec\"],\n", - " featureId = \"label\",\n", - " colors = [\"#f0af07\", \"#0f8755\", \"#76b349\"],\n", - " ax = ax\n", + " type=\"bar\",\n", + " properties=[f\"0{i}_ppt\" for i in range(1, 13)],\n", + " labels=[dt(2000, m, 1).strftime(\"%b\").lower() for m in range(1, 13)],\n", + " featureId=\"label\",\n", + " colors=[\"#f0af07\", \"#0f8755\", \"#76b349\"],\n", + " ax=ax,\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -455,12 +475,12 @@ "\n", "# initialize theplot with the ecoregions data\n", "ax = ecoregions.geetools.plot_by_properties(\n", - " type = \"plot\",\n", - " properties = [\"01_ppt\", \"02_ppt\", \"03_ppt\", \"04_ppt\", \"05_ppt\", \"06_ppt\", \"07_ppt\", \"08_ppt\", \"09_ppt\", \"10_ppt\", \"11_ppt\", \"12_ppt\"],\n", - " featureId = \"label\",\n", - " labels = [\"jan\", \"feb\", \"mar\", \"apr\", \"may\", \"jun\", \"jul\", \"aug\", \"sep\", \"oct\", \"nov\", \"dec\"],\n", - " colors = [\"#f0af07\", \"#0f8755\", \"#76b349\"],\n", - " ax = ax\n", + " type=\"plot\",\n", + " properties=[f\"0{i}_ppt\" for i in range(1, 13)],\n", + " featureId=\"label\",\n", + " labels=[dt(2000, m, 1).strftime(\"%b\").lower() for m in range(1, 13)],\n", + " colors=[\"#f0af07\", \"#0f8755\", \"#76b349\"],\n", + " ax=ax,\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -489,12 +509,12 @@ "\n", "# initialize the plot with the ecoregions data\n", "ax = ecoregions.geetools.plot_by_properties(\n", - " type = \"fill_between\",\n", - " properties = [\"01_ppt\", \"02_ppt\", \"03_ppt\", \"04_ppt\", \"05_ppt\", \"06_ppt\", \"07_ppt\", \"08_ppt\", \"09_ppt\", \"10_ppt\", \"11_ppt\", \"12_ppt\"],\n", - " labels = [\"jan\", \"feb\", \"mar\", \"apr\", \"may\", \"jun\", \"jul\", \"aug\", \"sep\", \"oct\", \"nov\", \"dec\"],\n", - " featureId = \"label\",\n", - " colors = [\"#f0af07\", \"#0f8755\", \"#76b349\"],\n", - " ax = ax\n", + " type=\"fill_between\",\n", + " properties=[f\"0{i}_ppt\" for i in range(1, 13)],\n", + " labels=[dt(2000, m, 1).strftime(\"%b\").lower() for m in range(1, 13)],\n", + " featureId=\"label\",\n", + " colors=[\"#f0af07\", \"#0f8755\", \"#76b349\"],\n", + " ax=ax,\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -526,7 +546,7 @@ "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", "# load some data\n", - "normClim = ee.ImageCollection('OREGONSTATE/PRISM/Norm91m').toBands()\n", + "normClim = ee.ImageCollection(\"OREGONSTATE/PRISM/Norm91m\").toBands()\n", "\n", "# Make a point sample of climate variables for a region in western USA.\n", "region = ee.Geometry.Rectangle(-123.41, 40.43, -116.38, 45.14)\n", @@ -535,24 +555,13 @@ "\n", "# initialize the plot with the ecoregions data\n", "ax = climSamp.geetools.plot_hist(\n", - " property = \"07_ppt\",\n", - " label = \"July Precipitation (mm)\",\n", - " color = '#1d6b99',\n", - " ax = ax,\n", - " bins = 30\n", + " property=\"07_ppt\", label=\"July Precipitation (mm)\", color=\"#1d6b99\", ax=ax, bins=30\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", "ax.set_title(\"July Precipitation Distribution for NW USA\")\n", "plt.show()" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/docs/usage/plot/plot-image.ipynb b/docs/usage/plot/plot-image.ipynb index cf18b020..9fec375e 100644 --- a/docs/usage/plot/plot-image.ipynb +++ b/docs/usage/plot/plot-image.ipynb @@ -19,7 +19,8 @@ }, "outputs": [], "source": [ - "import ee, geetools\n", + "import ee\n", + "\n", "from geetools.utils import initialize_documentation\n", "\n", "initialize_documentation()" @@ -58,10 +59,11 @@ "metadata": {}, "outputs": [], "source": [ + "from datetime import datetime as dt\n", + "\n", "from matplotlib import pyplot as plt\n", "\n", - "import ee\n", - "import geetools #noqa: F401" + "import geetools # noqa: F401" ] }, { @@ -90,8 +92,10 @@ "metadata": {}, "outputs": [], "source": [ - "ecoregions = ee.FeatureCollection(\"projects/google/charts_feature_example\").select([\"label\", \"value\",\"warm\"])\n", - "normClim = ee.ImageCollection('OREGONSTATE/PRISM/Norm91m').toBands()" + "ecoregions = ee.FeatureCollection(\"projects/google/charts_feature_example\").select(\n", + " [\"label\", \"value\", \"warm\"]\n", + ")\n", + "normClim = ee.ImageCollection(\"OREGONSTATE/PRISM/Norm91m\").toBands()" ] }, { @@ -115,11 +119,10 @@ }, "outputs": [], "source": [ - "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "# Data for the chart\n", - "features = ['r1', 'r2', 'r3']\n", + "features = [\"r1\", \"r2\", \"r3\"]\n", "p1_values = [0.5, 2.5, 4.5]\n", "p2_values = [1.5, 3.5, 5.5]\n", "p3_values = [2.5, 4.0, 6.5]\n", @@ -133,18 +136,18 @@ "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", "# Plotting the bars\n", - "rects1 = ax.bar(index, p1_values, bar_width, label='b1', color='#1d6b99')\n", - "rects2 = ax.bar(index + (bar_width + offset), p2_values, bar_width, label='b2', color='#cf513e')\n", - "rects3 = ax.bar(index + 2 * (bar_width + offset), p3_values, bar_width, label='b3', color='#f0af07')\n", + "rects1 = ax.bar(index, p1_values, bar_width, label=\"b1\", color=\"#1d6b99\")\n", + "rects2 = ax.bar(index + (bar_width + offset), p2_values, bar_width, label=\"b2\", color=\"#cf513e\")\n", + "rects3 = ax.bar(index + 2 * (bar_width + offset), p3_values, bar_width, label=\"b3\", color=\"#f0af07\")\n", "\n", "# Add labels, title, and custom x-axis tick labels\n", - "ax.set_xlabel('Regions by feature property value')\n", - "ax.set_ylabel('Series reduction value')\n", + "ax.set_xlabel(\"Regions by feature property value\")\n", + "ax.set_ylabel(\"Series reduction value\")\n", "ax.set_xticks(index + bar_width)\n", "ax.set_xticklabels(features)\n", "\n", "# Add a legend\n", - "ax.legend(loc='upper center', bbox_to_anchor=(0.85, 1.15), ncol=3, title='Band names')\n", + "ax.legend(loc=\"upper center\", bbox_to_anchor=(0.85, 1.15), ncol=3, title=\"Band names\")\n", "\n", "# set the grid display\n", "ax.grid(axis=\"y\")\n", @@ -184,16 +187,25 @@ "source": [ "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", + "# define the colors to use for the display\n", + "# fmt: off\n", + "colors = [\n", + " \"#604791\", \"#1d6b99\", \"#39a8a7\", \"#0f8755\",\n", + " \"#76b349\", \"#f0af07\", \"#e37d05\", \"#cf513e\",\n", + " \"#96356f\", \"#724173\", \"#9c4f97\", \"#696969\",\n", + "]\n", + "# fmt: on\n", + "\n", "normClim.geetools.plot_by_regions(\n", - " type = \"bar\",\n", - " regions = ecoregions,\n", - " reducer = \"mean\",\n", - " scale = 500,\n", - " regionId = \"label\",\n", - " bands = [\"01_tmean\", \"02_tmean\", \"03_tmean\", \"04_tmean\", \"05_tmean\", \"06_tmean\", \"07_tmean\", \"08_tmean\", \"09_tmean\", \"10_tmean\", \"11_tmean\", \"12_tmean\"],\n", - " labels = [\"jan\", \"feb\", \"mar\", \"apr\", \"may\", \"jun\", \"jul\", \"aug\", \"sep\", \"oct\", \"nov\", \"dec\"],\n", - " colors = ['#604791', '#1d6b99', '#39a8a7', '#0f8755', '#76b349', '#f0af07', '#e37d05', '#cf513e', '#96356f', '#724173', '#9c4f97', '#696969'],\n", - " ax = ax\n", + " type=\"bar\",\n", + " regions=ecoregions,\n", + " reducer=\"mean\",\n", + " scale=500,\n", + " regionId=\"label\",\n", + " bands=[f\"0{i}_tmean\" for i in range(1, 13)],\n", + " labels=[dt(2000, m, 1).strftime(\"%b\")[:3].lower() for m in range(1, 13)],\n", + " colors=colors,\n", + " ax=ax,\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -220,16 +232,24 @@ "source": [ "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", + "# define the colors to use for the display\n", + "# fmt: off\n", + "colors = [\n", + " \"#604791\", \"#1d6b99\", \"#39a8a7\", \"#0f8755\",\n", + " \"#76b349\", \"#f0af07\", \"#e37d05\", \"#cf513e\",\n", + " \"#96356f\", \"#724173\", \"#9c4f97\", \"#696969\",\n", + "]\n", + "\n", "fc = normClim.geetools.plot_by_regions(\n", - " type = \"barh\",\n", - " regions = ecoregions,\n", - " reducer = \"mean\",\n", - " scale = 500,\n", - " regionId = \"label\",\n", - " bands = [\"01_tmean\", \"02_tmean\", \"03_tmean\", \"04_tmean\", \"05_tmean\", \"06_tmean\", \"07_tmean\", \"08_tmean\", \"09_tmean\", \"10_tmean\", \"11_tmean\", \"12_tmean\"],\n", - " labels = [\"jan\", \"feb\", \"mar\", \"apr\", \"may\", \"jun\", \"jul\", \"aug\", \"sep\", \"oct\", \"nov\", \"dec\"],\n", - " colors = ['#604791', '#1d6b99', '#39a8a7', '#0f8755', '#76b349', '#f0af07', '#e37d05', '#cf513e', '#96356f', '#724173', '#9c4f97', '#696969'],\n", - " ax = ax\n", + " type=\"barh\",\n", + " regions=ecoregions,\n", + " reducer=\"mean\",\n", + " scale=500,\n", + " regionId=\"label\",\n", + " bands=[f\"0{i}_tmean\" for i in range(1, 13)],\n", + " labels=[dt(2000, m, 1).strftime('%b')[:3].lower() for m in range(1, 13)],\n", + " colors=colors,\n", + " ax=ax,\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -256,16 +276,25 @@ "source": [ "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", + "# define the colors to use for the display\n", + "# fmt: off\n", + "colors = [\n", + " \"#604791\", \"#1d6b99\", \"#39a8a7\", \"#0f8755\",\n", + " \"#76b349\", \"#f0af07\", \"#e37d05\", \"#cf513e\",\n", + " \"#96356f\", \"#724173\", \"#9c4f97\", \"#696969\",\n", + "]\n", + "# fmt: on\n", + "\n", "fc = normClim.geetools.plot_by_regions(\n", - " type = \"stacked\",\n", - " regions = ecoregions,\n", - " reducer = \"mean\",\n", - " scale = 500,\n", - " regionId = \"label\",\n", - " bands = ['01_ppt', '02_ppt', '03_ppt', '04_ppt', '05_ppt', '06_ppt', '07_ppt', '08_ppt', '09_ppt', '10_ppt', '11_ppt', '12_ppt'],\n", - " labels = [\"jan\", \"feb\", \"mar\", \"apr\", \"may\", \"jun\", \"jul\", \"aug\", \"sep\", \"oct\", \"nov\", \"dec\"],\n", - " colors = ['#604791', '#1d6b99', '#39a8a7', '#0f8755', '#76b349', '#f0af07', '#e37d05', '#cf513e', '#96356f', '#724173', '#9c4f97', '#696969'],\n", - " ax = ax\n", + " type=\"stacked\",\n", + " regions=ecoregions,\n", + " reducer=\"mean\",\n", + " scale=500,\n", + " regionId=\"label\",\n", + " bands=[f\"0{i}_ppt\" for i in range(1, 13)],\n", + " labels=[dt(2000, m, 1).strftime(\"%b\")[:3].lower() for m in range(1, 13)],\n", + " colors=colors,\n", + " ax=ax,\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -298,7 +327,7 @@ "import numpy as np\n", "\n", "# Data for the chart\n", - "features = ['b1', 'b2', 'b3']\n", + "features = [\"b1\", \"b2\", \"b3\"]\n", "p1_values = [0.5, 2.5, 4.5]\n", "p2_values = [1.5, 3.5, 5.5]\n", "p3_values = [2.5, 4.0, 6.5]\n", @@ -312,18 +341,23 @@ "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", "# Plotting the bars\n", - "rects1 = ax.bar(index, p1_values, bar_width, label='r1', color='#1d6b99')\n", - "rects2 = ax.bar(index + (bar_width + offset), p2_values, bar_width, label='r2', color='#cf513e')\n", - "rects3 = ax.bar(index + 2 * (bar_width + offset), p3_values, bar_width, label='r3', color='#f0af07')\n", + "rects1 = ax.bar(index, p1_values, bar_width, label=\"r1\", color=\"#1d6b99\")\n", + "rects2 = ax.bar(index + (bar_width + offset), p2_values, bar_width, label=\"r2\", color=\"#cf513e\")\n", + "rects3 = ax.bar(index + 2 * (bar_width + offset), p3_values, bar_width, label=\"r3\", color=\"#f0af07\")\n", "\n", "# Add labels, title, and custom x-axis tick labels\n", - "ax.set_xlabel('band names')\n", - "ax.set_ylabel('Series reduction value')\n", + "ax.set_xlabel(\"band names\")\n", + "ax.set_ylabel(\"Series reduction value\")\n", "ax.set_xticks(index + bar_width)\n", "ax.set_xticklabels(features)\n", "\n", "# Add a legend\n", - "ax.legend(loc='upper center', bbox_to_anchor=(0.85, 1.15), ncol=3, title='Regions by feature property value')\n", + "ax.legend(\n", + " loc=\"upper center\",\n", + " bbox_to_anchor=(0.85, 1.15),\n", + " ncol=3,\n", + " title=\"Regions by feature property value\",\n", + ")\n", "\n", "# set the grid display\n", "ax.grid(axis=\"y\")\n", @@ -354,15 +388,15 @@ "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", "fc = normClim.geetools.plot_by_bands(\n", - " type = \"bar\",\n", - " regions = ecoregions,\n", - " reducer = \"mean\",\n", - " scale = 500,\n", - " regionId = \"label\",\n", - " bands = ['01_ppt', '02_ppt', '03_ppt', '04_ppt', '05_ppt', '06_ppt', '07_ppt', '08_ppt', '09_ppt', '10_ppt', '11_ppt', '12_ppt'],\n", - " labels = [\"jan\", \"feb\", \"mar\", \"apr\", \"may\", \"jun\", \"jul\", \"aug\", \"sep\", \"oct\", \"nov\", \"dec\"],\n", - " colors = [\"#f0af07\", \"#0f8755\", \"#76b349\"],\n", - " ax = ax\n", + " type=\"bar\",\n", + " regions=ecoregions,\n", + " reducer=\"mean\",\n", + " scale=500,\n", + " regionId=\"label\",\n", + " bands=[f\"0{i}_ppt\" for i in range(1, 13)],\n", + " labels=[dt(2000, m, 1).strftime(\"%b\")[:3].lower() for m in range(1, 13)],\n", + " colors=[\"#f0af07\", \"#0f8755\", \"#76b349\"],\n", + " ax=ax,\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -390,15 +424,15 @@ "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", "fc = normClim.geetools.plot_by_bands(\n", - " type = \"plot\",\n", - " regions = ecoregions,\n", - " reducer = \"mean\",\n", - " scale = 500,\n", - " regionId = \"label\",\n", - " bands = ['01_ppt', '02_ppt', '03_ppt', '04_ppt', '05_ppt', '06_ppt', '07_ppt', '08_ppt', '09_ppt', '10_ppt', '11_ppt', '12_ppt'],\n", - " labels = [\"jan\", \"feb\", \"mar\", \"apr\", \"may\", \"jun\", \"jul\", \"aug\", \"sep\", \"oct\", \"nov\", \"dec\"],\n", - " colors = [\"#f0af07\", \"#0f8755\", \"#76b349\"],\n", - " ax = ax\n", + " type=\"plot\",\n", + " regions=ecoregions,\n", + " reducer=\"mean\",\n", + " scale=500,\n", + " regionId=\"label\",\n", + " bands=[f\"0{i}_ppt\" for i in range(1, 13)],\n", + " labels=[dt(2000, m, 1).strftime(\"%b\")[:3].lower() for m in range(1, 13)],\n", + " colors=[\"#f0af07\", \"#0f8755\", \"#76b349\"],\n", + " ax=ax,\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -426,15 +460,15 @@ "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", "fc = normClim.geetools.plot_by_bands(\n", - " type = \"fill_between\",\n", - " regions = ecoregions,\n", - " reducer = \"mean\",\n", - " scale = 500,\n", - " regionId = \"label\",\n", - " bands = ['01_ppt', '02_ppt', '03_ppt', '04_ppt', '05_ppt', '06_ppt', '07_ppt', '08_ppt', '09_ppt', '10_ppt', '11_ppt', '12_ppt'],\n", - " labels = [\"jan\", \"feb\", \"mar\", \"apr\", \"may\", \"jun\", \"jul\", \"aug\", \"sep\", \"oct\", \"nov\", \"dec\"],\n", - " colors = [\"#f0af07\", \"#0f8755\", \"#76b349\"],\n", - " ax = ax\n", + " type=\"fill_between\",\n", + " regions=ecoregions,\n", + " reducer=\"mean\",\n", + " scale=500,\n", + " regionId=\"label\",\n", + " bands=[f\"0{i}_ppt\" for i in range(1, 13)],\n", + " labels=[dt(2000, m, 1).strftime(\"%b\")[:3].lower() for m in range(1, 13)],\n", + " colors=[\"#f0af07\", \"#0f8755\", \"#76b349\"],\n", + " ax=ax,\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -461,16 +495,25 @@ "source": [ "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", + "# define the colors to use for the display\n", + "# fmt: off\n", + "colors = [\n", + " \"#604791\", \"#1d6b99\", \"#39a8a7\", \"#0f8755\",\n", + " \"#76b349\", \"#f0af07\", \"#e37d05\", \"#cf513e\",\n", + " \"#96356f\", \"#724173\", \"#9c4f97\", \"#696969\",\n", + "]\n", + "# fmt: on\n", + "\n", "normClim.geetools.plot_by_bands(\n", - " type = \"pie\",\n", - " regions = ecoregions.filter(ee.Filter.eq(\"label\", \"Forest\")),\n", - " reducer = \"mean\",\n", - " scale = 500,\n", - " regionId = \"label\",\n", - " bands = ['01_ppt', '02_ppt', '03_ppt', '04_ppt', '05_ppt', '06_ppt', '07_ppt', '08_ppt', '09_ppt', '10_ppt', '11_ppt', '12_ppt'],\n", - " labels = [\"jan\", \"feb\", \"mar\", \"apr\", \"may\", \"jun\", \"jul\", \"aug\", \"sep\", \"oct\", \"nov\", \"dec\"],\n", - " colors = ['#604791', '#1d6b99', '#39a8a7', '#0f8755', '#76b349', '#f0af07', '#e37d05', '#cf513e', '#96356f', '#724173', '#9c4f97', '#696969'],\n", - " ax = ax\n", + " type=\"pie\",\n", + " regions=ecoregions.filter(ee.Filter.eq(\"label\", \"Forest\")),\n", + " reducer=\"mean\",\n", + " scale=500,\n", + " regionId=\"label\",\n", + " bands=[f\"0{i}_ppt\" for i in range(1, 13)],\n", + " labels=[dt(2000, m, 1).strftime(\"%b\")[:3].lower() for m in range(1, 13)],\n", + " colors=colors,\n", + " ax=ax,\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -495,16 +538,25 @@ "source": [ "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", + "# define the colors to use for the display\n", + "# fmt: off\n", + "colors = [\n", + " \"#604791\", \"#1d6b99\", \"#39a8a7\", \"#0f8755\",\n", + " \"#76b349\", \"#f0af07\", \"#e37d05\", \"#cf513e\",\n", + " \"#96356f\", \"#724173\", \"#9c4f97\", \"#696969\",\n", + "]\n", + "# fmt: on\n", + "\n", "fc = normClim.geetools.plot_by_bands(\n", - " type = \"donut\",\n", - " regions = ecoregions.filter(ee.Filter.eq(\"label\", \"Forest\")),\n", - " reducer = \"mean\",\n", - " scale = 500,\n", - " regionId = \"label\",\n", - " bands = ['01_ppt', '02_ppt', '03_ppt', '04_ppt', '05_ppt', '06_ppt', '07_ppt', '08_ppt', '09_ppt', '10_ppt', '11_ppt', '12_ppt'],\n", - " labels = [\"jan\", \"feb\", \"mar\", \"apr\", \"may\", \"jun\", \"jul\", \"aug\", \"sep\", \"oct\", \"nov\", \"dec\"],\n", - " colors = ['#604791', '#1d6b99', '#39a8a7', '#0f8755', '#76b349', '#f0af07', '#e37d05', '#cf513e', '#96356f', '#724173', '#9c4f97', '#696969'],\n", - " ax = ax\n", + " type=\"donut\",\n", + " regions=ecoregions.filter(ee.Filter.eq(\"label\", \"Forest\")),\n", + " reducer=\"mean\",\n", + " scale=500,\n", + " regionId=\"label\",\n", + " bands=[f\"0{i}_ppt\" for i in range(1, 13)],\n", + " labels=[dt(2000, m, 1).strftime(\"%b\")[:3].lower() for m in range(1, 13)],\n", + " colors=colors,\n", + " ax=ax,\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -547,13 +599,13 @@ "\n", "# initialize the plot with the ecoregions data\n", "modisSr.geetools.plot_hist(\n", - " bands = [\"sur_refl_b01\", \"sur_refl_b02\", \"sur_refl_b06\"],\n", - " labels = [['Red', 'NIR', 'SWIR']],\n", - " colors = [\"#cf513e\", \"#1d6b99\", \"#f0af07\"],\n", - " ax = ax,\n", - " bins = 100,\n", - " scale = 500,\n", - " region = histRegion,\n", + " bands=[\"sur_refl_b01\", \"sur_refl_b02\", \"sur_refl_b06\"],\n", + " labels=[[\"Red\", \"NIR\", \"SWIR\"]],\n", + " colors=[\"#cf513e\", \"#1d6b99\", \"#f0af07\"],\n", + " ax=ax,\n", + " bins=100,\n", + " scale=500,\n", + " region=histRegion,\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -579,7 +631,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.10.15" } }, "nbformat": 4, diff --git a/docs/usage/plot/plot-imagecollection.ipynb b/docs/usage/plot/plot-imagecollection.ipynb index 2d652c18..1ac3a48b 100644 --- a/docs/usage/plot/plot-imagecollection.ipynb +++ b/docs/usage/plot/plot-imagecollection.ipynb @@ -19,7 +19,8 @@ }, "outputs": [], "source": [ - "import ee, geetools\n", + "import ee\n", + "\n", "from geetools.utils import initialize_documentation\n", "\n", "initialize_documentation()" @@ -58,11 +59,11 @@ "metadata": {}, "outputs": [], "source": [ - "from matplotlib import pyplot as plt\n", "from datetime import datetime as dt\n", "\n", - "import ee\n", - "import geetools #noqa: F401" + "from matplotlib import pyplot as plt\n", + "\n", + "import geetools # noqa: F401" ] }, { @@ -92,9 +93,8 @@ "outputs": [], "source": [ "## Import the example feature collection and drop the data property.\n", - "ecoregions = (\n", - " ee.FeatureCollection(\"projects/google/charts_feature_example\")\n", - " .select([\"label\", \"value\", \"warm\"])\n", + "ecoregions = ee.FeatureCollection(\"projects/google/charts_feature_example\").select(\n", + " [\"label\", \"value\", \"warm\"]\n", ")\n", "\n", "\n", @@ -148,12 +148,12 @@ "ax.plot(dates, b3, label=\"b3\", color=\"#f0af07\")\n", "\n", "# Add titles and labels\n", - "ax.set_title('Single-region spatial reduction')\n", - "ax.set_xlabel('Image date')\n", - "ax.set_ylabel('Spatial reduction')\n", + "ax.set_title(\"Single-region spatial reduction\")\n", + "ax.set_xlabel(\"Image date\")\n", + "ax.set_ylabel(\"Spatial reduction\")\n", "\n", "# Add a legend\n", - "ax.legend(loc='upper center', bbox_to_anchor=(0.85, 1.15), ncol=3, title='Band names')\n", + "ax.legend(loc=\"upper center\", bbox_to_anchor=(0.85, 1.15), ncol=3, title=\"Band names\")\n", "\n", "# set the grid display\n", "ax.grid(axis=\"y\")\n", @@ -183,12 +183,12 @@ "fig, ax = plt.subplots(figsize=(10, 4))\n", "region = ecoregions.filter(ee.Filter.eq(\"label\", \"Forest\"))\n", "vegIndices.geetools.plot_dates_by_bands(\n", - " region = region.geometry(),\n", - " reducer = \"mean\",\n", - " scale = 500,\n", - " bands = [\"NDVI\", \"EVI\"],\n", - " ax = ax,\n", - " dateProperty = \"system:time_start\",\n", + " region=region.geometry(),\n", + " reducer=\"mean\",\n", + " scale=500,\n", + " bands=[\"NDVI\", \"EVI\"],\n", + " ax=ax,\n", + " dateProperty=\"system:time_start\",\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -246,7 +246,7 @@ "ax.set_ylabel(\"Spatial reduction\")\n", "\n", "# Add a legend\n", - "ax.legend(loc='upper center', bbox_to_anchor=(0.85, 1.15), ncol=3, title='Regions')\n", + "ax.legend(loc=\"upper center\", bbox_to_anchor=(0.85, 1.15), ncol=3, title=\"Regions\")\n", "\n", "# set the grid display\n", "ax.grid(axis=\"y\")\n", @@ -276,14 +276,14 @@ "fig, ax = plt.subplots(figsize=(10, 4))\n", "region = ecoregions.filter(ee.Filter.eq(\"label\", \"Forest\"))\n", "vegIndices.geetools.plot_dates_by_regions(\n", - " band = \"NDVI\",\n", - " regions = ecoregions,\n", - " label = \"label\",\n", - " reducer = \"mean\",\n", - " scale = 500,\n", - " ax = ax,\n", - " dateProperty = \"system:time_start\",\n", - " colors = ['#f0af07', '#0f8755', '#76b349']\n", + " band=\"NDVI\",\n", + " regions=ecoregions,\n", + " label=\"label\",\n", + " reducer=\"mean\",\n", + " scale=500,\n", + " ax=ax,\n", + " dateProperty=\"system:time_start\",\n", + " colors=[\"#f0af07\", \"#0f8755\", \"#76b349\"],\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -352,7 +352,7 @@ "ax.set_ylabel(\"Reduced values\")\n", "\n", "# Add a legend\n", - "ax.legend(loc='upper center', bbox_to_anchor=(0.85, 1.15), ncol=3, title='Band names')\n", + "ax.legend(loc=\"upper center\", bbox_to_anchor=(0.85, 1.15), ncol=3, title=\"Band names\")\n", "\n", "# set the grid display\n", "ax.grid(axis=\"y\")\n", @@ -379,17 +379,17 @@ "metadata": {}, "outputs": [], "source": [ - "fig, ax = plt.subplots(figsize=(10,4))\n", + "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", "vegIndices.geetools.plot_doy_by_bands(\n", - " region = ecoregions.filter(ee.Filter.eq(\"label\", \"Grassland\")).geometry(),\n", - " spatialReducer = \"mean\",\n", - " timeReducer = \"mean\",\n", - " scale = 500,\n", - " bands = [\"NDVI\", \"EVI\"],\n", - " ax = ax,\n", - " dateProperty = \"system:time_start\",\n", - " colors = ['#e37d05', '#1d6b99']\n", + " region=ecoregions.filter(ee.Filter.eq(\"label\", \"Grassland\")).geometry(),\n", + " spatialReducer=\"mean\",\n", + " timeReducer=\"mean\",\n", + " scale=500,\n", + " bands=[\"NDVI\", \"EVI\"],\n", + " ax=ax,\n", + " dateProperty=\"system:time_start\",\n", + " colors=[\"#e37d05\", \"#1d6b99\"],\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -447,7 +447,7 @@ "ax.set_ylabel(\"Reduced values\")\n", "\n", "# Add a legend\n", - "ax.legend(loc='upper center', bbox_to_anchor=(0.85, 1.15), ncol=3, title='regions')\n", + "ax.legend(loc=\"upper center\", bbox_to_anchor=(0.85, 1.15), ncol=3, title=\"regions\")\n", "\n", "# set the grid display\n", "ax.grid(axis=\"y\")\n", @@ -474,18 +474,18 @@ "metadata": {}, "outputs": [], "source": [ - "fig, ax = plt.subplots(figsize=(10,4))\n", + "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", "vegIndices.geetools.plot_doy_by_regions(\n", - " regions = ecoregions,\n", - " label = \"label\",\n", - " spatialReducer = \"mean\",\n", - " timeReducer = \"mean\",\n", - " scale = 500,\n", - " band = \"NDVI\",\n", - " ax = ax,\n", - " dateProperty = \"system:time_start\",\n", - " colors = ['#f0af07', '#0f8755', '#76b349']\n", + " regions=ecoregions,\n", + " label=\"label\",\n", + " spatialReducer=\"mean\",\n", + " timeReducer=\"mean\",\n", + " scale=500,\n", + " band=\"NDVI\",\n", + " ax=ax,\n", + " dateProperty=\"system:time_start\",\n", + " colors=[\"#f0af07\", \"#0f8755\", \"#76b349\"],\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -543,7 +543,7 @@ "ax.set_ylabel(\"Reduced values\")\n", "\n", "# Add a legend\n", - "ax.legend(loc='upper center', bbox_to_anchor=(0.85, 1.15), ncol=3, title='iage years')\n", + "ax.legend(loc=\"upper center\", bbox_to_anchor=(0.85, 1.15), ncol=3, title=\"iage years\")\n", "\n", "# set the grid display\n", "ax.grid(axis=\"y\")\n", @@ -575,10 +575,10 @@ "\n", "# for plot speed and lisibility only keep 2 years (2010 and 2020) for the example\n", "indices = vegIndices.filter(\n", - " ee.Filter.Or(\n", - " ee.Filter.date(\"2012-01-01\", \"2012-12-31\"),\n", - " ee.Filter.date(\"2019-01-01\", \"2019-12-31\"),\n", - " )\n", + " ee.Filter.Or(\n", + " ee.Filter.date(\"2012-01-01\", \"2012-12-31\"),\n", + " ee.Filter.date(\"2019-01-01\", \"2019-12-31\"),\n", + " )\n", ")" ] }, @@ -588,15 +588,15 @@ "metadata": {}, "outputs": [], "source": [ - "fig, ax = plt.subplots(figsize=(10,4))\n", + "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", "indices.geetools.plot_doy_by_years(\n", - " band = \"NDVI\",\n", - " region = grassland.geometry(),\n", - " reducer = \"mean\",\n", - " scale = 500,\n", - " ax = ax,\n", - " colors = ['#39a8a7', '#9c4f97']\n", + " band=\"NDVI\",\n", + " region=grassland.geometry(),\n", + " reducer=\"mean\",\n", + " scale=500,\n", + " ax=ax,\n", + " colors=[\"#39a8a7\", \"#9c4f97\"],\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", @@ -649,17 +649,17 @@ "metadata": {}, "outputs": [], "source": [ - "fig, ax = plt.subplots(figsize=(10,4))\n", + "fig, ax = plt.subplots(figsize=(10, 4))\n", "\n", "indices.geetools.plot_doy_by_seasons(\n", - " band = \"NDVI\",\n", - " region = grassland.geometry(),\n", - " seasonStart = ee.Date(\"2022-04-15\").getRelative(\"day\", \"year\"),\n", - " seasonEnd = ee.Date(\"2022-09-15\").getRelative(\"day\", \"year\"),\n", - " reducer = \"mean\",\n", - " scale = 500,\n", - " ax = ax,\n", - " colors = ['#39a8a7', '#9c4f97']\n", + " band=\"NDVI\",\n", + " region=grassland.geometry(),\n", + " seasonStart=ee.Date(\"2022-04-15\").getRelative(\"day\", \"year\"),\n", + " seasonEnd=ee.Date(\"2022-09-15\").getRelative(\"day\", \"year\"),\n", + " reducer=\"mean\",\n", + " scale=500,\n", + " ax=ax,\n", + " colors=[\"#39a8a7\", \"#9c4f97\"],\n", ")\n", "\n", "# once created the axes can be modified as needed using pure matplotlib functions\n", diff --git a/docs/usage/profile.ipynb b/docs/usage/profile.ipynb index a51cbce7..e9c5477f 100644 --- a/docs/usage/profile.ipynb +++ b/docs/usage/profile.ipynb @@ -19,7 +19,8 @@ }, "outputs": [], "source": [ - "import ee, geetools\n", + "import ee\n", + "\n", "from geetools.utils import initialize_documentation\n", "\n", "initialize_documentation()" @@ -58,9 +59,9 @@ "metadata": {}, "outputs": [], "source": [ - "import ee\n", - "import geetools\n", - "import pandas as pd" + "import pandas as pd\n", + "\n", + "import geetools # noqa: F401" ] }, { @@ -89,12 +90,11 @@ "metadata": {}, "outputs": [], "source": [ - "ecoregions = (\n", - " ee.FeatureCollection(\"projects/google/charts_feature_example\")\n", - " .select([\"label\", \"value\",\"warm\"])\n", + "ecoregions = ee.FeatureCollection(\"projects/google/charts_feature_example\").select(\n", + " [\"label\", \"value\", \"warm\"]\n", ")\n", "\n", - "normClim = ee.ImageCollection('OREGONSTATE/PRISM/Norm91m').toBands()" + "normClim = ee.ImageCollection(\"OREGONSTATE/PRISM/Norm91m\").toBands()" ] }, { @@ -114,11 +114,11 @@ "source": [ "with ee.profilePrinting():\n", " normClim.geetools.byBands(\n", - " regions = ecoregions,\n", - " reducer = \"mean\",\n", - " scale = 500,\n", - " regionId = \"label\",\n", - " bands = [f\"{i:02d}_tmean\" for i in range(1,13)],\n", + " regions=ecoregions,\n", + " reducer=\"mean\",\n", + " scale=500,\n", + " regionId=\"label\",\n", + " bands=[f\"{i:02d}_tmean\" for i in range(1, 13)],\n", " ).getInfo()" ] }, @@ -165,11 +165,11 @@ "source": [ "with ee.geetools.Profiler() as p:\n", " normClim.geetools.byBands(\n", - " regions = ecoregions,\n", - " reducer = \"mean\",\n", - " scale = 500,\n", - " regionId = \"label\",\n", - " bands = [f\"{i:02d}_tmean\" for i in range(1,13)],\n", + " regions=ecoregions,\n", + " reducer=\"mean\",\n", + " scale=500,\n", + " regionId=\"label\",\n", + " bands=[f\"{i:02d}_tmean\" for i in range(1, 13)],\n", " ).getInfo()\n", "df = pd.DataFrame(p.profile)\n", "df.head()" diff --git a/docs/usage/reduce.ipynb b/docs/usage/reduce.ipynb index c8e7f7a2..ba0b2889 100644 --- a/docs/usage/reduce.ipynb +++ b/docs/usage/reduce.ipynb @@ -17,7 +17,8 @@ }, "outputs": [], "source": [ - "import ee, geetools\n", + "import ee\n", + "\n", "from geetools.utils import initialize_documentation\n", "\n", "initialize_documentation()" @@ -63,8 +64,7 @@ "metadata": {}, "outputs": [], "source": [ - "import ee\n", - "import geetools #noqa: F401" + "import geetools # noqa: F401" ] }, { @@ -93,9 +93,8 @@ "outputs": [], "source": [ "## Import the example feature collection and drop the data property.\n", - "ecoregions = (\n", - " ee.FeatureCollection(\"projects/google/charts_feature_example\")\n", - " .select([\"label\", \"value\", \"warm\"])\n", + "ecoregions = ee.FeatureCollection(\"projects/google/charts_feature_example\").select(\n", + " [\"label\", \"value\", \"warm\"]\n", ")\n", "\n", "\n", @@ -134,11 +133,11 @@ "outputs": [], "source": [ "vegIndices.geetools.reduceRegion(\n", - " reducer = ee.Reducer.mean(),\n", - " idProperty = \"system:time_start\",\n", - " idType = ee.Date,\n", - " geometry = ecoregions.filter(ee.Filter.eq(\"label\", \"Forest\")).geometry(),\n", - " scale = 500\n", + " reducer=ee.Reducer.mean(),\n", + " idProperty=\"system:time_start\",\n", + " idType=ee.Date,\n", + " geometry=ecoregions.filter(ee.Filter.eq(\"label\", \"Forest\")).geometry(),\n", + " scale=500,\n", ").getInfo()" ] } diff --git a/docs/usage/template.ipynb b/docs/usage/template.ipynb index faa27def..f71364d8 100644 --- a/docs/usage/template.ipynb +++ b/docs/usage/template.ipynb @@ -17,7 +17,8 @@ }, "outputs": [], "source": [ - "import ee, geetools\n", + "import ee\n", + "\n", "from geetools.utils import initialize_documentation\n", "\n", "initialize_documentation()" @@ -56,8 +57,7 @@ "metadata": {}, "outputs": [], "source": [ - "import ee\n", - "import geetools #noqa: F401" + "import geetools # noqa: F401" ] }, { diff --git a/geetools/__init__.py b/geetools/__init__.py index 80b83e81..8640ac08 100644 --- a/geetools/__init__.py +++ b/geetools/__init__.py @@ -4,6 +4,7 @@ processing tools for the most used satellite platforms by adding utility methods for different Earth Engine Objects that are friendly with the Python method chaining using the geetools namespace. """ + import ee # import the accessor namespace @@ -39,13 +40,6 @@ from .ee_export import ExportAccessor from .ee_profiler import Profiler -__title__ = "geetools" -__summary__ = "A set of useful tools to use with Google Earth Engine Python" "API" -__uri__ = "http://geetools.readthedocs.io" __version__ = "1.9.1" - __author__ = "Rodrigo E. Principe" __email__ = "fitoprincipe82@gmail.com" - -__license__ = "MIT" -__copyright__ = "2017 Rodrigo E. Principe" diff --git a/geetools/accessors.py b/geetools/accessors.py index 31a2cce9..9827c815 100644 --- a/geetools/accessors.py +++ b/geetools/accessors.py @@ -1,4 +1,5 @@ """Generic accessor to add extra function to the base GEE API classes.""" + from __future__ import annotations from typing import Callable @@ -49,7 +50,6 @@ def register_function_accessor(func: type, name: str) -> Callable: """ def decorator(accessor: Callable) -> object: - # check if the accessor already exists for this class if hasattr(func, name): raise AttributeError(f"Member {name} already exists for {func}") diff --git a/geetools/ee_array.py b/geetools/ee_array.py index a9a19ef9..739dc871 100644 --- a/geetools/ee_array.py +++ b/geetools/ee_array.py @@ -1,4 +1,5 @@ """Extra methods for the ``ee.Array`` class.""" + from __future__ import annotations import ee diff --git a/geetools/ee_asset.py b/geetools/ee_asset.py index 6c81a931..3d1ae0c6 100644 --- a/geetools/ee_asset.py +++ b/geetools/ee_asset.py @@ -1,4 +1,5 @@ """An Asset management class mimicking the ``pathlib.Path`` class behaviour.""" + from __future__ import annotations import os @@ -74,7 +75,7 @@ def __fspath__(self): return self.as_posix() def __hash__(self): - """make the Asset object hashable.""" + """Make the Asset object hashable.""" return hash(self.as_posix()) def __getattr__(self, name): @@ -615,7 +616,6 @@ def delete(asset): is_container = self.is_folder() or self.is_image_collection() if recursive is True and is_container: - # get all the assets asset_list = self.iterdir(recursive=True) diff --git a/geetools/ee_authenticate.py b/geetools/ee_authenticate.py index 6ee59656..c65880c8 100644 --- a/geetools/ee_authenticate.py +++ b/geetools/ee_authenticate.py @@ -1,4 +1,5 @@ """Toolbox for the ``ee.Authenticate`` function.""" + from __future__ import annotations from contextlib import suppress @@ -81,7 +82,7 @@ def delete_user(name: str = "", credential_pathname: str = "") -> None: @staticmethod def list_user(credential_pathname: str = "") -> list: - """return all the available users in the set folder. + """Return all the available users in the set folder. To reach "default" simply omit the ``name`` parameter in the User methods diff --git a/geetools/ee_computed_object.py b/geetools/ee_computed_object.py index 94a02f64..2cfa91b2 100644 --- a/geetools/ee_computed_object.py +++ b/geetools/ee_computed_object.py @@ -1,4 +1,5 @@ """Extra tools for the ``ee.ComputedObject`` class.""" + from __future__ import annotations import json diff --git a/geetools/ee_date.py b/geetools/ee_date.py index 45a392f8..9454cf92 100644 --- a/geetools/ee_date.py +++ b/geetools/ee_date.py @@ -1,4 +1,5 @@ """Extra methods for the ``ee.Date`` class.""" + from __future__ import annotations from datetime import datetime diff --git a/geetools/ee_date_range.py b/geetools/ee_date_range.py index 18bdd40a..d9f3c02a 100644 --- a/geetools/ee_date_range.py +++ b/geetools/ee_date_range.py @@ -1,4 +1,5 @@ """Extra tools for the ``ee.DateRange`` class.""" + from __future__ import annotations import ee diff --git a/geetools/ee_dictionary.py b/geetools/ee_dictionary.py index 49320bd2..7219d676 100644 --- a/geetools/ee_dictionary.py +++ b/geetools/ee_dictionary.py @@ -1,4 +1,5 @@ """Extra methods for the ``ee.Dictionary`` class.""" + from __future__ import annotations import ee diff --git a/geetools/ee_export.py b/geetools/ee_export.py index 206dabab..6ac6a8d7 100644 --- a/geetools/ee_export.py +++ b/geetools/ee_export.py @@ -1,4 +1,5 @@ """Toolbox for the ``ee.Export`` class.""" + from __future__ import annotations import ee diff --git a/geetools/ee_feature.py b/geetools/ee_feature.py index aae47a12..dd36ea00 100644 --- a/geetools/ee_feature.py +++ b/geetools/ee_feature.py @@ -1,4 +1,5 @@ """Toolbox for the ``ee.Feature`` class.""" + from __future__ import annotations import ee diff --git a/geetools/ee_feature_collection.py b/geetools/ee_feature_collection.py index ead0dada..f5f4b43d 100644 --- a/geetools/ee_feature_collection.py +++ b/geetools/ee_feature_collection.py @@ -1,4 +1,5 @@ """Toolbox for the `ee.FeatureCollection` class.""" + from __future__ import annotations import ee diff --git a/geetools/ee_filter.py b/geetools/ee_filter.py index d60c923e..6b97724d 100644 --- a/geetools/ee_filter.py +++ b/geetools/ee_filter.py @@ -1,4 +1,5 @@ """Extra method for the ``ee.Filter`` class.""" + from __future__ import annotations import ee diff --git a/geetools/ee_geometry.py b/geetools/ee_geometry.py index 70b37551..84f3a2ab 100644 --- a/geetools/ee_geometry.py +++ b/geetools/ee_geometry.py @@ -1,4 +1,5 @@ """Toolbox for the ``ee.Geometry`` class.""" + from __future__ import annotations import ee diff --git a/geetools/ee_image.py b/geetools/ee_image.py index f176fe4c..74132ba4 100644 --- a/geetools/ee_image.py +++ b/geetools/ee_image.py @@ -1,4 +1,5 @@ """Toolbox for the ``ee.Image`` class.""" + from __future__ import annotations from typing import Optional @@ -2066,7 +2067,7 @@ def plot_hist( # the values are treated the same way we simply drop the last duplication to get the same size. p = 10**precision # multiplier use to truncate the float values x = [int(d[0] * p) / p for d in raw_data[labels[0]] for _ in range(2)][1:] - data = {l: [int(d[1]) for d in raw_data[l] for _ in range(2)][:-1] for l in labels} + data = {e: [int(d[1]) for d in raw_data[e] for _ in range(2)][:-1] for e in labels} # create the graph objcet if not provided if ax is None: diff --git a/geetools/ee_image_collection.py b/geetools/ee_image_collection.py index 9d92aca1..4aa57125 100644 --- a/geetools/ee_image_collection.py +++ b/geetools/ee_image_collection.py @@ -1,4 +1,5 @@ """Toolbox for the ``ee.ImageCollection`` class.""" + from __future__ import annotations import uuid @@ -1214,6 +1215,7 @@ def datesByRegions( reduced = collection.geetools.datesByRegions("B1", regions, "name", "mean", 10000, "system:time_start") print(reduced.getInfo()) """ + # aggregate all the dates of the image collection into bands of a single image def to_string(date: ee.Date) -> ee.String: return ee.Date(date).format(EE_DATE_FORMAT) @@ -1766,7 +1768,7 @@ def plot_dates_by_bands( def to_date(dict): return {dt.strptime(d, PY_DATE_FORMAT): v for d, v in dict.items()} - data = {l: to_date(dict) for l, dict in raw_data.items()} + data = {e: to_date(dict) for e, dict in raw_data.items()} # create the plot ax = plot_data("date", data, "Date", colors, ax) @@ -1853,7 +1855,7 @@ def plot_dates_by_regions( def to_date(dict): return {dt.strptime(d, PY_DATE_FORMAT): v for d, v in dict.items()} - data = {l: to_date(dict) for l, dict in raw_data.items()} + data = {e: to_date(dict) for e, dict in raw_data.items()} # create the plot ax = plot_data("date", data, "Date", colors, ax) @@ -1945,7 +1947,7 @@ def plot_doy_by_bands( def to_int(d): return {int(k): v for k, v in d.items()} - data = {l: dict(sorted(to_int(raw_data[l]).items())) for l in raw_data} + data = {e: dict(sorted(to_int(raw_data[e]).items())) for e in raw_data} # create the plot ax = plot_data("doy", data, "Day of Year", colors, ax) @@ -2035,7 +2037,7 @@ def plot_doy_by_regions( def to_int(d): return {int(k): v for k, v in d.items()} - data = {l: dict(sorted(to_int(raw_data[l]).items())) for l in raw_data} + data = {e: dict(sorted(to_int(raw_data[e]).items())) for e in raw_data} # create the plot ax = plot_data("doy", data, "Day of Year", colors, ax) @@ -2144,7 +2146,7 @@ def plot_doy_by_seasons( def to_int(d): return {int(k): v for k, v in d.items()} - data = {l: dict(sorted(to_int(raw_data[l]).items())) for l in raw_data} + data = {i: dict(sorted(to_int(raw_data[i]).items())) for i in raw_data} # create the plot ax = plot_data("doy", data, "Day of Year", colors, ax) diff --git a/geetools/ee_initialize.py b/geetools/ee_initialize.py index 8aa2d276..d3b7ebc9 100644 --- a/geetools/ee_initialize.py +++ b/geetools/ee_initialize.py @@ -1,4 +1,5 @@ """Tools for the ``ee.Initialize`` function.""" + from __future__ import annotations import json diff --git a/geetools/ee_join.py b/geetools/ee_join.py index 7cfff2ca..8647fe3b 100644 --- a/geetools/ee_join.py +++ b/geetools/ee_join.py @@ -1,4 +1,5 @@ """Extra methods for the ``ee.Join`` class.""" + from __future__ import annotations import ee diff --git a/geetools/ee_list.py b/geetools/ee_list.py index ebe31cea..9e34f798 100644 --- a/geetools/ee_list.py +++ b/geetools/ee_list.py @@ -1,4 +1,5 @@ """Extra methods for the ``ee.List`` class.""" + from __future__ import annotations import ee diff --git a/geetools/ee_number.py b/geetools/ee_number.py index a996dd1c..bff2efd1 100644 --- a/geetools/ee_number.py +++ b/geetools/ee_number.py @@ -1,4 +1,5 @@ """Extra methods for the ``ee.Number`` class.""" + from __future__ import annotations import ee diff --git a/geetools/ee_profiler.py b/geetools/ee_profiler.py index 6ff812d9..6d92e66b 100644 --- a/geetools/ee_profiler.py +++ b/geetools/ee_profiler.py @@ -1,4 +1,5 @@ """A profiler context manager for Earth Engine Python API.""" + from __future__ import annotations import io diff --git a/geetools/ee_string.py b/geetools/ee_string.py index 00d099ca..7d967007 100644 --- a/geetools/ee_string.py +++ b/geetools/ee_string.py @@ -1,4 +1,5 @@ """Extra methods for the ``ee.String`` class.""" + from __future__ import annotations import ee diff --git a/geetools/tools/__init__.py b/geetools/tools/__init__.py index 12fcdb77..ea8f5c98 100644 --- a/geetools/tools/__init__.py +++ b/geetools/tools/__init__.py @@ -1,2 +1,3 @@ """Legacy import package for tools.""" + from . import _deprecated_imagecollection as imagecollection # noqa: F401 diff --git a/geetools/tools/_deprecated_imagecollection.py b/geetools/tools/_deprecated_imagecollection.py index 26c6b514..31788e89 100644 --- a/geetools/tools/_deprecated_imagecollection.py +++ b/geetools/tools/_deprecated_imagecollection.py @@ -1,5 +1,6 @@ # coding=utf-8 """legacy Module holding tools for ee.ImageCollections.""" + import ee from deprecated.sphinx import deprecated @@ -47,7 +48,7 @@ def reduceDayIntervals(collection, reducer, interval=30, reverse=False, buffer=" @deprecated(version="1.4.0", reason="Removed from the lib as untested") def linearFunctionBand(*args, **kwargs): - """Apply a linear function over the bands across every image of the ImageCollection""" + """Apply a linear function over the bands across every image of the ImageCollection.""" raise NotImplementedError( "As it was vastly untested this method has been removed from the lib." "If a real use case for this method can be provided, please open an issue and we'll reimplement it." @@ -56,7 +57,7 @@ def linearFunctionBand(*args, **kwargs): @deprecated(version="1.4.0", reason="Removed from the lib as untested") def linearFunctionProperty(*args, **kwargs): - """Apply a linear function over the properties across every image of the ImageCollection""" + """Apply a linear function over the properties across every image of the ImageCollection.""" raise NotImplementedError( "As it was vastly untested this method has been removed from the lib." "If a real use case for this method can be provided, please open an issue and we'll reimplement it." @@ -92,7 +93,7 @@ def gaussFunctionProperty(*args, **kwargs): @deprecated(version="1.4.0", reason="Removed from the lib as untested.") def normalDistributionProperty(*args, **kwargs): - """Compute a normal distribution using a specified property, over an ImageCollection""" + """Compute a normal distribution using a specified property, over an ImageCollection.""" raise NotImplementedError( "As it was vastly untested this method has been removed from the lib." "If a real use case for this method can be provided, please open an issue and we'll reimplement it." diff --git a/geetools/utils.py b/geetools/utils.py index 7328655b..cc6cb78b 100644 --- a/geetools/utils.py +++ b/geetools/utils.py @@ -1,4 +1,5 @@ """Utils methods for file and asset manipulation in the context of batch processing.""" + from __future__ import annotations import os diff --git a/notebooks/algorithms/brdf.ipynb b/notebooks/algorithms/brdf.ipynb deleted file mode 100644 index 90c0553d..00000000 --- a/notebooks/algorithms/brdf.ipynb +++ /dev/null @@ -1,305 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools, algorithms, collection, ui" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from ipygee import *" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map = Map()\n", - "Map.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## BRDF correction in Landsat 8 TOA" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "i = ee.Image('LANDSAT/LC8_L1T_TOA_FMASK/LC81780592016030LGN00').select(\n", - " ['B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B9', 'B10', 'fmask'],\n", - " ['blue', 'green', 'red', 'nir', 'swir1', 'swir2', 'cirrus', 'thermal', 'fmask']\n", - ");" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ic = algorithms.Landsat.brdfCorrect(i)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p = ee.Geometry.Point([22.0227, 1.4801])\n", - "Map.centerObject(p, zoom=10)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ival = 0.10098563879728317\n", - "icval = 0.10012929931321499" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ival_here = tools.image.getValue(i, p, 30, 'client')['blue']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ival_here == ival" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "icval_here = tools.image.getValue(ic, p, 30, 'client')['blue']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "icval_here == icval" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "vis = {'bands':['nir', 'swir1','red'], 'min':0, 'max': 0.5}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(i, vis, 'original')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(ic, vis, 'corrected')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Using `collection` module" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "l8toa = collection.Landsat8TOA()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "vis = l8toa.visualization('NSR')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p = ee.Geometry.Point([22.21, 1.5])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col = l8toa.collection.filterBounds(p)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "i2 = col.first()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "proxy = ee.Image.constant(0).rename('proxy')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "colr = col.map(lambda img: l8toa.rename(img)).map(lambda img: img.addBands(proxy))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "colbrdf = colr.map(lambda img: l8toa.brdf(img, True))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(i2, vis, 'Landsat 8 TOA')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "i2c = colbrdf.first()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(i2c, l8toa.visualization('NSR', True), 'Landsat 8 TOA BRDF Corrected')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "diff = i2.subtract(i2c).multiply(100)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(diff, vis.update(dict(min=-1, max=1)), 'BRDF difference')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.5.2" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/algorithms/distance_to_mask.ipynb b/notebooks/algorithms/distance_to_mask.ipynb deleted file mode 100644 index 30196c12..00000000 --- a/notebooks/algorithms/distance_to_mask.ipynb +++ /dev/null @@ -1,157 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Distance to Mask" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import algorithms, ui, cloud_mask, tools" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from ipygee import *" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Area of Interest" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p = ee.Geometry.Point([-71.33972167968751, -42.737619925503054])\n", - "aoi = p.buffer(8000).bounds()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Masked image" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "i = ee.Image('COPERNICUS/S2/20181122T142749_20181122T143353_T18GYT')\n", - "masked = cloud_mask.sentinel2()(i)\n", - "masked = masked.clip(aoi)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Distance to mask" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "max_distance = 2000" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "distance = algorithms.distanceToMask(masked, radius=max_distance, geometry=aoi)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map = Map()\n", - "Map.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(masked, {'bands':['B8', 'B11', 'B4'], 'min':0, 'max':5000}, 'Masked image')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.centerObject(aoi)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(distance, {'min':0, 'max':max_distance}, 'distance')" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/algorithms/euclidean_distance.ipynb b/notebooks/algorithms/euclidean_distance.ipynb deleted file mode 100644 index 1daf39d5..00000000 --- a/notebooks/algorithms/euclidean_distance.ipynb +++ /dev/null @@ -1,466 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Euclidean distance between two images" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools, algorithms" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "bands = ['B1','B2','B3']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "image1 = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_232089_20170126').select(bands)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "image2 = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_232089_20170211').select(bands)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "image3 = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_232089_20170227').select(bands)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p = ee.Geometry.Point(-72, -42)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "data1 = tools.image.getValue(image1, p, 30, side='client')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "data1" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "data2 = tools.image.getValue(image2, p, 30, side='client')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "data2" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "data3 = tools.image.getValue(image3, p, 30, side='client')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "data3" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "distance = algorithms.euclideanDistance(image1, image2)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "data_dist = tools.image.getValue(distance, p, 30, side='client')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "data_dist" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Compute locally to compare" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import math" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Euclidean distance\n", - "def distanceF(arr1, arr2):\n", - " zipped = zip(arr1, arr2)\n", - " accum = 0\n", - " for a, b in zipped:\n", - " rest = (a-b)\n", - " calc = rest*rest\n", - " accum += calc\n", - " return math.sqrt(accum)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "arr1 = data1.values()\n", - "arr1" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "arr2 = data2.values()\n", - "arr2" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "local_distance = distanceF(arr1, arr2)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "local_distance" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Distance sum between one image and a collection of images" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col = ee.ImageCollection.fromImages([image2, image3])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "summed = algorithms.sumDistance(image1, col)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "summed_data = tools.image.getValue(summed, p, 30, side='client')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "summed_data" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Compute locally to compare results" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from copy import copy\n", - "# Sum of distances\n", - "def sum_distances(values):\n", - " results = {}\n", - " for i, val in enumerate(values):\n", - " val = list(val)\n", - " cop = copy(values)\n", - " cop = [list(a) for a in cop]\n", - " cop.remove(val)\n", - " dist = 0\n", - " for r in cop:\n", - " r = list(r)\n", - " d = distanceF(val, r)\n", - " dist += d\n", - " results[i] = dist\n", - "\n", - " return results" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "values = [list(data1.values()), list(data2.values()), list(data3.values())]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "values" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "sum_distances(values)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Handling mask values" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "masked_image = image2.updateMask(image2.gte(0).Not())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "data_masked = tools.image.getValue(masked_image, p, 30, side='client')\n", - "data_masked" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "data1" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "distance_masked = algorithms.euclideanDistance(image1, masked_image)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "data_dist_masked = tools.image.getValue(distance_masked, p, 30, side='client')\n", - "data_dist_masked" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "distanceF(data1.values(), [0, 0, 0])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "outside = image1\n", - "inside = masked_image" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col_masked = ee.ImageCollection.fromImages([inside])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "summed_masked = algorithms.sumDistance(outside, col_masked)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "summed_data_masked = tools.image.getValue(summed_masked, p, 30, side='client')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "summed_data_masked" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/algorithms/harmonize.ipynb b/notebooks/algorithms/harmonize.ipynb deleted file mode 100644 index 94e9ca6c..00000000 --- a/notebooks/algorithms/harmonize.ipynb +++ /dev/null @@ -1,116 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ipygee as ui\n", - "import geedatasets\n", - "import geetools" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map = ui.Map()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "l8 = geedatasets.landsat.Landsat8SR()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "i = l8.collection().filterBounds(ee.Geometry.Point([-72,-42])).first()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(i, l8.visualization('NSR'), 'Original L8 Image')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "i_harmonized = geetools.algorithms.Landsat.harmonization(i)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(i_harmonized, l8.visualization('NSR'), 'Harmonized L8 Image')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/algorithms/mask_cover.ipynb b/notebooks/algorithms/mask_cover.ipynb deleted file mode 100644 index 78563e27..00000000 --- a/notebooks/algorithms/mask_cover.ipynb +++ /dev/null @@ -1,197 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Mask Cover\n", - "Percentage of masked pixels" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import algorithms, ui, cloud_mask, tools" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from ipygee import *" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Area of Interest" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p = ee.Geometry.Point([-71.33972167968751, -42.737619925503054])\n", - "aoi = p.buffer(8000).bounds()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Masked image" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "i = ee.Image('COPERNICUS/S2/20181122T142749_20181122T143353_T18GYT')\n", - "masked = cloud_mask.sentinel2()(i)\n", - "masked = masked.clip(aoi)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Compute Mask Cover" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cover = algorithms.maskCover(masked, aoi, 10)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "eprint(cover.get('MASK_COVER'))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Show Image on Map" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map = Map()\n", - "Map.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "vis = {'bands': ['B8', 'B11','B4'], 'min':0, 'max':5000}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(masked, vis, 'Masked image')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.centerObject(aoi)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Make it an image band" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "metadata = cover.metadata('MASK_COVER')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "tools.image.getValue(metadata, aoi.centroid(1), 10, side='client')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/algorithms/pansharpen.ipynb b/notebooks/algorithms/pansharpen.ipynb deleted file mode 100644 index 2114633c..00000000 --- a/notebooks/algorithms/pansharpen.ipynb +++ /dev/null @@ -1,238 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools, batch, algorithms" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from ipygee import *" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map = Map()\n", - "Map.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p = ee.Geometry.Point([-72, -42])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.centerObject(p, zoom=10)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA').filterBounds(p).filterMetadata('CLOUD_COVER', 'less_than', 10)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "l8i = ee.Image(l8.first())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "rgb = ['B4', 'B3', 'B2']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "nsr = ['B5', 'B6', 'B4']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "visrgb = {'bands': rgb, 'min':0, 'max':0.3}\n", - "visnsr = {'bands': nsr, 'min':0, 'max':0.5}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(l8i, visrgb, 'original RGB')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(l8i, visnsr, 'original NSR')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "pansharpening hsv" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "pan_hsv_rgb = algorithms.pansharpenIhsFusion(l8i, 'B8', rgb)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(pan_hsv_rgb, {'bands':['red', 'green', 'blue'], 'min':0, 'max':0.2}, 'HSV pansharpen RGB')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "pan_hsv_nsr = algorithms.pansharpenIhsFusion(l8i, 'B8', nsr)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(pan_hsv_nsr, {'bands':['red', 'green', 'blue'], 'min':0, 'max':0.2}, 'HSV pansharpen NSR')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "pansharpening kernel" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "pan_kernel_rgb = algorithms.pansharpenKernel(l8i, 'B8', rgb)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(pan_kernel_rgb, {'bands':rgb, 'min':0, 'max':0.3}, 'kernel pansharpen RGB')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "pan_kernel_nsr = algorithms.pansharpenKernel(l8i, 'B8', nsr)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(pan_kernel_nsr, {'bands':nsr, 'min':0, 'max':0.5}, 'kernel pansharpen NSR')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.8" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/cloud_mask/cloud_masking.ipynb b/notebooks/cloud_mask/cloud_masking.ipynb deleted file mode 100644 index ea4819e5..00000000 --- a/notebooks/cloud_mask/cloud_masking.ipynb +++ /dev/null @@ -1,325 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Cloud Masking" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Make all imports" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import ui, cloud_mask" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ipygee as ui" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Landsat 8 SR" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map = ui.Map()\n", - "Map.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "visL8 = {'bands':['B5','B6','B4'],'min':0, 'max':5000}\n", - " \n", - "image = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_232090_20140915')\n", - "Map.addLayer(image, visL8, 'Landsat 8 SR Original')\n", - "Map.centerObject(image, zoom=12)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Using BQA band" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mask_l8SR_all = cloud_mask.landsatSR()\n", - "mask_l8SR_cloud = cloud_mask.landsatSR(['cloud'])\n", - "mask_l8SR_shadow = cloud_mask.landsatSR(['shadow'])\n", - "mask_l8SR_snow = cloud_mask.landsatSR(['snow'])\n", - "\n", - "l8sr_masked_all = mask_l8SR_all(image)\n", - "l8sr_masked_cloud = mask_l8SR_cloud(image)\n", - "l8sr_masked_shadow = mask_l8SR_shadow(image)\n", - "l8sr_masked_snow = mask_l8SR_snow(image)\n", - "\n", - "Map.addLayer(l8sr_masked_all, visL8, 'L8SR masked all')\n", - "Map.addLayer(l8sr_masked_cloud, visL8, 'L8SR masked cloud')\n", - "Map.addLayer(l8sr_masked_shadow, visL8, 'L8SR masked shadow')\n", - "Map.addLayer(l8sr_masked_snow, visL8, 'L8SR masked snow')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Landsat TOA" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "MapTOA = ui.Map()\n", - "MapTOA.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "visTOA = {'bands': visL8['bands'], 'min':0, 'max':0.5}\n", - "i_toa = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_232090_20140915')\n", - "MapTOA.addLayer(i_toa, visTOA, 'Landsat 8 TOA Original')\n", - "MapTOA.centerObject(i_toa, zoom=12)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Using BQA band" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mask_l8TOA_all = cloud_mask.landsat8ToaBQA()\n", - "mask_l8TOA_cloud = cloud_mask.landsat8ToaBQA(['cloud'])\n", - "mask_l8TOA_shadow = cloud_mask.landsat8ToaBQA(['shadow'])\n", - "mask_l8TOA_snow = cloud_mask.landsat8ToaBQA(['snow'])\n", - "\n", - "l8toa_masked_all = mask_l8TOA_all(i_toa)\n", - "l8toa_masked_cloud = mask_l8TOA_cloud(i_toa)\n", - "l8toa_masked_shadow = mask_l8TOA_shadow(i_toa)\n", - "l8toa_masked_snow = mask_l8TOA_snow(i_toa)\n", - "\n", - "MapTOA.addLayer(l8toa_masked_all, visTOA, 'L8TOA masked all')\n", - "MapTOA.addLayer(l8toa_masked_cloud, visTOA, 'L8TOA masked cloud')\n", - "MapTOA.addLayer(l8toa_masked_shadow, visTOA, 'L8TOA masked shadow')\n", - "MapTOA.addLayer(l8toa_masked_snow, visTOA, 'L8TOA masked snow')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Sentinel 2" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "MapS2 = ui.Map()\n", - "MapS2.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "visS2 = {'bands':['B8','B11','B4'],'min':0, 'max':5000}\n", - "is2 = ee.Image('COPERNICUS/S2/20151123T142942_20170221T180430_T18GYT')\n", - "MapS2.centerObject(is2, zoom=12)\n", - "MapS2.addLayer(is2, visS2, 'Sentinel 2 Original')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## ESA Cloud Masking" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ESA_mask_all = cloud_mask.sentinel2()\n", - "is2_ESA = ESA_mask_all(is2)\n", - "MapS2.addLayer(is2_ESA, visS2, 'Sentinel 2 ESA maked')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Hollstein Decision Tree" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "is2_Holl_all = cloud_mask.applyHollstein(is2)\n", - "is2_Holl_cloud = cloud_mask.applyHollstein(is2, ['cloud'])\n", - "is2_Holl_shadow = cloud_mask.applyHollstein(is2, ['shadow'])\n", - "is2_Holl_snow = cloud_mask.applyHollstein(is2, ['snow'])\n", - "is2_Holl_water = cloud_mask.applyHollstein(is2, ['water'])\n", - "is2_Holl_cirrus = cloud_mask.applyHollstein(is2, ['cirrus'])\n", - "\n", - "MapS2.addLayer(is2_Holl_all, visS2, 'Sentinel 2 Hollstein all')\n", - "MapS2.addLayer(is2_Holl_cloud, visS2, 'Sentinel 2 Hollstein cloud')\n", - "MapS2.addLayer(is2_Holl_shadow, visS2, 'Sentinel 2 Hollstein shadow')\n", - "MapS2.addLayer(is2_Holl_snow, visS2, 'Sentinel 2 Hollstein snow')\n", - "MapS2.addLayer(is2_Holl_water, visS2, 'Sentinel 2 Hollstein water')\n", - "MapS2.addLayer(is2_Holl_cirrus, visS2, 'Sentinel 2 Hollstein cirrus')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# MODIS" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "modis = ee.ImageCollection('MODIS/006/MOD09GA')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "MapMOD = ui.Map()\n", - "MapMOD.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "site = ee.Geometry.Point([-71.8, -43])\n", - "date = ee.Date('2017-08-01')\n", - "visMOD = {'bands':['sur_refl_b02', 'sur_refl_b06', 'sur_refl_b01'],'min':0, 'max':5000}\n", - "modis = modis.filterDate(date, date.advance(4, 'month'))\n", - "i_mod = ee.Image(modis.first())\n", - "MapMOD.addLayer(i_mod, visMOD, 'MODIS TERRA Original Image')\n", - "MapMOD.centerObject(site, zoom=8)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Using `state_1km` band" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mod_mask = cloud_mask.modis09ga()\n", - "i_masked = mod_mask(i_mod)\n", - "MapMOD.addLayer(i_masked, visMOD, 'Masked MODIS')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/collection/joinByProperty.ipynb b/notebooks/collection/joinByProperty.ipynb deleted file mode 100644 index 81516ea5..00000000 --- a/notebooks/collection/joinByProperty.ipynb +++ /dev/null @@ -1,104 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Join the data of two collections that share a common property, commonly an id property" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()\n", - "import geetools" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "nullGeom = ee.Geometry.Point([0, 0])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col1 = ee.FeatureCollection([\n", - " ee.Feature(nullGeom, {'fid': 1, 'a': 10, 'b': 20}),\n", - " ee.Feature(nullGeom, {'fid': 2, 'a': 20, 'b': 10}),\n", - " ee.Feature(nullGeom, {'fid': 3, 'a': 5, 'b': 5}),\n", - " ee.Feature(nullGeom, {'fid': 4, 'a': 30, 'b': 40})\n", - "])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col2 = ee.FeatureCollection([\n", - " ee.Feature(nullGeom, {'fid': 2, 'c': 1000, 'd': 2000}),\n", - " ee.Feature(nullGeom, {'fid': 3, 'c': 3000, 'd': 4000}),\n", - " ee.Feature(nullGeom, {'fid': 5, 'c': 5000, 'd': 6000})\n", - "])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "joined = geetools.tools.collection.joinByProperty(col1, col2, 'fid')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "joined.toDictionary().getInfo()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/notebooks/composite/closest_date.ipynb b/notebooks/composite/closest_date.ipynb deleted file mode 100644 index 3c12ac2e..00000000 --- a/notebooks/composite/closest_date.ipynb +++ /dev/null @@ -1,251 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Composite \"Closest Date\"\n", - "Takes the last image of the given collection and fills the masked pixels with the last available pixel" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools, composite, cloud_mask, algorithms" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import geedatasets\n", - "import ipygee as ui" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map = ui.Map()\n", - "Map.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "l8 = geedatasets.landsat.Landsat8SR()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "vis = l8.visualization('NSR')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "l8col = l8.collection()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p = ee.Geometry.Point([-70.72, -41.92]).buffer(50000)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(p)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.centerObject(p, zoom=8)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### add date band" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col = l8col.map(lambda img: img.addBands(tools.date.makeDateBand(img)))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Filter and mask clouds" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col = col.filterBounds(p)\\\n", - " .filterDate('2017-01-01', '2017-03-01')\\\n", - " .map(lambda img: l8.applyMask(img, 'pixel_qa', ['cloud', 'shadow', 'snow']))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(col.size())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### add all images to the map" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addImageCollection(col, vis, '{system_date} {id}')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Make composite" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "comp = composite.closestDate(col)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(comp, vis, 'composite')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(comp.select('date').randomVisualizer(), {'bands':['viz-red', 'viz-green', 'viz-blue'], 'min':0, 'max':255}, 'dates')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### clip to first image (target date)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "comp_clip = composite.closestDate(col, clip_to_first=True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(comp_clip, vis, 'composite 2017-02-25 clip to first')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/composite/medoid.ipynb b/notebooks/composite/medoid.ipynb deleted file mode 100644 index 77f8a526..00000000 --- a/notebooks/composite/medoid.ipynb +++ /dev/null @@ -1,607 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Medoid Compositing\n", - "*Seasonal Composite Landsat TM/ETM+ Images Using the Medoid (a Multi-Dimensional Median), Neil Flood, 2013, doi:10.3390/rs5126481*" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools, composite, cloud_mask, indices" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ipygee as ui" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Build a collection" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p = ee.Geometry.Point(-72, -42)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')\\\n", - " .filterBounds(p).filterDate('2017-01-01', '2017-12-01')\\\n", - " .map(cloud_mask.landsat8SRPixelQA())\\\n", - " .map(lambda img: img.addBands(indices.ndvi(img,'B5', 'B4')))\\\n", - " .limit(7)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(col.size())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Other simple composites to compare" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "max_ndvi = col.qualityMosaic('ndvi')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mosaic = col.mosaic()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Medoid" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### add date band before compositing" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def add_date(img):\n", - " date = tools.date.getDateBand(img)\n", - " return img.addBands(date).copyProperties(date, ['day_since_epoch'])\n", - "col = col.map(add_date)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "minval = ee.Number(col.aggregate_min('day_since_epoch'))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "maxval = ee.Number(col.aggregate_max('day_since_epoch'))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "medoid = composite.medoid(col, bands=bands)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "medoid = medoid.set('min_date', minval, 'max_date', maxval)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Medoid without taking in count zero values" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "medoid_no_zeros = composite.medoid(col, bands=bands, discard_zeros=True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "medoid_no_zeros = medoid_no_zeros.set('min_date', minval, 'max_date', maxval)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Show on Map" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map = ui.Map()\n", - "Map.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "vis = {'bands':['B5', 'B6','B4'], 'min':0, 'max':5000}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(p)\n", - "Map.centerObject(p)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(max_ndvi, vis, 'max NDVI')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(mosaic, vis, 'simply Mosaic')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(medoid, vis, 'Medoid')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(medoid.select('date').randomVisualizer(), {'bands':['viz-red', 'viz-green', 'viz-blue'], 'min':0, 'max':255}, 'dates')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(medoid_no_zeros, vis, 'Medoid without zero values')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(medoid_no_zeros.select('date').randomVisualizer(), {'bands':['viz-red', 'viz-green', 'viz-blue'], 'min':0, 'max':255}, 'dates of medoid without zero values')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Extract data from images and compute locally to compare" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Extract medoid values in point" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "medoid_values = tools.image.getValue(medoid.select(bands), p, scale=30, side='client')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "medoid_values" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "List of values" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "medoid_values_list = [val for _, val in medoid_values.items()]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "medoid_values_list" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Extract values at point in each image of the collection" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col_values = tools.imagecollection.getValues(col.select(bands), p, scale=30, side='client')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Get bandnames" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col_key_list = []\n", - "for _, d in col_values.items():\n", - " keys = []\n", - " for k, v in d.items():\n", - " keys.append(k) \n", - " col_key_list.append(keys)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col_key_list" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Get values as a list" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col_values_list = []\n", - "for _, d in col_values.items():\n", - " values = []\n", - " for _, v in d.items():\n", - " if v:\n", - " values.append(v)\n", - " else:\n", - " values.append(0)\n", - " col_values_list.append(values)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col_values_list" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Medoid Method locally" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def local_medoid(values):\n", - " from copy import copy\n", - " import math\n", - "\n", - " def distance(arr1, arr2):\n", - " zipped = zip(arr1, arr2)\n", - " accum = 0\n", - " for a, b in zipped:\n", - " calc = (a-b)*(a-b)\n", - " accum += calc\n", - " return math.sqrt(accum)\n", - "\n", - " def med(values):\n", - " results = {}\n", - " for i, val in enumerate(values):\n", - " val = list(val)\n", - " cop = copy(values)\n", - " cop = [list(a) for a in cop]\n", - " cop.remove(val)\n", - " dist = 0\n", - " for r in cop:\n", - " r = list(r)\n", - " d = distance(val, r)\n", - " dist += d\n", - " results[i] = dist\n", - "\n", - " return results\n", - " \n", - " def getmin(d):\n", - " minval = min(d.values())\n", - " for k, v in d.items():\n", - " if v == minval:\n", - " return k\n", - " \n", - " values = med(values)\n", - " min_value = getmin(values)\n", - " \n", - " # return the index of the minimized sum as first argument, and all options as second\n", - " return min_value, values" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Compute medoid locally and compare" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "local = local_medoid(col_values_list)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "local" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Get the values that correspond to the medoid" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "min_values = col_values_list[local[0]]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "min_values" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Match bands with values" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "local_medoid = dict(zip(col_key_list[0], min_values))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "local_medoid" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "medoid_values" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Finally, compare values from medoid mosaic against locally computed medoid (from images values)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "medoid_values == local_medoid" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/composite/medoid_score.ipynb b/notebooks/composite/medoid_score.ipynb deleted file mode 100644 index 46e588e4..00000000 --- a/notebooks/composite/medoid_score.ipynb +++ /dev/null @@ -1,142 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Compute a medoid score of 'how far is from medoid'\n", - "This is the previous step to compute the medoid composite\n", - "\n", - "When `normalize` parameter is `True`, pixels with value 1 are the actual medoid, and 0 is the further" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import composite, tools, cloud_mask, indices" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ipygee as ui" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p = ee.Geometry.Point(-72, -42)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')\\\n", - " .filterBounds(p).filterDate('2017-01-01', '2017-12-01')\\\n", - " .map(cloud_mask.landsat8SRPixelQA())\\\n", - " .map(lambda img: img.addBands(indices.ndvi(img, 'B5', 'B4')))\\\n", - " .limit(7)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Bands for medoid" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Medoid score including zero values" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "medscore = composite.medoidScore(col, bands, False)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "values = tools.imagecollection.getValues(medscore, p, scale=30)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(values)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/date/dayRangeIntervals.ipynb b/notebooks/date/dayRangeIntervals.ipynb deleted file mode 100644 index 2c428ced..00000000 --- a/notebooks/date/dayRangeIntervals.ipynb +++ /dev/null @@ -1,108 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Divide a date range into equal day intervals" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()\n", - "import geetools" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ipygee as ui" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "start = '2020-01-01'\n", - "end = '2020-06-07'\n", - "# make 30 day intervals\n", - "interval = 30" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "intervals = geetools.tools.date.dayRangeIntervals(\n", - " start, end, \n", - " interval=interval,\n", - " reverse=False\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(intervals)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "intervals_inverse = geetools.tools.date.dayRangeIntervals(\n", - " start, end, \n", - " interval=interval,\n", - " reverse=True\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(intervals_inverse)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/notebooks/date/since_epoch.ipynb b/notebooks/date/since_epoch.ipynb deleted file mode 100644 index 898e73f8..00000000 --- a/notebooks/date/since_epoch.ipynb +++ /dev/null @@ -1,157 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ipygee as ui" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "test_image = ee.Image('LANDSAT/LT05/C01/T1_SR/LT05_226087_20000102')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# `get_date_band`\n", - "Get the date of an image, compute how many `units` (for example `day`) has ellpsed since the epoch (1970-01-01) and set it to a band (called `date`) and a property (called `unit_since_epoch`, for example, `day_since_epoch`)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "date_band = tools.date.getDateBand(test_image, 'day')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(date_band)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# `date_since_epoch`\n", - "Given an elapsed time since epoch (for example the result of `get_date_band`) compute what day it is" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "image_date = date_band.get('day_since_epoch')\n", - "date_since_epoch = tools.date.dateSinceEpoch(image_date)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(date_since_epoch)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# `unit_since_epoch`\n", - "Return the number of `unit` (for example, `day`) since the epoch (1970-1-1)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "date = ee.Date('2000-01-02')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "days = tools.date.unitSinceEpoch(date)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(days)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/geometry/.ipynb_checkpoints/getRegion-checkpoint.ipynb b/notebooks/geometry/.ipynb_checkpoints/getRegion-checkpoint.ipynb deleted file mode 100644 index dec1dd87..00000000 --- a/notebooks/geometry/.ipynb_checkpoints/getRegion-checkpoint.ipynb +++ /dev/null @@ -1,197 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# getRegion(eeObject, bounds)\n", - "Get the `region` for functions that need it as an argument (like Export.image)\n", - "\n", - "**params**\n", - "- eeObject: any eeObject that has a geometry\n", - "- bounds: return only bounds (rectangle). Defaults to `False`" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Bounded Images" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "image = ee.Image(ee.ImageCollection('COPERNICUS/S2').first())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "tools.geometry.getRegion(image)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Unbounded Images" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "uimage = ee.Image.constant(0)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "tools.geometry.getRegion(uimage)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Geometry" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "pol = ee.Geometry.Polygon([[0,0], [10,10], [20,0], [0, 0]])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "tools.geometry.getRegion(pol)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "tools.geometry.getRegion(pol, True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Feature" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "feat = ee.Feature(pol, {'test':'getRegion'})" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "tools.geometry.getRegion(feat)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# FeatureCollection" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "fc = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017').filterMetadata('wld_rgn', 'equals', 'South America')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "tools.geometry.getRegion(fc, True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/geometry/getRegion.ipynb b/notebooks/geometry/getRegion.ipynb deleted file mode 100644 index dec1dd87..00000000 --- a/notebooks/geometry/getRegion.ipynb +++ /dev/null @@ -1,197 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# getRegion(eeObject, bounds)\n", - "Get the `region` for functions that need it as an argument (like Export.image)\n", - "\n", - "**params**\n", - "- eeObject: any eeObject that has a geometry\n", - "- bounds: return only bounds (rectangle). Defaults to `False`" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Bounded Images" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "image = ee.Image(ee.ImageCollection('COPERNICUS/S2').first())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "tools.geometry.getRegion(image)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Unbounded Images" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "uimage = ee.Image.constant(0)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "tools.geometry.getRegion(uimage)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Geometry" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "pol = ee.Geometry.Polygon([[0,0], [10,10], [20,0], [0, 0]])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "tools.geometry.getRegion(pol)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "tools.geometry.getRegion(pol, True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Feature" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "feat = ee.Feature(pol, {'test':'getRegion'})" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "tools.geometry.getRegion(feat)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# FeatureCollection" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "fc = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017').filterMetadata('wld_rgn', 'equals', 'South America')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "tools.geometry.getRegion(fc, True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/image/addConstantBand.ipynb b/notebooks/image/addConstantBand.ipynb deleted file mode 100644 index 274aafab..00000000 --- a/notebooks/image/addConstantBand.ipynb +++ /dev/null @@ -1,168 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# addConstantBands(value, *names, **pairs)\n", - "Adds bands with a constant value\n", - "\n", - "- names: final names for the additional bands\n", - "- value: constant value\n", - "- pairs: keywords for the bands (see example)\n", - "\n", - "return the function for ee.ImageCollection.map()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col = ee.ImageCollection('COPERNICUS/S2').select(['B1', 'B2', 'B3']).limit(10)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "helper function to print values for the centroid of the first image of a collection" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def print_center(collection):\n", - " first = ee.Image(collection.first())\n", - " p = first.geometry().centroid()\n", - " return tools.image.getValue(first, p, scale=10, side='client')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Option 1 - arguments" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "newcol = col.map(lambda i: tools.image.addConstantBands(i, 0, \"a\", \"b\", \"c\"))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print_center(newcol)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Option 2 - keyword arguments" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "newcolCK = col.map(lambda i: tools.image.addConstantBands(i, a=0, b=1, c=2))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print_center(newcolCK)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Option 3 - combined" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "newcolCC = col.map(lambda i:tools.image.addConstantBands(i, 0, \"a\", \"b\", \"c\", d=1, e=2))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print_center(newcolCC)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/image/addSuffix_addPrefix.ipynb b/notebooks/image/addSuffix_addPrefix.ipynb deleted file mode 100644 index 64acf4c6..00000000 --- a/notebooks/image/addSuffix_addPrefix.ipynb +++ /dev/null @@ -1,210 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Add a suffix or a prefix to bands" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ipygee as ui" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "i = ee.Image('COPERNICUS/S2/20181122T142749_20181122T143353_T18GYT').select('B.')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(i.bandNames())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## add a suffix" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "suffix = '_suffix'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "renamed_s = tools.image.addSuffix(i, suffix, ['B2', 'B4', 'B8'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(renamed_s.bandNames())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## add prefix" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "prefix = 'prefix_'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "renamed_p = tools.image.addPrefix(i, prefix, ['B2', 'B4', 'B8'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(renamed_p.bandNames())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## In a collection" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col = ee.ImageCollection('COPERNICUS/S2').limit(5)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def print_bands(col):\n", - " info = col.getInfo()\n", - " images = info['features']\n", - " for image in images:\n", - " bands = image['bands']\n", - " print([band['id'] for band in bands])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print_bands(col)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "renamed_col_s = col.map(lambda img: tools.image.addSuffix(img, suffix, ['B2', 'B4', 'B8']))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print_bands(renamed_col_s)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/image/bufferMask.ipynb b/notebooks/image/bufferMask.ipynb deleted file mode 100644 index 6fcaab98..00000000 --- a/notebooks/image/bufferMask.ipynb +++ /dev/null @@ -1,140 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()\n", - "import geetools" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ipygee as ui" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map = ui.Map()\n", - "Map.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Site" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "site = ee.Geometry.Point([-71.5, -41.7]).buffer(2000)\n", - "Map.centerObject(site)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Masked image" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "image = ee.Image('COPERNICUS/S2/20151123T142942_20170221T180430_T18GYU')\n", - "fclouds = geetools.cloud_mask.sentinel2()\n", - "masked = fclouds(image)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "vis = dict(bands=['B4', 'B3', 'B2'], min=0, max=2500)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(masked, vis, 'Not buffered')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Buffer Mask" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "buffer = geetools.tools.image.bufferMask(masked, 500, units='meters')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(buffer, vis, 'buffered 500 m')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/notebooks/image/clipToCollection.ipynb b/notebooks/image/clipToCollection.ipynb deleted file mode 100644 index 8d7219f5..00000000 --- a/notebooks/image/clipToCollection.ipynb +++ /dev/null @@ -1,167 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Clip an Image using each Feature of a FeatureCollection and return an ImageCollection" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ipygee as ui" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import geetools\n", - "import geedatasets as dsets" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map = ui.Map()\n", - "Map.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p = ee.Geometry.Point([-71, -43]).buffer(1000)\n", - "p2 = ee.Geometry.Point([-70.8, -42.8]).buffer(1000)\n", - "p3 = ee.Geometry.Point([-71.4, -42.8]).buffer(1000)\n", - "p4 = ee.Geometry.Point([-71, -42.5]).buffer(1000)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "fc = ee.FeatureCollection([\n", - " ee.Feature(p, {'ID': 1}),\n", - " ee.Feature(p2, {'ID': 2}),\n", - " ee.Feature(p3, {'ID': 3}),\n", - " ee.Feature(p4, {'ID': 4}),\n", - "])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(fc, name='Feature Collection')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "s2 = dsets.fromShortName('S2TOA')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col = s2.collection().filterBounds(p).filterDate('2018-01-01', '2018-02-01')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "image = col.first()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(image, s2.visualization('NSR'), 'image')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "clipped = geetools.image.clipToCollection(image, fc)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addImageCollection(clipped, s2.visualization('NSR'), 'image {ID}')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/notebooks/image/distributions.ipynb b/notebooks/image/distributions.ipynb deleted file mode 100644 index 4feeba2c..00000000 --- a/notebooks/image/distributions.ipynb +++ /dev/null @@ -1,250 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools, utils\n", - "import geedatasets" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ipygee as ui" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Get a NDVI Image" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "l8 = geedatasets.landsat.Landsat8SR()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p = ee.Geometry.Point([-72,-42])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col = l8.collection().filterBounds(p)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "i = ee.Image(col.first())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ndvi = l8.ndvi.apply(i)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Get point grid" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "points = ndvi.sample(scale=10000, geometries=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Linear Function" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "d = tools.image.linearFunction(ndvi, 'NDVI', mean=0.3, range_min=0, range_max=1, min=2, max=5)\n", - "result = ndvi.addBands(d)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "chart = ui.chart.Image.bandsByRegion(result, points.limit(100), xProperty='NDVI')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Gauss Function" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss = tools.image.gaussFunction(ndvi, 'NDVI', 0, 1, mean=0.3, output_min=0, output_max=1, stretch=2)\n", - "gauss = ndvi.addBands(gauss)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "chart_gauss = ui.chart.Image.bandsByRegion(gauss, points.limit(100), xProperty='NDVI', bands=['gauss'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "chart_gauss.renderWidget(width=800)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Normal Distribution" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "normal = tools.image.normalDistribution(ndvi, 'NDVI', scale=30, maxPixels=1e13)\n", - "result_n = ndvi.addBands(normal)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "chart_normal = ui.chart.Image.bandsByRegion(result_n, points.limit(100), xProperty='NDVI', bands=['normal_distribution'])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Charts" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "charts = chart.cat(chart_gauss, chart_normal)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "charts.renderWidget(width=800)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "charts.dataframe" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/image/parametrize.ipynb b/notebooks/image/parametrize.ipynb deleted file mode 100644 index ef3f1f05..00000000 --- a/notebooks/image/parametrize.ipynb +++ /dev/null @@ -1,195 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Parametrize pixel values to fit a desired range\n", - "You must know the actual range (computing it could take too much EE memory capacity)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ipygee as ui" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "i = ee.Image('COPERNICUS/S2/20181122T142749_20181122T143353_T18GYT').select('B1')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map = ui.Map()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(i, {'min':0, 'max': 6000}, 'Original')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "As values in Sentinel 2 go from 0 to 10000, parametrize values to be between 0 and 1" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "parametrized = tools.image.parametrize(i, (0, 10000), (0, 1))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(parametrized, {'min':0, 'max': 0.6}, 'Parametrized')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "BEFORE" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "tools.image.getValue(i, i.geometry().centroid(), 10, 'client')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "AFTER" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "tools.image.getValue(parametrized, i.geometry().centroid(), 10, 'client')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Range can be switched" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "switch_parametrized = tools.image.parametrize(i, (0, 10000), (1, 0))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "AFTER\n", - "\n", - " 1 - 0.4712 = 0.5288" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "tools.image.getValue(switch_parametrized, i.geometry().centroid(), 10, 'client')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/image/removeBands.ipynb b/notebooks/image/removeBands.ipynb deleted file mode 100644 index 7e2c1268..00000000 --- a/notebooks/image/removeBands.ipynb +++ /dev/null @@ -1,160 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ipygee as ui" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "i = ee.Image('COPERNICUS/S2/20181122T142749_20181122T143353_T18GYT').select('B.')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(i.bandNames())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Remove some bands" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "removed = tools.image.removeBands(i, ['B1', 'B2', 'B7'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(removed.bandNames())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## In a collection" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col = ee.ImageCollection('COPERNICUS/S2').limit(5)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def print_bands(col):\n", - " info = col.getInfo()\n", - " images = info['features']\n", - " for image in images:\n", - " bands = image['bands']\n", - " print([band['id'] for band in bands])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print_bands(col)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "removed_col = col.map(lambda img: tools.image.removeBands(img, ['B1', 'B2', 'B7']))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print_bands(removed_col)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/image/renameDict.ipynb b/notebooks/image/renameDict.ipynb deleted file mode 100644 index b13e7c87..00000000 --- a/notebooks/image/renameDict.ipynb +++ /dev/null @@ -1,178 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Rename bands using a dict" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ipygee as ui" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "i = ee.Image('COPERNICUS/S2/20181122T142749_20181122T143353_T18GYT').select('B.')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "bands = i.bandNames()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(bands)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "renamed = tools.image.renameDict(i, {'B2':'BLUE', 'B3':'GREEN', 'B4':'RED'})" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "renamed_bands = renamed.bandNames()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(renamed_bands)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## In collection" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col = ee.ImageCollection('COPERNICUS/S2').limit(5)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def print_bands(col):\n", - " info = col.getInfo()\n", - " images = info['features']\n", - " for image in images:\n", - " bands = image['bands']\n", - " print([band['id'] for band in bands])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print_bands(col)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "renamed_col = col.map(lambda img: tools.image.renameDict(img, {'B2':'BLUE', 'B3':'GREEN', 'B4':'RED'}))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print_bands(renamed_col)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/image/renamePattern.ipynb b/notebooks/image/renamePattern.ipynb deleted file mode 100644 index 59f7f46a..00000000 --- a/notebooks/image/renamePattern.ipynb +++ /dev/null @@ -1,177 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ipygee as ui" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "test_i = ee.Image([0,1,2,3]).rename('a', 'b', 'c', 'd')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(test_i.bandNames())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "pattern = 'new pattern {band} '" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "renamed = tools.image.renamePattern(test_i, pattern)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(renamed.bandNames())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "renamed2 = tools.image.renamePattern(test_i, pattern, bands=['a', 'b'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(renamed2.bandNames())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "pattern2 = 'no{band}'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "renamed3 = tools.image.renamePattern(test_i, pattern2, bands=['a', 'b'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(renamed3.bandNames())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "pattern3 = 'nothing'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "renamed4 = tools.image.renamePattern(test_i, pattern3, bands=['a', 'b'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(renamed4.bandNames())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/image/toGrid.ipynb b/notebooks/image/toGrid.ipynb deleted file mode 100644 index b9a5c336..00000000 --- a/notebooks/image/toGrid.ipynb +++ /dev/null @@ -1,197 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Make a grid out of Image pixels" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from ipygee import *" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Geometry" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p = ee.Geometry.Point([-71.33972167968751, -42.737619925503054])\n", - "aoi = p.buffer(8000).bounds()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Image" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "i = ee.Image('COPERNICUS/S2/20181122T142749_20181122T143353_T18GYT').clip(aoi)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Make Grid" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "grid = tools.image.toGrid(i, 3, geometry=aoi)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Show on Map" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map = Map()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(i, {'bands':['B2'], 'min':0, 'max':3000}, 'Image')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(grid, None, 'Grid')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "eprint(ee.Feature(grid.first()).geometry().projection())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "eprint(i.select(0).projection())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(ee.Feature(grid.first()).geometry().transform(i.select(0).projection(), 1), None, 'reprojected')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(ee.Feature(grid.first()), None, 'first')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "eprint(Map.getObject('reprojected'))" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/imagecollection/distributions.ipynb b/notebooks/imagecollection/distributions.ipynb deleted file mode 100644 index 1fff0e07..00000000 --- a/notebooks/imagecollection/distributions.ipynb +++ /dev/null @@ -1,630 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Applying different distributions to collections and images" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ipygee as ui" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p = ee.Geometry.Point([0, 0])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Build a Test Collection" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# values = ee.List([0, 2, 5, 8, 10, 12, 15, 18, 22, 25, 28, 31, 35, 39, 42, 48, 51, 55])\n", - "# values = ee.List([-10, -8, -7, -1, -2, 0, 1, 5, 7, 8, 10, 12, 14, 16, 18, 20, 22, 24]) # With negative values\n", - "values = ee.List([-20, -32, -15, -8, -5, 0, 2, 4, 6, 8, 9, 10, 12, 14, 16, 18, 20, 23])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def build_collection(n):\n", - " n = ee.Number(n)\n", - " return ee.Image.constant(n).rename('test').set('test', n).toFloat()\n", - "images = values.map(build_collection)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "collection = ee.ImageCollection.fromImages(images)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Linear Function" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Using a band" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "help(tools.imagecollection.linearFunctionBand)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_band1 = tools.imagecollection.linearFunctionBand(collection, 'test')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_band1_chart = ui.chart.Image.series(linear_band1, p, scale=1000, xProperty='test', bands=['linear_function'], label_bands=['default values'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_band2 = tools.imagecollection.linearFunctionBand(collection, 'test', mean=10)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_band2_chart = ui.chart.Image.series(linear_band2, p, scale=1000, xProperty='test', bands=['linear_function'], label_bands=['mean=10'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_band3 = tools.imagecollection.linearFunctionBand(collection, 'test', mean=10, output_min=0)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_band3_chart = ui.chart.Image.series(linear_band3, p, scale=1000, xProperty='test', bands=['linear_function'], label_bands=['mean=10 min=0'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_band4 = tools.imagecollection.linearFunctionBand(collection, 'test', mean=10, output_min=10, output_max=20)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_band4_chart = ui.chart.Image.series(linear_band4, p, scale=1000, xProperty='test', bands=['linear_function'], label_bands=['mean=10 min=0 max=12'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_chart = linear_band1_chart.cat(linear_band2_chart, linear_band3_chart, linear_band4_chart)\n", - "linear_chart.renderWidget(width=800)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Using a Property" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_prop1 = tools.imagecollection.linearFunctionProperty(collection, 'test')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_prop1_chart = ui.chart.Image.series(linear_prop1, p, scale=1000, xProperty='test', properties=['LINEAR_FUNCTION'], label_properties=['default values'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_prop2 = tools.imagecollection.linearFunctionProperty(collection, 'test', mean=10)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_prop2_chart = ui.chart.Image.series(linear_prop2, p, scale=1000, xProperty='test', properties=['LINEAR_FUNCTION'], label_properties=['mean=10'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_prop3 = tools.imagecollection.linearFunctionProperty(collection, 'test', mean=10, output_min=0)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_prop3_chart = ui.chart.Image.series(linear_prop3, p, scale=1000, xProperty='test', properties=['LINEAR_FUNCTION'], label_properties=['mean=10 min=0'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_prop4 = tools.imagecollection.linearFunctionProperty(collection, 'test', mean=10, output_min=0, output_max=10)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_prop4_chart = ui.chart.Image.series(linear_prop4, p, scale=1000, xProperty='test', properties=['LINEAR_FUNCTION'], label_properties=['mean=10 min=0 max=10'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_prop5 = tools.imagecollection.linearFunctionProperty(collection, 'test', mean=10, output_min=5, output_max=20)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_prop5_chart = ui.chart.Image.series(linear_prop5, p, scale=1000, xProperty='test', properties=['LINEAR_FUNCTION'], label_properties=['mean=10 min=5 max=20'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_chart_prop = linear_prop1_chart.cat(linear_prop2_chart, linear_prop3_chart, linear_prop4_chart, linear_prop5_chart)\n", - "linear_chart_prop.renderWidget(width=800)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "linear_chart_prop.dataframe" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Gauss Function" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Over a band" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_band1 = tools.imagecollection.gaussFunctionBand(collection, 'test')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_band1_chart = ui.chart.Image.series(gauss_band1, ee.Geometry.Point([0, 0]), scale=1000, xProperty='test', bands=['gauss'], label_bands=['default'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_band2 = tools.imagecollection.gaussFunctionBand(collection, 'test', mean=10)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_band2_chart = ui.chart.Image.series(gauss_band2, ee.Geometry.Point([0, 0]), scale=1000, xProperty='test', bands=['gauss'], label_bands=['mean=10'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_band3 = tools.imagecollection.gaussFunctionBand(collection, 'test', mean=10, output_min=0.5)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_band3_chart = ui.chart.Image.series(gauss_band3, ee.Geometry.Point([0, 0]), scale=1000, xProperty='test', bands=['gauss'], label_bands=['mean=10 min=0.5'])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Exponential function using the gauss function\n", - "Use as mean value the range_max" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_band4 = tools.imagecollection.gaussFunctionBand(collection, 'test', mean=23, output_min=0.5)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_band4_chart = ui.chart.Image.series(gauss_band4, ee.Geometry.Point([0, 0]), scale=1000, xProperty='test', bands=['gauss'], label_bands=['Exponential'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_band_chart = gauss_band1_chart.cat(gauss_band2_chart, gauss_band3_chart, gauss_band4_chart)\n", - "gauss_band_chart.renderWidget(width=800)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_band_chart.dataframe" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Over a Property" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_prop1 = tools.imagecollection.gaussFunctionProperty(collection, 'test')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_prop1_chart = ui.chart.Image.series(gauss_prop1, ee.Geometry.Point([0, 0]), scale=1000, xProperty='test', properties=['GAUSS'], label_properties=['default'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_prop2 = tools.imagecollection.gaussFunctionProperty(collection, 'test', mean=10)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_prop2_chart = ui.chart.Image.series(gauss_prop2, ee.Geometry.Point([0, 0]), scale=1000, xProperty='test', properties=['GAUSS'], label_properties=['mean=10'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_prop3 = tools.imagecollection.gaussFunctionProperty(collection, 'test', mean=10, output_min=0.5)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_prop3_chart = ui.chart.Image.series(gauss_prop3, ee.Geometry.Point([0, 0]), scale=1000, xProperty='test', properties=['GAUSS'], label_properties=['mean=10 min=0.5'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_prop = gauss_prop1_chart.cat(gauss_prop2_chart, gauss_prop3_chart)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_prop.renderWidget(width=800)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gauss_prop.dataframe" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Normal Distribution (applies the Gauss function using a computed stdDev and mean)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Over a Property" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "normal_prop = tools.imagecollection.normalDistributionProperty(collection, 'test')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "normal_prop_chart = ui.chart.Image.series(normal_prop, ee.Geometry.Point([0, 0]), scale=1000, xProperty='test', properties=['NORMAL_DISTRIBUTION'], label_properties=['default'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "normal_prop_chart.renderWidget(width=800)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "normal_prop_chart.dataframe" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Over a Band" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "normal_band = tools.imagecollection.normalDistributionBand(collection, 'test')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "normal_band_chart = ui.chart.Image.series(normal_band, ee.Geometry.Point([0, 0]), scale=1000, xProperty='test', bands=['normal_distribution'], label_bands=['default'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "normal_band_chart.renderWidget(width=800)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "normal_band_chart.dataframe" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/imagecollection/mosaicSameDay.ipynb b/notebooks/imagecollection/mosaicSameDay.ipynb deleted file mode 100644 index 3fdb9282..00000000 --- a/notebooks/imagecollection/mosaicSameDay.ipynb +++ /dev/null @@ -1,196 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Mosaic Same Day\n", - "Images inside an ImageCollection that where taken in the same day are fusioned into one image using a reducer (default: mean). The resulting images will have 2 properties only:\n", - "\n", - "- system:time_start\n", - "- system:footprint (this will contain the fusioned geometries)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import geedatasets" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ipygee as ui" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map = ui.Map()\n", - "Map.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "sat = geedatasets.sentinel.Sentinel2SR()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "vis = sat.visualization('NSR')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p = ee.Geometry.Point([-72, -42])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col = sat.collection().filterBounds(p).filterDate('2019-01-01', '2019-05-01')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(col.size())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Get dates\n", - "def get_dates(col):\n", - " dates = ee.List(col.toList(col.size()).map(lambda img: ee.Image(img).date().format()))\n", - " return dates\n", - "\n", - "ui.eprint(get_dates(col))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mosaics = tools.imagecollection.mosaicSameDay(col)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(mosaics.size())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(get_dates(mosaics))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addImageCollection(col.limit(2), vis)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(mosaics.first(), sat.visualization('NSR'), 'Day 1 mosaicked')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Map.addLayer(mosaics.first().geometry(), name='Footprint day 1 mosaicked')" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/imagecollection/parametrizeProperty.ipynb b/notebooks/imagecollection/parametrizeProperty.ipynb deleted file mode 100644 index c0da2e28..00000000 --- a/notebooks/imagecollection/parametrizeProperty.ipynb +++ /dev/null @@ -1,147 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ee\n", - "ee.Initialize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from geetools import tools" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import ipygee as ui\n", - "import geedatasets" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "l8 = geedatasets.landsat.Landsat8SR()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "col = l8.collection().limit(10)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Parametrize CLOUD_COVER from 0-100 to 0-1" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "parametrized = tools.imagecollection.parametrizeProperty(col, 'CLOUD_COVER', [0, 100], [0, 1])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cloud_cover = parametrized.toList(10).map(lambda img: ee.Image(img).get('CLOUD_COVER_PARAMETRIZED'))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(cloud_cover)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Values out of range" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "parametrized2 = tools.imagecollection.parametrizeProperty(col, 'CLOUD_COVER', [0, 80], [0, 1])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "out_of_range = parametrized2.toList(10).map(lambda img: ee.Image(img).get('CLOUD_COVER_PARAMETRIZED'))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ui.eprint(out_of_range)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/noxfile.py b/noxfile.py index d2b79b12..a9b7051f 100644 --- a/noxfile.py +++ b/noxfile.py @@ -3,60 +3,50 @@ The nox run are build in isolated environment that will be stored in .nox. to force the venv update, remove the .nox/xxx folder. """ +import datetime +import fileinput + import nox nox.options.sessions = ["lint", "test", "docs", "mypy"] -@nox.session(reuse_venv=True) +@nox.session(reuse_venv=True, venv_backend="uv") def lint(session): """Apply the pre-commits.""" session.install("pre-commit") session.run("pre-commit", "run", "--all-files", *session.posargs) -@nox.session(reuse_venv=True, name="ci-test") -def ci_test(session): - """Run all the test using the environment variable of the running machine.""" +@nox.session(reuse_venv=True, venv_backend="uv") +def test(session): + """Run the selected tests and report coverage in html.""" session.install(".[test]") test_files = session.posargs or ["tests"] - session.run( - "pytest", - "--color=yes", - "--cov", - "--cov-report=xml", - *test_files, - ) + session.run("pytest", "--cov", "--cov-report=html", *test_files) -@nox.session(reuse_venv=True) -def test(session): - """Run all the test using the environment variable of the running machine.""" +@nox.session(reuse_venv=True, name="ci-test", venv_backend="uv") +def ci_test(session): + """Run all the test and report coverage in xml.""" session.install(".[test]") - test_files = session.posargs or ["tests"] - session.run( - "pytest", - "--color=yes", - "--cov", - "--cov-report=html", - *test_files, - ) + session.run("pytest", "--cov", "--cov-report=xml") -@nox.session(reuse_venv=True, name="dead-fixtures") +@nox.session(reuse_venv=True, name="dead-fixtures", venv_backend="uv") def dead_fixtures(session): """Check for dead fixtures within the tests.""" session.install(".[test]") session.run("pytest", "--dead-fixtures") -@nox.session(reuse_venv=True) +@nox.session(reuse_venv=True, venv_backend="uv") def docs(session): """Build the documentation.""" build = session.posargs.pop() if session.posargs else "html" session.install(".[doc]") - dst, warn = f"docs/_build/{build}", "warnings.txt" - session.run("sphinx-build", "-v", "-b", build, "docs", dst, "-w", warn) + dst = f"docs/_build/{build}" + session.run("sphinx-build", "-v", "-b", build, "docs", dst) @nox.session(name="mypy", reuse_venv=True) @@ -67,9 +57,22 @@ def mypy(session): session.run("mypy", *test_files) -@nox.session(reuse_venv=True) +@nox.session(reuse_venv=True, venv_backend="uv") def stubgen(session): """Generate stub files for the lib but requires human attention before merge.""" session.install("mypy") package = session.posargs or ["geetools"] session.run("stubgen", "-p", package[0], "-o", "stubs", "--include-private") + + +@nox.session(name="release-date", reuse_venv=True, venv_backend="uv") +def release_date(session): + """Update the release date of the citation file.""" + current_date = datetime.datetime.now().strftime("%Y-%m-%d") + + with fileinput.FileInput("CITATION.cff", inplace=True) as file: + for line in file: + if line.startswith("date-released:"): + print(f'date-released: "{current_date}"') + else: + print(line, end="") diff --git a/pyproject.toml b/pyproject.toml index 2f7bab33..5845ba86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,12 +51,7 @@ content-type = "text/x-rst" Homepage = "https://github.com/gee-community/geetools" [project.optional-dependencies] -"dev" = [ - "pre-commit", - "nox", - "commitizen" -] -"test" = [ +test = [ "pytest", "pytest-cov", "pytest-deadfixtures", @@ -71,7 +66,7 @@ doc = [ "pydata-sphinx-theme", "sphinx-copybutton", "sphinx-design", - "sphinx-autoapi==3.1.0a3", # until v3.1 is released with the single page fix + "sphinx-autoapi>=3.1", # single page implementation "ipykernel", "httplib2", "jupyter-sphinx", @@ -88,60 +83,56 @@ only-include = ["geetools"] dependencies = [ "pre-commit", "commitizen", - "nox" + "nox[uv]" ] post-install-commands = ["pre-commit install"] -[tool.licensecheck] -using = "PEP631:test;dev;doc" +[tool.commitizen] +tag_format = "v$major.$minor.$patch$prerelease" +update_changelog_on_bump = false +version = "1.9.1" +version_files = [ + "pyproject.toml:version", + "geetools/__init__.py:__version__", + "docs/conf.py:release", + "CITATION.cff:version" +] + +[tool.pytest.ini_options] +testpaths = "tests" [tool.ruff] -ignore-init-module-imports = true +line-length = 100 fix = true +extend-exclude = ["geetools/__init__.py"] + +[tool.ruff.lint] select = ["E", "F", "W", "I", "D", "RUF"] -extend-exclude = ["geetools/__init__.py", "geetools/tools/_deprecated_imagecollection.py"] -force-exclude = true # to make sure exclude is respected when used via pre-commit ignore = [ "E501", # line too long | Black take care of it - "D213", # Multi-line docstring | We use D212 - "E741", # Ambiguous variable name: `l` | TODO + "D212", # Multi-line docstring | We use D213 + "D101", # Missing docstring in public class | We use D106 ] -[tool.ruff.flake8-quotes] +[tool.ruff.lint.flake8-quotes] docstring-quotes = "double" -[tool.ruff.pydocstyle] +[tool.ruff.lint.pydocstyle] convention = "google" -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "tests/*" = ["D102"] # Missing docstring in public method | this is test who cares -[tool.pytest.ini_options] -testpaths = "tests" - [tool.coverage.run] source = ["geetools"] branch = true -[tool.commitizen] -tag_format = "v$major.$minor.$patch$prerelease" -update_changelog_on_bump = false -version = "1.9.1" -version_files = [ - "pyproject.toml:version", - "geetools/__init__.py:__version__", - "docs/conf.py:release", -] - -[tool.codespell] -skip = "geetools/tools/*,geetools/classification.py,**/*.ipynb,**/*.yml" - -[tool.black] -line-length = 100 - [tool.mypy] scripts_are_modules = true ignore_missing_imports = true install_types = true non_interactive = true warn_redundant_casts = true + +[tool.codespell] +skip = "geetools/tools/*,geetools/classification.py,**/*.ipynb,**/*.yml" diff --git a/tests/test_Array.py b/tests/test_Array.py index 8af04926..14a5c8fb 100644 --- a/tests/test_Array.py +++ b/tests/test_Array.py @@ -1,4 +1,5 @@ """Test the Array class methods.""" + import ee diff --git a/tests/test_Asset.py b/tests/test_Asset.py index e3955a16..e88523e6 100644 --- a/tests/test_Asset.py +++ b/tests/test_Asset.py @@ -1,4 +1,5 @@ """Test cases for the Asset class.""" + import os from unittest.mock import patch diff --git a/tests/test_Date.py b/tests/test_Date.py index 1f60205f..02050b1b 100644 --- a/tests/test_Date.py +++ b/tests/test_Date.py @@ -1,4 +1,5 @@ """Test the Date class methods.""" + import ee import pytest diff --git a/tests/test_DateRange.py b/tests/test_DateRange.py index 6d05c9a9..81d3b0f2 100644 --- a/tests/test_DateRange.py +++ b/tests/test_DateRange.py @@ -1,4 +1,5 @@ """Test the ``DateRange`` class.""" + import ee import pytest diff --git a/tests/test_Dictionary.py b/tests/test_Dictionary.py index 9e410cea..bf23e27e 100644 --- a/tests/test_Dictionary.py +++ b/tests/test_Dictionary.py @@ -1,4 +1,5 @@ """Test the Dictionary class methods.""" + import ee diff --git a/tests/test_Export.py b/tests/test_Export.py index 31543653..13344b15 100644 --- a/tests/test_Export.py +++ b/tests/test_Export.py @@ -1,4 +1,5 @@ """Test the ``Export`` class.""" + import ee import pytest from ee.cli.utils import wait_for_task diff --git a/tests/test_FeatureCollection.py b/tests/test_FeatureCollection.py index 19f7f9aa..0e594c67 100644 --- a/tests/test_FeatureCollection.py +++ b/tests/test_FeatureCollection.py @@ -1,4 +1,5 @@ """Test the ``FeatureCollection`` class.""" + import io import ee diff --git a/tests/test_Filter.py b/tests/test_Filter.py index 67e6bbf0..19ba9fa1 100644 --- a/tests/test_Filter.py +++ b/tests/test_Filter.py @@ -1,4 +1,5 @@ """Test the Filter class methods.""" + import ee diff --git a/tests/test_Float.py b/tests/test_Float.py index dd6756d5..9fad5794 100644 --- a/tests/test_Float.py +++ b/tests/test_Float.py @@ -1,4 +1,5 @@ """Test the Float placeholder object.""" + import ee import pytest diff --git a/tests/test_Image.py b/tests/test_Image.py index 978eb561..6a7aaaed 100644 --- a/tests/test_Image.py +++ b/tests/test_Image.py @@ -1,4 +1,5 @@ """Test the ``Image`` class.""" + import io import zipfile from io import BytesIO @@ -301,7 +302,7 @@ def dates(self): @pytest.fixture def image_source(self, vatican_buffer, dates): - """image from the S2 copernicus program over vatican city.""" + """Image from the S2 copernicus program over vatican city.""" return ( ee.ImageCollection("COPERNICUS/S2_SR_HARMONIZED") .filterBounds(vatican_buffer) @@ -313,7 +314,7 @@ def image_source(self, vatican_buffer, dates): @pytest.fixture def image_target(self, vatican_buffer, dates): - """image from the L8 Landsat program over vatican city.""" + """Image from the L8 Landsat program over vatican city.""" return ( ee.ImageCollection("LANDSAT/LC08/C02/T1_L2") .filterBounds(vatican_buffer) @@ -362,7 +363,6 @@ def test_islet_mask(self, image_instance, tmp_path, image_regression): image_regression.check(file.read_bytes()) def get_image(self, image, dst): - link = image.getDownloadURL( { "name": "test", diff --git a/tests/test_ImageCollection.py b/tests/test_ImageCollection.py index 6a7c6525..12e073ce 100644 --- a/tests/test_ImageCollection.py +++ b/tests/test_ImageCollection.py @@ -1,4 +1,5 @@ """Test the ImageCollection class.""" + from __future__ import annotations import io @@ -22,7 +23,7 @@ def reduce( return image.reduceRegion(ee.Reducer.mean(), geometry, 1) -def round_dict(d: dict = None, decimals: int = 2) -> dict: +def round_dict(d: dict | None = None, decimals: int = 2) -> dict: """Round all the values of a dictionary.""" d = d or {} for k, v in d.items(): diff --git a/tests/test_Integer.py b/tests/test_Integer.py index 1a80f041..8e7f4933 100644 --- a/tests/test_Integer.py +++ b/tests/test_Integer.py @@ -1,4 +1,5 @@ """Test the Integer placeholder object.""" + import ee import pytest diff --git a/tests/test_Join.py b/tests/test_Join.py index 3545f434..d4944e0c 100644 --- a/tests/test_Join.py +++ b/tests/test_Join.py @@ -1,4 +1,5 @@ """Test the ``Join`` class.""" + import ee import pytest diff --git a/tests/test_List.py b/tests/test_List.py index df0d5a29..415a2446 100644 --- a/tests/test_List.py +++ b/tests/test_List.py @@ -1,4 +1,5 @@ """Test the List class methods.""" + import ee @@ -67,11 +68,11 @@ def test_sequence(self): def test_sequence_with_step(self): seq = ee.List.geetools.sequence(1, 10, 2) - assert seq.getInfo() == list(range(1, 11, 2)) + [10] + assert seq.getInfo() == [*list(range(1, 11, 2)), 10] def test_sequence_with_uneven_step(self): seq = ee.List.geetools.sequence(1, 10, 3) - assert seq.getInfo() == list(range(1, 10, 3)) + [10] + assert seq.getInfo() == [*list(range(1, 10, 3)), 10] def test_sequence_with_0_step(self): seq = ee.List.geetools.sequence(1, 10, 0) diff --git a/tests/test_Profiler.py b/tests/test_Profiler.py index 54d1db6a..c2d3298d 100644 --- a/tests/test_Profiler.py +++ b/tests/test_Profiler.py @@ -1,4 +1,5 @@ """Test the ee_profiler module.""" + import ee import geetools # noqa: F401 diff --git a/tests/test_String.py b/tests/test_String.py index 6fbe5f85..1f6e9741 100644 --- a/tests/test_String.py +++ b/tests/test_String.py @@ -1,4 +1,5 @@ """Test the String class methods.""" + import ee diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 3de8a9f7..9a7fae7a 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -1,6 +1,5 @@ """Test all the deprecated methods that have not been kept in the new implementation.""" - import pytest import geetools