From 0e2768dc3fd43880d8a89cad7d182283008f2ba7 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Tue, 12 Aug 2025 15:53:14 -0400 Subject: [PATCH 1/2] no need for abs for scopes --- src/backend.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/backend.py b/src/backend.py index 059a0dd..ecdb9cb 100644 --- a/src/backend.py +++ b/src/backend.py @@ -375,8 +375,6 @@ 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 ) From 7d1085dc7adc45c1c6583d3066147aeed25436a8 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Tue, 12 Aug 2025 16:20:59 -0400 Subject: [PATCH 2/2] working example --- src/backend.py | 25 +++++++++++++++++++++++++ src/nodeConfig.js | 4 +++- src/python/custom_pathsim_blocks.py | 17 +++++++++++++++++ src/python/pathsim_utils.py | 2 ++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/backend.py b/src/backend.py index ecdb9cb..92329d5 100644 --- a/src/backend.py +++ b/src/backend.py @@ -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 @@ -381,6 +382,30 @@ def run_pathsim(): 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() diff --git a/src/nodeConfig.js b/src/nodeConfig.js index 01de910..997b47e 100644 --- a/src/nodeConfig.js +++ b/src/nodeConfig.js @@ -59,6 +59,7 @@ export const nodeTypes = { butterworthbandstop: DefaultNode, fir: DefaultNode, ode: DynamicHandleNode, + table: SourceNode, }; export const nodeMathTypes = { @@ -116,7 +117,7 @@ export const nodeCategories = { description: 'Fuel cycle specific nodes' }, 'Others': { - nodes: ['samplehold', 'comparator'], + nodes: ['samplehold', 'comparator', 'table'], description: 'Miscellaneous nodes' }, 'Output': { @@ -184,6 +185,7 @@ export const getNodeDisplayName = (nodeType) => { '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); diff --git a/src/python/custom_pathsim_blocks.py b/src/python/custom_pathsim_blocks.py index 39b96bc..d1f709d 100644 --- a/src/python/custom_pathsim_blocks.py +++ b/src/python/custom_pathsim_blocks.py @@ -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 diff --git a/src/python/pathsim_utils.py b/src/python/pathsim_utils.py index 51b0208..fca0c14 100644 --- a/src/python/pathsim_utils.py +++ b/src/python/pathsim_utils.py @@ -33,6 +33,7 @@ Bubbler, FestimWall, Integrator, + Table1D, ) from flask import jsonify import inspect @@ -112,6 +113,7 @@ "butterworthbandpass": pathsim.blocks.ButterworthBandpassFilter, "butterworthbandstop": pathsim.blocks.ButterworthBandstopFilter, "fir": pathsim.blocks.FIR, + "table": Table1D, } math_blocks = {