diff --git a/1_prepare_data.ipynb b/1_prepare_data.ipynb index 517ddf53441d7a4196967dc298f065670b00f54f..c4d9a8fe8c1273a1250c4b3099ba50e7595e76dd 100644 --- a/1_prepare_data.ipynb +++ b/1_prepare_data.ipynb @@ -16,8 +16,7 @@ "source": [ "DATADIR = 'era5/' # directory containing downloaded era5 data\n", "FIREDATADIR = 'fire_danger/' # directory containing fire data\n", - "DESTDIR = 'processed_era5/' # directory to save .npy files for each time step and variable\n", - "FIREDESTDIR = 'processed_fire_data/' # directory to save .npy files for each time step and variable for fire data" + "DESTDIR = 'processed_data/' # directory to save .npy files for each time step and variable" ] }, { @@ -54,10 +53,9 @@ "metadata": {}, "outputs": [], "source": [ - "vars = ['u10','v10','t2m','lai_hv','lai_lv','tp'] #considered variables (see 0_download_data.ipynb for long names)\n", + "vars = ['u10','v10','t2m','lai_hv','lai_lv','tp','fdimrk'] #considered variables (see 0_download_data.ipynb for long names)\n", "months = [(1,31),(2,28),(12,31)] # months + days in month in dowloaded era5 .nc files\n", - "years = np.arange(2002,2023) # downloaded years\n", - "fire_vars = ['fdimrk'] # fire data variables" + "years = np.arange(2002,2023) # downloaded years" ] }, { @@ -65,107 +63,25 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Procesar datos ERA5" + "# Procesamiento de datos para crear archivos .npy" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "77f93c51256047b981775b4b6469c9d7", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - " 0%| | 0/21 [00:00<?, ?it/s]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "9a27a43175944c7aad21cf81d8c3b31f", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - " 0%| | 0/21 [00:00<?, ?it/s]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "5ef1a176e6204c19a63852d952442609", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - " 0%| | 0/21 [00:00<?, ?it/s]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "fbf30b91845a4c9bb5ca2ee543ea20ec", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - " 0%| | 0/21 [00:00<?, ?it/s]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "6dc83680a62a42f78ba7cb7e056ac54e", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - " 0%| | 0/21 [00:00<?, ?it/s]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "b4f23446188144a389cf64ca317e40cc", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - " 0%| | 0/21 [00:00<?, ?it/s]" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ - "# Processing ERA5 data\n", + "# Processing Data to create .npy files\n", "for var in vars:\n", " if not os.path.exists(DESTDIR + f\"{var}\"):\n", " os.makedirs(DESTDIR + f\"{var}\")\n", " \n", " for year in tqdm(years):\n", - " root = nc.Dataset(DATADIR + f\"{year:d}.nc\", 'r')\n", + " if var=='fdimrk':\n", + " root = nc.Dataset(FIREDATADIR + f\"{year:d}.nc\", 'r')\n", + " else:\n", + " root = nc.Dataset(DATADIR + f\"{year:d}.nc\", 'r')\n", " v = root.variables[var][:,:-9,:-5] #crop to get to a size suitable for the considered Unet-like model, here 140x140\n", " v = v.data\n", " root.close()\n", @@ -186,44 +102,6 @@ "# Procesar datos de Ãndice de peligro de incendio" ] }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "b3a75dfe23fa44d7a96e2ff92f9ed211", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - " 0%| | 0/21 [00:00<?, ?it/s]" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "# Processing Fire danger index data\n", - "for var in fire_vars:\n", - " if not os.path.exists(FIREDESTDIR + f\"{var}\"):\n", - " os.makedirs(FIREDESTDIR + f\"{var}\")\n", - " \n", - " for year in tqdm(years):\n", - " root = nc.Dataset(FIREDATADIR + f\"{year:d}.nc\", 'r')\n", - " v = root.variables[var][:,:-9,:-5] #crop to get to a size suitable for the considered Unet-like model, here 140x140\n", - " v = v.data\n", - " root.close()\n", - " t = 0 # time step within v array that I am working on\n", - " for month, days in months:\n", - " for day in range(days):\n", - " np.save(FIREDESTDIR + f\"{var}/{year}_{month:02d}_{day+1:02d}.npy\",v[t])\n", - " t += 1" - ] - }, { "attachments": {}, "cell_type": "markdown",