Skip to content

Commit

Permalink
version all h5 files (data schema)
Browse files Browse the repository at this point in the history
  • Loading branch information
nzjrs committed May 15, 2021
1 parent cc5af42 commit feab8ec
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
22 changes: 22 additions & 0 deletions flyvr/audio/io_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
DAQ_NUM_INPUT_SAMPLES = 10000
DAQ_NUM_INPUT_SAMPLES_PER_EVENT = 10000

H5_SYNC_VERSION = 1
H5_DATA_VERSION = 1

INPUT_SYNCHRONIZATION_INFO_FIELDS = ('fictrac_frame_num',
'daq_output_num_samples_written',
Expand Down Expand Up @@ -161,6 +163,9 @@ def __init__(self, dev_name="Dev1", cha_ids=("ai0",), cha_type="input", cha_name
self.flyvr_shared_state.logger.log("/daq/chunk_synchronization_info",
int(self.num_samples_per_event),
attribute_name='sample_buffer_size')
self.flyvr_shared_state.logger.log("/daq/chunk_synchronization_info",
H5_SYNC_VERSION,
attribute_name='__version')

for cn, cname in enumerate(SampleChunk.SYNCHRONIZATION_INFO_FIELDS):
self.flyvr_shared_state.logger.log("/daq/chunk_synchronization_info",
Expand All @@ -182,6 +187,10 @@ def __init__(self, dev_name="Dev1", cha_ids=("ai0",), cha_type="input", cha_name
self.flyvr_shared_state.logger.log(self.samples_dset_name,
int(self.num_samples_per_chan),
attribute_name='sample_buffer_size')
self.flyvr_shared_state.logger.log(self.samples_dset_name,
H5_DATA_VERSION,
attribute_name='__version')

if cha_names and cha_ids:
for cn, cname in enumerate(cha_names):
self.flyvr_shared_state.logger.log(self.samples_dset_name,
Expand All @@ -193,11 +202,16 @@ def __init__(self, dev_name="Dev1", cha_ids=("ai0",), cha_type="input", cha_name
chunks=(1024, INPUT_SYNCHRONIZATION_INFO_NUM_FIELDS),
maxshape=[None, INPUT_SYNCHRONIZATION_INFO_NUM_FIELDS],
dtype=np.int64)

for cn, cname in enumerate(INPUT_SYNCHRONIZATION_INFO_FIELDS):
self.flyvr_shared_state.logger.log(self.samples_sync_dset_name,
str(cname),
attribute_name='column_%d' % cn)

self.flyvr_shared_state.logger.log(self.samples_sync_dset_name,
H5_SYNC_VERSION,
attribute_name='__version')

elif cha_type == "input" and digital:
self.samples_dset_name = "/daq/input/digital/samples"
self.samples_sync_dset_name = "/daq/input/digital/synchronization_info"
Expand All @@ -213,17 +227,25 @@ def __init__(self, dev_name="Dev1", cha_ids=("ai0",), cha_type="input", cha_name
self.flyvr_shared_state.logger.log(self.samples_dset_name,
int(self.num_samples_per_chan),
attribute_name='sample_buffer_size')
self.flyvr_shared_state.logger.log(self.samples_dset_name,
H5_DATA_VERSION,
attribute_name='__version')

self.flyvr_shared_state.logger.create(self.samples_sync_dset_name,
shape=[1024, INPUT_SYNCHRONIZATION_INFO_NUM_FIELDS],
chunks=(1024, INPUT_SYNCHRONIZATION_INFO_NUM_FIELDS),
maxshape=[None, INPUT_SYNCHRONIZATION_INFO_NUM_FIELDS],
dtype=np.float64)

for cn, cname in enumerate(INPUT_SYNCHRONIZATION_INFO_FIELDS):
self.flyvr_shared_state.logger.log(self.samples_sync_dset_name,
str(cname),
attribute_name='column_%d' % cn)

self.flyvr_shared_state.logger.log(self.samples_sync_dset_name,
H5_SYNC_VERSION,
attribute_name='__version')

if not digital:
self._data = np.zeros((self.num_samples_per_chan, self.num_channels),
dtype=np.float64) # init empty data array
Expand Down
8 changes: 8 additions & 0 deletions flyvr/audio/sound_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
from flyvr.common.build_arg_parser import setup_logging


H5_SYNC_VERSION = 1
H5_DATA_VERSION = 1


_QUIT = object()


Expand Down Expand Up @@ -267,6 +271,10 @@ def run(self):
str(cname),
attribute_name='column_%d' % cn)

self.flyvr_shared_state.logger.log("/audio/chunk_synchronization_info",
H5_SYNC_VERSION,
attribute_name='__version')

# open stream using control
self._stream = sd.OutputStream(device=self._device,
samplerate=self._sample_rate, blocksize=self._frames_per_buffer,
Expand Down
9 changes: 9 additions & 0 deletions flyvr/video/video_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
from psychopy.visual.windowframepack import ProjectorFramePacker


H5_SYNC_VERSION = 1
H5_DATA_VERSION = 1


SYNCHRONIZATION_INFO_FIELDS = ('fictrac_frame_num',
'daq_output_num_samples_written',
'daq_input_num_samples_read',
Expand Down Expand Up @@ -278,6 +282,8 @@ def create_h5_log(cls, logger):
for cn, cname in enumerate(cls.H5_FIELDS):
logger.log(log_name, str(cname), attribute_name='column_%d' % cn)

logger.log(log_name, H5_DATA_VERSION, attribute_name='__version')

def h5_log(self, logger, frame_num, *fields):
row = [frame_num]
row.extend(fields)
Expand Down Expand Up @@ -986,6 +992,9 @@ def __init__(self, shared_state=None, calibration_file=None, use_lightcrafter=Tr
self.flyvr_shared_state.logger.log("/video/synchronization_info",
1,
attribute_name='sample_buffer_size')
self.flyvr_shared_state.logger.log("/video/synchronization_info",
H5_SYNC_VERSION,
attribute_name='__version')

# This is how many records of calls to the callback function we store in memory.
CALLBACK_TIMING_LOG_SIZE = 10000
Expand Down

0 comments on commit feab8ec

Please sign in to comment.