Guest User

ScriptToReadRDVXZ.py

a guest
May 18th, 2018
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.10 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Wed May 16 21:32:53 2018
  4.  
  5. @author: rkabealo
  6.  
  7. A program to import .rdvxz files collected from the RedVox app, decode the files
  8. and extract the collected Microphone data (using methods declared in reader.py), and finally plot this data and
  9. save the plotted figure (visually, a waveform)
  10. """
  11. import api900_pb2
  12. import reader
  13.  
  14. import struct
  15. import typing
  16.  
  17. import google.protobuf.internal.containers as containers
  18. import lz4.block
  19. import numpy
  20.  
  21. import numpy as np  
  22. from matplotlib import pyplot as plt
  23.  
  24. """ A list of test files we have, as well as the file we've designated
  25. for testing """
  26. rPhone = "0937537210_1526315748790.rdvxz"
  27. spaceX = "1637160009_1526493437311.rdvxz"
  28. cTest = ""
  29. testFile = rPhone
  30.  
  31. """ Gets the decoded version of the data from the test file and displays
  32. it to the console """
  33. dRVOP = reader.read_file(testFile)
  34. #print(dRVOP)
  35.  
  36. """ Gets the wrapped RedVox packet for our data """
  37. wRVP = reader.WrappedRedvoxPacket(dRVOP)
  38.  
  39. """ Displays whether the microphone channel exists (just checking
  40. for our own sanity) """  
  41. findMic = wRVP.has_channel(api900_pb2.MICROPHONE)
  42. #print(findMic)
  43.  
  44. """ Gets the different types of channels, so we can see which ones are
  45. interleaved. From this call we see that the MICROPHONE channel (denoted [0])
  46. is NOT interleaved. """
  47. listofChannels = wRVP.get_channel_types()
  48. #print(listofChannels)
  49.  
  50. """ We can check again that the microphone is
  51. NOT interleaved through this method """
  52. listofChannelNames = wRVP.get_channel_type_names()
  53. #print(listofChannelNames)
  54.  
  55. """ Gets the microphone channel in its entirity
  56. # Takes: channel_type enum
  57. # Returns: api900_pb2.EvenlySampledChannel"""
  58. micChannel = wRVP.get_channel(api900_pb2.MICROPHONE)
  59. #print(micChannel)
  60.  
  61. """ Failure #1: Gets the payload from the mic data
  62. # Takes: channel_type enum
  63. # Returns: api900_pb2.EvenlySampledChannel"""
  64. #payloadMic = reader.InterleavedChannel(micChannel).get_payload()
  65. #print(payloadMic)
  66.  
  67. """ Failure #2: Gets the payload from the mic data
  68. # Takes: channel_type enum
  69. # Returns: api900_pb2.EvenlySampledChannel"""
  70. #strMic = reader.InterleavedChannel(micChannel).has_payload(api900_pb2.MICROPHONE)
  71. #reader.extract_payload(micChannel)
  72. #print(strMic)
  73.  
  74. """ Gets the sample rate (in Hz) from the microphone channel. We
  75. can access the sample rate like this because it's an attribute of the
  76. microphone channel """
  77. #print(micChannel.sample_rate_hz)
  78.  
  79. """ Gets the payload data from the microphone channel as a numpy array. We
  80. can access the payload like this because it's an attribute of the
  81. microphone channel. Just like above with sample_rate_hz"""
  82. data = micChannel.payload
  83. #print(data)
  84.  
  85. """Plotting the payload"""
  86. fig, ax = plt.subplots(nrows=1, ncols=1,figsize=(5,1.25))  # create figure & 1 axis
  87. ax.plot(data, color='blue')
  88. ax.set_title('ID: 1637650005 Data', fontsize=3.75)
  89. ax.set_xlabel('Time (s)', fontsize=3.75)
  90. ax.set_ylabel('Amplitude', fontsize=3.75)
  91. plt.xticks(fontsize=3.875, rotation=0)
  92. plt.yticks(fontsize=3.875, rotation=90)
  93.  
  94. """Save the figure"""
  95. fig.savefig('testFile.png', dpi = 250)
Advertisement
Add Comment
Please, Sign In to add comment