Repository navigation
Feature/additional variables exports - #43
mads-bertelsen merged 5 commits into
Conversation
| 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"`` | ||
| """ | ||
|
|
There was a problem hiding this comment.
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: strthe type hinting itself will be the type validation hints
and one more custom validator will be needed to prevent empty string.
There was a problem hiding this comment.
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!
| for name, value in ( | ||
| ("coord_name", coord_name), | ||
| ("variable_name", variable_name), | ||
| ("unit", unit), |
There was a problem hiding this comment.
Unit can be technically empty, no...? If the unit is None for example.
There was a problem hiding this comment.
Good point, unit now defaults to None
| Show all components | ||
| """ | ||
| self.logger.info("All components in file:") | ||
| sys.stdout.write("All components in file:\n") |
There was a problem hiding this comment.
What is the reason to use sys.stdout.write instead of the logger?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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...
| from .ReadNeXus import McStasNeXus | ||
|
|
||
|
|
||
| class Variable: |
There was a problem hiding this comment.
Maybe confusing with scipp.Variable...?
There was a problem hiding this comment.
Was renamed to Transfer as it describes how to transfer some information from McStas to Scipp
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.