<jupyter_start><jupyter_text>Example: Writing a thermal network model to the extended 3DCityDBThis example shows how to write a simple thermal network model to the extended *3DCityDB*, using the `dblayer` package. Basic knowledge about [CityGML](http://www.citygmlwiki.org) and the [Utility Network ADE](https://en.wiki.utilitynetworks.sig3d.org) are required for this notebook. A nice overview of the of the basic concepts of the Utility Network ADE can be found [here](https://en.wiki.utilitynetworks.sig3d.org/images/upload/20160913_-_Kolbe_-_Modeling_3D_Utility_Networks_%2B_UtilityNetwork_ADE_Core_Model.pdf).For the example, a simple thermal network is used, as shown in the following figure (SRC = thermal source, SNK = thermal sink, N = network node / pipe junction).  Getting started ...Import the required funtionality from package `dblayer`.<jupyter_code>from dblayer.helpers.utn.thermal_network import *<jupyter_output><empty_output><jupyter_text>Load data from CSV files, containing information about busses, lines and loads.<jupyter_code>import pandas as pd
import os.path

sinks_csv_data = pd.read_csv( os.path.join( 'csv', 'thermal_sink_data.csv' ), index_col = 0 )
junctions_csv_data = pd.read_csv( os.path.join( 'csv', 'thermal_junction_data.csv' ), index_col = 0 )
pipes_csv_data = pd.read_csv( os.path.join( 'csv', 'thermal_pipe_data.csv' ), index_col = 0 )<jupyter_output><empty_output><jupyter_text>Dict for most relevant data of thermal nodes (i.e., thermal sources, thermal loads, pipe junctions) added to the database<jupyter_code>nodes_data = {}<jupyter_output><empty_output><jupyter_text>Connect to databaseDefine connection parameters for 3DCityDB instance.<jupyter_code>connect = PostgreSQLConnectionInfo(
    user = 'postgres',
    pwd = '<PASSWORD>',
    host = 'localhost',
    port = '5432',
    dbname = 'citydb'
    )<jupyter_output><empty_output><jupyter_text>Connect to database using an instance of class `DBAccess`.<jupyter_code>db_access = DBAccess()
db_access.connect_to_citydb( connect )<jupyter_output><empty_output><jupyter_text>For the purpose of this notebook yoi might want to use an empty 3DCityDB. To this end, the next two lines erase all data from an existing database. **Only execute the next two lines if you really want to erase all data from your database!**<jupyter_code>db_access.cleanup_citydb_schema()
db_access.cleanup_simpkg_schema()<jupyter_output><empty_output><jupyter_text>Write the network to the databaseDefine the spatial reference ID (SRID) of the network. This should be consistent with the setup of your database.<jupyter_code>srid = 4326<jupyter_output><empty_output><jupyter_text>Insert a new *network* and an associated *network graph*. The *network* basically contains the topographical representation - the so-called *network features* - of all the network network components. The *network graph* contains the toplogical representation - of all these components the topological links between them. Use function `write_network_to_db` from package `dblayer.helpers.utn.thermal_network`.<jupyter_code>( ntw_id, ntw_graph_id ) = write_network_to_db(
    db_access,
    name = 'thermal_example_network',
    id = 2000
    )<jupyter_output><empty_output><jupyter_text>Add thermal source to the network. Use function `write_terminal_element_to_db` from package `dblayer.helpers.utn.thermal_network`.<jupyter_code>source_name = 'source-SRC'

nodes_data[source_name] = write_terminal_element_to_db( 
    db_access,
    source_name,
    Point2D( 0., 0. ),
    'thermal-source',
    srid,
    ntw_id,
    ntw_graph_id
    )<jupyter_output><empty_output><jupyter_text>Add thermal sinks to the network. Use function `write_dhw_sink_to_db` from package `dblayer.helpers.utn.thermal_network`.<jupyter_code>for sink_name, sink_csv_data in sinks_csv_data.iterrows():

    nodes_data[sink_name] = write_dhw_sink_to_db(
        db_access,
        sink_name,
        Point2D( sink_csv_data.x, sink_csv_data.y ),
        sink_csv_data.heat_diss_kw,
        'kW',
        srid,
        ntw_id,
        ntw_graph_id )<jupyter_output><empty_output><jupyter_text>Add pipe junctions to the network. Use function `write_junction_to_db` from package `dblayer.helpers.utn.thermal_network`.<jupyter_code>for junction_name, junction_csv_data in junctions_csv_data.iterrows():

    nodes_data[junction_name] = write_junction_to_db(
        db_access,
        junction_name,
        Point2D( junction_csv_data.x, junction_csv_data.y ),
        srid,
        ntw_id,
        ntw_graph_id
        )<jupyter_output><empty_output><jupyter_text>Add all pipes to the network and connect them. Use function `write_round_pipe_to_db` from package `dblayer.helpers.utn.thermal_network`.<jupyter_code>for pipe_name, pipe_csv_data in pipes_csv_data.iterrows():

    write_round_pipe_to_db(
        db_access,
        pipe_name,
        nodes_data[pipe_csv_data.from_node],
        nodes_data[pipe_csv_data.to_node],
        srid,
        ntw_id,
        ntw_graph_id,
        'distribution-pipe'
    )<jupyter_output><empty_output><jupyter_text>Commit changes to database.<jupyter_code>db_access.commit_citydb_session()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08822393822393823, 'fraction_numerical': 0.0069498069498069494, 'mean_word_length': 5.145907473309609, 'pattern_counts': {'":': 0, '<': 54, '<?xml version=': 0, '>': 54, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '486980', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 1758, 'n_tokens_neox': 1697, 'n_words': 419, 'path': 'examples/ThermalNetworkModelWriteDB.ipynb', 'repo_name': 'IntegrCiTy/dblayer', 'size': '5178'}