Spaces:
Sleeping
Sleeping
File size: 3,698 Bytes
925969f 2b4c3af 925969f 773572e 925969f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e9cedd8043c54aceb1d5e8d381b4bcd0",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[23.916287330629192, -102.18542161782723], controls=(WidgetControl(options=['position', 'transparen…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import ee\n",
"ee.Initialize()\n",
"import geemap\n",
"\n",
"# Carga de Terra Climate y declaracion de parámetros\n",
"img_coll = ee.ImageCollection(\"IDAHO_EPSCOR/TERRACLIMATE\")\n",
"scale_img_coll = 4638.3\n",
"img_coll_start_year = 1958 # Empezando en Enero\n",
"img_coll_end_year = 2022 # Terminando en Diciembre\n",
"\n",
"# Geometria de México\n",
"fc_polygons_countries = ee.FeatureCollection(\"USDOS/LSIB/2017\")\n",
"geom_mexico = fc_polygons_countries.filter(ee.Filter.eq(\"COUNTRY_NA\",\"Mexico\")).first().geometry()\n",
"\n",
"# Banda de interés\n",
"banda_interes = \"pdsi\"\n",
"\n",
"# Escalar a unidades \"reales\"\n",
"def scalling_funcion_pdsi(img):\n",
" return img.multiply(0.01).copyProperties(img, img.propertyNames())\n",
"\n",
"# Dar como propiedad a la imagen: date_month y date_year\n",
"def create_month_year(img):\n",
" full_date = ee.Date(ee.Number(img.get(\"system:time_start\")))\n",
" date_year = ee.Number(full_date.get(\"year\"))\n",
" date_month = ee.Number(full_date.get(\"month\"))\n",
" return img.set({\"date_month\": date_month, \"date_year\": date_year})\n",
"\n",
"\n",
"# Cargar datos, seleccionar banda, escalarlos y limitarlos a la mexico\n",
"img_coll_pdsi = img_coll.select(banda_interes).filterBounds(geom_mexico).map(scalling_funcion_pdsi)\n",
"\n",
"# Etiquetar date_month y date_year como prop de la imagen\n",
"img_coll_pdsi_tag_month_year = img_coll_pdsi.map(create_month_year)#.map(lambda img: img.clip(geom_mexico))\n",
"\n",
"labels_dates = list()\n",
"for year in range(1958,2023):\n",
" for month in list(map(lambda x: '0'+str(x) if x <= 9 else str(x), range(1,13))):\n",
" date_year_month_str = str(year) + \"-\" + month + \"-01\"\n",
" labels_dates.append(date_year_month_str)\n",
"\n",
"mapVisParamsPDSI = dict(min = -5, max = 5, palette = [\"FB322C\", \"FFFFFF\", \"039DAB\"])\n",
"\n",
"Mapa = geemap.Map(center=(22, -100), zoom=4, height='800px', basemap = \"CartoDB.DarkMatter\")\n",
"Mapa.center_object(geom_mexico, 5)\n",
"Mapa.add_time_slider(img_coll_pdsi_tag_month_year, mapVisParamsPDSI,\n",
" layer_name = \"Índice de Severidad de Sequía de Palmer\",\n",
" labels = labels_dates,\n",
" position='bottomleft',\n",
" slider_length = \"300px\",\n",
" time_interval=1)\n",
"Mapa\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.15"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
|