def generate_code(self, hdf5_file): Device.generate_code(self, hdf5_file) # This group must exist in order for BLACS to know that this # device is part of the experiment: group = hdf5_file.create_group('/devices/%s' % self.name) outputs = self.get_all_outputs() change_times = self.collect_change_times(outputs) for output in outputs: output.make_timeseries(change_times) for time in change_times: outputarray = [0] * self.n_digitals for output in outputs: channel = output.connection # We have to subtract one from the channel number to get # the correct index, as ADWin is one-indexed, curse it. outputarray[channel - 1] = array(output.timeseries) bits = bitfield(outputarray, dtype=self.digital_dtype) self.formatted_instructions = [] for t, value in zip(change_times, bits): formatted_instruction = { 't': t, 'card': self.card_number, 'bitfield': value } self.formatted_instructions.append(formatted_instruction)
def generate_code(self, hdf5_file): Device.generate_code(self, hdf5_file) inputs = {} for device in self.child_devices: if isinstance(device, AnalogIn): inputs[device.connection] = device else: raise Exception('Got unexpected device.') input_connections = sorted(inputs) input_attrs = [] acquisitions = [] for connection in input_connections: input_attrs.append(self.name+'/'+connection) for acq in inputs[connection].acquisitions: acquisitions.append((connection, acq['label'], acq['start_time'], acq['end_time'], acq['wait_label'], acq['scale_factor'], acq['units'])) acquisitions_table_dtypes = [('connection', 'a256'), ('label', 'a256'), ('start', float), ('stop', float), ('wait label', 'a256'), ('scale factor', float), ('units', 'a256')] acquisition_table = np.empty( len(acquisitions), dtype=acquisitions_table_dtypes) for i, acq in enumerate(acquisitions): acquisition_table[i] = acq grp = self.init_device_group(hdf5_file) if len(acquisition_table): # Table must be non empty grp.create_dataset( 'ACQUISITIONS', compression=config.compression, data=acquisition_table) self.set_property('analog_in_channels', ', '.join( input_attrs), location='device_properties')
def generate_code(self, hdf5_file): """Packs the recorded temperature value into the hdf5 file (into device properties). Args: hdf5_file: used file format """ Device.generate_code(self, hdf5_file) self.init_device_group(hdf5_file) self.set_property("Temperature", float(self.value), location="device_properties")
def generate_code(self, hdf5_file): Device.generate_code(self, hdf5_file) # This group must exist in order for BLACS to know that this # device is part of the experiment: group = hdf5_file.create_group('/devices/%s' % self.name) # OK, let's collect up all the analog instructions! self.formatted_instructions = [] for output in self.get_all_outputs(): for t, instruction in output.instructions.items(): card_number = self.card_number channel_number = output.connection if isinstance(instruction, RampInstruction): duration = instruction.duration if isinstance(instruction, LinearRamp): ramp_type = 0 elif isinstance(instruction, SinRamp): ramp_type = 1 elif isinstance(instruction, CosRamp): ramp_type = 2 elif isinstance(instruction, ExpRamp): ramp_type = 3 else: raise ValueError(instruction) A = instruction.A B = instruction.B C = instruction.C else: # Let's construct a ramp out of the single value instruction: duration = self.clock_resolution ramp_type = 0 A = instruction B = 0 C = instruction formatted_instruction = { 't': t, 'duration': duration, 'card': card_number, 'channel': channel_number, 'ramp_type': ramp_type, 'A': A, 'B': B, 'C': C } self.formatted_instructions.append(formatted_instruction)
def generate_code(self, hdf5_file): outputs = self.get_all_outputs() # We call the following to do the error checking it includes, # but we're not actually interested in the set of change times. # Each card will handle its own timebase issues. ignore = self.collect_change_times(outputs) self.do_checks(outputs) # This causes the cards to have their generate_code() methods # called. They collect up the instructions of their outputs, # and then we will collate them together into one big instruction # table. Device.generate_code(self, hdf5_file) self.collect_card_instructions(hdf5_file) # We don't actually care about these other things that pseudoclock # classes normally do, but they still do some error checking # that we want: change_times = self.collect_change_times(outputs) for output in outputs: output.make_timeseries(change_times) all_times, clock = self.expand_change_times(change_times, outputs)
def generate_code(self, hdf5_file): Device.generate_code(self, hdf5_file) # This group must exist in order for BLACS to know that this # device is part of the experiment: group = hdf5_file.create_group('/devices/%s'%self.name) outputs = self.get_all_outputs() change_times = self.collect_change_times(outputs) for output in outputs: output.make_timeseries(change_times) for time in change_times: outputarray = [0]*self.n_digitals for output in outputs: channel = output.connection # We have to subtract one from the channel number to get # the correct index, as ADWin is one-indexed, curse it. outputarray[channel - 1] = array(output.timeseries) bits = bitfield(outputarray, dtype=self.digital_dtype) self.formatted_instructions = [] for t, value in zip(change_times, bits): formatted_instruction = {'t': t, 'card': self.card_number,'bitfield': value} self.formatted_instructions.append(formatted_instruction)
def generate_code(self, hdf5_file): Device.generate_code(self, hdf5_file) # This group must exist in order for BLACS to know that this # device is part of the experiment: group = hdf5_file.create_group('/devices/%s'%self.name) # OK, let's collect up all the analog instructions! self.formatted_instructions = [] for output in self.get_all_outputs(): for t, instruction in output.instructions.items(): card_number = self.card_number channel_number = output.connection if isinstance(instruction, RampInstruction): duration = instruction.duration if isinstance(instruction, LinearRamp): ramp_type = 0 elif isinstance(instruction, SinRamp): ramp_type = 1 elif isinstance(instruction, CosRamp): ramp_type = 2 elif isinstance(instruction, ExpRamp): ramp_type = 3 else: raise ValueError(instruction) A = instruction.A B = instruction.B C = instruction.C else: # Let's construct a ramp out of the single value instruction: duration = self.clock_resolution ramp_type = 0 A = instruction B = 0 C = instruction formatted_instruction = {'t':t, 'duration': duration, 'card': card_number, 'channel': channel_number, 'ramp_type': ramp_type, 'A': A, 'B': B, 'C': C} self.formatted_instructions.append(formatted_instruction)
def generate_code(self, hdf5_file): # group = self.init_device_name(hdf5_file) Device.generate_code(self, hdf5_file)
def generate_code(self, hdf5_file): '''Automatically called by compiler to write acquisition instructions to h5 file. Configures counters, analog and digital acquisitions.''' Device.generate_code(self, hdf5_file) trans = {'pulse': 'PUL', 'edge': 'EDG', 'pos': 'P', 'neg': 'N'} acqs = {'ANALOG': [], 'POD1': [], 'POD2': []} for channel in self.child_devices: if channel.acquisitions: # make sure channel is allowed if channel.connection in self.allowed_analog_chan: acqs['ANALOG'].append( (channel.connection, channel.acquisitions[0]['label'])) elif channel.connection in self.allowed_pod1_chan: acqs['POD1'].append( (channel.connection, channel.acquisitions[0]['label'])) elif channel.connection in self.allowed_pod2_chan: acqs['POD2'].append( (channel.connection, channel.acquisitions[0]['label'])) else: raise LabscriptError( '{0:s} is not a valid channel.'.format( channel.connection)) acquisition_table_dtypes = np.dtype({ 'names': ['connection', 'label'], 'formats': ['a256', 'a256'] }) grp = self.init_device_group(hdf5_file) # write tables if non-empty to h5_file for acq_group, acq_chan in acqs.items(): if len(acq_chan): table = np.empty(len(acq_chan), dtype=acquisition_table_dtypes) for i, acq in enumerate(acq_chan): table[i] = acq grp.create_dataset(acq_group + '_ACQUISITIONS', compression=config.compression, data=table) grp[acq_group + '_ACQUISITIONS'].attrs['trigger_time'] = self.trigger_time # now do the counters counts = [] for channel in self.child_devices: if hasattr(channel, 'counts'): for counter in channel.counts: counts.append((channel.connection, trans[counter['type']], trans[counter['polarity']])) counts_table_dtypes = np.dtype({ 'names': ['connection', 'type', 'polarity'], 'formats': ['a256', 'a256', 'a256'] }) counts_table = np.empty(len(counts), dtype=counts_table_dtypes) for i, count in enumerate(counts): counts_table[i] = count if len(counts_table): grp.create_dataset('COUNTERS', compression=config.compression, data=counts_table) grp['COUNTERS'].attrs['trigger_time'] = self.trigger_time
def generate_code(self, hdf5_file): self.do_checks() Device.generate_code(self, hdf5_file)