Skip to content

Commit 0720c79

Browse files
paulneves77DrPaulSharp
authored andcommitted
moved duplicate code in parse_quantity to a call of parse_float, changed name of parse_float_first to parse_float
1 parent a638f4c commit 0720c79

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

sasdata/temp_hdf5_reader.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
test_file = "./example_data/2d_data/BAM_2D.h5"
3434
# test_file = "./example_data/2d_data/14250_2D_NoDetInfo_NXcanSAS_v3.h5"
3535
# test_file = "./example_data/2d_data/33837rear_2D_1.75_16.5_NXcanSAS_v3.h5"
36+
test_file = "./test/sasdataloader/data/nxcansas_1Dand2D_multisasentry_multisasdata.h5"
3637

3738
logger = logging.getLogger(__name__)
3839

@@ -178,11 +179,8 @@ def find_canSAS_key(node: HDF5Group, canSAS_class: str):
178179
return matches
179180

180181
def parse_quantity(node : HDF5Group) -> Quantity[float]:
181-
"""Pull a single quantity with length units out of an HDF5 node"""
182-
if node.shape == (): # scalar dataset
183-
magnitude = node.astype(float)[()]
184-
else: # vector dataset
185-
magnitude = node.astype(float)[0]
182+
"""Pull a single quantity with units out of an HDF5 node"""
183+
magnitude = parse_float(node)
186184
unit = node.attrs["units"]
187185
return Quantity(magnitude, parse(unit))
188186

@@ -193,7 +191,7 @@ def parse_string(node : HDF5Group) -> str:
193191
else: # vector dataset
194192
return node.asstr()[0]
195193

196-
def parse_float_first(node: HDF5Group) -> float:
194+
def parse_float(node: HDF5Group) -> float:
197195
"""Return the first element (or scalar) of a numeric dataset as float."""
198196
if node.shape == ():
199197
return float(node[()].astype(str))
@@ -319,7 +317,7 @@ def parse_sample(node : HDF5Group) -> Sample:
319317
name = attr_parse(node, "name")
320318
sample_id = opt_parse(node, "ID", parse_string)
321319
thickness = opt_parse(node, "thickness", parse_quantity)
322-
transmission = opt_parse(node, "transmission", parse_float_first)
320+
transmission = opt_parse(node, "transmission", parse_float)
323321
temperature = opt_parse(node, "temperature", parse_quantity)
324322
position = opt_parse(node, "position", parse_vec3)
325323
orientation = opt_parse(node, "orientation", parse_rot3)

0 commit comments

Comments
 (0)