Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #207 from ess-dmsc/156_pull_out_nxs_tags
Browse files Browse the repository at this point in the history
Pulling out nexus tags to avoid typos
  • Loading branch information
matthew-d-jones authored Apr 25, 2019
2 parents fbf6ec6 + 9d786cf commit ad2079a
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions nexus_constructor/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Geometry,
Component,
)
from nexus_constructor.transformations import Rotation, Translation
from nexus_constructor.geometry_types import (
OFFGeometry,
CylindricalGeometry,
Expand All @@ -17,6 +16,9 @@
from nexus_constructor.qml_models.instrument_model import InstrumentModel
from PySide2.QtCore import QObject, QUrl, Slot

NX_CLASS = "NX_class"
DEPENDS_ON = "depends_on"


class HdfWriter(QObject):
"""
Expand All @@ -40,10 +42,10 @@ def save_instrument(self, file_url: QUrl, model: InstrumentModel):

def save_instrument_to_file(self, file: h5py.File, model: InstrumentModel):
root = file.create_group("entry")
root.attrs["NX_class"] = "NXentry"
root.attrs[NX_CLASS] = "NXentry"

instrument = root.create_group("instrument")
instrument.attrs["NX_class"] = "NXinstrument"
instrument.attrs[NX_CLASS] = "NXinstrument"

external_types = NexusEncoder.external_component_types()
for component in model.components:
Expand All @@ -55,7 +57,7 @@ def save_instrument_to_file(self, file: h5py.File, model: InstrumentModel):
def store_component(self, parent_group: h5py.Group, component: Component):
nx_component = parent_group.create_group(component.name)
nx_component.attrs["description"] = component.description
nx_component.attrs["NX_class"] = NexusEncoder.component_class_name(
nx_component.attrs[NX_CLASS] = NexusEncoder.component_class_name(
component.component_type
)
self.store_transformations(nx_component, component)
Expand All @@ -66,22 +68,22 @@ def store_transformations(self, nx_component: h5py.Group, component: Component):

if len(component.transforms) > 0:
nx_transforms = nx_component.create_group("transforms")
nx_transforms.attrs["NX_class"] = "NXtransformations"
nx_transforms.attrs[NX_CLASS] = "NXtransformations"

for i in range(len(component.transforms)):
transform = component.transforms[i]
name = transform.name
if isinstance(transform, Rotation):
if transform.type == "Rotation":
rotate = nx_transforms.create_dataset(name, data=[transform.angle])
rotate.attrs["depends_on"] = dependent_on
rotate.attrs["transformation_type"] = "rotation"
rotate.attrs[DEPENDS_ON] = dependent_on
rotate.attrs["transformation_type"] = transform.type.lower()
rotate.attrs["units"] = "degrees"
rotate.attrs["vector"] = transform.axis.normalized().toTuple()
elif isinstance(transform, Translation):
elif transform.type == "Translation":
magnitude = transform.vector.length()
translate = nx_transforms.create_dataset(name, data=[magnitude])
translate.attrs["depends_on"] = dependent_on
translate.attrs["transformation_type"] = "translation"
translate.attrs[DEPENDS_ON] = dependent_on
translate.attrs["transformation_type"] = transform.type.lower()
translate.attrs["units"] = "m"
translate.attrs["vector"] = (
transform.vector.normalized().toTuple()
Expand All @@ -97,7 +99,7 @@ def store_transformations(self, nx_component: h5py.Group, component: Component):
not in NexusEncoder.external_component_types(),
)

nx_component.attrs["depends_on"] = dependent_on
nx_component.attrs[DEPENDS_ON] = dependent_on

def store_pixel_data(self, nx_component: h5py.Group, component: Component):
pixel_data = component.pixel_data
Expand Down Expand Up @@ -186,7 +188,7 @@ def store_geometry(self, nx_group: h5py.Group, geometry: Geometry):
pass

def store_off_geometry(self, nx_group: h5py.Group, geometry: OFFGeometry):
nx_group.attrs["NX_class"] = "NXoff_geometry"
nx_group.attrs[NX_CLASS] = "NXoff_geometry"
nx_group.create_dataset(
"vertices", data=[vector.toTuple() for vector in geometry.vertices]
)
Expand All @@ -196,7 +198,7 @@ def store_off_geometry(self, nx_group: h5py.Group, geometry: OFFGeometry):
def store_cylindrical_geometry(
self, nx_group: h5py.Group, geometry: CylindricalGeometry
):
nx_group.attrs["NX_class"] = "NXcylindrical_geometry"
nx_group.attrs[NX_CLASS] = "NXcylindrical_geometry"

nx_group.create_dataset(
"vertices",
Expand Down

0 comments on commit ad2079a

Please sign in to comment.