omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Binary files read and write

    Pythonista
    8
    99
    91745
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Phuket2
      Phuket2 last edited by

      Do issues still exist with byte order on different platforms? I really don't know. A long time ago, we used to have to consider this. Big and little Indien when reading binary/memory files without an API that took care of the translation

      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by

        Yes. Complexity is preserved but it is better hidden. The fortunate thing here is that the file in question was written out by one iOS app (SPLnFFT) and read in by another iOS app (Pythonista) so byte order is not an issue.

        1 Reply Last reply Reply Quote 0
        • Phuket2
          Phuket2 last edited by

          @ccc. Ok, understand. Honestly, was not even sure these issues still existed. Regardless, normally they have no impact as long as you are calling API calls, it's when we decide to get tricky and implement our functions/ methods for reading so called cross platform files. But in this environment, I think it's food for thought. But as you say in the case, both files written from iOS so not a problem

          1 Reply Last reply Reply Quote 0
          • ccc
            ccc last edited by

            Now I understand why numpy is all the rage with data scientists!!!

            3 lines of numpy do the whole thing!! Import, read, transform, and cleanse. Much faster execution time too.

            import numpy
            data = numpy.fromfile('SPLnFFT_2015_07_21.bin', dtype=numpy.float32).reshape(-1, 2)
            data = data[numpy.all(data > 0, axis=1)]  # cleanse
            print(type(data), len(data))  # numpy.ndarray, 2786
            print(data[:20])  # print first 20 fast, slow pairs
            
            1 Reply Last reply Reply Quote 0
            • ManuelU
              ManuelU last edited by

              Hi CCC. I tried your script with an edited version of a SPLnFFT binary files before the iOS two last updates. Last night I made some random noise mesurements. For my surprise the exported files had many chunks of zeroes alternating with random chunks of normal SPL values. That is not a mormal behavior. No NaN or Infinite values were detected this time. If you give me a mail address I can send you the link to some test files in my Dropbox account. The struct approach and the array approach render the same results. You JUST gave another present to SPLnFFT users with your SPLnFFT_Reader.py. I'll download and try it right away. Best Regards

              1 Reply Last reply Reply Quote 0
              • ccc
                ccc last edited by ccc

                Use the numpy version instead. It is simpler, faster, and easier to mess around with. If you have a computer with an iPython notebook, that would be a great environment for exploring the dataset.

                To send a Dropbox file, you can check it directly into the Github repo above via a pull request or you can go into your Dropbox client and tap once on the file to select it and then tap the share icon (a box with an arrow pointing up out of it) and share as email. Cut the URL out of that draft email, and paste it into a comment on the repo or here.

                1 Reply Last reply Reply Quote 0
                • JonB
                  JonB last edited by

                  does the splnfft guy have matlab scripts that read and plot the data? the screenshots show such an .m file. if younhave a copy of that, it would explain how to parse and interpret the data.

                  1 Reply Last reply Reply Quote 0
                  • ManuelU
                    ManuelU last edited by

                    Yes, it has a Matlab script that you can use with Octave, with no changes. There is also available an Excel Macro that allows you to process the whole file with one hour chunks. What is for me an attractive feature of Phytonista is the possibility to importe the SPLnFFT bin files or any other file type directly from the Dropbox to the sandbox. You don't need a desktop computer and overrides the cumbersome process of iTunes file Sharing. The SPLnFFT is linked to another App of the same author: SPLnWATCH, that can record in the background, an excellent battery and screen saver option.

                    1 Reply Last reply Reply Quote 0
                    • JonB
                      JonB last edited by

                      can you post a link to the matlab script?

                      1 Reply Last reply Reply Quote 0
                      • ccc
                        ccc last edited by

                        Is Octave this app http://octilab.com ? How did you get the .bin file into that app?

                        1 Reply Last reply Reply Quote 0
                        • ManuelU
                          ManuelU last edited by

                          You can get it at the SPLnFFT Noise Neter Developer Web Page. He currently uses a Face book account. If he sent you an email, I think you make ask him a copy and he will happy to send it t you. You have to use it in a desktop computer because the online iOS Apss Octalib and Octave pro don't have File I/O support. I now nothing about copyright, but as a user I have a copy stored in my Dropbox account. It's in fact a Matlap script but works in Octave. Of the scripts available, I just used the Excel Macro. You need Microsoft Office 10 or above. I had it installed in a PC with windows XP Pro but they stopped the OS support some months ago. With the excellent scripts you supplied and my IPad Air 2, I don't need it at all to import and process the binar Data. I have also an iOS Basic interpreter with a powerful graphic class that has an option to compile the source code wit XCode. I'm still struggling with the Python code to plot the imported data with your Phytonista scripts. By the way, can Phytonista scripts be compiled with Apple's Xcode?. I use it with a Mac Mini. I'll do anything needed to avoid the iTunes file sharing in the standalone iOS App I'm developing for my Noise project.

                          1 Reply Last reply Reply Quote 0
                          • ccc
                            ccc last edited by ccc

                            There is an XCode template that allows you to compile your Pythonista scripts into standalone iOS apps that you can put into the Apple AppStore.

                            See the changes made to SPLnFFT_Reader_numpy.py. I added a matplotlib scatter chart of the data to show you the graphics capabilities of Pythonista. I could really use the help of someone who knows matplotlib to make the graphic more relevant to this dataset (x=fastFFTs, y=slowFFTs).

                            1 Reply Last reply Reply Quote 0
                            • ManuelU
                              ManuelU last edited by ccc

                              Thanks CCC. The only thing needed is an X_time vector, depending on the total number of data points. This plot show the correlation between SLOW and FAST values.

                              In the Matlab script for a 24 hour record is created as:
                              count=24 * 3600 *8 *2;
                              TabTime=[0:count/2-1]/(count/2)*24;

                              The xCode Template sounds interesting. Unfortunately I have an Academic License and you need to register all devices where the App will be used. I only have an IPad 3 and IPad Air 2, and Xcode only allows 64 bits devices, from iPad 3 and above. This issue could be solved by buying a commercial license, but my intentions are only academic.

                              1 Reply Last reply Reply Quote 0
                              • JonB
                                JonB last edited by

                                in the matlab he also filters Inf values, and plots them in a third color with a value of 1 plus the max value in the dataset.

                                1 Reply Last reply Reply Quote 0
                                • ccc
                                  ccc last edited by

                                  My sense from my emails from the author of SPLnFFT is that the newer files have NO Infs and NO NaNs. I do not find either in the files that I generate with SPLnFFT. I will verify this with the author.

                                  If you know how to create a matplotlib plot that looks like what Matlab generates, I would be happy to accept the pull request ;-).

                                  1 Reply Last reply Reply Quote 0
                                  • JonB
                                    JonB last edited by

                                    pull request on the way. it is not clear what defines the time scale -- does the file always contain a full 24 hours (hence the msny zeros if it wasnt run for that long)?

                                    1 Reply Last reply Reply Quote 0
                                    • ccc
                                      ccc last edited by

                                      Before the cleansing step, each file is 8 readings per second times 24 hours.

                                      1 Reply Last reply Reply Quote 0
                                      • ManuelU
                                        ManuelU last edited by

                                        I'm using and observing SPLnFFT since more than one year ago. If you have the App with the 24 hours export option installed, please, start a recording, pause and go to the HISTO screen. You'll see in the lower right corner a camera icon. Pulse it and next pulse the icon below the 24 HOURS option. This action exports to Photos a 24 hours plot. If you start recording again, let's say after one hour, repeat the same process and observe the differences between plots. By observing this facts repeatedly, I came to the conclusion that when you start and pause the recording, the App must save in a memory buffer the previous SPL values until a 24 hours cycle is completed. It also explains the chunks of SPL values alternating with zero values chunks if you analyze the first of the two 5.2 MB files exported, I sent you a sample in a former comment. THEREFORE, YOU MUST OMITE THE CLEANSE PART OF YOUR CODE IF YOU WANT TO OBTAIN A SIMILAR PLOT with the first Python script you released. I reported this findings to the App developer. Hope this help.

                                        1 Reply Last reply Reply Quote 0
                                        • ccc
                                          ccc last edited by ccc

                                          I accepted the pull request from @JonB and then added more labels so the graph now looks quite presentable. There is also a remove_zero_readings flag to easily remove the cleansing step but if you set it to False, the graph can take more than a minute to appear. Be patient, it will appear.

                                          1 Reply Last reply Reply Quote 0
                                          • markconnors_
                                            markconnors_ last edited by

                                            Hello,
                                            I am new to coding and am going through Zed Shaw's Learning Python The Hard Way. I would like to practice the exercises using Pythonista but am a bit confused on how to proceed. In Zed's course we write the scripts in Text Wrangler then run them in the shell. Could someone point me in the right direction on how to do that but using Pythonista?
                                            Thank you for any advice you could offer.
                                            Mark Connors

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors