Skip to content

Feature/signal data operation#90

Open
jwasikpsnc wants to merge 34 commits into
iterorganization:developfrom
jwasikpsnc:feature/signal_data_operation
Open

Feature/signal data operation#90
jwasikpsnc wants to merge 34 commits into
iterorganization:developfrom
jwasikpsnc:feature/signal_data_operation

Conversation

@jwasikpsnc

Copy link
Copy Markdown
Collaborator
  • adds /data/plot_data/ signal_operations parameter
  • adds signal operations description in /info/data_manipulation_methods endpoint response
  • accepts operations as list ["operation:<URI>", "..."] e.g. ["add:<uri>","mul:<uri>","div:<uri>"]
  • operations are executed in order determined by position in the list
  • allowed operations:
    • add
    • sub
    • mul
    • div
  • updated docs
  • if <base_uri> and <operand_uri> have the same shapes - > no interpolation needed
  • if <base_uri> and <operand_uri> have different shapes -> error is being raised

Waiting for #89 to be merged first

@read-the-docs-community

read-the-docs-community Bot commented Jun 22, 2026

Copy link
Copy Markdown

Documentation build overview

📚 imas-ibex | 🛠️ Build #33724519 | 📁 Comparing 353af26 against latest (9fe753c)

  🔍 Preview build  

136 files changed · + 86 added · ± 50 modified

+ Added

± Modified

…re/signal_data_operation

# Conflicts:
#	backend/ibex/core/data_manipulation_methods.py
#	backend/ibex/data_source/imas_python_source.py
#	backend/ibex/data_source/imas_python_source_utils.py
#	backend/ibex/endpoints/schemas/request_data_schemas.py
#	backend/tests/conftest.py
#	backend/tests/test_data_endpoints.py
#	backend/tests/test_data_manipulation.py
#	docs/source/developers_manual/backend_development/data_manipulation.rst
@jwasikpsnc
jwasikpsnc marked this pull request as ready for review June 30, 2026 10:05
@jwasikpsnc

jwasikpsnc commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator Author

@olivhoenen

  • rebased onto develop
  • fixed bug in pyproject.toml which made pip download https://pypi.org/project/ibex/ instead of imas-ibex when installing pip install -e .[all]

Comment thread backend/ibex/data_source/imas_python_source_utils.py Outdated
# b. Otherwise use raw signal data directly (same shape path)
# 5. Build a flat uri->array dict and apply all signal operations

if plot_data_query.signal_operations:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After Square / Multiplication operation shown below, should unit of the quantity remains same?

$ curl -G http://127.0.0.1:8000/data/plot_data     --data-urlencode "uri=$BASE"  --data-urlencode "interpolate_over=$OTHER" --data-urlencode "interpolation_method=exact_value" --data-urlencode "signal_operations=mul:$OTHER" | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7880  100  7880    0     0   769k      0 --:--:-- --:--:-- --:--:--  769k
{
  "data": {
    "name": "b0",
    "unit": "T",
    "shape": [
      300
    ],
    "downsampled_shape": [
      300
    ],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure concerning physical interpretation of mentioned operations. If we multiply signal1 x signal2 the unit should be unit^2 ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure concerning physical interpretation of mentioned operations. If we multiply signal1 x signal2 the unit should be unit^2 ?

If signal1 and signal2 have the same unit, yes, this is correct. Combining units is only valid with your mul and div operators thought, with add and sub you shall make sure that units are the same or throw an error.
You may check this short video: https://www.youtube.com/watch?v=2DJjV3I4xGc

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DONE. ad0a37b

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add and sub you shall make sure that units are the same or throw an error. #90 (comment)

I think we are not checking if units are the same. and it did not throw exception.

[sawantp1@98dci4-srv-1005 frontend]$ echo $ANOTHER
imas:hdf5?path=/work/imas/shared/imasdb/ITER/3/134174/117#equilibrium/time_slice[0]/profiles_1d/psi
[sawantp1@98dci4-srv-1005 frontend]$ echo $ANOTHER1
imas:hdf5?path=/work/imas/shared/imasdb/ITER/3/134174/117#equilibrium/time_slice[0]/profiles_1d/pressure
$ curl -G http://127.0.0.1:8000/data/plot_data     --data-urlencode "uri=$ANOTHER1" --data-urlencode "signal_operations=add:$ANOTHER" | jq | head -n 20
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13737  100 13737    0     0   353k      0 --:--:-- --:--:-- --:--:--  353k
{
  "data": {
    "name": "pressure",
    "unit": "Pa",
    "shape": [
      299
    ],
    "downsampled_shape": [
      299
    ],
    "ndim": 1,
    "path": "#equilibrium/time_slice[0]/profiles_1d/pressure",
    "description": "Pressure",
    "coordinates": [
      {
        "name": "psi",
        "target": "#equilibrium/time_slice[0]/profiles_1d/pressure",
        "unit": "Wb",
        "shape": [
          299

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DONE

if (
other_signal["data"]["shape"] != "irregular"
and other_signal["data"]["shape"] == original_data_shape
):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other_signal["data"]["shape"] == original_data_shape if shape is same but coordinate has different time stamps, it won't ask for interpolation message and still can go for operation.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DONE. c218ca2
Now, signal operation fails due to time coordinates incompatibilities. Other signals should be chosen...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c218ca2 Should we check other coordinates if available for example dim1, dim2 or rho_tor_norm? May be its good to check dynamically..

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now all coordinates are checked for their mutual compatibility. d213449
Two coordinate are equal only when:

  • Both signals contain the same number of coordinates.
  • Each coordinate appears in the same position.
  • Corresponding coordinate names match exactly, such as "rho" == "rho".
  • Corresponding values match in shape and content.
  • NaN values at corresponding positions count as equal.

Comment thread backend/ibex/data_source/imas_python_source.py
@bpalak

bpalak commented Jul 20, 2026

Copy link
Copy Markdown

@prasad-sawantdesai : Could you provide me info about your test files (BASE and OTHER) ? I would like to reproduce your tests using the same data you are using.

@prasad-sawantdesai

Copy link
Copy Markdown
Contributor

@prasad-sawantdesai : Could you provide me info about your test files (BASE and OTHER) ? I would like to reproduce your tests using the same data you are using.
Here it is --

$ echo $OTHER
imas:hdf5?path=/work/imas/shared/imasdb/ITER/3/134174/117#equilibrium/vacuum_toroidal_field/b0
$ echo $BASE
imas:hdf5?path=/work/imas/shared/imasdb/ITER/3/53299/2#equilibrium/vacuum_toroidal_field/b0

)

# ============= END signal operations =============

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what I am doing wrong here?

import imas
import numpy as np

entries = [
    ("/tmp/ibex-grid-first",  [0.0, 0.5, 1.0], [10.0, 20.0, 30.0]),
    ("/tmp/ibex-grid-second", [0.0, 0.4, 0.8], [100.0, 200.0, 300.0]),
]

for path, rho, temperature in entries:
    with imas.DBEntry(f"imas:hdf5?path={path}", mode="w") as entry:
        cp = entry.factory.core_profiles()
        cp.ids_properties.homogeneous_time = 1
        cp.time = np.array([1.0])
        cp.profiles_1d.resize(1)
        cp.profiles_1d[0].grid.rho_tor_norm = np.array(rho)
        cp.profiles_1d[0].electrons.temperature = np.array(temperature)
        entry.put(cp)
# $ echo $FIRST
# imas:hdf5?path=/tmp/ibex-grid-first#core_profiles:0/profiles_1d[:]/electrons/temperature
# $ echo $SECOND
# imas:hdf5?path=/tmp/ibex-grid-second#core_profiles:0/profiles_1d[:]/electrons/temperature

# $ curl -sS -G http://127.0.0.1:8000/data/plot_data     --data-urlencode "uri=$FIRST"     --data-urlencode "interpolate_over=$FIRST"     --data-urlencode "interpolation_method=exact_value"     --data-urlencode "signal_operations=add:$SECOND"     | jq
# {
#   "message": "'interpolated_data'"
# }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am on it...

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected

axis_indices.append(lookup[value])

axis_indices = np.searchsorted(np.asarray(target), np.asarray(orig))
target_indices.append(axis_indices)

@prasad-sawantdesai prasad-sawantdesai Jul 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we verify that target[indices] == orig after searchsorted and reject coordinates missing from the target grid?

import imas
import numpy as np

entries = [
    ("/tmp/ibex-grid-first",  [0.0, 0.5, 1.0], [10.0, 20.0, 30.0]),
    ("/tmp/ibex-grid-second", [0.0, 0.4, 0.8], [100.0, 200.0, 300.0]),
]

for path, rho, temperature in entries:
    with imas.DBEntry(f"imas:hdf5?path={path}", mode="w") as entry:
        cp = entry.factory.core_profiles()
        cp.ids_properties.homogeneous_time = 1
        cp.time = np.array([1.0])
        cp.profiles_1d.resize(1)
        cp.profiles_1d[0].grid.rho_tor_norm = np.array(rho)
        cp.profiles_1d[0].electrons.temperature = np.array(temperature)
        entry.put(cp)

# This works correctly
curl -sS -G http://127.0.0.1:8000/data/plot_data     --data-urlencode "uri=$FIRST"     --data-urlencode "interpolate_over=$SECOND"     --data-urlencode "interpolation_method=exact_value"     --data-urlencode "signal_operations=add:$SECOND"     | jq '.data | {coordinates, value}'

  "value": [
    [
      110.0,
      null,
      null,
      null,
      null
    ]
  ]

# but this one gives wrong result seems. $SECOND coordinates 0.4 and 0.8 do not exist in $FIRST’s grid, should raise an error?
curl -sS -G http://127.0.0.1:8000/data/plot_data     --data-urlencode "uri=$FIRST"     --data-urlencode "interpolate_over=$FIRST"     --data-urlencode "interpolation_method=exact_value"     --data-urlencode "signal_operations=sub:$FIRST"     --data-urlencode "signal_operations=add:$SECOND"     | jq '.data | {coordinates, value}'
  "value": [
    [
      100.0,
      200.0,
      300.0
    ]
  ]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected

@bpalak
bpalak force-pushed the feature/signal_data_operation branch from 066171e to c20ea80 Compare July 23, 2026 11:49
@bpalak
bpalak force-pushed the feature/signal_data_operation branch from c20ea80 to 353af26 Compare July 23, 2026 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants