{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# New functions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "These are recently written functions that have not made it into the main documentation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Python Lesson: Errors and Exceptions" ] }, { "cell_type": "code", "execution_count": 1, "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", "\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" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When things go wrong in your eppy script, you get \"Errors and Exceptions\". \n", "\n", "To know more about how this works in python and eppy, take a look at [Python: Errors and Exceptions](http://docs.python.org/2/tutorial/errors.html)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setting IDD name" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When you work with Energyplus you are working with **idf** files (files that have the extension \\*.idf). There is another file that is very important, called the **idd** file. This is the file that defines all the objects in Energyplus. Esch version of Energyplus has a different **idd** file. \n", "\n", "So eppy needs to know which **idd** file to use. Only one **idd** file can be used in a script or program. This means that you cannot change the **idd** file once you have selected it. Of course you have to first select an **idd** file before eppy can work.\n", "\n", "If you use eppy and break the above rules, eppy will raise an exception. So let us use eppy incorrectly and make eppy raise the exception, just see how that happens.\n", "\n", "First let us try to open an **idf** file without setting an **idd** file." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "from eppy import modeleditor \n", "from eppy.modeleditor import IDF\n", "fname1 = \"../eppy/resources/idffiles/V_7_2/smallfile.idf\"\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let us open file fname1 without setting the **idd** file" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "try:\n", " idf1 = IDF(fname1)\n", "except Exception as e:\n", " raise e\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "OK. It does not let you do that and it raises an exception\n", "\n", "So let us set the **idd** file and then open the idf file" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "iddfile = \"../eppy/resources/iddfiles/Energy+V7_2_0.idd\"\n", "IDF.setiddname(iddfile)\n", "idf1 = IDF(fname1)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "That worked without raising an exception\n", "\n", "Now let us try to change the **idd** file. Eppy should not let you do this and should raise an exception." ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "ename": "IDDAlreadySetError", "evalue": "IDD file is set to: ../eppy/resources/iddfiles/Energy+V7_2_0.idd", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mIDDAlreadySetError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mIDF\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msetiddname\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"anotheridd.idd\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mIDF\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msetiddname\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"anotheridd.idd\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/Documents/coolshadow/github/cutter_eppy/r_eppy/eppy/modeleditor.py\u001b[0m in \u001b[0;36msetiddname\u001b[0;34m(cls, iddname, testing)\u001b[0m\n\u001b[1;32m 583\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtesting\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 584\u001b[0m \u001b[0merrortxt\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"IDD file is set to: %s\"\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mcls\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0middname\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 585\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mIDDAlreadySetError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0merrortxt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 586\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 587\u001b[0m \u001b[0;34m@\u001b[0m\u001b[0mclassmethod\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mIDDAlreadySetError\u001b[0m: IDD file is set to: ../eppy/resources/iddfiles/Energy+V7_2_0.idd" ] } ], "source": [ "try:\n", " IDF.setiddname(\"anotheridd.idd\")\n", "except Exception as e:\n", " raise e \n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Excellent!! It raised the exception we were expecting." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Check range for fields" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The fields of idf objects often have a range of legal values. The following functions will let you discover what that range is and test if your value lies within that range" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "demonstrate two new functions:\n", "\n", "- EpBunch.getrange(fieldname) # will return the ranges for that field\n", "- EpBunch.checkrange(fieldname) # will throw an exception if the value is outside the range" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "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\"\n" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "# IDF.setiddname(iddfile)# idd ws set further up in this page\n", "idf1 = IDF(fname1)\n" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "BUILDING,\n", " Empire State Building, !- Name\n", " 30, !- North Axis\n", " City, !- Terrain\n", " 0.04, !- Loads Convergence Tolerance Value\n", " 0.4, !- Temperature Convergence Tolerance Value\n", " FullExterior, !- Solar Distribution\n", " 25, !- Maximum Number of Warmup Days\n", " 6; !- Minimum Number of Warmup Days\n", "\n" ] } ], "source": [ "building = idf1.idfobjects['building'][0]\n", "print(building)\n" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'maximum': 0.5, 'minimum': None, 'maximum<': None, 'minimum>': 0.0, 'type': 'real'}\n" ] } ], "source": [ "print(building.getrange(\"Loads_Convergence_Tolerance_Value\"))\n" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.04\n" ] } ], "source": [ "print(building.checkrange(\"Loads_Convergence_Tolerance_Value\"))\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us set these values outside the range and see what happens" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "ename": "RangeError", "evalue": "Value 0.6 is not less or equal to the 'maximum' of 0.5", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mRangeError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbuilding\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcheckrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Loads_Convergence_Tolerance_Value\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mRangeError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0meppy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbunch_subclass\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mRangeError\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbuilding\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcheckrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Loads_Convergence_Tolerance_Value\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mRangeError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/Documents/coolshadow/github/cutter_eppy/r_eppy/eppy/bunch_subclass.py\u001b[0m in \u001b[0;36mcheckrange\u001b[0;34m(self, fieldname)\u001b[0m\n\u001b[1;32m 213\u001b[0m \"\"\"Check if the value for a field is within the allowed range.\n\u001b[1;32m 214\u001b[0m \"\"\"\n\u001b[0;32m--> 215\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mcheckrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfieldname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 216\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 217\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mgetrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfieldname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/Documents/coolshadow/github/cutter_eppy/r_eppy/eppy/bunch_subclass.py\u001b[0m in \u001b[0;36mcheckrange\u001b[0;34m(bch, fieldname)\u001b[0m\n\u001b[1;32m 427\u001b[0m \u001b[0mastr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"Value %s is not less or equal to the 'maximum' of %s\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 428\u001b[0m \u001b[0mastr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mastr\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mfieldvalue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtherange\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"maximum\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 429\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mRangeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mastr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 430\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtherange\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"minimum\"\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 431\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mfieldvalue\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0mtherange\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"minimum\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mRangeError\u001b[0m: Value 0.6 is not less or equal to the 'maximum' of 0.5" ] } ], "source": [ "building.Loads_Convergence_Tolerance_Value = 0.6\n", "from eppy.bunch_subclass import RangeError\n", "try:\n", " print(building.checkrange(\"Loads_Convergence_Tolerance_Value\"))\n", "except RangeError as e:\n", " raise e\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So the Range Check works" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Looping through all the fields in an idf object" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We have seen how to check the range of field in the idf object. What if you want to do a *range check* on all the fields in an idf object ? To do this we will need a list of all the fields in the idf object. We can do this easily by the following line" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['key', 'Name', 'North_Axis', 'Terrain', 'Loads_Convergence_Tolerance_Value', 'Temperature_Convergence_Tolerance_Value', 'Solar_Distribution', 'Maximum_Number_of_Warmup_Days', 'Minimum_Number_of_Warmup_Days']\n" ] } ], "source": [ "print(building.fieldnames)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So let us use this" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "key = BUILDING\n", "Name = Empire State Building\n", "North_Axis = 30.0\n", "Terrain = City\n", "Loads_Convergence_Tolerance_Value = 0.6\n", "Temperature_Convergence_Tolerance_Value = 0.4\n", "Solar_Distribution = FullExterior\n", "Maximum_Number_of_Warmup_Days = 25\n", "Minimum_Number_of_Warmup_Days = 6\n" ] } ], "source": [ "for fieldname in building.fieldnames:\n", " print(\"%s = %s\" % (fieldname, building[fieldname]))\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let us test if the values are in the legal range. We know that \"Loads_Convergence_Tolerance_Value\" is out of range" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "key = BUILDING #-in range\n", "Name = Empire State Building #-in range\n", "North_Axis = 30.0 #-in range\n", "Terrain = City #-in range\n", "Loads_Convergence_Tolerance_Value = 0.6 #-****OUT OF RANGE****\n", "Temperature_Convergence_Tolerance_Value = 0.4 #-in range\n", "Solar_Distribution = FullExterior #-in range\n", "Maximum_Number_of_Warmup_Days = 25 #-in range\n", "Minimum_Number_of_Warmup_Days = 6 #-in range\n" ] } ], "source": [ "from eppy.bunch_subclass import RangeError\n", "for fieldname in building.fieldnames:\n", " try:\n", " building.checkrange(fieldname)\n", " print(\"%s = %s #-in range\" % (fieldname, building[fieldname],))\n", " except RangeError as e:\n", " print(\"%s = %s #-****OUT OF RANGE****\" % (fieldname, building[fieldname],))\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You see, we caught the out of range value" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Blank idf file" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Until now in all our examples, we have been reading an idf file from disk:\n", "\n", "- How do I create a blank new idf file \n", "- give it a file name\n", "- Save it to the disk\n", "\n", "Here are the steps to do that" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "VERSION,\n", " 7.3; !- Version Identifier\n", "\n", "SIMULATIONCONTROL,\n", " Yes, !- Do Zone Sizing Calculation\n", " Yes, !- Do System Sizing Calculation\n", " Yes, !- Do Plant Sizing Calculation\n", " No, !- Run Simulation for Sizing Periods\n", " Yes; !- Run Simulation for Weather File Run Periods\n", "\n", "BUILDING,\n", " Empire State Building, !- Name\n", " 30, !- North Axis\n", " City, !- Terrain\n", " 0.04, !- Loads Convergence Tolerance Value\n", " 0.4, !- Temperature Convergence Tolerance Value\n", " FullExterior, !- Solar Distribution\n", " 25, !- Maximum Number of Warmup Days\n", " 6; !- Minimum Number of Warmup Days\n", "\n", "SITE:LOCATION,\n", " CHICAGO_IL_USA TMY2-94846, !- Name\n", " 41.78, !- Latitude\n", " -87.75, !- Longitude\n", " -6, !- Time Zone\n", " 190; !- Elevation\n", "\n" ] } ], "source": [ "# some initial steps\n", "from eppy.modeleditor import IDF\n", "iddfile = \"../eppy/resources/iddfiles/Energy+V7_2_0.idd\"\n", "# IDF.setiddname(iddfile) # Has already been set \n", "\n", "# - Let us first open a file from the disk\n", "fname1 = \"../eppy/resources/idffiles/V_7_2/smallfile.idf\"\n", "idf_fromfilename = IDF(fname1) # initialize the IDF object with the file name\n", "\n", "idf_fromfilename.printidf()\n" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "VERSION,\n", " 7.3; !- Version Identifier\n", "\n", "SIMULATIONCONTROL,\n", " Yes, !- Do Zone Sizing Calculation\n", " Yes, !- Do System Sizing Calculation\n", " Yes, !- Do Plant Sizing Calculation\n", " No, !- Run Simulation for Sizing Periods\n", " Yes; !- Run Simulation for Weather File Run Periods\n", "\n", "BUILDING,\n", " Empire State Building, !- Name\n", " 30, !- North Axis\n", " City, !- Terrain\n", " 0.04, !- Loads Convergence Tolerance Value\n", " 0.4, !- Temperature Convergence Tolerance Value\n", " FullExterior, !- Solar Distribution\n", " 25, !- Maximum Number of Warmup Days\n", " 6; !- Minimum Number of Warmup Days\n", "\n", "SITE:LOCATION,\n", " CHICAGO_IL_USA TMY2-94846, !- Name\n", " 41.78, !- Latitude\n", " -87.75, !- Longitude\n", " -6, !- Time Zone\n", " 190; !- Elevation\n", "\n" ] } ], "source": [ "# - now let us open a file from the disk differently\n", "fname1 = \"../eppy/resources/idffiles/V_7_2/smallfile.idf\"\n", "fhandle = open(fname1, 'r') # open the file for reading and assign it a file handle\n", "idf_fromfilehandle = IDF(fhandle) # initialize the IDF object with the file handle\n", "\n", "idf_fromfilehandle.printidf()\n" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "# So IDF object can be initialized with either a file name or a file handle\n", "\n", "# - How do I create a blank new idf file \n", "idftxt = \"\" # empty string\n", "from io import StringIO\n", "fhandle = StringIO(idftxt) # we can make a file handle of a string\n", "idf_emptyfile = IDF(fhandle) # initialize the IDF object with the file handle\n", "\n", "idf_emptyfile.printidf()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It did not print anything. Why should it. It was empty. \n", "\n", "What if we give it a string that was not blank" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "VERSION,\n", " 7.3; !- Version Identifier\n", "\n" ] } ], "source": [ "# - The string does not have to be blank\n", "idftxt = \"VERSION, 7.3;\" # Not an emplty string. has just the version number\n", "fhandle = StringIO(idftxt) # we can make a file handle of a string\n", "idf_notemptyfile = IDF(fhandle) # initialize the IDF object with the file handle\n", "\n", "idf_notemptyfile.printidf()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Aha !\n", "\n", "Now let us give it a file name" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [], "source": [ "# - give it a file name\n", "idf_notemptyfile.idfname = \"notemptyfile.idf\"\n", "# - Save it to the disk\n", "idf_notemptyfile.save()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us confirm that the file was saved to disk" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "!- Darwin Line endings \n", "\n", "VERSION,\n", " 7.3; !- Version Identifier\n" ] } ], "source": [ "txt = open(\"notemptyfile.idf\", 'r').read()# read the file from the disk\n", "print(txt)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Yup ! that file was saved. Let us delete it since we were just playing" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [], "source": [ "import os\n", "os.remove(\"notemptyfile.idf\")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Deleting, copying/adding and making new idfobjects" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Making a new idf object" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us start with a blank idf file and make some new \"MATERIAL\" objects in it" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "# making a blank idf object\n", "blankstr = \"\"\n", "from io import StringIO\n", "idf = IDF(StringIO(blankstr))\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To make and add a new idfobject object, we use the function IDF.newidfobject(). We want to make an object of type \"MATERIAL\"" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [], "source": [ "newobject = idf.newidfobject(\"material\") \n", "\n", " " ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "MATERIAL,\n", " , !- Name\n", " , !- Roughness\n", " , !- Thickness\n", " , !- Conductivity\n", " , !- Density\n", " , !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", "\n" ] } ], "source": [ "print(newobject)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us give this a name, say \"Shiny new material object\"" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "MATERIAL,\n", " Shiny new material object, !- Name\n", " , !- Roughness\n", " , !- Thickness\n", " , !- Conductivity\n", " , !- Density\n", " , !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", "\n" ] } ], "source": [ "newobject.Name = \"Shiny new material object\"\n", "print(newobject)\n" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "MATERIAL,\n", " third material, !- Name\n", " , !- Roughness\n", " , !- Thickness\n", " , !- Conductivity\n", " , !- Density\n", " , !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", "\n" ] } ], "source": [ "anothermaterial = idf.newidfobject(\"material\")\n", "anothermaterial.Name = \"Lousy material\"\n", "thirdmaterial = idf.newidfobject(\"material\")\n", "thirdmaterial.Name = \"third material\"\n", "print(thirdmaterial)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us look at all the \"MATERIAL\" objects" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[\n", "MATERIAL,\n", " Shiny new material object, !- Name\n", " , !- Roughness\n", " , !- Thickness\n", " , !- Conductivity\n", " , !- Density\n", " , !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", ", \n", "MATERIAL,\n", " Lousy material, !- Name\n", " , !- Roughness\n", " , !- Thickness\n", " , !- Conductivity\n", " , !- Density\n", " , !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", ", \n", "MATERIAL,\n", " third material, !- Name\n", " , !- Roughness\n", " , !- Thickness\n", " , !- Conductivity\n", " , !- Density\n", " , !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", "]\n" ] } ], "source": [ "print(idf.idfobjects[\"MATERIAL\"])\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As we can see there are three MATERIAL idfobjects. They are:\n", "\n", "1. Shiny new material object\n", "2. Lousy material\n", "3. third material" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Deleting an idf object" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us remove 2. Lousy material. It is the second material in the list. So let us remove the second material" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\n", "MATERIAL,\n", " Lousy material, !- Name\n", " , !- Roughness\n", " , !- Thickness\n", " , !- Conductivity\n", " , !- Density\n", " , !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "idf.popidfobject('MATERIAL', 1) # first material is '0', second is '1'\n" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[\n", "MATERIAL,\n", " Shiny new material object, !- Name\n", " , !- Roughness\n", " , !- Thickness\n", " , !- Conductivity\n", " , !- Density\n", " , !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", ", \n", "MATERIAL,\n", " third material, !- Name\n", " , !- Roughness\n", " , !- Thickness\n", " , !- Conductivity\n", " , !- Density\n", " , !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", "]\n" ] } ], "source": [ "print(idf.idfobjects['MATERIAL'])\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can see that the second material is gone ! Now let us remove the first material, but do it using a different function" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [], "source": [ "firstmaterial = idf.idfobjects['MATERIAL'][-1]\n" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [], "source": [ "idf.removeidfobject(firstmaterial)\n" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[\n", "MATERIAL,\n", " Shiny new material object, !- Name\n", " , !- Roughness\n", " , !- Thickness\n", " , !- Conductivity\n", " , !- Density\n", " , !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", "]\n" ] } ], "source": [ "print(idf.idfobjects['MATERIAL'])\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So we have two ways of deleting an idf object:\n", "\n", "1. popidfobject -> give it the idf key: \"MATERIAL\", and the index number\n", "2. removeidfobject -> give it the idf object to be deleted" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Copying/Adding an idf object" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Having deleted two \"MATERIAL\" objects, we have only one left. Let us make a copy of this object and add it to our idf file" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [], "source": [ "onlymaterial = idf.idfobjects[\"MATERIAL\"][0]" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\n", "MATERIAL,\n", " Shiny new material object, !- Name\n", " , !- Roughness\n", " , !- Thickness\n", " , !- Conductivity\n", " , !- Density\n", " , !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "idf.copyidfobject(onlymaterial)" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[\n", "MATERIAL,\n", " Shiny new material object, !- Name\n", " , !- Roughness\n", " , !- Thickness\n", " , !- Conductivity\n", " , !- Density\n", " , !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", ", \n", "MATERIAL,\n", " Shiny new material object, !- Name\n", " , !- Roughness\n", " , !- Thickness\n", " , !- Conductivity\n", " , !- Density\n", " , !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", "]\n" ] } ], "source": [ "print(idf.idfobjects[\"MATERIAL\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So now we have a copy of the material. You can use this method to copy idf objects from other idf files too." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Making an idf object with named arguments" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What if we wanted to make an idf object with values for it's fields? We can do that too." ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [], "source": [ "gypboard = idf.newidfobject('MATERIAL', Name=\"G01a 19mm gypsum board\",\n", " Roughness=\"MediumSmooth\",\n", " Thickness=0.019,\n", " Conductivity=0.16,\n", " Density=800,\n", " Specific_Heat=1090)" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "MATERIAL,\n", " G01a 19mm gypsum board, !- Name\n", " MediumSmooth, !- Roughness\n", " 0.019, !- Thickness\n", " 0.16, !- Conductivity\n", " 800, !- Density\n", " 1090, !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", "\n" ] } ], "source": [ "print(gypboard)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "newidfobject() also fills in the default values like \"Thermal Absorptance\", \"Solar Absorptance\", etc." ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[\n", "MATERIAL,\n", " Shiny new material object, !- Name\n", " , !- Roughness\n", " , !- Thickness\n", " , !- Conductivity\n", " , !- Density\n", " , !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", ", \n", "MATERIAL,\n", " Shiny new material object, !- Name\n", " , !- Roughness\n", " , !- Thickness\n", " , !- Conductivity\n", " , !- Density\n", " , !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", ", \n", "MATERIAL,\n", " G01a 19mm gypsum board, !- Name\n", " MediumSmooth, !- Roughness\n", " 0.019, !- Thickness\n", " 0.16, !- Conductivity\n", " 800, !- Density\n", " 1090, !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", "]\n" ] } ], "source": [ "print(idf.idfobjects[\"MATERIAL\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Renaming an idf object" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is easy to rename an idf object. If we want to rename the gypboard object that we created above, we simply say:\n" ] }, { "cell_type": "raw", "metadata": {}, "source": [ " gypboard.Name = \"a new name\".\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "But this could create a problem. What if this gypboard is part of a \"CONSTRUCTION\" object. The construction object will refer to the gypboard by name. If we change the name of the gypboard, we should change it in the construction object. \n", "\n", "But there may be many constructions objects using the gypboard. Now we will have to change it in all those construction objects. Sounds painfull. \n", "\n", "Let us try this with an example:" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "CONSTRUCTION,\n", " Interior Wall, !- Name\n", " G01a 19mm gypsum board, !- Outside Layer\n", " Shiny new material object, !- Layer 2\n", " G01a 19mm gypsum board; !- Layer 3\n", "\n" ] } ], "source": [ "interiorwall = idf.newidfobject(\"CONSTRUCTION\", Name=\"Interior Wall\",\n", " Outside_Layer=\"G01a 19mm gypsum board\",\n", " Layer_2=\"Shiny new material object\",\n", " Layer_3=\"G01a 19mm gypsum board\")\n", "print(interiorwall)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "to rename gypboard and have that name change in all the places we call modeleditor.rename(idf, key, oldname, newname)" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\n", "MATERIAL,\n", " peanut butter, !- Name\n", " MediumSmooth, !- Roughness\n", " 0.019, !- Thickness\n", " 0.16, !- Conductivity\n", " 800, !- Density\n", " 1090, !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance" ] }, "execution_count": 56, "metadata": {}, "output_type": "execute_result" } ], "source": [ "modeleditor.rename(idf, \"MATERIAL\", \"G01a 19mm gypsum board\", \"peanut butter\")" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "CONSTRUCTION,\n", " Interior Wall, !- Name\n", " peanut butter, !- Outside Layer\n", " Shiny new material object, !- Layer 2\n", " peanut butter; !- Layer 3\n", "\n" ] } ], "source": [ "print(interiorwall)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we have \"peanut butter\" everywhere. At least where we need it. Let us look at the entir idf file, just to be sure" ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "MATERIAL,\n", " Shiny new material object, !- Name\n", " , !- Roughness\n", " , !- Thickness\n", " , !- Conductivity\n", " , !- Density\n", " , !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", "\n", "MATERIAL,\n", " Shiny new material object, !- Name\n", " , !- Roughness\n", " , !- Thickness\n", " , !- Conductivity\n", " , !- Density\n", " , !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", "\n", "MATERIAL,\n", " peanut butter, !- Name\n", " MediumSmooth, !- Roughness\n", " 0.019, !- Thickness\n", " 0.16, !- Conductivity\n", " 800, !- Density\n", " 1090, !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", "\n", "CONSTRUCTION,\n", " Interior Wall, !- Name\n", " peanut butter, !- Outside Layer\n", " Shiny new material object, !- Layer 2\n", " peanut butter; !- Layer 3\n", "\n" ] } ], "source": [ "idf.printidf()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Turn off default values" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Can I turn off the defautl values. Yes you can:" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "MATERIAL,\n", " with default, !- Name\n", " , !- Roughness\n", " , !- Thickness\n", " , !- Conductivity\n", " , !- Density\n", " , !- Specific Heat\n", " 0.9, !- Thermal Absorptance\n", " 0.7, !- Solar Absorptance\n", " 0.7; !- Visible Absorptance\n", "\n", "\n", "MATERIAL,\n", " Without default; !- Name\n", "\n" ] } ], "source": [ "defaultmaterial = idf.newidfobject(\"MATERIAL\", \n", " Name='with default')\n", "print(defaultmaterial)\n", "nodefaultmaterial = idf.newidfobject(\"MATERIAL\", \n", " Name='Without default',\n", " defaultvalues=False)\n", "print(nodefaultmaterial)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- But why would you want to turn it off. \n", "- Well .... sometimes you have to \n", "- Try it with the object `DAYLIGHTING:CONTROLS`, and you will see the need for `defaultvalues=False`\n", "\n", "Of course, internally EnergyPlus will still use the default values it it is left blank. If just won't turn up in the IDF file." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Zone area and volume" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The idf file has zones with surfaces and windows. It is easy to get the attributes of the surfaces and windows as we have seen in the tutorial. Let us review this once more:\n" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [], "source": [ "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/box.idf\"\n", "# IDF.setiddname(iddfile)" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [], "source": [ "idf = IDF(fname1)" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "area = 30.0\n", "tilt = 180.0\n", "azimuth = 0.0\n" ] } ], "source": [ "surfaces = idf.idfobjects[\"BuildingSurface:Detailed\"]\n", "surface = surfaces[0]\n", "print(\"area = %s\" % (surface.area, ))\n", "print(\"tilt = %s\" % (surface.tilt, ))\n", "print( \"azimuth = %s\" % (surface.azimuth, ))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Can we do the same for zones ? \n", "\n", "Not yet .. not yet. Not in this version on eppy\n", "\n", "But we can still get the area and volume of the zone\n" ] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "zone area = 30.0\n", "zone volume = 90.0\n" ] } ], "source": [ "zones = idf.idfobjects[\"ZONE\"]\n", "zone = zones[0]\n", "area = modeleditor.zonearea(idf, zone.Name)\n", "volume = modeleditor.zonevolume(idf, zone.Name)\n", "print(\"zone area = %s\" % (area, ))\n", "print(\"zone volume = %s\" % (volume, ))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Not as slick, but still pretty easy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Some notes on the zone area calculation:\n", "\n", "- area is calculated by summing up all the areas of the floor surfaces\n", "- if there are no floors, then the sum of ceilings and roof is taken as zone area\n", "- if there are no floors, ceilings or roof, we are out of luck. The function returns 0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Using JSON to update idf" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "we are going to update `idf1` using json. First let us print the `idf1` before changing it, so we can see what has changed once we make an update" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "VERSION,\n", " 7.3; !- Version Identifier\n", "\n", "SIMULATIONCONTROL,\n", " Yes, !- Do Zone Sizing Calculation\n", " Yes, !- Do System Sizing Calculation\n", " Yes, !- Do Plant Sizing Calculation\n", " No, !- Run Simulation for Sizing Periods\n", " Yes; !- Run Simulation for Weather File Run Periods\n", "\n", "BUILDING,\n", " Empire State Building, !- Name\n", " 30, !- North Axis\n", " City, !- Terrain\n", " 0.6, !- Loads Convergence Tolerance Value\n", " 0.4, !- Temperature Convergence Tolerance Value\n", " FullExterior, !- Solar Distribution\n", " 25, !- Maximum Number of Warmup Days\n", " 6; !- Minimum Number of Warmup Days\n", "\n", "SITE:LOCATION,\n", " CHICAGO_IL_USA TMY2-94846, !- Name\n", " 41.78, !- Latitude\n", " -87.75, !- Longitude\n", " -6, !- Time Zone\n", " 190; !- Elevation\n", "\n" ] } ], "source": [ "idf1.printidf()" ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [], "source": [ "import eppy.json_functions as json_functions\n", "json_str = {\"idf.VERSION..Version_Identifier\":8.5,\n", " \"idf.SIMULATIONCONTROL..Do_Zone_Sizing_Calculation\": \"No\",\n", " \"idf.SIMULATIONCONTROL..Do_System_Sizing_Calculation\": \"No\",\n", " \"idf.SIMULATIONCONTROL..Do_Plant_Sizing_Calculation\": \"No\",\n", " \"idf.BUILDING.Empire State Building.North_Axis\": 52,\n", " \"idf.BUILDING.Empire State Building.Terrain\": \"Rural\",\n", " }\n", "json_functions.updateidf(idf1, json_str)" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "VERSION,\n", " 8.5; !- Version Identifier\n", "\n", "SIMULATIONCONTROL,\n", " No, !- Do Zone Sizing Calculation\n", " No, !- Do System Sizing Calculation\n", " No, !- Do Plant Sizing Calculation\n", " No, !- Run Simulation for Sizing Periods\n", " Yes; !- Run Simulation for Weather File Run Periods\n", "\n", "BUILDING,\n", " Empire State Building, !- Name\n", " 52, !- North Axis\n", " Rural, !- Terrain\n", " 0.6, !- Loads Convergence Tolerance Value\n", " 0.4, !- Temperature Convergence Tolerance Value\n", " FullExterior, !- Solar Distribution\n", " 25, !- Maximum Number of Warmup Days\n", " 6; !- Minimum Number of Warmup Days\n", "\n", "SITE:LOCATION,\n", " CHICAGO_IL_USA TMY2-94846, !- Name\n", " 41.78, !- Latitude\n", " -87.75, !- Longitude\n", " -6, !- Time Zone\n", " 190; !- Elevation\n", "\n" ] } ], "source": [ "idf1.printidf()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compare the first printidf() and the second printidf(). \n", "\n", "The syntax of the json string is described below::" ] }, { "cell_type": "raw", "metadata": {}, "source": [ " idf.BUILDING.Empire State Building.Terrain\": \"Rural\"\n", " \n", " The key fields are seperated by dots. Let us walk through each field:\n", " \n", " idf -> make a change to the idf. (in the future there may be changes that are not related to idf)\n", " BUILDING -> the key for object to be changed\n", " Empire State Building -> The name of the object. In other word - the value of the field `Name`\n", " Terrain -> the field to be changed\n", " \n", " \"Rural\" -> the new value of the field\n", " \n", " If the object does not have a `Name` field, you leave a blank between the two dots and the first object will be changed. \n", " This is done for the version number change.\n", " \n", " \"idf.VERSION..Version_Identifier\":8.5" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also create a new object using JSON, using the same syntax. Take a look at this:" ] }, { "cell_type": "code", "execution_count": 67, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[\n", "BUILDING,\n", " Empire State Building, !- Name\n", " 52, !- North Axis\n", " Rural, !- Terrain\n", " 0.6, !- Loads Convergence Tolerance Value\n", " 0.4, !- Temperature Convergence Tolerance Value\n", " FullExterior, !- Solar Distribution\n", " 25, !- Maximum Number of Warmup Days\n", " 6; !- Minimum Number of Warmup Days\n", ", \n", "BUILDING,\n", " Taj, !- Name\n", " 0, !- North Axis\n", " Rural, !- Terrain\n", " 0.04, !- Loads Convergence Tolerance Value\n", " 0.4, !- Temperature Convergence Tolerance Value\n", " FullExterior, !- Solar Distribution\n", " 25, !- Maximum Number of Warmup Days\n", " 6; !- Minimum Number of Warmup Days\n", "]" ] }, "execution_count": 67, "metadata": {}, "output_type": "execute_result" } ], "source": [ "json_str = {\"idf.BUILDING.Taj.Terrain\": \"Rural\",}\n", "json_functions.updateidf(idf1, json_str)\n", "idf1.idfobjects['building']\n", "# of course, you are creating an invalid E+ file. But we are just playing here." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What if you object name had a dot `.` in it? Will the json_function get confused?\n", "\n", "If the name has a dot in it, there are two ways of doing this." ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [], "source": [ "# first way\n", "json_str = {\"idf.BUILDING.Taj.with.dot.Terrain\": \"Rural\",}\n", "json_functions.updateidf(idf1, json_str)\n", "# second way (put the name in single quotes)\n", "json_str = {\"idf.BUILDING.'Another.Taj.with.dot'.Terrain\": \"Rural\",}\n", "json_functions.updateidf(idf1, json_str)" ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[\n", "BUILDING,\n", " Empire State Building, !- Name\n", " 52, !- North Axis\n", " Rural, !- Terrain\n", " 0.6, !- Loads Convergence Tolerance Value\n", " 0.4, !- Temperature Convergence Tolerance Value\n", " FullExterior, !- Solar Distribution\n", " 25, !- Maximum Number of Warmup Days\n", " 6; !- Minimum Number of Warmup Days\n", ", \n", "BUILDING,\n", " Taj, !- Name\n", " 0, !- North Axis\n", " Rural, !- Terrain\n", " 0.04, !- Loads Convergence Tolerance Value\n", " 0.4, !- Temperature Convergence Tolerance Value\n", " FullExterior, !- Solar Distribution\n", " 25, !- Maximum Number of Warmup Days\n", " 6; !- Minimum Number of Warmup Days\n", ", \n", "BUILDING,\n", " Taj.with.dot, !- Name\n", " 0, !- North Axis\n", " Rural, !- Terrain\n", " 0.04, !- Loads Convergence Tolerance Value\n", " 0.4, !- Temperature Convergence Tolerance Value\n", " FullExterior, !- Solar Distribution\n", " 25, !- Maximum Number of Warmup Days\n", " 6; !- Minimum Number of Warmup Days\n", ", \n", "BUILDING,\n", " Another.Taj.with.dot, !- Name\n", " 0, !- North Axis\n", " Rural, !- Terrain\n", " 0.04, !- Loads Convergence Tolerance Value\n", " 0.4, !- Temperature Convergence Tolerance Value\n", " FullExterior, !- Solar Distribution\n", " 25, !- Maximum Number of Warmup Days\n", " 6; !- Minimum Number of Warmup Days\n", "]" ] }, "execution_count": 69, "metadata": {}, "output_type": "execute_result" } ], "source": [ "idf1.idfobjects['building']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Note** When you us the json update function:\n", "\n", "- The json function expects the `Name` field to have a value.\n", "- If you try to update an object with a blank `Name` field, the results may be unexpected (undefined ? :-). So don't do this.\n", "- If the object has no `Name` field (some don't), changes are made to the first object in the list. Which should be fine, since usually there is only one item in the list\n", "- In any case, if the object does not exist, it is created with the default values" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Use Case for JSON update" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you have an eppy running on a remote server somewhere on the internet, you can change an idf file by sending it a JSON over the internet. This is very useful if you ever need it. If you don't need it, you shouldn't care :-)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Open a file quickly¶" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is rather cumbersome to open an IDF file in eppy. From the tutorial, the steps look like this:" ] }, { "cell_type": "code", "execution_count": 70, "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", "fname = \"../eppy/resources/idffiles/V_7_2/smallfile.idf\"\n", "IDF.setiddname(iddfile)\n", "idf = IDF(fname)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "- You have to find the IDD file on your hard disk.\n", "- Then set the IDD using setiddname(iddfile).\n", "- Now you can open the IDF file\n", "\n", "Why can’t you just open the IDF file without jumping thru all those hoops. Why do you have to find the IDD file. What is the point of having a computer, if it does not do the grunt work for you.\n", "\n", "The function easyopen will do the grunt work for you. It will automatically read the version number from the IDF file, locate the correct IDD file and set it in eppy and then open your file. It works like this:" ] }, { "cell_type": "code", "execution_count": 74, "metadata": {}, "outputs": [], "source": [ "from importlib import reload\n", "import eppy\n", "reload(eppy.modeleditor)\n", "from eppy.easyopen import easyopen\n", "\n", "fname = '../eppy/resources/idffiles/V8_8/smallfile.idf'\n", "idf = easyopen(fname)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For this to work,\n", "\n", "- the IDF file should have the VERSION object. You may not have this if you are just working on a file snippet.\n", "- you need to have the version of EnergyPlus installed that matches your IDF version.\n", "- Energyplus should be installed in the default location.\n", "\n", "If easyopen does not work, use the long winded steps shown in the tutorial. That is guaranteed to work" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Fast HTML table file read" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To read the html table files you would usually use the functions described in [Reading outputs from E+](./Outputs_Tutorial.html). For instance you would use the functions as shown below." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "('Site and Source Energy',\n", " [['',\n", " 'Total Energy [kWh]',\n", " 'Energy Per Total Building Area [kWh/m2]',\n", " 'Energy Per Conditioned Building Area [kWh/m2]'],\n", " ['Total Site Energy', 47694.47, 51.44, 51.44],\n", " ['Net Site Energy', 47694.47, 51.44, 51.44],\n", " ['Total Source Energy', 140159.1, 151.16, 151.16],\n", " ['Net Source Energy', 140159.1, 151.16, 151.16]])\n" ] } ], "source": [ "from eppy.results import readhtml # the eppy module with functions to read the html\n", "import pprint\n", "pp = pprint.PrettyPrinter()\n", "\n", "fname = \"../eppy/resources/outputfiles/V_7_2/5ZoneCAVtoVAVWarmestTempFlowTable_ABUPS.html\" # the html file you want to read\n", "html_doc = open(fname, 'r').read() \n", "\n", "\n", "htables = readhtml.titletable(html_doc) # reads the tables with their titles\n", "firstitem = htables[0]\n", "pp.pprint(firstitem)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`titletable` reads all the tables in the HTML file. With large E+ models, this file can be extremeely large and `titletable` will load all the tables into memory. This can take several minutes. If you are trying to get one table or one value from a table, waiting several minutes for you reseult can be exessive.\n", "\n", "If you know which table you are looking for, there is a faster way of doing this. We used index=0 in the above example to get the first table. If you know the index of the file you are looking for, you can use a faster function to get the table as shown below" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "from eppy.results import fasthtml\n", "fname = \"../eppy/resources/outputfiles/V_7_2/5ZoneCAVtoVAVWarmestTempFlowTable_ABUPS.html\" # the html file you want to read\n", "filehandle = open(fname, 'r') # get a file handle to the html file" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "('Site and Source Energy',\n", " [['',\n", " 'Total Energy [kWh]',\n", " 'Energy Per Total Building Area [kWh/m2]',\n", " 'Energy Per Conditioned Building Area [kWh/m2]'],\n", " ['Total Site Energy', 47694.47, 51.44, 51.44],\n", " ['Net Site Energy', 47694.47, 51.44, 51.44],\n", " ['Total Source Energy', 140159.1, 151.16, 151.16],\n", " ['Net Source Energy', 140159.1, 151.16, 151.16]])\n" ] } ], "source": [ "firsttable = fasthtml.tablebyindex(filehandle, 0)\n", "pp.pprint(firstitem)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also get the table if you know the title of the table. This is the **bold** text just before the table in the HTML file. The title of our table is **Site and Source Energy**. The function `tablebyname` will get us the table." ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['Site and Source Energy',\n", " [['',\n", " 'Total Energy [kWh]',\n", " 'Energy Per Total Building Area [kWh/m2]',\n", " 'Energy Per Conditioned Building Area [kWh/m2]'],\n", " ['Total Site Energy', 47694.47, 51.44, 51.44],\n", " ['Net Site Energy', 47694.47, 51.44, 51.44],\n", " ['Total Source Energy', 140159.1, 151.16, 151.16],\n", " ['Net Source Energy', 140159.1, 151.16, 151.16]]]\n" ] } ], "source": [ "filehandle = open(fname, 'r') # get a file handle to the html file\n", "namedtable = fasthtml.tablebyname(filehandle, \"Site and Source Energy\")\n", "pp.pprint(namedtable)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Couple of things to note here:\n", "\n", "- We have to open the file again using `filehandle = open(fname, 'r')`\n", " - This is because both `tablebyname` and `tablebyindex` will close the file once they are done \n", "- Some tables do not have a **bold title** just before the table. `tablebyname` will not work for those functions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Other miscellaneous functions¶" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Fan power in Watts, BHP and fan cfm¶" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We normally think of fan power in terms of Brake Horsepower (BHP), Watts. Also when working with IP units it is useful to think of fan flow volume in terms of cubic feet per minute (cfm).\n", "\n", "Energyplus does not have fields for those values. With eppy we have functions that will calculate the values\n", "\n", "- fan power in BHP\n", "- fan power in Watts\n", "- fan flow in CFM\n", "\n", "It will work for the following objects:\n", "\n", "- FAN:CONSTANTVOLUME\n", "- FAN:VARIABLEVOLUME\n", "- FAN:ONOFF\n", "- FAN:ZONEEXHAUST\n", "- FANPERFORMANCE:NIGHTVENTILATION\n", "\n", "The sample code would look like this:" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "thefans = idf.idfobjects['Fan:VariableVolume']\n", "thefan = thefans[0]\n", "bhp = thefan.fanpower_bhp\n", "watts = thefan.fanpower_watts\n", "cfm = thefan.fan_maxcfm" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*Note: This code was hacked together quickly. Needs peer review in ../eppy/fanpower.py*" ] } ], "metadata": { "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.7" } }, "nbformat": 4, "nbformat_minor": 1 }