sidpy.hdf.dtype_utils.stack_real_to_target_dtype

sidpy.hdf.dtype_utils.stack_real_to_target_dtype(ds_real, new_dtype, lazy=False)[source]

Transforms real data into the target dtype

Parameters:
Returns:

ret_val – N-dimensional array of the target data-type

Return type:

numpy.ndarray or dask.array.core.Array

Examples

>>> import numpy as np
>>> import sidpy
>>> struct_dtype = np.dtype({'names': ['r', 'g', 'b'],
>>>                          'formats': [np.float32, np.uint16, np.float64]})
>>> num_elems = 5
>>> real_val = np.concatenate((np.random.random(size=num_elems) * 1024,
>>>                            np.random.randint(0, high=1024, size=num_elems),
>>>                            np.random.random(size=num_elems) * 1024))
>>> print('Real valued dataset of shape {}:'.format(real_val.shape))
>>> print(real_val)
Real valued dataset of shape (15,):
[276.65339095 527.80665658 741.38145798 647.06743252 710.41729083
 380.         796.         504.         355.         985.
 960.70015068 567.47024098 881.25140299 105.48936013 933.13686734]
>>> comp_val = sidpy.dtype_utils.stack_real_to_target_dtype(real_val, struct_dtype)
>>> print('Structured array of shape: {}'.format(comp_val.shape))
>>> print(comp_val)
Structured array of shape: (5,)
[(276.65338, 380, 960.70015068) (527.80664, 796, 567.47024098)
 (741.3815 , 504, 881.25140299) (647.06744, 355, 105.48936013)
 (710.4173 , 985, 933.13686734)]