Spaces:
Sleeping
Sleeping
Commit
·
925969f
1
Parent(s):
507d98b
Upload gee_interactive_map.ipynb
Browse files
notebooks/gee_interactive_map.ipynb
ADDED
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"attachments": {},
|
5 |
+
"cell_type": "markdown",
|
6 |
+
"metadata": {},
|
7 |
+
"source": [
|
8 |
+
"# Cargar TerraClimate y geometria de México"
|
9 |
+
]
|
10 |
+
},
|
11 |
+
{
|
12 |
+
"cell_type": "code",
|
13 |
+
"execution_count": 1,
|
14 |
+
"metadata": {},
|
15 |
+
"outputs": [
|
16 |
+
{
|
17 |
+
"data": {
|
18 |
+
"application/vnd.jupyter.widget-view+json": {
|
19 |
+
"model_id": "e9cedd8043c54aceb1d5e8d381b4bcd0",
|
20 |
+
"version_major": 2,
|
21 |
+
"version_minor": 0
|
22 |
+
},
|
23 |
+
"text/plain": [
|
24 |
+
"Map(center=[23.916287330629192, -102.18542161782723], controls=(WidgetControl(options=['position', 'transparen…"
|
25 |
+
]
|
26 |
+
},
|
27 |
+
"metadata": {},
|
28 |
+
"output_type": "display_data"
|
29 |
+
}
|
30 |
+
],
|
31 |
+
"source": [
|
32 |
+
"import ee\n",
|
33 |
+
"import geemap\n",
|
34 |
+
"\n",
|
35 |
+
"# Carga de Terra Climate y declaracion de parámetros\n",
|
36 |
+
"img_coll = ee.ImageCollection(\"IDAHO_EPSCOR/TERRACLIMATE\")\n",
|
37 |
+
"scale_img_coll = 4638.3\n",
|
38 |
+
"img_coll_start_year = 1958 # Empezando en Enero\n",
|
39 |
+
"img_coll_end_year = 2022 # Terminando en Diciembre\n",
|
40 |
+
"\n",
|
41 |
+
"# Geometria de México\n",
|
42 |
+
"fc_polygons_countries = ee.FeatureCollection(\"USDOS/LSIB/2017\")\n",
|
43 |
+
"geom_mexico = fc_polygons_countries.filter(ee.Filter.eq(\"COUNTRY_NA\",\"Mexico\")).first().geometry()\n",
|
44 |
+
"\n",
|
45 |
+
"# Banda de interés\n",
|
46 |
+
"banda_interes = \"pdsi\"\n",
|
47 |
+
"\n",
|
48 |
+
"# Escalar a unidades \"reales\"\n",
|
49 |
+
"def scalling_funcion_pdsi(img):\n",
|
50 |
+
" return img.multiply(0.01).copyProperties(img, img.propertyNames())\n",
|
51 |
+
"\n",
|
52 |
+
"# Dar como propiedad a la imagen: date_month y date_year\n",
|
53 |
+
"def create_month_year(img):\n",
|
54 |
+
" full_date = ee.Date(ee.Number(img.get(\"system:time_start\")))\n",
|
55 |
+
" date_year = ee.Number(full_date.get(\"year\"))\n",
|
56 |
+
" date_month = ee.Number(full_date.get(\"month\"))\n",
|
57 |
+
" return img.set({\"date_month\": date_month, \"date_year\": date_year})\n",
|
58 |
+
"\n",
|
59 |
+
"\n",
|
60 |
+
"# Cargar datos, seleccionar banda, escalarlos y limitarlos a la mexico\n",
|
61 |
+
"img_coll_pdsi = img_coll.select(banda_interes).filterBounds(geom_mexico).map(scalling_funcion_pdsi)\n",
|
62 |
+
"\n",
|
63 |
+
"# Etiquetar date_month y date_year como prop de la imagen\n",
|
64 |
+
"img_coll_pdsi_tag_month_year = img_coll_pdsi.map(create_month_year)#.map(lambda img: img.clip(geom_mexico))\n",
|
65 |
+
"\n",
|
66 |
+
"\"\"\"\n",
|
67 |
+
"# Crear una ImageCollection con n Images de a 12 bandas cada una.\n",
|
68 |
+
"# n -> numero de años que tenga la ImageCollection\n",
|
69 |
+
"# 12 bandas -> 1 banda = 1 mes\n",
|
70 |
+
"list_new_collection_by_year = ee.List.sequence(img_coll_start_year, img_coll_end_year)\\\n",
|
71 |
+
" .map(\n",
|
72 |
+
" lambda element: img_coll_pdsi_tag_month_year\\\n",
|
73 |
+
" .filter(ee.Filter.eq(\"date_year\", element))\\\n",
|
74 |
+
" .toBands()\\\n",
|
75 |
+
" .set({\"date_year\": element})\\\n",
|
76 |
+
" .rename(list(map(lambda x: '0'+str(x) if x <=9 else str(x), range(1,13))))\n",
|
77 |
+
" )\n",
|
78 |
+
"\n",
|
79 |
+
"final_data_img_coll = ee.ImageCollection.fromImages(list_new_collection_by_year)\n",
|
80 |
+
"img_coll_2_geemap = final_data_img_coll.toBands()\"\"\"\n",
|
81 |
+
"\n",
|
82 |
+
"\n",
|
83 |
+
"labels_dates = list()\n",
|
84 |
+
"for year in range(1958,2023):\n",
|
85 |
+
" for month in list(map(lambda x: '0'+str(x) if x <= 9 else str(x), range(1,13))):\n",
|
86 |
+
" date_year_month_str = str(year) + \"-\" + month + \"-01\"\n",
|
87 |
+
" labels_dates.append(date_year_month_str)\n",
|
88 |
+
"\n",
|
89 |
+
"mapVisParamsPDSI = dict(min = -5, max = 5, palette = [\"FB322C\", \"FFFFFF\", \"039DAB\"])\n",
|
90 |
+
"\n",
|
91 |
+
"\n",
|
92 |
+
"Mapa = geemap.Map(basemap = \"CartoDB.DarkMatter\")\n",
|
93 |
+
"Mapa.center_object(geom_mexico, 5)\n",
|
94 |
+
"Mapa.add_time_slider(img_coll_pdsi_tag_month_year, mapVisParamsPDSI,\n",
|
95 |
+
" layer_name = \"Índice de Severidad de Sequía de Palmer\",\n",
|
96 |
+
" labels = labels_dates,\n",
|
97 |
+
" position='bottomleft',\n",
|
98 |
+
" slider_length = \"300px\",\n",
|
99 |
+
" time_interval=1)\n",
|
100 |
+
"Mapa\n"
|
101 |
+
]
|
102 |
+
},
|
103 |
+
{
|
104 |
+
"cell_type": "code",
|
105 |
+
"execution_count": null,
|
106 |
+
"metadata": {},
|
107 |
+
"outputs": [],
|
108 |
+
"source": []
|
109 |
+
}
|
110 |
+
],
|
111 |
+
"metadata": {
|
112 |
+
"kernelspec": {
|
113 |
+
"display_name": "Python 3 (ipykernel)",
|
114 |
+
"language": "python",
|
115 |
+
"name": "python3"
|
116 |
+
},
|
117 |
+
"language_info": {
|
118 |
+
"codemirror_mode": {
|
119 |
+
"name": "ipython",
|
120 |
+
"version": 3
|
121 |
+
},
|
122 |
+
"file_extension": ".py",
|
123 |
+
"mimetype": "text/x-python",
|
124 |
+
"name": "python",
|
125 |
+
"nbconvert_exporter": "python",
|
126 |
+
"pygments_lexer": "ipython3",
|
127 |
+
"version": "3.8.15"
|
128 |
+
}
|
129 |
+
},
|
130 |
+
"nbformat": 4,
|
131 |
+
"nbformat_minor": 4
|
132 |
+
}
|