Skip to content

Commit

Permalink
- fix tutorials
Browse files Browse the repository at this point in the history
- fix codacy issues
  • Loading branch information
mfranz13 committed Nov 12, 2024
1 parent 1e95bc5 commit a1adb81
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/pandapipes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pandapipes.properties.fluids import *
from pandapipes.component_models.component_registry import *
from pandapipes.component_models import *
from pandapipes.component_init import COMPONENT_REGISTRY
from pandapipes.component_init import COMPONENT_REGISTRY, COMPONENT_LIST
from pandapipes.create import *
from pandapipes.io.file_io import *
from pandapipes.pipeflow import *
Expand Down
15 changes: 8 additions & 7 deletions src/pandapipes/component_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
MassStorage, CirculationPumpMass, CirculationPumpPressure, Compressor, FlowControlComponent, HeatConsumer, \
HeatExchanger, ValvePipe

"""
every high level Component from pandapipes should be initialized here
"""
COMPONENT_REGISTRY = ComponentRegistry(
[Junction, Pipe, ExtGrid, Sink, Source, Valve, Pump, PressureControlComponent, MassStorage,
CirculationPumpMass, CirculationPumpPressure, Compressor, FlowControlComponent, HeatConsumer,
HeatExchanger, ValvePipe]).registry

# every high level Component from pandapipes should be initialized here

COMPONENT_LIST = [Junction, Pipe, ExtGrid, Sink, Source, Valve, Pump, PressureControlComponent, MassStorage,
CirculationPumpMass, CirculationPumpPressure, Compressor, FlowControlComponent, HeatConsumer,
HeatExchanger, ValvePipe]

COMPONENT_REGISTRY = ComponentRegistry(COMPONENT_LIST).registry
1 change: 0 additions & 1 deletion src/pandapipes/converter/stanet/stanet2pandapipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
create_sinks_meters, create_sinks_from_nodes, create_control_components, \
create_sinks_from_customers, create_pipes_house_connections
from pandapipes.create import create_empty_network
from pandapipes.component_init import COMPONENT_REGISTRY

try:
import pandaplan.core.pplog as logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from pandapipes.component_models.valve_pipe_component import ValvePipe
from pandapipes.create import _check_branch, _check_std_type
from pandapipes.pandapipes_net import pandapipesNet, add_new_component
from pandapipes.pandapipes_net import add_new_component


def create_valve_pipe(net, from_junction, to_junction, std_type, length_km, k_mm=0.15e-3,
Expand Down
12 changes: 2 additions & 10 deletions src/pandapipes/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from pandapipes.pandapipes_net import pandapipesNet
from pandapipes.topology import create_nxgraph
from pandapipes.utils.internals import get_lookup
from pandapipes.component_init import COMPONENT_REGISTRY
from pandapipes.component_init import COMPONENT_REGISTRY, COMPONENT_LIST

try:
import pandaplan.core.pplog as logging
Expand Down Expand Up @@ -110,22 +110,14 @@ def element_junction_tuples(include_node_elements=True, include_branch_elements=
:return: set of tuples with element names and column names
:rtype: set
"""
from pandapipes.component_models import Sink, Source, ExtGrid, Pipe, Valve, Pump, \
CirculationPumpMass, CirculationPumpPressure, HeatExchanger, PressureControlComponent, \
Compressor, FlowControlComponent, ValvePipe
from pandapipes.component_models import Junction, MassStorage, HeatConsumer # todo: wieso sind diese Komponenten da nicht mit drinne?
special_elements_junctions = [("press_control", "controlled_junction")]
move_elements = {"n2b": [], "b2n": []}
node_elements = []
branch_elements = []
if net is not None:
all_tables = {table_name: COMPONENT_REGISTRY[table_name].__class__ for table_name in net.component_list}
else:
comp_list = [Sink, Source, ExtGrid, Pipe, Valve, Pump, CirculationPumpMass,
CirculationPumpPressure, HeatExchanger, PressureControlComponent, Compressor,
FlowControlComponent, ValvePipe]
all_tables = {COMPONENT_REGISTRY[comp].table_name: comp for comp in comp_list}
# todo: from_json anpassen, damit Netze die so geladen werden nicht die Klassen, sondern die Tabellennamen haben
all_tables = {COMPONENT_REGISTRY[comp].table_name: comp for comp in COMPONENT_LIST}
ejts = set()
if include_node_elements:
node_elements = [tbl for tbl, comp in all_tables.items() if
Expand Down
2 changes: 1 addition & 1 deletion src/pandapipes/utils/result_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def get_gas_vel_numba(node_pit, branch_pit, comp_from, comp_to, comp_mean, p_abs
v_gas_from, v_gas_to, v_gas_mean, normfactor_from, normfactor_to, normfactor_mean = \
[np.empty_like(v_mps) for _ in range(6)]
from_nodes = branch_pit[:, FROM_NODE].astype(np.int32)
for i in range(len(v_mps)):
for i, _ in enumerate(v_mps):
t_from = node_pit[from_nodes[i], TINIT_NODE]
t_to = branch_pit[i, TOUTINIT]
tm = (t_from + t_to) / 2
Expand Down
9 changes: 5 additions & 4 deletions tutorials/circular_flow_in_a_district_heating_grid.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@
"outputs": [],
"source": [
"from pandapipes.component_models import Pipe\n",
"pipe_results = Pipe.get_internal_results(net, [0])"
"from pandapipes.component_init import COMPONENT_REGISTRY\n",
"pipe_results = COMPONENT_REGISTRY[Pipe].get_internal_results(net, [0])"
]
},
{
Expand Down Expand Up @@ -227,7 +228,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -241,9 +242,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.12.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
11 changes: 6 additions & 5 deletions tutorials/temperature_calculation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"outputs": [],
"source": [
"import pandapipes\n",
"from pandapipes.component_models import Pipe"
"from pandapipes.component_models import Pipe\n",
"from pandapipes.component_init import COMPONENT_REGISTRY"
]
},
{
Expand Down Expand Up @@ -167,7 +168,7 @@
"metadata": {},
"outputs": [],
"source": [
"pipe_1_results = Pipe.get_internal_results(net, [0])"
"pipe_1_results = COMPONENT_REGISTRY[Pipe].get_internal_results(net, [0])"
]
},
{
Expand Down Expand Up @@ -217,7 +218,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -231,9 +232,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.12.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

0 comments on commit a1adb81

Please sign in to comment.