microsoft / yardl

Tooling for streaming instrument data
https://microsoft.github.io/yardl/
MIT License
29 stars 5 forks source link

`get_dtype` does not work with union cases #152

Open johnstairs opened 1 month ago

johnstairs commented 1 month ago

OK I followed your suggestion:

UnsignedIntegerArray: !union
  uint8: uint8[y,x]
  uint16: uint16[y,x]
  uint32: uint32[y,x]
  uint64: uint64[y,x]

Sample: !record
  fields:
    timestamp: datetime
    data: UnsignedIntegerArray
    projectionmatrix: float64[y:3,x:4]?

But I struggle to use it:

def generate_projections():
    myDtype = get_dtype(UnsignedIntegerArray.Uint16)
    yield Sample(timestamp=DateTime.now(), data=np.array([[0,1,0],[0,1,0],[0,1,0]], dtype=myDtype))

yields:

File "d:\src\ComputedTomographyRawData\python\test.py", line 5, in generate_projections
    myDtype = get_dtype(UnsignedIntegerArray.Uint16)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\src\ComputedTomographyRawData\python\ctrd\_dtypes.py", line 89, in <lambda>
    return lambda t: get_dtype_impl(dtype_map, t)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\src\ComputedTomographyRawData\python\ctrd\_dtypes.py", line 78, in get_dtype_impl
    raise RuntimeError(f"Cannot find dtype for {t}")
RuntimeError: Cannot find dtype for <class 'abc.UnsignedIntegerArray.Uint16'>

Can you provide more examples how to use the get_dtype function?

Originally posted by @wuerflts in https://github.com/microsoft/yardl/discussions/151#discussioncomment-9467915