Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from pathview.convert_to_python import convert_graph_to_python
from pathview.pathsim_utils import make_pathsim_model, map_str_to_object
from pathview.custom_pathsim_blocks import Table1D
from pathsim.blocks import Scope, Spectrum

# Sphinx imports for docstring processing
Expand Down Expand Up @@ -375,14 +376,36 @@ def run_pathsim():

for p, d in enumerate(data):
lb = scope.labels[p] if p < len(scope.labels) else f"port {p}"
if isinstance(scope, Spectrum):
d = abs(d)
fig.add_trace(
go.Scatter(x=time, y=d, mode="lines", name=lb), row=i + 1, col=1
)

fig.update_xaxes(title_text="Time", row=len(scopes), col=1)

# make Table1D plots
for b in my_simulation.blocks:
# if it's a Table1d, check if it's connected to a scope
if isinstance(b, Table1D):
for c in my_simulation.connections:
if b in c.get_blocks():
for s in scopes:
if s in c.get_blocks():
# if connected to a scope, add a vertical line at each table point
time_points = b.points
values = b.values
# add scatter points
fig.add_trace(
go.Scatter(
x=time_points,
y=values,
mode="markers",
name=f"{b.label} points",
marker=dict(symbol="x", size=10),
),
row=scopes.index(s) + 1,
col=1,
)

# make spectrum plots
for i, spec in enumerate(spectra):
time, data = spec.read()
Expand Down
4 changes: 3 additions & 1 deletion src/nodeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import AdderNode from './components/nodes/AdderNode';
import ScopeNode from './components/nodes/ScopeNode';
import StepSourceNode from './components/nodes/StepSourceNode';
import { createFunctionNode } from './components/nodes/FunctionNode';

Check failure on line 10 in src/nodeConfig.js

View workflow job for this annotation

GitHub Actions / test (20.x, 3.11)

'createFunctionNode' is defined but never used. Allowed unused vars must match /^[A-Z_]/u

Check failure on line 10 in src/nodeConfig.js

View workflow job for this annotation

GitHub Actions / test (20.x, 3.10)

'createFunctionNode' is defined but never used. Allowed unused vars must match /^[A-Z_]/u
import DefaultNode from './components/nodes/DefaultNode';
import MultiplierNode from './components/nodes/MultiplierNode';
import { Splitter2Node, Splitter3Node } from './components/nodes/Splitters';
Expand Down Expand Up @@ -59,6 +59,7 @@
butterworthbandstop: DefaultNode,
fir: DefaultNode,
ode: DynamicHandleNode,
table: SourceNode,
};

export const nodeMathTypes = {
Expand Down Expand Up @@ -116,7 +117,7 @@
description: 'Fuel cycle specific nodes'
},
'Others': {
nodes: ['samplehold', 'comparator'],
nodes: ['samplehold', 'comparator', 'table'],
description: 'Miscellaneous nodes'
},
'Output': {
Expand Down Expand Up @@ -184,6 +185,7 @@
'butterworthbandpass': 'Butterworth Band-Pass Filter',
'butterworthbandstop': 'Butterworth Band-Stop Filter',
'fir': 'FIR Filter',
'table': 'Table1D',
};

return displayNames[nodeType] || nodeType.charAt(0).toUpperCase() + nodeType.slice(1);
Expand Down
17 changes: 17 additions & 0 deletions src/python/custom_pathsim_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@ def func_act(_):
return [event]


class Table1D(Block):
"""Block that holds a 1D table of values."""

def __init__(self, points: list[float], values: list[float]):
"""
Args:
points: List of points (x-coordinates) for the table.
values: List of values (y-coordinates) for the table.
"""
super().__init__()
self.points = np.array(points)
self.values = np.array(values)

def update(self, t):
return


# BUBBLER SYSTEM


Expand Down
2 changes: 2 additions & 0 deletions src/python/pathsim_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
Bubbler,
FestimWall,
Integrator,
Table1D,
)
from flask import jsonify
import inspect
Expand Down Expand Up @@ -112,6 +113,7 @@
"butterworthbandpass": pathsim.blocks.ButterworthBandpassFilter,
"butterworthbandstop": pathsim.blocks.ButterworthBandstopFilter,
"fir": pathsim.blocks.FIR,
"table": Table1D,
}

math_blocks = {
Expand Down
Loading