Skip to content

Feature/additional variables exports - #43

Merged
mads-bertelsen merged 5 commits into
mccode-dev:mainfrom
mads-bertelsen-agentic:feature/additional-variables-exports
Oct 7, 2026
Merged

mads-bertelsen merged 5 commits into
mccode-dev:mainfrom
mads-bertelsen-agentic:feature/additional-variables-exports

Conversation

@mads-bertelsen-agentic

Copy link
Copy Markdown
Contributor

Adds a keyword argument that load additional variables into the scipp object. These variables are described with a new Variable object that has the name read from McStas, the name for the coordinate in scipp, and its unit.

Adds some additional tests for this feature.

Comment thread src/mcstastox/LoadFile.py Outdated
Comment on lines +12 to +21
class Variable:
"""
Additional event variable to load and export as a scipp coordinate

:param coord_name: Name of the scipp coordinate to create
:param variable_name: Name of the variable in the McStas event data,
see ``Data.get_component_variables``
:param unit: Unit of the variable as a scipp unit string, e.g. ``"s"``
"""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It looks like the constructor is mainly doing validation and data representation.
Do you want to use pydantic.BaseModel? It works like dataclass but has a built-in validation features. Then it'll be like:

class Variable(pydantic.BaseModel):
    coord_name: str
    variable_name: str
    unit: str

the type hinting itself will be the type validation hints
and one more custom validator will be needed to prevent empty string.

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 have renamed the class to Transfer because it defines how to transfer something from McStas to Scipp, the members are now:

  • mcstas_variable
  • scipp_coord
  • unit (which can now be None)

I didn't jump to pydantic yet, will need to read up on that!

Comment thread src/mcstastox/LoadFile.py Outdated
for name, value in (
("coord_name", coord_name),
("variable_name", variable_name),
("unit", unit),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Unit can be technically empty, no...? If the unit is None for example.

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.

Good point, unit now defaults to None

Comment thread src/mcstastox/LoadFile.py Outdated
Show all components
"""
self.logger.info("All components in file:")
sys.stdout.write("All components in file:\n")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What is the reason to use sys.stdout.write instead of the logger?

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.

These are just help prints and not describing any actions done to the contained data, so actually went all the way back to print for this as there is no reason to complicate that further

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If we want to build an application with mcstastox and using these methods, I still think we should use logger instead of printing so that the downstream application can customize how they are recorded.

But I'm okay with just turning them into print for now, to get rid of the multiple logger handler issue...

And... how come linter doesn't compalin about the print...?
It should be blocked by ruff though.... strange...

Comment thread src/mcstastox/LoadFile.py Outdated
from .ReadNeXus import McStasNeXus


class Variable:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe confusing with scipp.Variable...?

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.

Was renamed to Transfer as it describes how to transfer some information from McStas to Scipp

@mads-bertelsen
mads-bertelsen merged commit be091e3 into mccode-dev:main Oct 7, 2026
4 checks passed
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.

3 participants