{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "c9db7d7c", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import matplotlib as plt\n", "import datetime as dt\n", "import os\n", "import re" ] }, { "cell_type": "code", "execution_count": null, "id": "a5d5a7f4", "metadata": {}, "outputs": [], "source": [ "# All directories\n", "root = \"C:/Users/freiste/OneDrive - Ilmatieteen laitos/Documents/IIASA YSSP 2023\"\n", "this_dir = os.getcwd()\n", "\n", "input_dir = f\"{root}/03 - Research and ForgetMeNots\"\n", "output_dir = f\"{root}/02 - Data/AUT\"" ] }, { "cell_type": "code", "execution_count": null, "id": "e931169f", "metadata": {}, "outputs": [], "source": [ "# Add more historical data from Dokumentation der Waldschädigungsfaktoren\n", "\n", "file = 'Research_BWF_DokumentationDerWaldschädigungsfaktoren.xlsx'\n", "\n", "DWF = pd.read_excel(f\"{input_dir}/{file}\", header=0, sheet_name='DWF_HistoricalData', usecols='A:I', nrows=15)\n", "DWF = DWF.melt(id_vars='year').rename(columns={'variable':'district', 'value':'beetle_damage (Efm)'})\n", "DWF" ] }, { "cell_type": "code", "execution_count": null, "id": "9788e016", "metadata": {}, "outputs": [], "source": [ "DWF.to_csv(f\"{output_dir}/Data_BWF_DocumentationOfForestdamagefactors\")" ] }, { "cell_type": "code", "execution_count": null, "id": "941ff974", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "8e5b672b", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "10db0a7f", "metadata": {}, "outputs": [], "source": [ "# Opional: Combine with Annual Logging reports" ] }, { "cell_type": "code", "execution_count": null, "id": "ea5354fd", "metadata": {}, "outputs": [], "source": [ "# Missing: load logging reports" ] }, { "cell_type": "code", "execution_count": null, "id": "e2478264", "metadata": {}, "outputs": [], "source": [ "def map_data_to_districts(col_nr, new_col_name):\n", " map_dict = lookup_table[[lookup_table.columns[0], lookup_table.columns[col_nr]]].set_index(lookup_table.columns[0]).to_dict()\n", " \n", " HEM[new_col_name] = HEM['district'].map(map_dict[list(map_dict.keys())[0]])\n", "\n", "col_nrs = [1,2,3,4]\n", "new_col_names = ['state','totarea(km2)','pop(2023)','popdens(ppl/km2)']\n", "\n", "for c, col_nr in enumerate(col_nrs):\n", " new_col_name = new_col_names[c]\n", " map_data_to_districts(col_nr, new_col_name)\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "031d1c34", "metadata": {}, "outputs": [], "source": [ "# Reorder columns\n", "HEM_order1 = ['year', 'state', 'district',\n", " 'totarea(km2)', 'pop(2023)', 'popdens(ppl/km2)',\n", " 'beetle_damage (Efm)', 'storm_damage (Efm)']\n", "HEM = HEM[HEM_order1]\n", "HEM = HEM.sort_values(['state', 'district', 'year'], ascending=(True, True, True)).reset_index(drop=True)" ] } ], "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.5" } }, "nbformat": 4, "nbformat_minor": 5 }