├── MANIFEST.in ├── dask_ee ├── __init__.py ├── write.py ├── read_test.py ├── read_integrationtest.py └── read.py ├── demo.png ├── conftest.py ├── pyproject.toml ├── .github └── workflows │ ├── lint.yml │ ├── ci-build.yml │ └── publish.yml ├── .gitignore ├── README.md └── LICENSE /MANIFEST.in: -------------------------------------------------------------------------------- 1 | global-exclude *test.py -------------------------------------------------------------------------------- /dask_ee/__init__.py: -------------------------------------------------------------------------------- 1 | from .read import read_ee 2 | -------------------------------------------------------------------------------- /demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alxmrs/dask-ee/HEAD/demo.png -------------------------------------------------------------------------------- /dask_ee/write.py: -------------------------------------------------------------------------------- 1 | # TODO(alxmrs): This is open for design and implementation. 2 | 3 | 4 | def to_ee(ddf, *args, **kwargs): 5 | raise NotImplementedError('This has not yet been designed.') 6 | -------------------------------------------------------------------------------- /dask_ee/read_test.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class ReadFeatureCollections(unittest.TestCase): 5 | 6 | def test_can_import_read_op(self): 7 | try: 8 | from dask_ee import read_ee 9 | except ModuleNotFoundError: 10 | self.fail('Cannot import `read_ee` function.') 11 | 12 | def test_rejects_auto_chunks(self): 13 | import dask_ee 14 | 15 | with self.assertRaises(NotImplementedError): 16 | dask_ee.read_ee('WRI/GPPD/power_plants', 'auto') 17 | 18 | 19 | if __name__ == '__main__': 20 | unittest.main() 21 | -------------------------------------------------------------------------------- /conftest.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ============================================================================== 15 | """Configure FLAGS with default values for absltest.""" 16 | from absl import app 17 | 18 | try: 19 | app.run(lambda argv: None) 20 | except SystemExit: 21 | pass 22 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "dask-ee" 3 | dynamic = ["version"] 4 | description = "Google Earth Engine FeatureCollections via Dask DataFrames." 5 | readme = "README.md" 6 | requires-python = ">=3.8" 7 | license = {text = "Apache-2.0"} 8 | authors = [ 9 | {name = "Alexander Merose", email = "al@merose.com"}, 10 | {name = "Aaron Zuspan"} 11 | ] 12 | classifiers = [ 13 | "Development Status :: 4 - Beta", 14 | "Intended Audience :: Science/Research", 15 | "Intended Audience :: Developers", 16 | "Intended Audience :: Information Technology", 17 | "License :: OSI Approved :: Apache Software License", 18 | "Operating System :: MacOS :: MacOS X", 19 | "Operating System :: Microsoft :: Windows", 20 | "Operating System :: POSIX", 21 | "Programming Language :: Python :: 3.9", 22 | "Programming Language :: Python :: 3.10", 23 | "Programming Language :: Python :: 3.11", 24 | "Programming Language :: Python :: 3.12", 25 | "Topic :: Scientific/Engineering :: Atmospheric Science", 26 | "Topic :: Scientific/Engineering :: GIS", 27 | "Topic :: Scientific/Engineering :: Hydrology", 28 | "Topic :: Scientific/Engineering :: Oceanography", 29 | ] 30 | dependencies = [ 31 | "earthengine-api>=0.1.374", 32 | "dask[dataframe]", 33 | "pandas", 34 | ] 35 | 36 | [project.optional-dependencies] 37 | tests = [ 38 | "absl-py", 39 | "pytest", 40 | "pyink", 41 | ] 42 | dev = [ 43 | "dask-ee[tests]", 44 | "build", 45 | ] 46 | 47 | [project.urls] 48 | Homepage = "https://github.com/alxmrs/dask-ee" 49 | Issues = "https://github.com/alxmrs/dask-ee/issues" 50 | 51 | [build-system] 52 | requires = ["setuptools>=64", "setuptools_scm>=8"] 53 | build-backend = "setuptools.build_meta" 54 | 55 | [tool.pyink] 56 | line-length = 80 57 | preview = true 58 | pyink-indentation = 2 59 | pyink-use-majority-quotes = true 60 | 61 | [tool.setuptools_scm] -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | # Taken from Xee and minimally modified: https://github.com/google/Xee/blob/main/.github/workflows/lint.yml 2 | # 3 | # Copyright 2023 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # ============================================================================== 17 | name: lint 18 | 19 | on: 20 | # Triggers the workflow on push or pull request events but only for the main branch 21 | push: 22 | branches: [ main ] 23 | pull_request: 24 | branches: [ main ] 25 | # Allows you to run this workflow manually from the Actions tab 26 | workflow_dispatch: 27 | 28 | jobs: 29 | build: 30 | name: "python ${{ matrix.python-version }} lint" 31 | runs-on: ubuntu-latest 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | python-version: ["3.9", "3.10", "3.11"] 36 | steps: 37 | - name: Cancel previous 38 | uses: styfle/cancel-workflow-action@0.7.0 39 | with: 40 | access_token: ${{ github.token }} 41 | if: ${{github.ref != 'refs/head/main'}} 42 | - uses: actions/checkout@v2 43 | - name: Set up Python ${{ matrix.python-version }} 44 | uses: actions/setup-python@v2 45 | with: 46 | python-version: ${{ matrix.python-version }} 47 | - name: Get pip cache dir 48 | id: pip-cache 49 | run: | 50 | python -m pip install --upgrade pip wheel 51 | echo "::set-output name=dir::$(pip cache dir)" 52 | - name: pip cache 53 | uses: actions/cache@v3 54 | with: 55 | path: ${{ steps.pip-cache.outputs.dir }} 56 | key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }} 57 | - name: Install dask-ee 58 | run: | 59 | pip install -e .[tests] 60 | - name: Lint with pyink 61 | run: | 62 | pyink --check . -------------------------------------------------------------------------------- /.github/workflows/ci-build.yml: -------------------------------------------------------------------------------- 1 | # Taken from Xee and minimally modified: https://github.com/google/Xee/blob/main/.github/workflows/ci-build.yml 2 | # 3 | # Copyright 2023 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # ============================================================================== 17 | name: ci 18 | 19 | on: 20 | # Triggers the workflow on push or pull request events but only for the main branch 21 | push: 22 | branches: [ main ] 23 | pull_request: 24 | branches: [ main ] 25 | # Allows you to run this workflow manually from the Actions tab 26 | workflow_dispatch: 27 | 28 | jobs: 29 | build: 30 | name: "python ${{ matrix.python-version }} tests" 31 | runs-on: ubuntu-latest 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | python-version: [ 36 | "3.8", 37 | "3.9", 38 | "3.10", 39 | "3.11", 40 | "3.12", 41 | ] 42 | permissions: 43 | id-token: write # This is required for requesting the JWT. 44 | steps: 45 | - name: Cancel previous 46 | uses: styfle/cancel-workflow-action@0.7.0 47 | with: 48 | access_token: ${{ github.token }} 49 | if: ${{github.ref != 'refs/head/main'}} 50 | - uses: actions/checkout@v2 51 | - name: Set up Python ${{ matrix.python-version }} 52 | uses: actions/setup-python@v4 53 | with: 54 | python-version: ${{ matrix.python-version }} 55 | cache: 'pip' 56 | - name: Install dask-ee 57 | run: | 58 | pip install -e .[tests] 59 | - uses: 'actions/checkout@v4' 60 | # # TODO(alxmrs): Add back gcloud auth, when it's needed. 61 | # - id: 'auth' 62 | # name: 'Authenticate to Google Cloud' 63 | # uses: 'google-github-actions/auth@v1' 64 | # with: 65 | # service_account: ${{ secrets.SERVICE_ACCOUNT }} 66 | # workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }} 67 | - name: Run unit tests 68 | run: | 69 | pytest dask_ee -------------------------------------------------------------------------------- /dask_ee/read_integrationtest.py: -------------------------------------------------------------------------------- 1 | """Integration tests with Google Earth Engine. 2 | 3 | Before running, please authenticate: 4 | ``` 5 | earthengine authenticate 6 | ``` 7 | """ 8 | 9 | import cProfile 10 | import pstats 11 | import unittest 12 | 13 | import dask.dataframe as dd 14 | import ee 15 | 16 | import dask_ee 17 | 18 | 19 | class ReadIntegrationTests(unittest.TestCase): 20 | 21 | @classmethod 22 | def setUpClass(cls): 23 | ee.Initialize() 24 | 25 | def test_reads_dask_dataframe(self): 26 | fc = ee.FeatureCollection('WRI/GPPD/power_plants') 27 | df = dask_ee.read_ee(fc) 28 | 29 | head = df.head() 30 | columns = df.columns 31 | 32 | self.assertIsNotNone(df) 33 | self.assertIsNotNone(head) 34 | self.assertIsInstance(df, dd.DataFrame) 35 | self.assertEqual(df.compute().shape, (28_664, 23)) 36 | 37 | print(columns) 38 | print(head) 39 | 40 | def test_works_with_defined_features(self): 41 | # Make a list of Features. 42 | features = [ 43 | ee.Feature( 44 | ee.Geometry.Rectangle(30.01, 59.80, 30.59, 60.15), 45 | {'name': 'Voronoi'}, 46 | ), 47 | ee.Feature(ee.Geometry.Point(-73.96, 40.781), {'name': 'Thiessen'}), 48 | ee.Feature(ee.Geometry.Point(6.4806, 50.8012), {'name': 'Dirichlet'}), 49 | ] 50 | 51 | fc = ee.FeatureCollection(features) 52 | 53 | df = dask_ee.read_ee(fc) 54 | 55 | self.assertEqual(list(df.columns), ['geo', 'name']) 56 | 57 | def test_works_with_a_single_feature_in_fc(self): 58 | from_geom = ee.FeatureCollection(ee.Geometry.Point(16.37, 48.225)) 59 | 60 | df = dask_ee.read_ee(from_geom) 61 | 62 | self.assertEqual(list(df.columns), ['geo']) 63 | self.assertEqual(df.compute().shape, (1, 1)) 64 | 65 | def test_can_create_random_points(self): 66 | # Define an arbitrary region in which to compute random points. 67 | region = ee.Geometry.Rectangle(-119.224, 34.669, -99.536, 50.064) 68 | 69 | # Create 1000 random points in the region. 70 | random_points = ee.FeatureCollection.randomPoints(region) 71 | 72 | # Note: these random points have no system:index! 73 | df = dask_ee.read_ee(random_points) 74 | 75 | self.assertEqual(list(df.columns), ['geo']) 76 | self.assertEqual(df.compute().shape, (1000, 1)) 77 | 78 | def test_prof__read_ee(self): 79 | fc = ee.FeatureCollection('WRI/GPPD/power_plants') 80 | with cProfile.Profile() as pr: 81 | _ = dask_ee.read_ee(fc) 82 | 83 | # Modified version of `pr.print_stats()`. 84 | pstats.Stats(pr).sort_stats('cumtime').print_stats() 85 | 86 | 87 | if __name__ == '__main__': 88 | unittest.main() 89 | -------------------------------------------------------------------------------- /dask_ee/read.py: -------------------------------------------------------------------------------- 1 | # Special thanks to @aazuspan for help with the implementation 2 | import typing as t 3 | 4 | import dask.dataframe as dd 5 | import ee 6 | import numpy as np 7 | import pandas as pd 8 | 9 | # Order is in appearance of types in the EE documentation. This looks alphabetical. 10 | _BUILTIN_DTYPES = { 11 | 'Byte': np.uint8, 12 | 'Double': np.float64, 13 | 'Float': np.float32, 14 | 'Int': np.int32, 15 | 'Integer': np.int32, 16 | 'Int16': np.int16, 17 | 'Int32': np.int32, 18 | 'Int64': np.int64, 19 | 'Int8': np.int8, 20 | 'Json': np.object_, # added to handle GeoJSON columns. 21 | 'Long': np.int64, 22 | 'Short': np.int16, 23 | 'Uint16': np.uint16, 24 | 'Uint32': np.uint32, 25 | 'Uint8': np.uint8, 26 | 'String': np.str_, 27 | } 28 | 29 | 30 | def read_ee( 31 | fc: t.Union[ee.FeatureCollection, str], 32 | chunksize: t.Union[int, t.Literal['auto']] = 5_000, 33 | ) -> dd.DataFrame: 34 | """Read Google Earth Engine FeatureCollections into a Dask Dataframe. 35 | 36 | Args: 37 | fc: A Google Earth Engine FeatureCollection or valid string path to a FeatureCollection. 38 | chunksize: The number of rows per partition to use. 39 | 40 | Returns: 41 | A dask DataFrame with paged Google Earth Engine data. 42 | """ 43 | # TODO(#4): Support 'auto' chunks, where we calculate the maximum allowed page size given the number of 44 | # bytes in each row. 45 | if chunksize == 'auto': 46 | raise NotImplementedError('Auto chunksize is not implemented yet!') 47 | 48 | if isinstance(fc, str): 49 | fc = ee.FeatureCollection(fc) 50 | 51 | # Make all the getInfo() calls at once, up front. 52 | fc_size, all_info = ee.List([fc.size(), fc.limit(0)]).getInfo() 53 | 54 | columns = {'geo': 'Json'} 55 | columns.update(all_info['columns']) 56 | if 'system:index' in columns: 57 | del columns['system:index'] 58 | 59 | divisions = tuple(range(0, fc_size, chunksize)) 60 | 61 | # TODO(#5): Compare `toList()` to other range operations, like getting all index IDs via `getInfo()`. 62 | pages = [ee.FeatureCollection(fc.toList(chunksize, i)) for i in divisions] 63 | # Get the remainder, if it exists. `chunksize` is not likely to evenly partition the data. 64 | d, r = divmod(fc_size, chunksize) 65 | if r != 0: 66 | pages.append(ee.FeatureCollection(fc.toList(r, d))) 67 | divisions += (fc_size,) 68 | 69 | def to_df(page: ee.FeatureCollection) -> pd.DataFrame: 70 | return ee.data.computeFeatures( 71 | { 72 | 'expression': page, 73 | 'fileFormat': 'PANDAS_DATAFRAME', 74 | } 75 | ) 76 | 77 | meta = {k: _BUILTIN_DTYPES[v] for k, v in columns.items()} 78 | 79 | return dd.from_map( 80 | to_df, 81 | pages, 82 | meta=meta, 83 | divisions=divisions, 84 | ) 85 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | # Taken from Xee and minimally modified: https://github.com/google/Xee/blob/main/.github/workflows/publish.yml 2 | # 3 | # Copyright 2023 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | name: Publish to PyPi 17 | 18 | on: 19 | release: 20 | types: [published] 21 | 22 | workflow_dispatch: 23 | 24 | 25 | jobs: 26 | build-artifacts: 27 | runs-on: ubuntu-latest 28 | steps: 29 | - uses: actions/checkout@v2 30 | - name: Set up Python 31 | uses: actions/setup-python@v2.3.1 32 | with: 33 | python-version: 3.9 34 | 35 | - name: Install dependencies 36 | run: | 37 | python -m pip install --upgrade pip 38 | python -m pip install setuptools setuptools-scm wheel twine check-manifest 39 | 40 | - name: Build tarball and wheels 41 | run: | 42 | git clean -xdf 43 | git restore -SW . 44 | python -m build --sdist --wheel . 45 | - name: Check built artifacts 46 | run: | 47 | python -m twine check dist/* 48 | pwd 49 | - uses: actions/upload-artifact@v4 50 | with: 51 | name: releases 52 | path: dist 53 | 54 | test-built-dist: 55 | needs: build-artifacts 56 | runs-on: ubuntu-latest 57 | steps: 58 | - uses: actions/setup-python@v2.3.1 59 | name: Install Python 60 | with: 61 | python-version: 3.9 62 | - uses: actions/download-artifact@v4 63 | with: 64 | name: releases 65 | path: dist 66 | - name: List contents of built dist 67 | run: | 68 | ls -ltrh 69 | ls -ltrh dist 70 | - name: Publish package to TestPyPI 71 | if: github.event_name == 'push' 72 | uses: pypa/gh-action-pypi-publish@v1.13.0 73 | with: 74 | user: __token__ 75 | password: ${{ secrets.TESTPYPI_TOKEN }} 76 | repository_url: https://test.pypi.org/legacy/ 77 | verbose: true 78 | 79 | - name: Check uploaded package 80 | if: github.event_name == 'push' 81 | run: | 82 | sleep 3 83 | python -m pip install --upgrade pip 84 | python -m pip install --extra-index-url https://test.pypi.org/simple --upgrade dask-ee 85 | python -c "import dask_ee; print(dask_ee.__version__)" 86 | upload-to-pypi: 87 | needs: test-built-dist 88 | if: github.event_name == 'release' 89 | runs-on: ubuntu-latest 90 | steps: 91 | - uses: actions/download-artifact@v4 92 | with: 93 | name: releases 94 | path: dist 95 | - name: Publish package to PyPI 96 | uses: pypa/gh-action-pypi-publish@v1.13.0 97 | with: 98 | user: __token__ 99 | password: ${{ secrets.PYPI_TOKEN }} 100 | verbose: true -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dask-ee 2 | 3 | _Google Earth Engine Feature Collections via Dask DataFrames._ 4 | 5 | [![ci](https://github.com/alxmrs/dask-ee/actions/workflows/ci-build.yml/badge.svg)](https://github.com/alxmrs/dask-ee/actions/workflows/ci-build.yml) 6 | [![PyPi Version](https://img.shields.io/pypi/v/dask-ee.svg)](https://pypi.python.org/pypi/dask-ee) 7 | [![Downloads](https://static.pepy.tech/badge/dask-ee)](https://pepy.tech/project/dask-ee) 8 | [![Conda Recipe](https://img.shields.io/badge/recipe-dask--ee-green.svg)](https://anaconda.org/conda-forge/dask-ee) 9 | [![Conda Version](https://img.shields.io/conda/vn/conda-forge/dask-ee.svg)](https://anaconda.org/conda-forge/dask-ee) 10 | [![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/dask-ee.svg)](https://anaconda.org/conda-forge/dask-ee) 11 | 12 | ## How to use 13 | 14 | Install with pip: 15 | 16 | ```shell 17 | pip install dask-ee 18 | ``` 19 | 20 | Install with conda: 21 | 22 | ```shell 23 | conda install -c conda-forge dask-ee 24 | ``` 25 | 26 | Then, authenticate Earth Engine: 27 | 28 | ```shell 29 | earthengine authenticate 30 | ``` 31 | 32 | In your Python environment, you may now import the library: 33 | 34 | ```python 35 | import ee 36 | import dask_ee 37 | ``` 38 | 39 | You'll need to initialize Earth Engine before working with data: 40 | 41 | ```python 42 | ee.Initialize() 43 | ``` 44 | 45 | From here, you can read Earth Engine FeatureCollections like they are DataFrames: 46 | 47 | ```python 48 | df = dask_ee.read_ee("WRI/GPPD/power_plants") 49 | df.head() 50 | ``` 51 | 52 | These work like Pandas DataFrames, but they are lazily evaluated via [Dask](https://dask.org/). 53 | 54 | Feel free to do any analysis you wish. For example: 55 | 56 | ```python 57 | # Thanks @aazuspan, https://www.aazuspan.dev/blog/dask_featurecollection 58 | ( 59 | df[df.comm_year.gt(1940) & df.country.eq("USA") & df.fuel1.isin(["Coal", "Wind"])] 60 | .astype({"comm_year": int}) 61 | .drop(columns=["geo"]) 62 | .groupby(["comm_year", "fuel1"]) 63 | .agg({"capacitymw": "sum"}) 64 | .reset_index() 65 | .sort_values(by=["comm_year"]) 66 | .compute(scheduler="threads") 67 | .pivot_table(index="comm_year", columns="fuel1", values="capacitymw", fill_value=0) 68 | .plot() 69 | ) 70 | ``` 71 | 72 | ![Coal vs Wind in the US since 1940](https://raw.githubusercontent.com/alxmrs/dask-ee/main/demo.png) 73 | 74 | There are a few other useful things you can do. 75 | 76 | For one, you may pass in a pre-processed `ee.FeatureCollection`. This allows full utilization 77 | of the Earth Engine API. 78 | 79 | ```python 80 | fc = ( 81 | ee.FeatureCollection("WRI/GPPD/power_plants") 82 | .filter(ee.Filter.gt("comm_year", 1940)) 83 | .filter(ee.Filter.eq("country", "USA")) 84 | ) 85 | df = dask_ee.read_ee(fc) 86 | ``` 87 | 88 | In addition, you may change the `chunksize`, which controls how many rows are included in each 89 | Dask partition. 90 | 91 | ```python 92 | df = dask_ee.read_ee("WRI/GPPD/power_plants", chunksize=7_000) 93 | df.head() 94 | ``` 95 | 96 | ## Contributing 97 | 98 | Contributions are welcome. A good way to start is to check out open [issues](https://github.com/alxmrs/dask-ee/issues) 99 | or file a new one. We're happy to review pull requests, too. 100 | 101 | Before writing code, please install the development dependencies (after cloning the repo): 102 | 103 | ```shell 104 | pip install -e ".[dev]" 105 | ``` 106 | 107 | ## License 108 | 109 | ``` 110 | Copyright 2024 Alexander S Merose 111 | 112 | Licensed under the Apache License, Version 2.0 (the "License"); 113 | you may not use this file except in compliance with the License. 114 | You may obtain a copy of the License at 115 | 116 | https://www.apache.org/licenses/LICENSE-2.0 117 | 118 | Unless required by applicable law or agreed to in writing, software 119 | distributed under the License is distributed on an "AS IS" BASIS, 120 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 121 | See the License for the specific language governing permissions and 122 | limitations under the License. 123 | ``` 124 | 125 | Some sources are re-distributed from Google LLC via https://github.com/google/Xee (also Apache-2.0 License) with and 126 | without modification. These files are subject to the original copyright; they include the original license header 127 | comment as well as a note to indicate modifications (when appropriate). 128 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------