diff --git a/src/scippnexus/nxcylindrical_geometry.py b/src/scippnexus/nxcylindrical_geometry.py index 6036f3f8..97b500f5 100644 --- a/src/scippnexus/nxcylindrical_geometry.py +++ b/src/scippnexus/nxcylindrical_geometry.py @@ -19,10 +19,13 @@ def _parse( face1_center = cylinders['vertex_index', 0] face1_edge = cylinders['vertex_index', 1] face2_center = cylinders['vertex_index', 2] - ds = sc.Dataset() - ds['face1_center'] = vertices[face1_center.values] - ds['face1_edge'] = vertices[face1_edge.values] - ds['face2_center'] = vertices[face2_center.values] + ds = sc.Dataset( + { + 'face1_center': vertices[face1_center.values], + 'face1_edge': vertices[face1_edge.values], + 'face2_center': vertices[face2_center.values], + } + ) ds = ds.rename(**{vertices.dim: 'cylinder'}) if detector_number is None: # All cylinders belong to the same shape diff --git a/src/scippnexus/v1/nxcylindrical_geometry.py b/src/scippnexus/v1/nxcylindrical_geometry.py index 46d4e3ce..6fb7905a 100644 --- a/src/scippnexus/v1/nxcylindrical_geometry.py +++ b/src/scippnexus/v1/nxcylindrical_geometry.py @@ -18,10 +18,13 @@ def _parse( face1_center = cylinders['vertex_index', 0] face1_edge = cylinders['vertex_index', 1] face2_center = cylinders['vertex_index', 2] - ds = sc.Dataset() - ds['face1_center'] = vertices[face1_center.values] - ds['face1_edge'] = vertices[face1_edge.values] - ds['face2_center'] = vertices[face2_center.values] + ds = sc.Dataset( + { + 'face1_center': vertices[face1_center.values], + 'face1_edge': vertices[face1_edge.values], + 'face2_center': vertices[face2_center.values], + } + ) ds = ds.rename(**{vertices.dim: 'cylinder'}) if detector_number is None: # All cylinders belong to the same shape diff --git a/tests/nxdata_test.py b/tests/nxdata_test.py index 61c8d90c..2fc5a726 100644 --- a/tests/nxdata_test.py +++ b/tests/nxdata_test.py @@ -203,20 +203,18 @@ def test_transpose_indices_attribute_for_coord(h5root): def test_auxiliary_signal_causes_load_as_dataset(h5root): - da = sc.DataArray( - sc.array(dims=['xx', 'yy'], unit='m', values=[[1, 2, 3], [4, 5, 6]]) - ) - da.coords['xx'] = da.data['xx', 0] + signal = sc.array(dims=['xx', 'yy'], unit='m', values=[[1, 2, 3], [4, 5, 6]]) + aux = signal * 2 data = snx.create_class(h5root, 'data1', NXdata) - data.attrs['axes'] = da.dims + data.attrs['axes'] = signal.dims data.attrs['signal'] = 'signal' # We flag 'xx' as auxiliary_signal. It should thus not be loaded as a coord, # even though we create the field. data.attrs['auxiliary_signals'] = ['xx'] - snx.create_field(data, 'signal', da.data) - snx.create_field(data, 'xx', da.coords['xx']) + snx.create_field(data, 'signal', signal) + snx.create_field(data, 'xx', aux) data = snx.Group(data, definitions=snx.base_definitions()) - assert_identical(data[...], sc.Dataset({'signal': da.data, 'xx': da.coords['xx']})) + assert_identical(data[...], sc.Dataset({'signal': signal, 'xx': aux})) def test_NXlog_data_is_loaded_as_time_dependent_data_array(nxroot):