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

Unable to open *.raw (float 32) #848

Closed
blackwiz4rd opened this issue Mar 11, 2021 · 8 comments
Closed

Unable to open *.raw (float 32) #848

blackwiz4rd opened this issue Mar 11, 2021 · 8 comments

Comments

@blackwiz4rd
Copy link

blackwiz4rd commented Mar 11, 2021

Expected Behavior

Open *.raw file without exception.

Actual Behavior

Traceback (most recent call last):
File "/usr/lib/python3.9/site-packages/urh/controller/MainController.py", line 564, in on_open_recent_action_triggered
self.add_files(FileOperator.uncompress_archives([action.data()], QDir.tempPath()))
File "/usr/lib/python3.9/site-packages/urh/controller/MainController.py", line 408, in add_files
self.add_signalfile(filename, group_id, enforce_sample_rate=enforce_sample_rate)
File "/usr/lib/python3.9/site-packages/urh/controller/MainController.py", line 285, in add_signalfile
signal = Signal(filename, sig_name, sample_rate=sample_rate)
File "/usr/lib/python3.9/site-packages/urh/signalprocessing/Signal.py", line 75, in init
self.__load_complex_file(filename)
File "/usr/lib/python3.9/site-packages/urh/signalprocessing/Signal.py", line 83, in __load_complex_file
self.iq_array = IQArray.from_file(filename)
File "/usr/lib/python3.9/site-packages/urh/signalprocessing/IQArray.py", line 203, in from_file
return IQArray(data=np.fromfile(filename, dtype=np.float32))
File "/usr/lib/python3.9/site-packages/urh/signalprocessing/IQArray.py", line 17, in init
self.__data = self.convert_array_to_iq(data)
File "/usr/lib/python3.9/site-packages/urh/signalprocessing/IQArray.py", line 212, in convert_array_to_iq
return arr.reshape((-1, 2), order="C")
ValueError: cannot reshape array of size 12717211 into shape (2)

Comment: maybe this happens because gnuradio does not save an even number of samples and the reshape cannot take place so the fix might be easy.

Steps To Reproduce
  1. Save file to file sink *.raw in gnuradio
  2. Open file in urh
Platform Specifications
  • OS: Arch Linux
  • URH version: 2.9.1-1
  • Python version: 3.9.2
  • Installed via pacman
@jopohl
Copy link
Owner

jopohl commented Mar 11, 2021

What complex format has the .raw file? 2xint8, 2xuint8, 2xint16, ...? Please rename it accordingly, see https://github.com/jopohl/urh/wiki/Supported-signal-file-formats

@blackwiz4rd
Copy link
Author

It is a Float 32 in gnuradio, so it should be .complex in urh. After capture sometimes it gets opened, other times not.

@blackwiz4rd blackwiz4rd changed the title Unable to open *.raw Unable to open *.raw (float 32) Mar 13, 2021
@jopohl
Copy link
Owner

jopohl commented Mar 13, 2021

After capture sometimes it gets opened, other times not.

This sounds rather like a bug in GNU Radio and/or a problem with your flow-graph. This error indicates that the file gets not completely written by the application.

@jopohl
Copy link
Owner

jopohl commented Mar 13, 2021

As a side question: Why do you capture in GR and not directly in URH?

@blackwiz4rd
Copy link
Author

blackwiz4rd commented Mar 13, 2021

After capture sometimes it gets opened, other times not.

This sounds rather like a bug in GNU Radio and/or a problem with your flow-graph. This error indicates that the file gets not completely written by the application.

I thought so too, however I can open and display it with a simple np.fromfile(filename, np.float32).

As a side question: Why do you capture in GR and not directly in URH?

That is because I need to set up more options during capture (e.g. enable direct sampling mode, set RF gain) and also add filters if necessary.

@jopohl
Copy link
Owner

jopohl commented Mar 13, 2021

I thought so too, however I can open and display it with a simple np.fromfile(filename, np.float32)

That only gives you a stream of float32, not complex. Try np.fromfile(filename, np.complex64), if that works for a file in a Python shell that makes URH crash we have indeed a bug. Otherwise GNU Radio swallowed half of the last sample.

@blackwiz4rd
Copy link
Author

blackwiz4rd commented Mar 13, 2021

I thought so too, however I can open and display it with a simple np.fromfile(filename, np.float32)

That only gives you a stream of float32, not complex. Try np.fromfile(filename, np.complex64), if that works for a file in a Python shell that makes URH crash we have indeed a bug. Otherwise GNU Radio swallowed half of the last sample.

I have tried with np.complex64 and it works correctly. I have sent you an email with one file that won't open in urh.
Let me know if you need more information to solve the issue.

@jopohl
Copy link
Owner

jopohl commented Mar 13, 2021

Thank you for providing the file! Seems like numpy just skips the last sample to avoid a conversion error. I implemented the same behavior in #849.

@jopohl jopohl closed this as completed in 71153ba Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants