-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add examples from GEM hackathon (#36)
- Loading branch information
1 parent
2600caa
commit 9a0c803
Showing
6 changed files
with
30,086 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM obarrilero/notebook:latest | ||
|
||
USER jovyan | ||
# Make sure the contents of our repo are in ${HOME} | ||
COPY --chown=jovyan:users . ${HOME} |
3,017 changes: 3,017 additions & 0 deletions
3,017
GEM-hackathon-2023-satcen/Exercise2_Meteo_EO_data.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
26,915 changes: 26,915 additions & 0 deletions
26,915
GEM-hackathon-2023-satcen/Exercise_1_webinar.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# gem-hackathon-2023 | ||
|
||
|
||
## Run the notebook on Binder | ||
|
||
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/alunacob/gem-hackathon-2023/main?urlpath=lab) | ||
|
||
## Run the notebook locally using docker | ||
|
||
Clone this repository with: | ||
|
||
```bash | ||
git clone https://github.com/alunacob/gem-hackathon-2023.git | ||
``` | ||
|
||
Go to the directory containing the cloned repository: | ||
|
||
```bash | ||
cd gem-hackathon-2023 | ||
``` | ||
|
||
Use docker compose to build the docker image: | ||
|
||
```bash | ||
docker-compose build | ||
``` | ||
|
||
This step can take a few minutes... | ||
|
||
Finally run the docker with: | ||
|
||
``` | ||
docker-compose up | ||
``` | ||
|
||
Open a browser window at the address http://0.0.0.0:9005 or http://127.0.0.1:9005 and run the notebook | ||
|
||
## About the hackathon | ||
|
||
### Description: | ||
|
||
|
||
### Tentative Agenda: | ||
|
||
|
||
|
||
### Requirements: | ||
This [Binder](https://mybinder.readthedocs.io/en/latest/introduction.html#what-is-a-binder) repository was set up so that you can participate with no pre-requirement to be installed on your side. | ||
However, the notebook must target a computing environment with 2 GB of RAM. After some inactivity, the docker container is culled. Access to a web browser should be enough for your successful participation. | ||
|
||
### Target Participants: | ||
Students, Software developers, Data scientists, EO-developers, anyone with an interest in the topic. | ||
|
||
### Time requirements: | ||
|
||
45 minutes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import folium | ||
# import matplotlib | ||
import matplotlib.pyplot as plt | ||
import matplotlib | ||
from matplotlib.colors import BoundaryNorm, ListedColormap | ||
from matplotlib.patches import Polygon as plt_polygon | ||
import numpy as np | ||
from aenum import MultiValueEnum | ||
|
||
|
||
from IPython.core.display import display, HTML | ||
|
||
|
||
def evalscript_template(bands, sample_type): | ||
evaluate_pixel = ", ".join(f"sample.{band}" for band in bands) | ||
return f""" | ||
//VERSION=3 | ||
function setup() {{ | ||
return {{ | ||
input: {bands}, | ||
output: [ | ||
{{ | ||
id: "bands", | ||
bands: {len(bands)}, | ||
sampleType: "{sample_type}" | ||
}} | ||
] | ||
}}; | ||
}} | ||
function evaluatePixel(sample) {{ | ||
return [{evaluate_pixel}]; | ||
}} | ||
""" | ||
|
||
|
||
def plot_tiff_folium(data, bounds, variable_name): | ||
ymin, xmin, ymax, xmax = list(bounds) | ||
m = folium.Map(location=[(xmin+xmax)/2, (ymin+ymax)/2], zoom_start=5, control_scale=True) | ||
folium.raster_layers.ImageOverlay( | ||
#name=month, | ||
image=data, | ||
bounds=[[xmin, ymin], [xmax, ymax]], | ||
opacity=0.9, | ||
mercator_project=True, | ||
colormap=plt.cm.Reds if variable_name == 'TEMPERATURE' else plt.cm.Blues, | ||
control=True | ||
).add_to(m) | ||
return m | ||
|
||
def plot_multiple_foliums(maps, size_x, size_y): | ||
template = '<iframe srcdoc="{}" style="float:left; width: {}px; height: {}px; display:inline-block; width: 50%; margin: 0 auto; border: 2px solid black"></iframe>' | ||
html_map = '' | ||
for i, m in enumerate(maps): | ||
html_map = html_map + template.format(m.get_root().render().replace('"', '"'),size_x,size_y) | ||
return HTML(html_map) | ||
|
||
|
||
class EWC(MultiValueEnum): | ||
"""Enum class containing basic LULC EWC types""" | ||
|
||
NO_DATA = "No data", 0, "black" | ||
TREE_COVER = "Tree cover", 10, "darkgreen" | ||
SHRUBLAND = "Shrubland", 20, "orange" | ||
GRASSLAND = "Grassland", 30, "yellow" | ||
CROPLAND = "Cropland", 40, "violet" | ||
BUILT_UP = "Built up", 50, "red" | ||
BARE_SPARSE_VEGETATION = "Bare /sparse vegetation", 60, "dimgrey" | ||
SNOW_ICE = "Snow and Ice", 70, "silver" | ||
PERMANENT_WATER_BODIES = "Permanent water bodies", 80, "blue" | ||
HERBACEOUS_WETLAND = "Herbaceous wetland", 90, "darkcyan" | ||
MANGROVES = "Mangroves", 95, "springgreen" | ||
MOSS_LICHEN = "Moss and lichen", 100, "khaki" | ||
|
||
def construct_cmap(colors, data, name="cmap"): | ||
sub = [] | ||
un = np.unique(data) | ||
for i, entry in enumerate(colors): | ||
if np.isin(entry.values[1], un): | ||
sub.append([entry.values[0], entry.values[1], entry.values[2]]) | ||
bounds = [sub[0][1] - 0.5] | ||
[bounds.append((0.5 + entry[1])) for entry in sub] | ||
ticks = [np.mean([bounds[i], bounds[i - 1]]) for i in range(1, len(bounds))] | ||
cmap = ListedColormap([rgb_int(entry) for entry in sub], name=name) | ||
norm = BoundaryNorm(bounds, cmap.N) | ||
labels = [entry[0] for entry in sub] | ||
|
||
return cmap, norm, ticks, labels | ||
|
||
def rgb_int(row): | ||
hex_val = row[2] | ||
rgb_val = matplotlib.colors.to_rgb(hex_val) | ||
return rgb_val |
Empty file.