Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added utility function to automate data type str generation #185

Merged
merged 1 commit into from
Nov 3, 2021

Conversation

gmabey
Copy link
Contributor

@gmabey gmabey commented Oct 1, 2021

The get_endian_str() function is separate to support my own hack
for generating the string for complex int16 data ...

>>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype=float))
'f64_le'
>>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype=complex))
'cf128_le'
>>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype=numpy.uint32))
'u32_le'
>>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype=numpy.uint16))
'u16_le'
>>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype=numpy.complex64))
'cf64_le'
>>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype='>f4'))
'f32_be'
>>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype='=f4'))
'f32_le'
>>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype='<f4'))
'f32_le'
>>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype='<c8'))
'cf64_le'
>>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype='?'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/s/sigmf/utils.py", line 98, in get_data_type_str
    raise error.SigMFError('Unsupported data type:', atype)
sigmf.error.SigMFError: ('Unsupported data type:', dtype('bool'))

Copy link
Contributor

@bhilburn bhilburn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a good useful function. My comments are minor, we should get @Teque5's review.

README.md Show resolved Hide resolved
sigmf/utils.py Outdated
if atype.byteorder == '>':
return '_be'
# must be '=' (native) or '|' (doesn't matter)
return '_le' if sys.byteorder == 'little' else '_be'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this meant to be effectively a catch case where if the endianness is not already defined, it gets set to whatever the current system's endianness is? I don't think I follow the comment on L90

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think L90 is the case where it gets past L86 & L88.
This should be slightly modified to just if, elif, else and it will make more sense.

@bhilburn bhilburn requested a review from Teque5 October 8, 2021 00:48
@bhilburn bhilburn added this to PR Filed in v1.0.0 Release via automation Oct 8, 2021
@bhilburn bhilburn added this to the Release v1.0.0 milestone Oct 8, 2021
Copy link
Collaborator

@Teque5 Teque5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With small changes this is ready to merge.

README.md Show resolved Hide resolved
sigmf/utils.py Outdated
if atype.byteorder == '>':
return '_be'
# must be '=' (native) or '|' (doesn't matter)
return '_le' if sys.byteorder == 'little' else '_be'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think L90 is the case where it gets past L86 & L88.
This should be slightly modified to just if, elif, else and it will make more sense.

sigmf/utils.py Outdated
# must be '=' (native) or '|' (doesn't matter)
return '_le' if sys.byteorder == 'little' else '_be'

def get_data_type_str(a):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to add a docstring. Also single letter variables aren't the best. Maybe change it to ray.

@gmabey gmabey force-pushed the get_data_type_str branch 2 times, most recently from d33ae71 to 84149f4 Compare October 28, 2021 23:46
The get_endian_str() function is separate to support my own hack
for generating the string for complex int16 data ...

    >>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype=float))
    'f64_le'
    >>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype=complex))
    'cf128_le'
    >>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype=numpy.uint32))
    'u32_le'
    >>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype=numpy.uint16))
    'u16_le'
    >>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype=numpy.complex64))
    'cf64_le'
    >>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype='>f4'))
    'f32_be'
    >>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype='=f4'))
    'f32_le'
    >>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype='<f4'))
    'f32_le'
    >>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype='<c8'))
    'cf64_le'
    >>> sigmf.utils.get_data_type_str(numpy.zeros(1, dtype='?'))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/s/sigmf/utils.py", line 98, in get_data_type_str
        raise error.SigMFError('Unsupported data type:', atype)
    sigmf.error.SigMFError: ('Unsupported data type:', dtype('bool'))
@gmabey
Copy link
Contributor Author

gmabey commented Oct 28, 2021

@Teque5 @bhilburn Ok, I think I have now fully integrated that helpful feedback.
Question: I couldn't find in the spec just now whether it's appropriate or not to append _le or _be when the datatype is a single byte. In this case, I've just used whatever the endianness of the system is (the "|" case), but seems to me that the endian suffix could be left off altogether, for the case of single-byte datatypes.

@bhilburn
Copy link
Contributor

bhilburn commented Nov 3, 2021

@gmabey - You're correct, it can be left off for single byte datatypes, and while the spec provides an example of that, it doesn't explicitly say that. It would be good to clarify that in the spec (that's a note for another PR 😅).

@gmabey - According to Github, it says there is one change requested by @Teque5 that is still unresolved, his comment on L110 regarding the import statement. Do you mind addressing that and pushing, and marking the change as resolved? I think this is then ready to merge 👍

@gmabey
Copy link
Contributor Author

gmabey commented Nov 3, 2021

@bhilburn @Teque5 Forgive my GitHub follies, but I do believe I addressed that issue (the only one I can find is to replace line 110 with from sigmf.utils import get_data_type_str) -- it's definitely there now.

When I try to find and close the change request, I get: "Sometimes commits can disappear after a force-push."

@jacobagilbert
Copy link
Member

Thanks @gmabey - two approvals and Ben has given his ✅. Merging.

@jacobagilbert jacobagilbert merged commit 20cf29b into sigmf:sigmf-v1.x Nov 3, 2021
v1.0.0 Release automation moved this from PR Filed to Done Nov 3, 2021
@gmabey gmabey deleted the get_data_type_str branch January 11, 2022 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants