From 856007f27bcba690d9e30591e69d5fe3dc11e231 Mon Sep 17 00:00:00 2001 From: Joao Rocha <6793019+jmrocha@users.noreply.github.com> Date: Sun, 7 Jan 2024 21:12:10 +0000 Subject: [PATCH] Install eppy and fetch input files online #431 The `/docs/Main_Tutorial.ipynb` notebook now installs the `eppy` package and fetches one `.idd` and three `.idf` files. Previously, the notebook assumed that the package was already installed and that the files were present in local storage at specific locations. - The `eppy` package is installed with `pip`. - The `.idd` file is obtained from the `v23.2.0` tag of the EnergyPlus project. It comes encoded in CP-1252. - The `.idf` files are now fetched from the `master` branch of this repository. --- docs/Main_Tutorial.ipynb | 100 +++++++++++++++------------------------ 1 file changed, 37 insertions(+), 63 deletions(-) diff --git a/docs/Main_Tutorial.ipynb b/docs/Main_Tutorial.ipynb index c39abf0d..8bf43026 100644 --- a/docs/Main_Tutorial.ipynb +++ b/docs/Main_Tutorial.ipynb @@ -92,37 +92,44 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# you would normaly install eppy by doing\n", - "# python setup.py install\n", - "# or\n", - "# pip install eppy\n", - "# or\n", - "# easy_install eppy\n", + "!pip install eppy" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "def from_url_to_file(url, output_path):\n", + " import os\n", + " if not os.path.exists(output_path):\n", + " import urllib.request, urllib.parse\n", + " with urllib.request.urlopen(url) as response, open(output_path, mode='w') as file:\n", + " data = response.read().decode('cp1252')\n", + " file.write(data)\n", "\n", - "# if you have not done so, uncomment the following three lines\n", - "import sys\n", - "# pathnameto_eppy = 'c:/eppy'\n", - "pathnameto_eppy = '../'\n", - "sys.path.append(pathnameto_eppy) \n", + "idd_url = 'https://raw.githubusercontent.com/NREL/EnergyPlus/v23.2.0/idd/versions/V7-2-0-Energy%2B.idd'\n", + "idf_url = 'https://raw.githubusercontent.com/santoshphilip/eppy/master/eppy/resources/idffiles/V_7_2/smallfile.idf'\n", "\n", - "from eppy import modeleditor \n", - "from eppy.modeleditor import IDF\n", - "iddfile = \"../eppy/resources/iddfiles/Energy+V7_2_0.idd\"\n", - "fname1 = \"../eppy/resources/idffiles/V_7_2/smallfile.idf\"" + "from_url_to_file(idd_url, 'in.idd')\n", + "from_url_to_file(idf_url, 'in1.idf')" ] }, { "cell_type": "code", - "execution_count": 83, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ - "IDF.setiddname(iddfile)\n", - "idf1 = IDF(fname1)\n" + "from eppy.modeleditor import IDF\n", + "\n", + "IDF.setiddname('in.idd')\n", + "idf1 = IDF('in1.idf')" ] }, { @@ -851,28 +858,20 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Let us open a small idf file that has only \"CONSTRUCTION\" and \"MATERIAL\" objects in it. You can go into \"../idffiles/V_7_2/constructions.idf\" and take a look at the file. We are not printing it here because it is too big. \n", + "Let us open a small idf file that has only \"CONSTRUCTION\" and \"MATERIAL\" objects in it. You can open https://raw.githubusercontent.com/santoshphilip/eppy/0d99f8be881e7cf998208edb5e86c0654aaf5dc8/eppy/resources/idffiles/V_7_2/constructions.idf and take a look at the file. We are not printing it here because it is too long. \n", "\n", "So let us open it using the idfreader -" ] }, { "cell_type": "code", - "execution_count": 105, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ - "from eppy import modeleditor\n", - "from eppy.modeleditor import IDF\n", - "\n", - "iddfile = \"../eppy/resources/iddfiles/Energy+V7_2_0.idd\"\n", - "try:\n", - " IDF.setiddname(iddfile)\n", - "except modeleditor.IDDAlreadySetError as e:\n", - " pass\n", - "\n", - "fname1 = \"../eppy/resources/idffiles/V_7_2/constructions.idf\"\n", - "idf1 = IDF(fname1)\n" + "idf_url = 'https://raw.githubusercontent.com/santoshphilip/eppy/0d99f8be881e7cf998208edb5e86c0654aaf5dc8/eppy/resources/idffiles/V_7_2/constructions.idf'\n", + "from_url_to_file(idf_url, 'in2.idf')\n", + "idf1 = IDF('in2.idf')" ] }, { @@ -884,7 +883,7 @@ }, { "cell_type": "code", - "execution_count": 106, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -2988,44 +2987,19 @@ }, { "cell_type": "code", - "execution_count": 172, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ - "# OLD CODE, SHOULD BE DELETED\n", - "# from idfreader import idfreader\n", - "\n", - "# iddfile = \"../iddfiles/Energy+V7_0_0_036.idd\"\n", - "# fname = \"../idffiles/V_7_0/5ZoneSupRetPlenRAB.idf\"\n", - " \n", - "# model, to_print, idd_info = idfreader(fname, iddfile)\n", - "# surfaces = model['BUILDINGSURFACE:DETAILED'] # all the surfaces\n" - ] - }, - { - "cell_type": "code", - "execution_count": 173, - "metadata": {}, - "outputs": [], - "source": [ - "from eppy import modeleditor\n", - "from eppy.modeleditor import IDF\n", - "\n", - "iddfile = \"../eppy/resources/iddfiles/Energy+V7_2_0.idd\"\n", - "try:\n", - " IDF.setiddname(iddfile)\n", - "except modeleditor.IDDAlreadySetError as e:\n", - " pass\n", - "\n", - "\n", - "fname1 = \"../eppy/resources/idffiles/V_7_0/5ZoneSupRetPlenRAB.idf\"\n", - "idf1 = IDF(fname1)\n", + "idf_url = 'https://raw.githubusercontent.com/santoshphilip/eppy/master/eppy/resources/idffiles/V_7_0/5ZoneSupRetPlenRAB.idf'\n", + "from_url_to_file(idf_url, 'in3.idf')\n", + "idf1 = IDF('in3.idf')\n", "surfaces = idf1.idfobjects['BUILDINGSURFACE:DETAILED']\n" ] }, { "cell_type": "code", - "execution_count": 174, + "execution_count": 10, "metadata": {}, "outputs": [ {