Skip to content

Instantly share code, notes, and snippets.

@tama-sh
Created October 10, 2015 12:54
Show Gist options
  • Save tama-sh/c62a4bbbd4725bcd0731 to your computer and use it in GitHub Desktop.
Save tama-sh/c62a4bbbd4725bcd0731 to your computer and use it in GitHub Desktop.
import h5py
import numpy as np
def main():
data = read_segment_h5_files()
np.save("osc_data", data)
def read_segment_h5_files(input_basename="ch", n_channel=4):
"""Read Keysight segmented acquisition data (h5 format) as a list of numpy arrays.
Args:
input_basename: base filename of input h5 data
n_channel: number of channels used
Returns:
A list of numpy arrays
"""
out_data = []
for ch_i in range(1, n_channel+1):
input_file = "ch{0}.h5".format(ch_i)
input_h5 = h5py.File(input_file, 'r')
wfm = input_h5["Waveforms/Channel {0}".format(ch_i)]
y_inc = wfm.attrs.get("YInc")
N = wfm.attrs.get("NumSegments")
all_seg_data = []
for i in range(1, N+1):
seg_str = "Channel {0} Seg{1}Data".format(ch_i, i)
dataset = wfm[seg_str]
data = np.array(dataset.value)*y_inc
all_seg_data.append(data)
out_data.append(np.array(all_seg_data))
return out_data
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment