diff --git a/CIM outputs.ipynb b/CIM outputs.ipynb deleted file mode 100755 index 2d64da5..0000000 --- a/CIM outputs.ipynb +++ /dev/null @@ -1,105 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - " Script prepared by Dr. Dasaraden Mauree \n", - " Contact: EPFL \n", - " dasaraden.mauree@epfl.ch / dasaraden.mauree@gmail.com \n", - " \n", - " Use this script to read Profils.csv from CIM, select \n", - " specific rows and create new file." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#importing necessary packages\n", - "\n", - "import pandas as pd\n", - "import numpy as np\n", - "import time\n", - "import math\n", - "import matplotlib.pyplot as plt\n", - "import matplotlib.dates as dates\n", - "%matplotlib inline \n", - "from datetime import datetime, timedelta\n", - "from IPython.core.interactiveshell import InteractiveShell\n", - "InteractiveShell.ast_node_interactivity = \"all\"\n", - "\n", - "#Opening file and saving in array\n", - "profils=pd.read_csv(\"confluence/v2/Profils_july.csv\", header=\"infer\", sep=\";\", names = [\"z\", \"u\", \"v\", \"pt\", \"tke\"])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#Selecting data\n", - "cf=profils[profils['z']==7.5]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "#Computing horizontal wind speed and air temperature (°C)\n", - "cf['U (m s$^{-1}$)']=(cf['u']**(2)+cf['v']**(2))**(1/2)\n", - "cf['Air Temp. (°C)']=cf['pt']-273.15" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cf=cf.drop(['u', 'v','pt', 'tke'], axis=1)\n", - "cf=cf.round(1)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "#Printing output in txt file\n", - "cf.to_csv(r'cf_results_july.txt', header=None, sep=' ', mode='a')" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python [default]", - "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.5.2" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/CIM/CIM outputs.ipynb b/CIM/CIM outputs.ipynb deleted file mode 100755 index 2d64da5..0000000 --- a/CIM/CIM outputs.ipynb +++ /dev/null @@ -1,105 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - " Script prepared by Dr. Dasaraden Mauree \n", - " Contact: EPFL \n", - " dasaraden.mauree@epfl.ch / dasaraden.mauree@gmail.com \n", - " \n", - " Use this script to read Profils.csv from CIM, select \n", - " specific rows and create new file." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#importing necessary packages\n", - "\n", - "import pandas as pd\n", - "import numpy as np\n", - "import time\n", - "import math\n", - "import matplotlib.pyplot as plt\n", - "import matplotlib.dates as dates\n", - "%matplotlib inline \n", - "from datetime import datetime, timedelta\n", - "from IPython.core.interactiveshell import InteractiveShell\n", - "InteractiveShell.ast_node_interactivity = \"all\"\n", - "\n", - "#Opening file and saving in array\n", - "profils=pd.read_csv(\"confluence/v2/Profils_july.csv\", header=\"infer\", sep=\";\", names = [\"z\", \"u\", \"v\", \"pt\", \"tke\"])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#Selecting data\n", - "cf=profils[profils['z']==7.5]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "#Computing horizontal wind speed and air temperature (°C)\n", - "cf['U (m s$^{-1}$)']=(cf['u']**(2)+cf['v']**(2))**(1/2)\n", - "cf['Air Temp. (°C)']=cf['pt']-273.15" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cf=cf.drop(['u', 'v','pt', 'tke'], axis=1)\n", - "cf=cf.round(1)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "#Printing output in txt file\n", - "cf.to_csv(r'cf_results_july.txt', header=None, sep=' ', mode='a')" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python [default]", - "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.5.2" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/Read_cli_citysim_v1.ipynb b/Read_cli_citysim_v1.ipynb new file mode 100644 index 0000000..5ccc6ec --- /dev/null +++ b/Read_cli_citysim_v1.ipynb @@ -0,0 +1,76 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Preparing climate file for CIM" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " Script prepared by Dr. Dasaraden Mauree \n", + " Contact: EPFL \n", + " dasaraden.mauree@epfl.ch / dasaraden.mauree@gmail.com \n", + " \n", + " use this script to read the standard climate file from\n", + " Meteonorm for CitySim and save new file for CIM. " + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "#importing necessary packages\n", + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "#Opening file and saving in array\n", + "meteonorm=pd.read_csv(\"Ecublens.cli\", header=\"infer\", sep=\"\\s+\", encoding = \"ISO-8859-1\", skiprows=3)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "#Selecting columns and saving in file for CIM\n", + "cim=meteonorm[['Ta','FF','DD','RH']]\n", + "cim.to_csv(r'for_cim.cli', header=None, sep=' ', mode='a', index=False)" + ] + } + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "Python 3", + "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.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/canopy.dbx b/canopy.dbx new file mode 100755 index 0000000..5f36c3c Binary files /dev/null and b/canopy.dbx differ diff --git a/citysim-SW_buil_surf_v1.ipynb b/citysim-SW_buil_surf_v1.ipynb new file mode 100644 index 0000000..4f94e9e --- /dev/null +++ b/citysim-SW_buil_surf_v1.ipynb @@ -0,0 +1,403 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " Script prepared by Dr. Dasaraden Mauree \n", + " Contact: EPFL \n", + " dasaraden.mauree@epfl.ch / dasaraden.mauree@gmail.com \n", + " \n", + " use this script to read surface temperature data \n", + " from CitySim and calculate the hourly mean data \n", + " for each direction and then used as input for CIM. " + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#importing necessary packages\n", + "\n", + "import pandas as pd\n", + "import numpy as np\n", + "import time\n", + "import math\n", + "import matplotlib.pyplot as plt\n", + "import matplotlib.dates as dates\n", + "%matplotlib inline \n", + "from datetime import datetime, timedelta\n", + "from IPython.core.interactiveshell import InteractiveShell\n", + "InteractiveShell.ast_node_interactivity = \"all\"\n", + "\n", + "#Opening file and saving in array\n", + "buil_surf=pd.read_csv(\"jonction/jonction_vitrage_standard_VF.out\", header=\"infer\", sep=\"\t\", encoding = \"ISO-8859-1\")\n", + "buil_surf=buil_surf.T" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "buil_surf.index.name = 'ID'\n", + "buil_surf=buil_surf.reset_index()" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#selecting only the columns corresponding to building surfaces\n", + "buil_surf=buil_surf[buil_surf['ID'].str.contains(\"NA\")==False]\n", + "buil_surf=buil_surf[buil_surf['ID'].str.contains(\"TREE\")==False]\n", + "buil_surf=buil_surf[buil_surf['ID'].str.contains(\"Pedestrian\")==False]\n", + "buil_surf=buil_surf.T" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "buil_surf.columns = buil_surf.iloc[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "buil_surf.columns=buil_surf.columns.str.extract('(\\d+)',expand=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "buil_surf=buil_surf.reindex(buil_surf.index.drop('ID'))" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "azim=pd.DataFrame(buil_surf.iloc[1])\n", + "azim=azim.iloc[1:-1] #this is included to remove unnecessary lines in the dataframe\n", + "azim.columns = [\"Angle\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "direction=[]\n", + "azimuth=azim.iloc[:,0]\n", + "#azimuth=azimuth.iloc[1:-1] " + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Calculating direction from Azimuth given by CitySim (1 - East, 2 - South, 3 - West, 4 - North, 5 - Roof)\n", + "\n", + "i=0\n", + "while i < len(azimuth):\n", + " if(azimuth.iloc[i]>45 and azimuth.iloc[i]<135):\n", + " dir=1\n", + " if(azimuth.iloc[i]>135 and azimuth.iloc[i]<225):\n", + " dir=2\n", + " if(azimuth.iloc[i]>225 and azimuth.iloc[i]<315):\n", + " dir=3\n", + " if(azimuth.iloc[i]>315 and azimuth.iloc[i]<360 or azimuth.iloc[i]>0 and azimuth.iloc[i]<45):\n", + " dir=4\n", + " if(azimuth.iloc[i]==0):\n", + " dir=5\n", + " direction.append(dir)\n", + " i=i+1" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "azim['Dir']=direction\n", + "#azim['Faces'] = azim.index" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "viewT=buil_surf.T\n", + "viewT=viewT[1:-1]\n", + "azim['Area']=viewT[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "azim=azim.drop(['Angle'],axis=1) #to remove Angles from dataframe" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "#reading file for surface temperature from CitySim\n", + "sw=pd.read_csv(\"jonction/jonction_vitrage_standard_SW.out\", header=\"infer\", sep=\"\t\", encoding = \"ISO-8859-1\")\n", + "\n", + "#dropping columns for Ke\n", + "sw.drop([col for col in sw.columns if \"#Igh\" in col], axis=1, inplace=True)\n", + "\n", + "#Transforming header to keep only face id\n", + "#surf_temp.columns=surf_temp.columns.str.extract('(\\d\\d\\d\\d\\d)',expand=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "sw=sw.T" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "sw.index.name = 'ID'\n", + "sw=sw.reset_index()" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\dmauree\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\ipykernel\\__main__.py:2: UserWarning: Boolean Series key will be reindexed to match DataFrame index.\n", + " from ipykernel import kernelapp as app\n", + "C:\\Users\\dmauree\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\ipykernel\\__main__.py:3: UserWarning: Boolean Series key will be reindexed to match DataFrame index.\n", + " app.launch_new_instance()\n" + ] + } + ], + "source": [ + "buil_sw=sw[sw['ID'].str.contains(\"NA\")== False][:-1] #added to remove line from file (EPFL campus file)\n", + "buil_sw=buil_sw[sw['ID'].str.contains(\"TREE\")== False]\n", + "buil_sw=buil_sw[sw['ID'].str.contains(\"Pedestrian\")== False]" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "buil_sw=buil_sw.T" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "buil_sw.columns = buil_sw.iloc[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "buil_sw=buil_sw.reindex(buil_sw.index.drop('ID'))" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "buil_sw.columns=buil_sw.columns.str.extract('(\\d+)',expand=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "buil_sw=buil_sw.T\n", + "#buil_surf_temp=buil_surf_temp[:-1]" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#concatenating both direction dataframe and shortwave dataframe\n", + "surf_dir=pd.concat([buil_sw, azim],axis=1)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "collapsed": true, + "scrolled": true + }, + "outputs": [], + "source": [ + "meansurf=surf_dir.groupby(\"Dir\").apply(lambda surf_dir: np.average(surf_dir, weights=surf_dir['Area'], axis=0))" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "fi=meansurf.tolist()\n", + "fi=pd.DataFrame(fi)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "fi=fi.T" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [], + "source": [ + "fi.to_csv(r'sw_jonctio_vitr_std.txt', header=None, sep=' ', mode='a')" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [], + "source": [ + "area_dir=[]\n", + "area_dir=azim.groupby(\"Dir\").sum()" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [], + "source": [ + "area_dir.to_csv(r'area_dir.txt', header=None, sep=' ', mode='a')" + ] + } + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "Python [default]", + "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.5.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/citysim-SW_buil_surf_v1.py b/citysim-SW_buil_surf_v1.py new file mode 100644 index 0000000..13ce450 --- /dev/null +++ b/citysim-SW_buil_surf_v1.py @@ -0,0 +1,206 @@ + +# coding: utf-8 + +# Script prepared by Dr. Dasaraden Mauree +# Contact: EPFL +# dasaraden.mauree@epfl.ch / dasaraden.mauree@gmail.com +# +# use this script to read surface temperature data +# from CitySim and calculate the hourly mean data +# for each direction and then used as input for CIM. + +# In[1]: + +#importing necessary packages + +import pandas as pd +import numpy as np +import time +import math +import matplotlib.pyplot as plt +import matplotlib.dates as dates +get_ipython().magic('matplotlib inline') +from datetime import datetime, timedelta +from IPython.core.interactiveshell import InteractiveShell +InteractiveShell.ast_node_interactivity = "all" + +#Opening file and saving in array +buil_surf=pd.read_csv("jonction/jonction_vitrage_standard_VF.out", header="infer", sep=" ", encoding = "ISO-8859-1") +buil_surf=buil_surf.T + + +# In[2]: + +buil_surf.index.name = 'ID' +buil_surf=buil_surf.reset_index() + + +# In[3]: + +#selecting only the columns corresponding to building surfaces +buil_surf=buil_surf[buil_surf['ID'].str.contains("NA")==False] +buil_surf=buil_surf[buil_surf['ID'].str.contains("TREE")==False] +buil_surf=buil_surf[buil_surf['ID'].str.contains("Pedestrian")==False] +buil_surf=buil_surf.T + + +# In[4]: + +buil_surf.columns = buil_surf.iloc[0] + + +# In[5]: + +buil_surf.columns=buil_surf.columns.str.extract('(\d+)',expand=False) + + +# In[6]: + +buil_surf=buil_surf.reindex(buil_surf.index.drop('ID')) + + +# In[7]: + +azim=pd.DataFrame(buil_surf.iloc[1]) +azim=azim.iloc[1:-1] #this is included to remove unnecessary lines in the dataframe +azim.columns = ["Angle"] + + +# In[8]: + +direction=[] +azimuth=azim.iloc[:,0] +#azimuth=azimuth.iloc[1:-1] + + +# In[9]: + +# Calculating direction from Azimuth given by CitySim (1 - East, 2 - South, 3 - West, 4 - North, 5 - Roof) + +i=0 +while i < len(azimuth): + if(azimuth.iloc[i]>45 and azimuth.iloc[i]<135): + dir=1 + if(azimuth.iloc[i]>135 and azimuth.iloc[i]<225): + dir=2 + if(azimuth.iloc[i]>225 and azimuth.iloc[i]<315): + dir=3 + if(azimuth.iloc[i]>315 and azimuth.iloc[i]<360 or azimuth.iloc[i]>0 and azimuth.iloc[i]<45): + dir=4 + if(azimuth.iloc[i]==0): + dir=5 + direction.append(dir) + i=i+1 + + +# In[10]: + +azim['Dir']=direction +#azim['Faces'] = azim.index + + +# In[11]: + +viewT=buil_surf.T +viewT=viewT[1:-1] +azim['Area']=viewT[0] + + +# In[12]: + +azim=azim.drop(['Angle'],axis=1) #to remove Angles from dataframe + + +# In[14]: + +#reading file for surface temperature from CitySim +sw=pd.read_csv("jonction/jonction_vitrage_standard_SW.out", header="infer", sep=" ", encoding = "ISO-8859-1") + +#dropping columns for Ke +sw.drop([col for col in sw.columns if "#Igh" in col], axis=1, inplace=True) + +#Transforming header to keep only face id +#surf_temp.columns=surf_temp.columns.str.extract('(\d\d\d\d\d)',expand=False) + + +# In[15]: + +sw=sw.T + + +# In[16]: + +sw.index.name = 'ID' +sw=sw.reset_index() + + +# In[17]: + +buil_sw=sw[sw['ID'].str.contains("NA")== False][:-1] #added to remove line from file (EPFL campus file) +buil_sw=buil_sw[sw['ID'].str.contains("TREE")== False] +buil_sw=buil_sw[sw['ID'].str.contains("Pedestrian")== False] + + +# In[19]: + +buil_sw=buil_sw.T + + +# In[20]: + +buil_sw.columns = buil_sw.iloc[0] + + +# In[22]: + +buil_sw=buil_sw.reindex(buil_sw.index.drop('ID')) + + +# In[23]: + +buil_sw.columns=buil_sw.columns.str.extract('(\d+)',expand=False) + + +# In[24]: + +buil_sw=buil_sw.T +#buil_surf_temp=buil_surf_temp[:-1] + + +# In[25]: + +#concatenating both direction dataframe and shortwave dataframe +surf_dir=pd.concat([buil_sw, azim],axis=1) + + +# In[26]: + +meansurf=surf_dir.groupby("Dir").apply(lambda surf_dir: np.average(surf_dir, weights=surf_dir['Area'], axis=0)) + + +# In[29]: + +fi=meansurf.tolist() +fi=pd.DataFrame(fi) + + +# In[30]: + +fi=fi.T + + +# In[33]: + +fi.to_csv(r'sw_jonctio_vitr_std.txt', header=None, sep=' ', mode='a') + + +# In[45]: + +area_dir=[] +area_dir=azim.groupby("Dir").sum() + + +# In[48]: + +area_dir.to_csv(r'area_dir.txt', header=None, sep=' ', mode='a') + diff --git a/citysim-hum_surf_v2.ipynb b/citysim-hum_surf_v2.ipynb new file mode 100644 index 0000000..81bded2 --- /dev/null +++ b/citysim-hum_surf_v2.ipynb @@ -0,0 +1,221 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Preparing evapotranspiration flux for CIM" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " Script prepared by Dr. Dasaraden Mauree \n", + " Contact: EPFL \n", + " dasaraden.mauree@epfl.ch / dasaraden.mauree@gmail.com \n", + " \n", + " use this script to read evapotranspiration ata \n", + " from CitySim and calculate the hourly mean data \n", + " for the ground surface and then used as input for CIM. \n", + " \n", + " This file originates from citysim_hum_surf-v1.\n", + " \n", + " This version works for CitySim version April 2020 output files." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "#importing necessary packages\n", + "\n", + "import pandas as pd\n", + "import numpy as np\n", + "import time\n", + "import math\n", + "import matplotlib.pyplot as plt\n", + "import matplotlib.dates as dates\n", + "%matplotlib inline \n", + "from datetime import datetime, timedelta\n", + "from IPython.core.interactiveshell import InteractiveShell\n", + "InteractiveShell.ast_node_interactivity = \"all\"" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "#Opening file and saving in array\n", + "all_surf=pd.read_csv(\"building_VF.out\", header=\"infer\", sep=\"\t\", encoding = \"ISO-8859-1\")\n", + "#all_surf=all_surf.T\n", + "\n", + "header=['ID', 'Type','Area', 'Azimuth', 'Altitude','SVF','GVF']\n", + "#header=['Area', 'Azimuth','SVF','GVF']\n", + "all_surf.columns=header\n", + "\n", + "#Creating an index\n", + "#all_surf=all_surf.rename(columns={'#':'ID'})\n", + "#all_surf.index.name = 'ID'\n", + "#all_surf=all_surf.reset_index()[1:-1]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Ground surfaces" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "grd_surf=pd.DataFrame()\n", + "grd_surf=all_surf[all_surf['ID'].str.contains(\"NA\")]\n", + "grd_surf=grd_surf.T\n", + "\n", + "grd_surf.columns=grd_surf.iloc[0].str.split(':').str[-1]\n", + "grd_surf=grd_surf.reindex(grd_surf.index.drop('ID'))" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "azim_grd=pd.DataFrame(index=grd_surf.T.index)\n", + "azim_grd['Area']=grd_surf.iloc[0].values\n", + "azim_grd['Dir']=6" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## ET rate" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "#reading file for surface temperature from CitySim\n", + "all_surf_et=pd.read_csv(\"building_ET.out\", header=\"infer\", sep=\"\t\", encoding = \"ISO-8859-1\")\n", + "all_surf_et=all_surf_et.T\n", + "\n", + "#Creating an index\n", + "all_surf_et.index.name = 'ID'\n", + "all_surf_et=all_surf_et.reset_index()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Ground ET" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [], + "source": [ + "#selecting only the columns corresponding to ground surfaces\n", + "grd_surf_et=pd.DataFrame()\n", + "grd_surf_et=all_surf_et[all_surf_et['ID'].str.contains(\"NA\")]\n", + "\n", + "grd_surf_et['ID']=grd_surf_et['ID'].str.split(':').str[-2]\n", + "grd_surf_et=grd_surf_et.set_index('ID')" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [], + "source": [ + "#concatenating both direction dataframe and ground surface temp dataframe\n", + "grd_surf_dir=pd.merge(grd_surf_et, azim_grd, on='ID')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Computing weighted ET rates" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "DataFrame is empty!\n" + ] + } + ], + "source": [ + "if len(grd_surf_et.columns)<=1:\n", + " print('ET is equal to zero!')\n", + " grd_surf_et_dir = pd.DataFrame(np.zeros((8760, 1)))\n", + "else:\n", + " meansurf_grd=grd_surf_dir.groupby(\"Dir\").apply(lambda grd_surf_dir: np.average(grd_surf_dir, weights=grd_surf_dir['Area'], axis=0))\n", + "\n", + " grd_surf_et_dir=pd.DataFrame(meansurf_grd.tolist()).T[:-2]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Saving file to CSV" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [], + "source": [ + "grd_surf_et_dir.to_csv(r'surf_hum.txt', header=None, sep=' ', mode='a', index=False)" + ] + } + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "Python 3", + "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.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/citysim-hum_surf_v2.py b/citysim-hum_surf_v2.py new file mode 100644 index 0000000..57cfa49 --- /dev/null +++ b/citysim-hum_surf_v2.py @@ -0,0 +1,127 @@ +#!/usr/bin/env python +# coding: utf-8 + +# # Preparing evapotranspiration flux for CIM + +# Script prepared by Dr. Dasaraden Mauree +# Contact: EPFL +# dasaraden.mauree@epfl.ch / dasaraden.mauree@gmail.com +# +# use this script to read evapotranspiration ata +# from CitySim and calculate the hourly mean data +# for the ground surface and then used as input for CIM. +# +# This file originates from citysim_hum_surf-v1. +# +# This version works for CitySim version April 2020 output files. + +# In[1]: + + +#importing necessary packages + +import pandas as pd +import numpy as np +import time +import math +import matplotlib.pyplot as plt +import matplotlib.dates as dates +get_ipython().run_line_magic('matplotlib', 'inline') +from datetime import datetime, timedelta +from IPython.core.interactiveshell import InteractiveShell +InteractiveShell.ast_node_interactivity = "all" + + +# In[2]: + + +#Opening file and saving in array +all_surf=pd.read_csv("building_VF.out", header="infer", sep=" ", encoding = "ISO-8859-1") +#all_surf=all_surf.T + +header=['ID', 'Type','Area', 'Azimuth', 'Altitude','SVF','GVF'] +#header=['Area', 'Azimuth','SVF','GVF'] +all_surf.columns=header + +#Creating an index +#all_surf=all_surf.rename(columns={'#':'ID'}) +#all_surf.index.name = 'ID' +#all_surf=all_surf.reset_index()[1:-1] + + +# ## Ground surfaces + +# In[3]: + + +grd_surf=pd.DataFrame() +grd_surf=all_surf[all_surf['ID'].str.contains("NA")] +grd_surf=grd_surf.T + +grd_surf.columns=grd_surf.iloc[0].str.split(':').str[-1] +grd_surf=grd_surf.reindex(grd_surf.index.drop('ID')) + + +# In[4]: + + +azim_grd=pd.DataFrame(index=grd_surf.T.index) +azim_grd['Area']=grd_surf.iloc[0].values +azim_grd['Dir']=6 + + +# ## ET rate + +# In[29]: + + +#reading file for surface temperature from CitySim +all_surf_et=pd.read_csv("building_ET.out", header="infer", sep=" ", encoding = "ISO-8859-1") +all_surf_et=all_surf_et.T + +#Creating an index +all_surf_et.index.name = 'ID' +all_surf_et=all_surf_et.reset_index() + + +# ## Ground ET + +# In[40]: + + +#selecting only the columns corresponding to ground surfaces +grd_surf_et=pd.DataFrame() +grd_surf_et=all_surf_et[all_surf_et['ID'].str.contains("NA")] + +grd_surf_et['ID']=grd_surf_et['ID'].str.split(':').str[-2] +grd_surf_et=grd_surf_et.set_index('ID') + + +# In[41]: + + +#concatenating both direction dataframe and ground surface temp dataframe +grd_surf_dir=pd.merge(grd_surf_et, azim_grd, on='ID') + + +# ## Computing weighted ET rates + +# In[42]: + + +if len(grd_surf_et.columns)<=1: + print('ET is equal to zero!') + grd_surf_et_dir = pd.DataFrame(np.zeros((8760, 1))) +else: + meansurf_grd=grd_surf_dir.groupby("Dir").apply(lambda grd_surf_dir: np.average(grd_surf_dir, weights=grd_surf_dir['Area'], axis=0)) + + grd_surf_et_dir=pd.DataFrame(meansurf_grd.tolist()).T[:-2] + + +# ## Saving file to CSV + +# In[44]: + + +grd_surf_et_dir.to_csv(r'surf_hum.txt', header=None, sep=' ', mode='a', index=False) + diff --git a/cim-citysim/citysim-surf_temp_buil_grd_surf_v1.py b/citysim-surf_temp_buil_grd_surf_v1.py similarity index 100% copy from cim-citysim/citysim-surf_temp_buil_grd_surf_v1.py copy to citysim-surf_temp_buil_grd_surf_v1.py diff --git a/citysim-surf_temp_buil_grd_surf_v2.ipynb b/citysim-surf_temp_buil_grd_surf_v2.ipynb new file mode 100644 index 0000000..a044a8f --- /dev/null +++ b/citysim-surf_temp_buil_grd_surf_v2.ipynb @@ -0,0 +1,377 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Preparing surface temperature for CIM" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " Script prepared by Dr. Dasaraden Mauree \n", + " Contact: EPFL \n", + " dasaraden.mauree@epfl.ch / dasaraden.mauree@gmail.com \n", + " \n", + " use this script to read surface temperature data \n", + " from CitySim and calculate the hourly mean data \n", + " for each direction and then used as input for CIM. \n", + " \n", + " This file originates from citysim-surf_temp_buil_grd_surf-v1.\n", + " \n", + " This version works for CitySim version April 2020 output files." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "#importing necessary packages\n", + "\n", + "import pandas as pd\n", + "import numpy as np\n", + "import time\n", + "import math\n", + "import matplotlib.pyplot as plt\n", + "import matplotlib.dates as dates\n", + "%matplotlib inline \n", + "from datetime import datetime, timedelta\n", + "from IPython.core.interactiveshell import InteractiveShell\n", + "InteractiveShell.ast_node_interactivity = \"all\"" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [], + "source": [ + "#Opening file and saving in array\n", + "all_surf=pd.read_csv(\"bee_minergie.tsv_VF.tsv\", header=\"infer\", sep=\"\t\", encoding = \"ISO-8859-1\")\n", + "#all_surf=all_surf.T\n", + "\n", + "header=['ID', 'Type','Area', 'Azimuth', 'Altitude','SVF','GVF']\n", + "all_surf.columns=header\n", + "\n", + "#Creating an index\n", + "#all_surf=all_surf.rename(columns={'#':'ID'})\n", + "#all_surf.index.name = 'ID'\n", + "#all_surf=all_surf.reset_index()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Building surfaces" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [], + "source": [ + "#selecting only the columns corresponding to building surfaces\n", + "buil_surf=pd.DataFrame()\n", + "buil_surf=all_surf[all_surf['ID'].str.contains(\"NA\")==False]\n", + "buil_surf=buil_surf[buil_surf['ID'].str.contains(\"TREE\")==False]\n", + "buil_surf=buil_surf[buil_surf['ID'].str.contains(\"Pedestrian\")==False]\n", + "buil_surf=buil_surf.T" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [], + "source": [ + "#Indexing the table with surface IDs.\n", + "buil_surf.columns=buil_surf.iloc[0].str.split(':').str[-1]\n", + "buil_surf=buil_surf.reindex(buil_surf.index.drop('ID'))" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [], + "source": [ + "#Creating new series with values of Azimuth and SVF.\n", + "direction=[]\n", + "azimuth=buil_surf.iloc[2]\n", + "svf=buil_surf.iloc[4]\n", + "#azimuth=azimuth.iloc[1:-1] " + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [], + "source": [ + "# Calculating direction from Azimuth given by CitySim (1 - East, 2 - South, 3 - West, 4 - North, 5 - Roof)\n", + "\n", + "i=0\n", + "while i < len(azimuth):\n", + " if(azimuth.iloc[i]>45 and azimuth.iloc[i]<135):\n", + " dir=1\n", + " if(azimuth.iloc[i]>135 and azimuth.iloc[i]<225):\n", + " dir=2\n", + " if(azimuth.iloc[i]>225 and azimuth.iloc[i]<315):\n", + " dir=3\n", + " if(azimuth.iloc[i]>315 and azimuth.iloc[i]<360 and svf.iloc[i]<=0.9 or azimuth.iloc[i]>0 and azimuth.iloc[i]<45 and svf.iloc[i]<=0.9):\n", + " dir=4\n", + " if(azimuth.iloc[i]==0 and svf.iloc[i]>0.9):\n", + " dir=5\n", + " direction.append(dir)\n", + " i=i+1" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [], + "source": [ + "azim=pd.DataFrame()\n", + "azim['Dir']=direction\n", + "azim['Area']=buil_surf.iloc[1].values" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Ground surfaces" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": {}, + "outputs": [], + "source": [ + "grd_surf=pd.DataFrame()\n", + "grd_surf=all_surf[all_surf['ID'].str.contains(\"NA\")]\n", + "grd_surf=grd_surf.T\n", + "\n", + "grd_surf.columns=grd_surf.iloc[0].str.split(':').str[-1]\n", + "grd_surf=grd_surf.reindex(grd_surf.index.drop('ID'))" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [], + "source": [ + "azim_grd=pd.DataFrame()\n", + "azim_grd['Area']=grd_surf.iloc[1].values\n", + "azim_grd['Dir']=6" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Surface temperature" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [], + "source": [ + "#reading file for surface temperature from CitySim\n", + "all_surf_temp=pd.read_csv(\"bee_minergie.tsv_TS.tsv\", header=\"infer\", sep=\"\t\", encoding = \"ISO-8859-1\")\n", + "\n", + "#dropping columns for Ke\n", + "all_surf_temp.drop([col for col in all_surf_temp.columns if \"Ke\" in col], axis=1, inplace=True)\n", + "\n", + "all_surf_temp=all_surf_temp.T\n", + "\n", + "#Creating an index\n", + "all_surf_temp.index.name = 'ID'\n", + "all_surf_temp=all_surf_temp.reset_index()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Building surface temperature" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": {}, + "outputs": [], + "source": [ + "#selecting only the columns corresponding to building surfaces\n", + "buil_surf_temp=pd.DataFrame()\n", + "buil_surf_temp=all_surf_temp[all_surf_temp['ID'].str.contains(\"NA\")== False][:-1] #added to remove line from file (EPFL campus file)\n", + "buil_surf_temp=buil_surf_temp[buil_surf_temp['ID'].str.contains(\"TREE\")== False]\n", + "buil_surf_temp=buil_surf_temp[buil_surf_temp['ID'].str.contains(\"Pedestrian\")== False]\n", + "\n", + "#Removing Index for concat\n", + "buil_surf_temp=buil_surf_temp.drop(['ID'],axis=1)" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": {}, + "outputs": [], + "source": [ + "#concatenating both direction dataframe and building surface temp dataframe\n", + "surf_dir=pd.concat([buil_surf_temp, azim],axis=1)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Ground surface temperature" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "metadata": {}, + "outputs": [], + "source": [ + "#selecting only the columns corresponding to ground surfaces\n", + "grd_surf_temp=pd.DataFrame()\n", + "grd_surf_temp=all_surf_temp[all_surf_temp['ID'].str.contains(\"NA\")]\n", + "\n", + "#Removing Index for concat\n", + "grd_surf_temp=grd_surf_temp.drop(['ID'],axis=1)\n", + "grd_surf_temp.reset_index(drop=True, inplace=True)\n", + "azim_grd.reset_index(drop=True, inplace=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [], + "source": [ + "#concatenating both direction dataframe and ground surface temp dataframe\n", + "grd_surf_dir=pd.concat([grd_surf_temp, azim_grd],axis=1)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Computing weighted building surface temperatures" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "meansurf=surf_dir.groupby(\"Dir\").apply(lambda surf_dir: np.average(surf_dir, weights=surf_dir['Area'], axis=0))\n", + "\n", + "surf_temp_dir=pd.DataFrame(meansurf.tolist()).T[:-2]" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "metadata": {}, + "outputs": [], + "source": [ + "meansurf_grd=grd_surf_dir.groupby(\"Dir\").apply(lambda grd_surf_dir: np.average(grd_surf_dir, weights=grd_surf_dir['Area'], axis=0))\n", + "\n", + "grd_surf_temp_dir=pd.DataFrame(meansurf_grd.tolist()).T[:-2]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Saving file to CSV" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": {}, + "outputs": [], + "source": [ + "all_surf_temp_dir=pd.concat([surf_temp_dir, grd_surf_temp_dir],axis=1)\n", + "header=['East', 'South','West', 'North', 'Roof','Ground']\n", + "all_surf_temp_dir.columns=header" + ] + }, + { + "cell_type": "code", + "execution_count": 112, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "all_surf_temp_dir.to_csv(r'Confluence_surf_temp.txt', header=None, sep=' ', mode='a')" + ] + }, + { + "cell_type": "code", + "execution_count": 198, + "metadata": {}, + "outputs": [], + "source": [ + "#In a previous version of the script the following lines where used instead of the one above.\n", + "\n", + "#buil_surf_temp=all_surf_temp[all_surf_temp['ID'].str.contains(\"NA\")== False][:-1] #added to remove line from file (EPFL campus file)\n", + "#buil_surf_temp=buil_surf_temp[buil_surf_temp['ID'].str.contains(\"TREE\")== False]\n", + "#buil_surf_temp=buil_surf_temp[buil_surf_temp['ID'].str.contains(\"Pedestrian\")== False]\n", + "#buil_surf_temp=buil_surf_temp.T\n", + "\n", + "#buil_surf_temp.columns = buil_surf_temp.iloc[0]\n", + "#buil_surf_temp=buil_surf_temp.reindex(buil_surf_temp.index.drop('ID'))\n", + "#buil_surf_temp.columns=buil_surf_temp.columns.str.split(':').str[-2]\n", + "#buil_surf_temp=buil_surf_temp.T\n", + "\n", + "#buil_surf_temp.reset_index(drop=True, inplace=True)\n", + "#azim.reset_index(drop=True, inplace=True)\n", + "\n", + "#surf_dir=pd.concat([buil_surf_temp, azim],axis=1)" + ] + } + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "Python 3", + "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.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/cim-citysim/citysim-surf_temp_buil_grd_surf_v1.py b/citysim-surf_temp_buil_grd_surf_v2.py old mode 100755 new mode 100644 similarity index 86% rename from cim-citysim/citysim-surf_temp_buil_grd_surf_v1.py rename to citysim-surf_temp_buil_grd_surf_v2.py index 97e3080..e9a85df --- a/cim-citysim/citysim-surf_temp_buil_grd_surf_v1.py +++ b/citysim-surf_temp_buil_grd_surf_v2.py @@ -1,241 +1,247 @@ #!/usr/bin/env python # coding: utf-8 # # Preparing surface temperature for CIM # Script prepared by Dr. Dasaraden Mauree # Contact: EPFL # dasaraden.mauree@epfl.ch / dasaraden.mauree@gmail.com # # use this script to read surface temperature data # from CitySim and calculate the hourly mean data # for each direction and then used as input for CIM. # -# This file originates from citysim-surf_temp_buil_surf-v5 +# This file originates from citysim-surf_temp_buil_surf-v5. +# +# This version works for CitySim version April 2020 output files. -# In[45]: +# In[1]: #importing necessary packages import pandas as pd import numpy as np import time import math import matplotlib.pyplot as plt import matplotlib.dates as dates get_ipython().run_line_magic('matplotlib', 'inline') from datetime import datetime, timedelta from IPython.core.interactiveshell import InteractiveShell InteractiveShell.ast_node_interactivity = "all" -# In[46]: +# In[34]: #Opening file and saving in array -all_surf=pd.read_csv("Confluence_V1_VF.out", header="infer", sep=" ", encoding = "ISO-8859-1") -all_surf=all_surf.T +all_surf=pd.read_csv("bee_minergie.tsv_VF.tsv", header="infer", sep=" ", encoding = "ISO-8859-1") +#all_surf=all_surf.T + +header=['ID', 'Type','Area', 'Azimuth', 'Altitude','SVF','GVF'] +all_surf.columns=header #Creating an index -all_surf.index.name = 'ID' -all_surf=all_surf.reset_index() +#all_surf=all_surf.rename(columns={'#':'ID'}) +#all_surf.index.name = 'ID' +#all_surf=all_surf.reset_index() # ## Building surfaces -# In[91]: +# In[44]: #selecting only the columns corresponding to building surfaces buil_surf=pd.DataFrame() buil_surf=all_surf[all_surf['ID'].str.contains("NA")==False] buil_surf=buil_surf[buil_surf['ID'].str.contains("TREE")==False] buil_surf=buil_surf[buil_surf['ID'].str.contains("Pedestrian")==False] buil_surf=buil_surf.T -# In[92]: +# In[47]: #Indexing the table with surface IDs. buil_surf.columns=buil_surf.iloc[0].str.split(':').str[-1] buil_surf=buil_surf.reindex(buil_surf.index.drop('ID')) -# In[93]: +# In[57]: #Creating new series with values of Azimuth and SVF. direction=[] -azimuth=buil_surf.iloc[1][1:-1] -svf=buil_surf.iloc[2][1:-1] +azimuth=buil_surf.iloc[2] +svf=buil_surf.iloc[4] #azimuth=azimuth.iloc[1:-1] -# In[94]: +# In[59]: # Calculating direction from Azimuth given by CitySim (1 - East, 2 - South, 3 - West, 4 - North, 5 - Roof) i=0 while i < len(azimuth): if(azimuth.iloc[i]>45 and azimuth.iloc[i]<135): dir=1 if(azimuth.iloc[i]>135 and azimuth.iloc[i]<225): dir=2 if(azimuth.iloc[i]>225 and azimuth.iloc[i]<315): dir=3 if(azimuth.iloc[i]>315 and azimuth.iloc[i]<360 and svf.iloc[i]<=0.9 or azimuth.iloc[i]>0 and azimuth.iloc[i]<45 and svf.iloc[i]<=0.9): dir=4 if(azimuth.iloc[i]==0 and svf.iloc[i]>0.9): dir=5 direction.append(dir) i=i+1 -# In[108]: +# In[65]: azim=pd.DataFrame() azim['Dir']=direction -azim['Area']=buil_surf.iloc[0][1:-1].values +azim['Area']=buil_surf.iloc[1].values # ## Ground surfaces -# In[228]: +# In[67]: grd_surf=pd.DataFrame() grd_surf=all_surf[all_surf['ID'].str.contains("NA")] grd_surf=grd_surf.T grd_surf.columns=grd_surf.iloc[0].str.split(':').str[-1] grd_surf=grd_surf.reindex(grd_surf.index.drop('ID')) -# In[235]: +# In[68]: azim_grd=pd.DataFrame() -azim_grd['Area']=grd_surf.iloc[0].values +azim_grd['Area']=grd_surf.iloc[1].values azim_grd['Dir']=6 # ## Surface temperature -# In[112]: +# In[70]: #reading file for surface temperature from CitySim -all_surf_temp=pd.read_csv("Confluence_V1_TS.out", header="infer", sep=" ", encoding = "ISO-8859-1") +all_surf_temp=pd.read_csv("bee_minergie.tsv_TS.tsv", header="infer", sep=" ", encoding = "ISO-8859-1") #dropping columns for Ke all_surf_temp.drop([col for col in all_surf_temp.columns if "Ke" in col], axis=1, inplace=True) all_surf_temp=all_surf_temp.T #Creating an index all_surf_temp.index.name = 'ID' all_surf_temp=all_surf_temp.reset_index() # ## Building surface temperature -# In[245]: +# In[73]: #selecting only the columns corresponding to building surfaces buil_surf_temp=pd.DataFrame() buil_surf_temp=all_surf_temp[all_surf_temp['ID'].str.contains("NA")== False][:-1] #added to remove line from file (EPFL campus file) buil_surf_temp=buil_surf_temp[buil_surf_temp['ID'].str.contains("TREE")== False] buil_surf_temp=buil_surf_temp[buil_surf_temp['ID'].str.contains("Pedestrian")== False] #Removing Index for concat buil_surf_temp=buil_surf_temp.drop(['ID'],axis=1) -# In[247]: +# In[74]: #concatenating both direction dataframe and building surface temp dataframe surf_dir=pd.concat([buil_surf_temp, azim],axis=1) # ## Ground surface temperature -# In[253]: +# In[76]: #selecting only the columns corresponding to ground surfaces grd_surf_temp=pd.DataFrame() grd_surf_temp=all_surf_temp[all_surf_temp['ID'].str.contains("NA")] #Removing Index for concat grd_surf_temp=grd_surf_temp.drop(['ID'],axis=1) grd_surf_temp.reset_index(drop=True, inplace=True) azim_grd.reset_index(drop=True, inplace=True) -# In[254]: +# In[77]: #concatenating both direction dataframe and ground surface temp dataframe grd_surf_dir=pd.concat([grd_surf_temp, azim_grd],axis=1) # ## Computing weighted building surface temperatures -# In[200]: +# In[78]: meansurf=surf_dir.groupby("Dir").apply(lambda surf_dir: np.average(surf_dir, weights=surf_dir['Area'], axis=0)) surf_temp_dir=pd.DataFrame(meansurf.tolist()).T[:-2] -# In[266]: +# In[79]: meansurf_grd=grd_surf_dir.groupby("Dir").apply(lambda grd_surf_dir: np.average(grd_surf_dir, weights=grd_surf_dir['Area'], axis=0)) grd_surf_temp_dir=pd.DataFrame(meansurf_grd.tolist()).T[:-2] # ## Saving file to CSV -# In[267]: +# In[80]: all_surf_temp_dir=pd.concat([surf_temp_dir, grd_surf_temp_dir],axis=1) header=['East', 'South','West', 'North', 'Roof','Ground'] all_surf_temp_dir.columns=header # In[112]: all_surf_temp_dir.to_csv(r'Confluence_surf_temp.txt', header=None, sep=' ', mode='a') # In[198]: #In a previous version of the script the following lines where used instead of the one above. #buil_surf_temp=all_surf_temp[all_surf_temp['ID'].str.contains("NA")== False][:-1] #added to remove line from file (EPFL campus file) #buil_surf_temp=buil_surf_temp[buil_surf_temp['ID'].str.contains("TREE")== False] #buil_surf_temp=buil_surf_temp[buil_surf_temp['ID'].str.contains("Pedestrian")== False] #buil_surf_temp=buil_surf_temp.T #buil_surf_temp.columns = buil_surf_temp.iloc[0] #buil_surf_temp=buil_surf_temp.reindex(buil_surf_temp.index.drop('ID')) #buil_surf_temp.columns=buil_surf_temp.columns.str.split(':').str[-2] #buil_surf_temp=buil_surf_temp.T #buil_surf_temp.reset_index(drop=True, inplace=True) #azim.reset_index(drop=True, inplace=True) #surf_dir=pd.concat([buil_surf_temp, azim],axis=1) diff --git a/create_citysim_cli_v2.ipynb b/create_citysim_cli_v2.ipynb new file mode 100644 index 0000000..2cc553b --- /dev/null +++ b/create_citysim_cli_v2.ipynb @@ -0,0 +1,118 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Preparing climate file for CIM" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " Script prepared by Dr. Dasaraden Mauree \n", + " Contact: EPFL \n", + " dasaraden.mauree@epfl.ch / dasaraden.mauree@gmail.com \n", + " \n", + " use this script to read the output from CIM and save \n", + " it as a standard file for CitySim." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "#importing necessary packages\n", + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [], + "source": [ + "#Opening file and saving in array\n", + "cim=pd.read_csv(\"Citysim.cli\", header=None, sep=\";\", encoding = \"ISO-8859-1\")\n", + "\n", + "header=['Ta','FF','DD','RH']\n", + "cim.columns=header\n", + "\n", + "cim[['Ta','FF']]=cim[['Ta','FF']].round(1)\n", + "cim[['DD','RH']]=cim[['DD','RH']].astype(int)\n", + "\n", + "meteonorm=pd.read_csv(\"Ecublens.cli\", header=\"infer\", sep=\"\\s+\", encoding = \"ISO-8859-1\", skiprows=3)" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [], + "source": [ + "# replacing values of Meteonorm file with values from CIM \n", + "meteonorm.loc[:len(cim)-1,('Ta')]=cim.loc[:len(cim)-1,('Ta')]\n", + "meteonorm.loc[:len(cim)-1,('FF')]=cim.loc[:len(cim)-1,('FF')]\n", + "meteonorm.loc[:len(cim)-1,('DD')]=cim.loc[:len(cim)-1,('DD')]\n", + "meteonorm.loc[:len(cim)-1,('RH')]=cim.loc[:len(cim)-1,('RH')]" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [], + "source": [ + "# open file in read mode \n", + "fn = open(\"Ecublens.cli\", 'r') \n", + "\n", + "# open other file in write mode \n", + "fn1 = open('Ecublens_cim.cli', 'w') \n", + "\n", + "# read the content of the file line by line \n", + "cont = fn.readlines() \n", + "for i in range(0, 3): \n", + " fn1.write(cont[i]) \n", + " \n", + "# close the file \n", + "fn.close() \n", + "fn1.close() " + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [], + "source": [ + "#Selecting columns and saving in file for Citysim\n", + "meteonorm.to_csv(r'Ecublens_cim.cli', sep=' ', mode='a', index=False)" + ] + } + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "Python 3", + "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.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/create_citysim_cli_v2.py b/create_citysim_cli_v2.py new file mode 100644 index 0000000..0115d53 --- /dev/null +++ b/create_citysim_cli_v2.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python +# coding: utf-8 + +# # Preparing climate file for CIM + +# Script prepared by Dr. Dasaraden Mauree +# Contact: EPFL +# dasaraden.mauree@epfl.ch / dasaraden.mauree@gmail.com +# +# use this script to read the output from CIM and save +# it as a standard file for CitySim. + +# In[1]: + + +#importing necessary packages +import pandas as pd + + +# In[46]: + + +#Opening file and saving in array +cim=pd.read_csv("Citysim.cli", header=None, sep=";", encoding = "ISO-8859-1") + +header=['Ta','FF','DD','RH'] +cim.columns=header + +cim[['Ta','FF']]=cim[['Ta','FF']].round(1) +cim[['DD','RH']]=cim[['DD','RH']].astype(int) + +meteonorm=pd.read_csv("Ecublens.cli", header="infer", sep="\s+", encoding = "ISO-8859-1", skiprows=3) + + +# In[49]: + + +# replacing values of Meteonorm file with values from CIM +meteonorm.loc[:len(cim)-1,('Ta')]=cim.loc[:len(cim)-1,('Ta')] +meteonorm.loc[:len(cim)-1,('FF')]=cim.loc[:len(cim)-1,('FF')] +meteonorm.loc[:len(cim)-1,('DD')]=cim.loc[:len(cim)-1,('DD')] +meteonorm.loc[:len(cim)-1,('RH')]=cim.loc[:len(cim)-1,('RH')] + + +# In[51]: + + +# open file in read mode +fn = open("Ecublens.cli", 'r') + +# open other file in write mode +fn1 = open('Ecublens_cim.cli', 'w') + +# read the content of the file line by line +cont = fn.readlines() +for i in range(0, 3): + fn1.write(cont[i]) + +# close the file +fn.close() +fn1.close() + + +# In[52]: + + +#Selecting columns and saving in file for Citysim +meteonorm.to_csv(r'Ecublens_cim.cli', sep=' ', mode='a', index=False) + diff --git a/create_cli_from_vahid_file_v1.ipynb b/create_cli_from_vahid_file_v1.ipynb new file mode 100644 index 0000000..00a3190 --- /dev/null +++ b/create_cli_from_vahid_file_v1.ipynb @@ -0,0 +1,201 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Preparing climate file for CIM" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " Script prepared by Dr. Dasaraden Mauree \n", + " Contact: EPFL \n", + " dasaraden.mauree@epfl.ch / dasaraden.mauree@gmail.com \n", + " \n", + " use this script to read the standard Meteonorm file\n", + " and replace some values from file obtained from \n", + " Vahid Nik file." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "#importing necessary packages\n", + "import pandas as pd\n", + "import os as os\n", + "import re" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "def swap_columns(df, c1, c2):\n", + " df['temp'] = df[c1]\n", + " df[c1] = df[c2]\n", + " df[c2] = df['temp']\n", + " df.drop(columns=['temp'], inplace=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "def new_col(df,df1):\n", + " header_met=df.columns\n", + " df1.columns=header_met\n", + " \n", + " df1[['dm', 'm', 'h', 'G_Dh', 'G_Bn', 'DD', 'RH', 'N']]= df1[['dm', 'm', 'h', 'G_Dh', 'G_Bn', 'DD', 'RH', 'N']].astype(int)\n", + " df1['h']=df1['h']+1\n", + " df1[['Ta', 'FF', 'RR']]=df1[['Ta', 'FF', 'RR']].round(1)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "def remove(string): \n", + " pattern = re.compile(r'\\s+') \n", + " return re.sub(pattern, ',', string) " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "extreme=\"data\\Vahid_files\"\n", + "path=\"data\\Meteonorm_files\"\n", + "out=\"data\\Merged_files\"\n", + "\n", + "filelist = os.listdir(path)\n", + "header_vf=['YY','m','dm','h','G_Dh','G_Bn','Ta','Ts','DD','FF','RH','HOR','N']\n", + "\n", + "for i in filelist:\n", + " city=i.split('.')[0]\n", + " #print(\"Reading \"+city)\n", + " meteonorm=pd.read_csv(path+\"/\"+i, header=\"infer\", sep=\"\\s+\", encoding = \"ISO-8859-1\", skiprows=3)\n", + " ecy=pd.read_csv(extreme+\"/\"+city+\"_ECY_multiple_13Scs_2070_2099\", header=None, names=header_vf, sep=\"\\s+\", encoding = \"ISO-8859-1\")\n", + " ewy=pd.read_csv(extreme+\"/\"+city+\"_EWY_multiple_13Scs_2070_2099\", header=None, names=header_vf, sep=\"\\s+\", encoding = \"ISO-8859-1\")\n", + " #print(\"Done reading \"+city)\n", + " \n", + " ecy=ecy.drop(['YY','Ts'], axis=1)\n", + " ewy=ewy.drop(['YY','Ts'], axis=1)\n", + " ecy['HOR']=meteonorm['RR']\n", + " ewy['HOR']=meteonorm['RR']\n", + " swap_columns(ecy,'DD','FF')\n", + " swap_columns(ewy,'DD','FF')\n", + " swap_columns(ecy,'m','dm')\n", + " swap_columns(ewy,'m','dm')\n", + " \n", + " new_col(meteonorm,ecy)\n", + " new_col(meteonorm,ewy)\n", + " \n", + " # open file in read mode \n", + " fn = open(path+\"/\"+i, 'r') \n", + "\n", + " # open other file in write mode \n", + " fn1 = open(out+\"/\"+city+'_ECY.cli', 'w')\n", + " fn2 = open(out+\"/\"+city+'_EWY.cli', 'w') \n", + "\n", + " # read the content of the file line by line \n", + " cont = fn.readlines() \n", + " for i in range(0, 3): \n", + " cont[i]=(cont[i].replace(',','.'))\n", + " if(i==1):\n", + " cont[i]=remove(cont[i])\n", + " cont[i]=cont[i][1:-1]\n", + " fn1.write(cont[i])\n", + " fn2.write(cont[i])\n", + " fn1.write('\\n')\n", + " fn2.write('\\n')\n", + "\n", + " # close the file \n", + " fn.close() \n", + " fn1.close()\n", + " fn2.close()\n", + " \n", + " #Selecting columns and saving in file for Citysim\n", + " ecy.to_csv(out+\"/\"+city+'_ECY.cli', sep=' ', mode='a', index=False)\n", + " ewy.to_csv(out+\"/\"+city+'_EWY.cli', sep=' ', mode='a', index=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 146, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 52.517 13.3889 43 1 \n", + "\n", + "52.517,13.3889,43,1\n" + ] + } + ], + "source": [ + "# open file in read mode \n", + "fn = open(path+\"/Berlin.cli\", 'r') \n", + "\n", + " # open other file in write mode \n", + "fn1 = open(\"test.cli\", 'w')\n", + "\n", + " # read the content of the file line by line \n", + "cont = fn.readlines() \n", + "for i in range(0, 3):\n", + " cont[i]=(cont[i].replace(',','.'))\n", + " if(i==1):\n", + " print(cont[i])\n", + " cont[i]=remove(cont[i])\n", + " cont[i]=cont[i][1:-1]\n", + " print(cont[i])\n", + " fn1.write(cont[i])\n", + "fn1.write('\\n')\n", + "\n", + " # close the file \n", + "fn.close() \n", + "fn1.close()\n", + " \n", + " #Selecting columns and saving in file for Citysim\n", + "ecy.to_csv(\"test.cli\", sep=' ', mode='a', index=False)" + ] + } + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "Python 3", + "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.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/epfl_geo_char.dat b/epfl_geo_char.dat new file mode 100644 index 0000000..5e140a1 --- /dev/null +++ b/epfl_geo_char.dat @@ -0,0 +1,20 @@ +Geometry file for CIM +=========================== + + Size of each level + 3. + ========== + + Number of levels where obstacles are present + 5 + ========== + + Obstacles sizes (widobsx, widobsy, widairx, widairy) +73 63 43 40 +73 63 43 40 +73 63 43 40 +63 53 53 50 +53 43 63 60 + + +END of file diff --git a/geo_char.gh b/geo_char.gh new file mode 100644 index 0000000..a8c7c99 Binary files /dev/null and b/geo_char.gh differ diff --git a/read.me b/read.me new file mode 100644 index 0000000..c89d26d --- /dev/null +++ b/read.me @@ -0,0 +1,8 @@ +in this repository you can find some scripts for processing the CitySim output to run CIM. +"canopy.dbx" is the executable for CIM and you have to download CitySim. +The "citysim-surf_temp_buil_grd_surf_v2.py" script read the VF and TS file from CitySim and creates a file with surface temperatures for each direction, the roof and the ground. +The "citysim-hum_surf_v2.py" is the same as the surface temperature file but read the ET file instead. +The "create_citysim_cli_v2.py" uses the output from CIM to create a new CLI file for CitySim. +The "read_cli_citysim_v1.py" reads the standard CLI file used by CiySim to create a file used as input for CIM. +The "geo_char.gh" grasshopper script is run with Rhino and Grasshopper to create a file with width of the obstacles present in the scene for every 3m. You should use this output to create a file like the example given in "epfl_geo_char.dat" +The "run-vDM.01-ECY" is a bash script that processes all the files and runs all the scripts needed to run a full CIM - CitySim simulation. diff --git a/read_cli_citysim_v1.py b/read_cli_citysim_v1.py new file mode 100644 index 0000000..be51c0e --- /dev/null +++ b/read_cli_citysim_v1.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +# coding: utf-8 + +# # Preparing climate file for CIM + +# Script prepared by Dr. Dasaraden Mauree +# Contact: EPFL +# dasaraden.mauree@epfl.ch / dasaraden.mauree@gmail.com +# +# use this script to read the standard climate file from +# Meteonorm for CitySim and save new file for CIM. + +# In[1]: + + +#importing necessary packages +import pandas as pd + + +# In[2]: + + +#Opening file and saving in array +meteonorm=pd.read_csv("Ecublens.cli", header="infer", sep="\s+", encoding = "ISO-8859-1", skiprows=3) + + +# In[3]: + + +#Selecting columns and saving in file for CIM +cim=meteonorm[['Ta','FF','DD','RH']] +cim.to_csv(r'for_cim.cli', header=None, sep=' ', mode='a', index=False) + diff --git a/run-vDM.01-ECY b/run-vDM.01-ECY new file mode 100755 index 0000000..3ccefc8 --- /dev/null +++ b/run-vDM.01-ECY @@ -0,0 +1,85 @@ +#!/bin/bash + +############################################################### +# Prepared by D. Mauree, EPFL # +# dasaraden.mauree@epfl.ch # +############################################################### + +# dasaraden.mauree@epfl.ch # +############################################################### + +List="London" + +script=/home/mauree/program/scripts/cim-citysim +inputdir=/home/mauree/program/citysim/study\ case/climate_cim_citysim/ECY/Inputs +canopydir=/home/mauree/program/CANOPY/Program/versionDM.28 + +for rundir in $List; + do + echo $rundir + +#First CitySim simulation + echo --------------First CitySim simulation-------------- + + mkdir ECY/$rundir + cd ECY/$rundir + +#Creating local directories + mkdir meteonorm + mkdir input_cim + mkdir cim + + cd meteonorm + + ln -fs "$inputdir/$rundir/$rundir"_"ECY.cli" city.cli + ln -fs "$inputdir/$rundir/$rundir.xml" building.xml + + CitySim building.xml + + echo --------------Done with first CitySim simulation-------------- + + echo --------------Preparing data CIM-------------- + + cd ../input_cim + + rm * + + ln -fs "$script/citysim-surf_temp_buil_grd_surf_v2.py" . + ln -fs "$script/citysim-hum_surf_v2.py" . + ln -fs "$script/read_cli_citysim_v1.py" . + + ln -fs "../meteonorm/building_VF.out" . + ln -fs "../meteonorm/building_TS.out" . + ln -fs "../meteonorm/building_ET.out" . + + + python citysim-surf_temp_buil_grd_surf_v2.py + python citysim-hum_surf_v2.py + python read_cli_citysim_v1.py + + echo --------------CIM simulation-------------- + + ln -fs "$inputdir/$rundir/$rundir"_geo_char.dat city_geo_char.dat + ln -fs "$inputdir/canopy.par" . + + + $canopydir/canopy.dbx canopy.par + + echo --------------Done with CIM simulation-------------- + + ln -fs "$script/create_citysim_cli_v2.py" . + + python create_citysim_cli_v2.py + + echo --------------Second CitySim simulation-------------- + + cd ../cim + + ln -fs "$inputdir/$rundir/$rundir.xml" building.xml + CitySim building.xml + + echo --------------Done with second CitySim simulation-------------- + + cd ../../../ + + done