romero61 commited on
Commit
37138d8
β€’
0 Parent(s):

Duplicate from romero61/solara-geemap-template

Browse files
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
.github/workflows/sync-hf.yml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync to Hugging Face hub
2
+ on:
3
+ push:
4
+ branches: [main]
5
+
6
+ # to run this workflow manually from the Actions tab
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ sync-to-hub:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v3
14
+ with:
15
+ fetch-depth: 0
16
+ lfs: true
17
+ - name: Push to hub
18
+ env:
19
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
20
+ run: git push --force https://giswqs:$HF_TOKEN@huggingface.co/spaces/giswqs/solara-geemap main
.gitignore ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ private/
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .nox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *.cover
50
+ *.py,cover
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ cover/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+
75
+ # PyBuilder
76
+ .pybuilder/
77
+ target/
78
+
79
+ # Jupyter Notebook
80
+ .ipynb_checkpoints
81
+
82
+ # IPython
83
+ profile_default/
84
+ ipython_config.py
85
+
86
+ # pyenv
87
+ # For a library or package, you might want to ignore these files since the code is
88
+ # intended to run in multiple environments; otherwise, check them in:
89
+ # .python-version
90
+
91
+ # pipenv
92
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
94
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
95
+ # install all needed dependencies.
96
+ #Pipfile.lock
97
+
98
+ # poetry
99
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
100
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
101
+ # commonly ignored for libraries.
102
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
103
+ #poetry.lock
104
+
105
+ # pdm
106
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
107
+ #pdm.lock
108
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
109
+ # in version control.
110
+ # https://pdm.fming.dev/#use-with-ide
111
+ .pdm.toml
112
+
113
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
114
+ __pypackages__/
115
+
116
+ # Celery stuff
117
+ celerybeat-schedule
118
+ celerybeat.pid
119
+
120
+ # SageMath parsed files
121
+ *.sage.py
122
+
123
+ # Environments
124
+ .env
125
+ .venv
126
+ env/
127
+ venv/
128
+ ENV/
129
+ env.bak/
130
+ venv.bak/
131
+
132
+ # Spyder project settings
133
+ .spyderproject
134
+ .spyproject
135
+
136
+ # Rope project settings
137
+ .ropeproject
138
+
139
+ # mkdocs documentation
140
+ /site
141
+
142
+ # mypy
143
+ .mypy_cache/
144
+ .dmypy.json
145
+ dmypy.json
146
+
147
+ # Pyre type checker
148
+ .pyre/
149
+
150
+ # pytype static type analyzer
151
+ .pytype/
152
+
153
+ # Cython debug symbols
154
+ cython_debug/
155
+
156
+ # PyCharm
157
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
158
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
159
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
160
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
161
+ #.idea/
Dockerfile ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM jupyter/base-notebook:latest
2
+
3
+ RUN mamba install -c conda-forge leafmap geopandas localtileserver -y && \
4
+ fix-permissions "${CONDA_DIR}" && \
5
+ fix-permissions "/home/${NB_USER}"
6
+
7
+ COPY requirements.txt .
8
+ RUN pip install -r requirements.txt
9
+
10
+ RUN mkdir ./pages
11
+ COPY /pages ./pages
12
+
13
+ ENV PROJ_LIB='/opt/conda/share/proj'
14
+
15
+ USER root
16
+ RUN chown -R ${NB_UID} ${HOME}
17
+ USER ${NB_USER}
18
+
19
+ EXPOSE 8765
20
+
21
+ CMD ["solara", "run", "./pages", "--host=0.0.0.0"]
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Open Geospatial Solutions
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Solara Geemap Template
3
+ emoji: πŸƒ
4
+ colorFrom: gray
5
+ colorTo: red
6
+ sdk: docker
7
+ pinned: false
8
+ license: mit
9
+ app_port: 8765
10
+ duplicated_from: romero61/solara-geemap-template
11
+ ---
12
+
13
+ ## Earth Engine Web Apps
14
+
15
+ ### Introduction
16
+
17
+ **A collection of Earth Engine web apps developed using [Solara](https://github.com/widgetti/solara) and geemap**
18
+
19
+ - Web App: <https://giswqs-solara-geemap.hf.space>
20
+ - GitHub: <https://github.com/opengeos/solara-geemap>
21
+ - Hugging Face: <https://huggingface.co/spaces/giswqs/solara-geemap>
22
+
23
+ ### How to deploy this app on Hugging Face Spaces
24
+
25
+ 1. Go to <https://huggingface.co/spaces/giswqs/solara-geemap/tree/main> and duplicate the space to your own space.
26
+
27
+ ![](https://i.imgur.com/gTg4V2x.png)
28
+
29
+ 2. You need to set `EARTHENGINE_TOKEN` in order to use Earth Engine. The token value should be copied from the following file depending on your operating system:
30
+
31
+ ```text
32
+ Windows: C:\\Users\\USERNAME\\.config\\earthengine\\credentials
33
+ Linux: /home/USERNAME/.config/earthengine/credentials
34
+ MacOS: /Users/USERNAME/.config/earthengine/credentials
35
+ ```
36
+
37
+ Simply open the file and copy **ALL** the content to the `EARTHENGINE_TOKEN` environment variable.
38
+
39
+ ![](https://i.imgur.com/i04gzyH.png)
40
+
41
+ ![](https://i.imgur.com/Ex37Ut7.png)
42
+
43
+ Alternatively, you can run the following code to retrieve your Earth Engine token:
44
+
45
+ ```python
46
+ import geemap
47
+ geemap.get_ee_token()
48
+ ```
49
+
50
+ Copy all the content of the printed token and set it as the `EARTHENGINE_TOKEN` environment variable.
51
+
52
+ 3. After the space is built successfully, click the `Embed this Space` menu and find the `Direct URL` for the app, such as <https://giswqs-solara-geemap.hf.space>.
53
+
54
+ ![](https://i.imgur.com/DNM36sk.png)
55
+
56
+ ![](https://i.imgur.com/KX82lSf.png)
57
+
58
+ 4. Add your own apps (\*.py) to the `pages` folder.
59
+ 5. Commit and push your changes to the repository. Wait for the space to be built successfully.
pages/00_home.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import solara
2
+
3
+
4
+ @solara.component
5
+ def Page():
6
+ with solara.Column(align="center"):
7
+ markdown = """
8
+ ## Earth Engine Web Apps
9
+
10
+ ### Introduction
11
+
12
+ **A collection of Earth Engine web apps developed using [Solara](https://github.com/widgetti/solara) and geemap**
13
+
14
+ - Web App: <https://giswqs-solara-geemap.hf.space>
15
+ - GitHub: <https://github.com/opengeos/solara-geemap>
16
+ - Hugging Face: <https://huggingface.co/spaces/giswqs/solara-geemap>
17
+
18
+
19
+ ### How to deploy this app on Hugging Face Spaces
20
+
21
+ 1. Go to <https://huggingface.co/spaces/giswqs/solara-geemap/tree/main> and duplicate the space to your own space.
22
+
23
+ ![](https://i.imgur.com/gTg4V2x.png)
24
+
25
+ 2. You need to set `EARTHENGINE_TOKEN` in order to use Earth Engine. The token value should be copied from the following file depending on your operating system:
26
+
27
+ ```text
28
+ Windows: C:\\Users\\USERNAME\\.config\\earthengine\\credentials
29
+ Linux: /home/USERNAME/.config/earthengine/credentials
30
+ MacOS: /Users/USERNAME/.config/earthengine/credentials
31
+ ```
32
+
33
+ Simply open the file and copy **ALL** the content to the `EARTHENGINE_TOKEN` environment variable.
34
+
35
+ ![](https://i.imgur.com/i04gzyH.png)
36
+
37
+ ![](https://i.imgur.com/Ex37Ut7.png)
38
+
39
+
40
+ ```python
41
+ import geemap
42
+ geemap.get_ee_token()
43
+ ```
44
+
45
+ Copy all the content of the printed token and set it as the `EARTHENGINE_TOKEN` environment variable.
46
+
47
+ 3. After the space is built successfully, click the `Embed this Space` menu and find the `Direct URL` for the app, such as <https://giswqs-solara-geemap.hf.space>.
48
+
49
+ ![](https://i.imgur.com/DNM36sk.png)
50
+
51
+ ![](https://i.imgur.com/KX82lSf.png)
52
+
53
+ 4. Add your own apps (*.py) to the `pages` folder.
54
+
55
+ 5. Commit and push your changes to the repository. Wait for the space to be built successfully.
56
+
57
+ """
58
+
59
+ solara.Markdown(markdown)
pages/02_inspector.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ee
2
+ import geemap
3
+
4
+ import solara
5
+
6
+
7
+ class Map(geemap.Map):
8
+ def __init__(self, **kwargs):
9
+ super().__init__(**kwargs)
10
+ self.add_ee_data()
11
+ self.add_layer_manager()
12
+ self.add_inspector()
13
+
14
+ def add_ee_data(self):
15
+ # Add Earth Engine dataset
16
+ dem = ee.Image('USGS/SRTMGL1_003')
17
+ landsat7 = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003').select(
18
+ ['B1', 'B2', 'B3', 'B4', 'B5', 'B7']
19
+ )
20
+ states = ee.FeatureCollection("TIGER/2018/States")
21
+
22
+ # Set visualization parameters.
23
+ vis_params = {
24
+ 'min': 0,
25
+ 'max': 4000,
26
+ 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],
27
+ }
28
+
29
+ # Add Earth Engine layers to Map
30
+ self.addLayer(
31
+ landsat7,
32
+ {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200, 'gamma': 2.0},
33
+ 'Landsat 7',
34
+ True,
35
+ )
36
+ self.addLayer(dem, vis_params, 'SRTM DEM', True, 1)
37
+ self.addLayer(states, {}, "US States")
38
+
39
+
40
+ @solara.component
41
+ def Page():
42
+ with solara.Column(style={"min-width": "500px"}):
43
+ Map.element(
44
+ center=[40, -100],
45
+ zoom=4,
46
+ height="800px",
47
+ )
pages/03_plotting.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ee
2
+ import geemap
3
+
4
+ import solara
5
+
6
+
7
+ class Map(geemap.Map):
8
+ def __init__(self, **kwargs):
9
+ super().__init__(**kwargs)
10
+ self.add_ee_data()
11
+ self.add_plot_gui()
12
+
13
+ def add_ee_data(self):
14
+ landsat7 = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003').select(
15
+ ['B1', 'B2', 'B3', 'B4', 'B5', 'B7']
16
+ )
17
+
18
+ landsat_vis = {'bands': ['B4', 'B3', 'B2'], 'gamma': 1.4}
19
+ self.addLayer(landsat7, landsat_vis, "Landsat")
20
+
21
+ hyperion = ee.ImageCollection('EO1/HYPERION').filter(
22
+ ee.Filter.date('2016-01-01', '2017-03-01')
23
+ )
24
+
25
+ hyperion_vis = {
26
+ 'min': 1000.0,
27
+ 'max': 14000.0,
28
+ 'gamma': 2.5,
29
+ }
30
+ self.addLayer(hyperion, hyperion_vis, 'Hyperion')
31
+
32
+
33
+ @solara.component
34
+ def Page():
35
+ with solara.Column(style={"min-width": "500px"}):
36
+ Map.element(
37
+ center=[40, -100],
38
+ zoom=4,
39
+ height="800px",
40
+ )
pages/04_split_map.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ee
2
+ import geemap
3
+
4
+ import solara
5
+
6
+
7
+ class Map(geemap.Map):
8
+ def __init__(self, **kwargs):
9
+ super().__init__(**kwargs)
10
+ self.add_ee_data()
11
+
12
+ def add_ee_data(self):
13
+ # Select the eight NLCD epochs after 2000.
14
+ years = ['2001', '2004', '2006', '2008', '2011', '2013', '2016', '2019']
15
+
16
+ # Get an NLCD image by year.
17
+ def getNLCD(year):
18
+ # Import the NLCD collection.
19
+ dataset = ee.ImageCollection('USGS/NLCD_RELEASES/2019_REL/NLCD')
20
+
21
+ # Filter the collection by year.
22
+ nlcd = dataset.filter(ee.Filter.eq('system:index', year)).first()
23
+
24
+ # Select the land cover band.
25
+ landcover = nlcd.select('landcover')
26
+ return landcover
27
+
28
+ ## Create an NLCD image collection for the selected years.
29
+ collection = ee.ImageCollection(ee.List(years).map(lambda year: getNLCD(year)))
30
+
31
+ # Create a list of labels to populate the dropdown list.
32
+ labels = [f'NLCD {year}' for year in years]
33
+
34
+ # Add a split-panel map for visualizing NLCD land cover change.
35
+ self.ts_inspector(
36
+ left_ts=collection,
37
+ right_ts=collection,
38
+ left_names=labels,
39
+ right_names=labels,
40
+ )
41
+
42
+ # Add the NLCD legend to the map.
43
+ self.add_legend(
44
+ title='NLCD Land Cover Type', builtin_legend='NLCD', height="460px", add_header=False
45
+ )
46
+
47
+
48
+ @solara.component
49
+ def Page():
50
+ with solara.Column(style={"min-width": "500px"}):
51
+ Map.element(
52
+ center=[40, -100],
53
+ zoom=4,
54
+ height="800px",
55
+ )
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ geemap
2
+ solara
3
+ geopandas
4
+ pydantic< 2.0