# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Reading and modifying EnergyPlus input files with EPInput.

# ## 1. Introduction
#
# This notebook shows how to use the [`EPInput`](https://eprun.readthedocs.io/en/latest/EPInput_class.html) class in the [eprun package](https://eprun.readthedocs.io/en/latest/index.html) to read and modify EnergyPlus .idf and .epJSON files. It uses the **'1ZoneUncontrolled'** file in the EnergyPlus example files.

# ## 2. Setup

# ### 2.1. Module import

from eprun import EPInput, EPSchema

# ### 2.2. Filepath to '1ZoneUncontrolled.idf' and  '1ZoneUncontrolled.epJSON' files

fp_idf='1ZoneUncontrolled.idf'
fp_epJSON='1ZoneUncontrolled.epJSON'

# ### 2.3. Set up EPSchema object

schema=EPSchema('Energy+.schema.epJSON')

# ## 3. Reading in the files

# ### 3.1. An .idf file
#
# Imports an EnergyPlus .idf file.

epi_idf=EPInput(fp_idf,schema)
type(epi_idf)

# Prints out the number of objects in the file.

len(epi_idf)

# ### 3.2. An .epJSON file
#
# Import an EnergyPlus .epJSON file. 
#
# *This is the equivalent file of the .idf file above.*

epi_epjson=EPInput(fp_epJSON,
                   schema  # optional, if imported then can be used for validation
                   )
type(epi_epjson)

# Prints out the number of objects in the file.

len(epi_epjson)

# *Note: At the point the .idf and the .epJSON file are now read into the same type of object, the EPInput object. So the remainder of this notebook needs only use one of these to demonstrate the EPInput class. Here the .idf file is used*

# ## 4. Viewing the contents of an EnergyPlus input file.

# ### 4.1. Number of objects

len(epi_idf)

# ### 4.2. List of objects

list(epi_idf)

# ### 4.3. Get object by index

epi_idf[0]

# ### 4.4. Iterate through objects

for o in epi_idf:
    print(o.object_type, end=' - ')

# ### 4.4. List of objects by object type

epi_idf['Construction']

# ### 4.5. Get object by name

epi_idf.get_object('Simple One Zone (Wireframe DXF)')

# ### 4.6. Get object by filter on properties

epi_idf.get_objects(surface_type='Floor')

# ### 4.7. Viewing the name of an object

epi_idf['Building'][0].name

# ### 4.8. Viewing the object type of an object

epi_idf['Building'][0].object_type

# ### 4.9. Viewing the properties of an object

dict(epi_idf['Building'][0])

# ### 4.10. Viewing a single property of an object

epi_idf['Building'][0]['terrain']  # index by key

epi_idf['Building'][0].terrain  # attribute fetch

# ### 4.11. Iterating through all properties of an object

for k,v in epi_idf['Building'][0].items():
    print(k, '->', v)

# ### 4.12. Viewing a summary count of all objects

epi_idf.summary()



















StarcoderdataJupyterScriptsDedupFiltered