Skip to content

Conversation

henrikjacobsenfys
Copy link
Member

It will need more methods for interacting with the data, such as plotting, binning and masking, but those are coming later.

@henrikjacobsenfys henrikjacobsenfys added the [scope] enhancement Adds/improves features (major.MINOR.patch) label Sep 29, 2025
Copy link

codecov bot commented Sep 29, 2025

Codecov Report

❌ Patch coverage is 61.53846% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.53%. Comparing base (3d99faa) to head (94a488a).

Files with missing lines Patch % Lines
src/easydynamics/experiment/experiment.py 60.86% 45 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           develop      #54       +/-   ##
============================================
+ Coverage     0.00%   61.53%   +61.53%     
============================================
  Files            1        2        +1     
  Lines            2      117      +115     
============================================
+ Hits             0       72       +72     
- Misses           2       45       +43     
Flag Coverage Δ
unittests 61.53% <61.53%> (+61.53%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@henrikjacobsenfys henrikjacobsenfys added the [priority] medium Normal/default priority label Oct 1, 2025
Copy link
Member

@rozyczko rozyczko left a comment

Choose a reason for hiding this comment

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

Good start! Minor comments only, mostly concerned about the code being too notebook-centric

import scipp as sc
import plopp as pp

from IPython.display import display
Copy link
Member

Choose a reason for hiding this comment

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

Your library should not import IPython - you should be able to run it from a python file or with a GUI - both of which don't need IPython.

data = self._data.get(name)
if data is None:
raise ValueError(f"No data found for name: {name}")
fig = pp.plot(data.transpose(), title=f"{name}")
Copy link
Member

Choose a reason for hiding this comment

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

This should be hidden behind a check for running in the notebook mode.

# Dunder methods
def __getitem__(self, key: str):
"""Allow dictionary-style access: my_exp['vanadium']"""
return self._data[key]
Copy link
Member

Choose a reason for hiding this comment

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

It would be prudent to add checks on key. Otherwise you need to try..except in the caller, which is suboptimal


def __setitem__(self, key: str, value: sc.DataArray):
"""Allow dictionary-style setting: my_exp['vanadium'] = data"""
self._data[key] = value
Copy link
Member

Choose a reason for hiding this comment

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

same here - add some key checks

for name, data in self._data.items():
sc.io.save_hdf5(data, os.path.join(folder, f"{name}.h5"))

def append_data(self, new_data: sc.DataArray, name: str):
Copy link

Choose a reason for hiding this comment

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

this method duplicates the functionality of __setitem__. You could use either one inside another to avoid duplication


# TODO: Add checks of dimensions etc. I'm not yet sure what dimensions I want to allow, so for now I trust myself.

self.append_data(sc.io.load_hdf5(filename), name)
Copy link

Choose a reason for hiding this comment

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

My linter swears at sc.io since they don't import io into scipp's __init__. Maybe the import is supposed be something like from scipp.io import load_hdf5?

"""
super().__init__(name)
self._data = None
self._data = {} # store data as {name: DataArray}
Copy link

Choose a reason for hiding this comment

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

you can just typehint the attribute like self._data: Dict[str, sc.DataArray] = {}

Load data from an HDF5 file.

Args:
file_path (str): Path to the data file.
Copy link

Choose a reason for hiding this comment

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

forgot the name here

f"Available datasets: {list(self._data.keys())}"
)

sc.io.save_hdf5(self._data[name], filename)
Copy link

Choose a reason for hiding this comment

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

do you think it makes sense to mkdirs the path to filename here as well as in save_all_hdf5?


self.append_data(sc.io.load_hdf5(filename), name)

def save_hdf5(self, name: str, filename: str):
Copy link

Choose a reason for hiding this comment

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

Does it make sense to make name optional to follow the same approach as in save_all_hdf5?

)
self._data[name] = new_data

def get_data(self, name: str = None):
Copy link

Choose a reason for hiding this comment

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

name typehint has to be optional here and in other methods with default None value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[priority] medium Normal/default priority [scope] enhancement Adds/improves features (major.MINOR.patch)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants