Coder Social home page Coder Social logo

rwth-ebc / pycity Goto Github PK

View Code? Open in Web Editor NEW
24.0 20.0 2.0 50.66 MB

Python package for data handling and scenario generation of city districts

License: MIT License

Python 73.77% Jupyter Notebook 26.23%
python urban city modeling urban-energy-modeling

pycity's Introduction

E.ON EBC RWTH Aachen University

Build Status Coverage Status License

pycity_base

Python package for data handling and scenario generation of city districts and urban energy systems.

Contributing

  1. Clone repository: git clone [email protected]:RWTH-EBC/pyCity.git (for SSH usage) Alternatively: Clone via https: git clone https://github.com/RWTH-EBC/pyCity.git
  2. Open an issue at https://github.com/RWTH-EBC/pyCity/issues
  3. Checkout development branch: git checkout development
  4. Update local development branch (if necessary): git pull origin development
  5. Create your feature branch: git checkout -b issueXY_explanation
  6. Commit your changes: git commit -m "Add some feature #XY"
  7. Push to the branch: git push origin issueXY_explanation
  8. Submit a pull request from issueXY_explanation to development branch via https://github.com/RWTH-EBC/pyCity/pulls

Installation

One important issue at the beginning: Please do NOT confuse pycity_base with the pycity package on pypi! This (other) pycity package is installable via pip. However, if you want to install pycity_base, follow this instruction.

pycity_base requires the following Python packages:

  • numpy==1.26.0
  • matplotlib==3.8.0
  • pandas==2.1.1
  • Shapely==2.0.1
  • openpyxl==3.1.2
  • networkx==2.5.1
  • pyproj==3.6.1

as well as the EBC Python packages:

  • richardsonpy==0.2.1

which is available at https://github.com/RWTH-EBC/richardsonpy

  • uesgraphs==0.6.4 (with dependencies to shapely and pyproj)

which is available at https://github.com/RWTH-EBC/uesgraphs

richardsonpy and uesgraphs can be installed via pip.

Installation of pycity_base

The latest version of pycity_base is 0.3.3.

When uesgraph and its dependencies are installed, you should be able to install pycity_base via pip:

pip install pycity_base

or:

pip install -e '<your_path_to_pycity_setup_folder>'

or:

<path_to_your_python_dist\Python.exe> -m pip install -e '<your_path_to_pycity_setup_folder>'

You can check if installation / adding packages to python has been successful by adding new .py file and trying to import uesgraphs and pyCity.

import uesgraphs

import pycity_base

Import should be possible without errors.

Example usage

import shapely.geometry.point as point
import matplotlib.pyplot as plt

import uesgraphs.visuals as uesvis

import pycity_base.classes.timer as time
import pycity_base.classes.weather as weath
import pycity_base.classes.prices as price
import pycity_base.classes.environment as env
import pycity_base.classes.demand.apartment as apart
import pycity_base.classes.demand.occupancy as occ
import pycity_base.classes.demand.domestic_hot_water as dhw
import pycity_base.classes.demand.electrical_demand as eldem
import pycity_base.classes.demand.space_heating as spaceheat
import pycity_base.classes.building as build
import pycity_base.classes.city_district as citydist
import pycity_base.classes.supply.building_energy_system as besys
import pycity_base.classes.supply.boiler as boil
import pycity_base.classes.supply.photovoltaic as pvsys


def main():
    #  Define the time discretization for the timer object
    timestep = 3600  # in seconds

    #  Define the total number of timesteps (in this case for one year)
    nb_timesteps = int(365 * 24 * 3600 / timestep)

    #  Generate environment with timer, weather, and prices objects
    #  ######################################################################
    timer = time.Timer(timeDiscretization=timestep,
                       timestepsTotal=nb_timesteps)
    weather = weath.Weather(timer=timer)
    prices = price.Prices()

    environment = env.Environment(timer=timer, weather=weather, prices=prices)

    #  Generate city district object
    #  ######################################################################
    city_district = citydist.CityDistrict(environment=environment)
    #  Annotations: To prevent some methods of subclasses uesgraph / nx.Graph
    #  from failing (e.g. '.subgraph()) environment is set as optional input
    #  parameter. However, it is necessary to use an environment object as
    #  input parameter to initialize a working cityDistrict object!

    #  Empty dictionary for building positions
    dict_pos = {}

    #  Generate shapely point positions
    dict_pos[0] = point.Point(0, 0)  # (x, y)
    dict_pos[1] = point.Point(20, 0)

    #  Use for loop to generate two identical building objects for city
    #  district
    #  ######################################################################
    for i in range(2):
        living_area = 200  # in m^2
        spec_sh_dem = 160  # Specific space heating demand in kWh/m^2
        number_occupants = 3  # Total number of occupants

        #  Generate space heating demand object (holding loadcurve attribute
        #  with space heating power)
        heat_demand = spaceheat.SpaceHeating(
            environment=environment,
            method=1,  # Standard load profile
            livingArea=living_area,  # in m^2
            specificDemand=spec_sh_dem)  # in kWh/m^2

        #  Generate occupancy object with stochastic user profile
        occupancy = occ.Occupancy(environment=environment,
                                  number_occupants=number_occupants)

        #  Generate electrical demand object
        el_dem_stochastic = eldem.ElectricalDemand(
            environment=environment,
            method=2,  # stochastic Richardson profile (richardsonpy)
            total_nb_occupants=number_occupants,  # Number of occupants
            randomizeAppliances=True,  # Random choice of installed appliances
            lightConfiguration=10,  # Light bulb configuration nb.
            occupancy=occupancy.occupancy,  # Occupancy profile (600 sec resolution)
            prev_heat_dev=True,  # Prevent space heating and hot water devices
            annualDemand=None,  # Annual el. demand in kWh could be used for
            do_normalization=False)  # rescaling (if do_normalization is True)
        #  Annotation: The calculation of stochastic electric load profiles
        #  is time consuming. If you prefer a faster method, you can either
        #  hand over an own array-like load curve (method=0) or generate a
        #  standardized load profile (SLP) (method=1)

        #  Generate domestic hot water demand object
        dhw_obj = dhw.DomesticHotWater(
            environment=environment,
            tFlow=60,  # DHW output temperature in degree Celsius
            method=2,  # Stochastic dhw profile
            supplyTemperature=25,  # DHW inlet flow temperature in degree C.
            occupancy=occupancy.occupancy)  # Occupancy profile (600 sec resolution)

        #  Generate apartment and add demand curves
        apartment = apart.Apartment(environment)
        apartment.addMultipleEntities([heat_demand,
                                       el_dem_stochastic,
                                       dhw_obj])

        #  Generate building and add apartment
        building = build.Building(environment)
        building.addEntity(apartment)

        #  Add buildings to city district
        city_district.addEntity(entity=building,
                                position=dict_pos[i])

    #  Access information on city district object instance
    #  ######################################################################
    print('Get number of building entities:')
    print(city_district.get_nb_of_building_entities())
    print()

    print('Get list with node ids of building entities:')
    print(city_district.get_list_build_entity_node_ids())
    print()

    print('Get city district overall space heating power load curve:')
    print(city_district.get_aggr_space_heating_power_curve(current_values=True))
    print()
    
    print('Get city district overall space cooling power load curve:')
    print(city_district.get_aggr_space_cooling_power_curve(current_values=True))
    print()

    #  We can use the Visuals class of uesgraphs to plot the city district

    #  Generate uesgraphs visuals object instance
    uesvisuals = uesvis.Visuals(uesgraph=city_district)

    fig = plt.figure()
    ax = fig.gca()
    ax = uesvisuals.create_plot_simple(ax=ax)
    plt.show()
    plt.close()

    #  Access buildings
    #  ######################################################################
    #  As city_district is a networkx graph object, we can access the building
    #  entities with the corresponding building node,
    #  Pointer to building object with id 1001:
    building_1001 = city_district.nodes[1001]['entity']

    print('Get building 1001 electric load curve:')
    print(building_1001.get_electric_power_curve())
    print()

    #  Add energy systems to buildings
    #  ######################################################################
    #  We can also add building energy systems (BES) to each building object

    #  Generate boiler object
    boiler = boil.Boiler(environment=environment,
                         qNominal=10000,  # Boiler thermal power in Watt
                         eta=0.85)  # Boiler efficiency

    #  Generate PV module object
    pv = pvsys.PV(environment=environment,
                  area=30,  # Area in m^2
                  eta=0.15)  # Electrical efficiency at NOCT conditions

    # Instantiate BES (container object for all energy systems)
    bes = besys.BES(environment)

    #  Add energy systems to bes
    bes.addMultipleDevices([boiler, pv])

    #  Add bes to building 1001
    building_1001.addEntity(entity=bes)

    print('Does building 1001 has a building energy system (BES)?')
    print(building_1001.hasBes)

    #  Access boiler nominal thermal power
    print('Nominal thermal power of boiler in kW:')
    print(building_1001.bes.boiler[0].qNominal / 1000)


if __name__ == '__main__':
    #  Run program
    main()

Tutorial

pycity_base also has also a jupyter notebook tutorial script under pycity/examples/tutorials/... To open the jupyter notebook, open a command/terminal window and change your directory to the directory, where tutorial_pycity_calc_1.ipynb is stored. Then type 'jupyter notebook' (without '' signs) and press Enter. Jupyter notebook should open within your browser (such as Firefox). Click on one notebook to start. If your Pyhton path does not point at your Python installation, you have to open jupyter notebook directly, e.g. by looking for the jupyter.exe in your distribution.

How to cite pycity_base

  • Schiefelbein, J., Rudnick, J., Scholl, A., Remmen, P., Fuchs, M., Müller, D. (2019), Automated urban energy system modeling and thermal building simulation based on OpenStreetMap data sets, Building and Environment, Volume 149, Pages 630-639, ISSN 0360-1323 pdf, bibtex

If you require a reference in German language:

  • Schiefelbein, J. , Javadi, A. , Fuchs, M. , Müller, D. , Monti, A. and Diekerhof, M. (2017), Modellierung und Optimierung von Mischgebieten. Bauphysik, 39: 23-32. doi:10.1002/bapi.201710001 pdf, bibtex

License

pyCity is released by RWTH Aachen University's E.ON Energy Research Center (E.ON ERC), Institute for Energy Efficient Buildings and Indoor Climate (EBC) and Institute for Automation of Complex Power Systems (ACS) under the MIT License

Acknowledgements

We gratefully acknowledge the financial support by BMWi (German Federal Ministry for Economic Affairs and Energy) under promotional references 03ET1138D and 03ET1381A.

pycity's People

Contributors

jschiefelbein avatar michamans avatar milu29 avatar mschumacher247 avatar sebuer avatar ss391347 avatar thomasschuetz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

kksharma3951

pycity's Issues

Clean up

Delete all unnecessary debugging files

Possible bug in changeResolution.py

The test method:

def test_change_res_mean_larger_timestep(self):
input_array = [10, 10, 20, 20]
output_array = chres.changeResolution(values=input_array,
oldResolution=900,
newResolution=3600,
method="mean")
assert output_array[0] == 15

results in an assertion error. However, method changeResolutionPD is able to process the same input with correct results.

get_aggr_space_h_power_curve crashes

get_aggr_space_h_power_curve method of citydistrict raises an error if current_values==False and
chosen combination of timeDiscretization and timesteps total is smaller than one year.

(same error for other aggr_methods)

test_cityDistrict.py crashes

test_cityDistrict.py crashes, if electrical demand curve is generated with method=2

Traceback (most recent call last):
File "D:/Arbeitsordner_Lokal/PyCharm_workspace/pyCity/pycity/tests/test_cityDisctrict.py", line 101, in
run_test()
File "D:/Arbeitsordner_Lokal/PyCharm_workspace/pyCity/pycity/tests/test_cityDisctrict.py", line 42, in run_test
annualDemand=3000)
File "D:\Arbeitsordner_Lokal\PyCharm_workspace\pyCity\pycity\classes\demand\ElectricalDemand.py", line 161, in init
current_occupancy)[0])
File "D:\Arbeitsordner_Lokal\PyCharm_workspace\pyCity\pycity\classes\demand\StochasticElectricalLoadWrapper.py", line 90, in demands
self.lighting_config)
File "D:\Arbeitsordner_Lokal\PyCharm_workspace\pyCity\pycity\functions\stochastic_electrical_load\lighting_model.py", line 130, in run_lighting_simulation
iActiveOccupants = vOccupancyArray[int(iTime / 10.0)]
IndexError: list index out of range

Add info to README

Add further information about:

  • Usage / Description
  • License
  • Acknowledgement

CityDistrict generator

A city district generator script should be added, which is able to generate a random city district or load existing city district information (e.g. as csv) and generate CityDistrict object.

Visualisation of cityDistrict graph doesn't work

Visualisation of edges in cityDistrict graph (e.g. two building entities) can not be shown with uesgraph.visuals class. See error message below.

_ File "D:/Git/pyCity/pycity/examples/example_cityDisctrict_msu.py", line 114, in run_test
vis.show_network(save_as=save_as, show_plot=False)

File "d:\git\uesgraphs\uesgraphs\visuals.py", line 257, in show_network
style=style,

UnboundLocalError: local variable 'style' referenced before assignment_

Normalization of stochastic electrical profiles

Currently, the usage of method=2 for ElectricalDemand class results in "randomly" generated profiles, even if user defines annualDemand input parameter. This might lead to confusion.

We should find a way to normalize the stochastic eletrical load profiles (e.g. via calibration factor for appliance power).

Extract occupancy computation

Currently, the occupancy computation is coupled with the stochastical electrical demand computation.

As the occupancy is also relevant for the stochastical dhw calculation and the set-temperatures/ventilation rates, the occupancy computation should be extracted into a separate function/class.

Different methods of subclass uesgraph / nx.Graph are not usable

Currently, initializiation of city district object requires environment as parameter. However, different methods of nx.Graph or uesgraph (e.g. '.subgraph()') use class method to initialize new object, which causes an error, when environment input parameter is missing.

We should probably split initialization of city district graph and adding of environment to enable these methods.

Add py.test into new test folder

py.test script should be added. Therefore, scripts within 'tests' folder should be moved to examples folder. New test scripts should be added to 'test' folder.

Readme

Provide readme for this repo

test_electricalDemand.py does not work

Version does not hold functions.occupancy.py. Therefore, import within test_electricalDemand.py fails

ImportError: No module named 'functions.occupancy_model'

Building zone parameterization

Currently, the parameterization of buildings requires a zoneParameters object which again needs a lot of manual inputs.

Better: Define typical buildings that only rely on a few significant parameters (e.g. construction year, construction type and surface areas)

Add grid structure to CityDistrict class

CityDistrict class should be extended with grid structure for:

  • Heating networks
  • Cooling networks
  • Decentralized electrical grids / Microgrids
  • Gas grids
  • Street networks
  • Other networks (place holder)

Add Occupancy object as optional parameter to Apartment

Currently, apartment holds optional parameters:

  • nb_of_occupants
  • occupancy_profile (array-like)
    Instead, Occupancy object should be stored, which holds this information.

First, this enables all options related to Occupancy object. Second, Number of occupants and occupancy profile should be consistent (which is not necessarily the case for current Apartment objects)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.