예제 #1
0
def load_from_HDF5_legacy(filename_or_fileobject):
    data = {}
    if isinstance(filename_or_fileobject, h5py.File):
        f = filename_or_fileobject
    else:
        f = h5py.File(filename_or_fileobject, 'r')
    for groupname in f:
        # Reconstruct the descrciptor
        descriptor = DataStreamDescriptor()
        g = f[groupname]
        axis_refs = g['descriptor']
        for ref in reversed(axis_refs):
            ax = g[ref]
            if not 'unit' in ax.attrs:
                # Unstructured

                names = [k for k in ax.dtype.fields.keys()]
                units = [ax.attrs['unit_'+name] for name in names]
                points = ax[:]
                points = points.view(np.float32).reshape(points.shape + (-1,))
                descriptor.add_axis(DataAxis(names, points=points, unit=units))
            else:
                # Structured
                name = ax.attrs['NAME'].decode('UTF-8')
                unit = ax.attrs['unit']
                points = ax[:]
                descriptor.add_axis(DataAxis(name, points=points, unit=unit))

        for attr_name in axis_refs.attrs.keys():
            descriptor.metadata[attr_name] = axis_refs.attrs[attr_name]

        data[groupname] = g['data'][:]

    f.close()
    return data, descriptor
예제 #2
0
    def update_descriptors(self):

        logger.debug("Updating Plotter %s descriptors based on input descriptor %s", self.filter_name, self.sink.descriptor)
        self.stream = self.sink.input_streams[0]
        self.descriptor = self.sink.descriptor
        try:
            self.time_pts = self.descriptor.axes[self.descriptor.axis_num("time")].points
            self.record_length = len(self.time_pts)
        except ValueError:
            raise ValueError("Single shot filter sink does not appear to have a time axis!")
        self.num_averages = len(self.sink.descriptor.axes[self.descriptor.axis_num("averages")].points)
        self.num_segments = len(self.sink.descriptor.axes[self.descriptor.axis_num("segment")].points)
        self.ground_data = np.zeros((self.record_length, self.num_averages), dtype=np.complex)
        self.excited_data = np.zeros((self.record_length, self.num_averages), dtype=np.complex)
        self.total_points = self.num_segments*self.record_length*self.num_averages # Total points BEFORE sweep axes

        output_descriptor = DataStreamDescriptor()
        output_descriptor.axes = [_ for _ in self.descriptor.axes if type(_) is SweepAxis]
        output_descriptor._exp_src = self.sink.descriptor._exp_src
        output_descriptor.dtype = np.complex128

        if len(output_descriptor.axes) == 0:
            output_descriptor.add_axis(DataAxis("Fidelity", [1]))

        for os in self.fidelity.output_streams:
            os.set_descriptor(output_descriptor)
            os.end_connector.update_descriptors()
예제 #3
0
    def get_descriptor(self, source_instr_settings, channel_settings):
        # Create a channel
        channel = X6Channel(channel_settings)

        descrip = DataStreamDescriptor()
        # If it's an integrated stream, then the time axis has already been eliminated.
        # Otherwise, add the time axis.
        if channel_settings['stream_type'] == 'Raw':
            samp_time = 4.0e-9
            descrip.add_axis(
                DataAxis(
                    "time",
                    samp_time *
                    np.arange(source_instr_settings['record_length'] // 4)))
            descrip.dtype = np.float64
        elif channel_settings['stream_type'] == 'Demodulated':
            samp_time = 32.0e-9
            descrip.add_axis(
                DataAxis(
                    "time",
                    samp_time *
                    np.arange(source_instr_settings['record_length'] // 32)))
            descrip.dtype = np.complex128
        elif channel_settings['stream_type'] == 'Integrated':
            descrip.dtype = np.complex128
        elif channel_settings[
                'stream_type'] == 'Correlated':  # Same as integrated
            descrip.dtype = np.complex128
        elif channel_settings['stream_type'] == 'State':
            descrip.dtype = np.complex128
        return channel, descrip
예제 #4
0
    def get_descriptor(self, source_instr_settings, channel_settings):
        channel = AlazarChannel(channel_settings)

        # Add the time axis
        samp_time = 1.0/source_instr_settings['sampling_rate']
        descrip = DataStreamDescriptor()
        descrip.add_axis(DataAxis("time", samp_time*np.arange(source_instr_settings['record_length'])))
        return channel, descrip
예제 #5
0
 def init_streams(self):
     # Add a "base" data axis: say we are averaging 5 samples per trigger
     descrip = DataStreamDescriptor()
     descrip.data_name = 'voltage'
     if self.is_complex:
         descrip.dtype = np.complex128
     descrip.add_axis(DataAxis("samples", list(range(self.samples))))
     self.voltage.set_descriptor(descrip)
예제 #6
0
 def init_streams(self):
     # Baked in data axes
     descrip = DataStreamDescriptor()
     descrip.data_name = 'voltage'
     descrip.add_axis(
         DataAxis("sample",
                  range(int(self.integration_time * self.ai_clock))))
     descrip.add_axis(DataAxis("attempt", range(self.attempts)))
     self.voltage.set_descriptor(descrip)
예제 #7
0
파일: DAQ_IV.py 프로젝트: caryan/Auspex
    def init_streams(self):
        descrip = DataStreamDescriptor()
        descrip.data_name='current_input'
        descrip.add_axis(DataAxis("time", np.arange(int(self.sample_rate*self.num_bursts/self.frequency))/self.sample_rate))
        self.current_input.set_descriptor(descrip)

        descrip = DataStreamDescriptor()
        descrip.data_name='voltage_sample'
        descrip.add_axis(DataAxis("time", np.arange(int(self.sample_rate*self.num_bursts/self.frequency))/self.sample_rate))
        self.voltage_sample.set_descriptor(descrip)
예제 #8
0
 def get_descriptor(self, stream_selector, receiver_channel):
     """Get the axis descriptor corresponding to this stream selector. For the Alazar cards this
     is always just a time axis."""
     samp_time = 1.0 / receiver_channel.receiver.sampling_rate
     descrip = DataStreamDescriptor()
     descrip.add_axis(
         DataAxis(
             "time",
             samp_time *
             np.arange(receiver_channel.receiver.record_length)))
     return descrip
예제 #9
0
def load_from_HDF5(filename_or_fileobject,
                   reshape=True,
                   return_structured_array=True):
    data = {}
    descriptors = {}
    if isinstance(filename_or_fileobject, h5py.File):
        f = filename_or_fileobject
    else:
        f = h5py.File(filename_or_fileobject, 'r')
    for groupname in f:
        # Reconstruct the descrciptor
        descriptor = DataStreamDescriptor()
        g = f[groupname]
        axis_refs = g['descriptor']
        for ref in reversed(axis_refs):
            ax = g[ref]
            if ax.attrs['unstructured']:
                # The entry for the main unstructured axis contains
                # references to the constituent axes.

                # The DataAxis expects points as tuples coordinates
                # in the form [(x1, y1), (x2, y2), ...].
                points = np.vstack([g[e] for e in ax[:]]).T
                names = [g[e].attrs["name"] for e in ax[:]]
                units = [g[e].attrs["unit"] for e in ax[:]]
                descriptor.add_axis(DataAxis(names, points=points, unit=units))
            else:
                name = ax.attrs['name']
                unit = ax.attrs['unit']
                points = ax[:]
                descriptor.add_axis(DataAxis(name, points=points, unit=unit))

        for attr_name in axis_refs.attrs.keys():
            descriptor.metadata[attr_name] = axis_refs.attrs[attr_name]

        col_names = list(g['data'].keys())
        if return_structured_array:
            dtype = [(g['data'][n].attrs['name'], g['data'][n].dtype.char)
                     for n in col_names]
            length = g['data'][col_names[0]].shape[0]
            group_data = np.empty((length, ), dtype=dtype)
            for cn in col_names:
                group_data[cn] = g['data'][cn]
        else:
            group_data = {n: g['data'][n][:] for n in col_names}

        if reshape:
            group_data = group_data.reshape(descriptor.dims())

        data[groupname] = group_data
        descriptors[groupname] = descriptor
    if not isinstance(filename_or_fileobject, h5py.File):
        f.close()
    return data, descriptors
예제 #10
0
 def test_copy_descriptor(self):
     dsd = DataStreamDescriptor()
     dsd.add_axis(DataAxis("One", [1, 2, 3, 4]))
     dsd.add_axis(DataAxis("Two", [1, 2, 3, 4, 5]))
     self.assertTrue(len(dsd.axes) == 2)
     self.assertTrue("One" in [a.name for a in dsd.axes])
     dsdc = copy(dsd)
     self.assertTrue(dsd.axes == dsdc.axes)
     ax = dsdc.pop_axis("One")
     self.assertTrue(ax.name == "One")
     self.assertTrue(len(dsdc.axes) == 1)
     self.assertTrue(dsdc.axes[0].name == "Two")
예제 #11
0
    def init_streams(self):
        # Baked in data axes
        descrip = DataStreamDescriptor()
        descrip.add_axis(DataAxis("time", 1e-9 * np.arange(self.samples)))
        if len(self.gate_durs) > 1:
            descrip.add_axis(DataAxis("gate_pulse_duration", self.gate_durs))
        descrip.add_axis(DataAxis("gate_pulse_amplitude", self.gate_amps))
        descrip.add_axis(DataAxis("attempt", range(self.attempts)))

        self.voltage.set_descriptor(descrip)
예제 #12
0
    def init_streams(self):
        descrip = DataStreamDescriptor()
        descrip.data_name = 'voltage_input'
        descrip.add_axis(DataAxis("index", np.arange(self.num_points + 2)))
        descrip.add_axis(DataAxis("repeat", np.arange(self.repeat)))
        self.voltage_input.set_descriptor(descrip)

        descrip = DataStreamDescriptor()
        descrip.data_name = 'voltage_sample'
        descrip.add_axis(DataAxis("index", np.arange(self.num_points + 2)))
        descrip.add_axis(DataAxis("repeat", np.arange(self.repeat)))
        self.voltage_sample.set_descriptor(descrip)
예제 #13
0
 def init_streams(self):
     descrip = DataStreamDescriptor()
     descrip.data_name = 'voltage'
     descrip.add_axis(DataAxis("sample", range(self.samps_per_trig)))
     descrip.add_axis(DataAxis("state", range(2)))
     descrip.add_axis(DataAxis("attempt", range(self.attempts)))
     self.voltage.set_descriptor(descrip)
예제 #14
0
 def init_streams(self):
     # Baked in data axes
     descrip = DataStreamDescriptor()
     descrip.add_axis(DataAxis("sample", range(self.samps_per_trig)))
     descrip.add_axis(DataAxis("state", range(2)))
     descrip.add_axis(DataAxis("attempt", range(self.attempts.value)))
     self.voltage.set_descriptor(descrip)
예제 #15
0
 def init_streams(self):
     # Baked in data axes
     descrip = DataStreamDescriptor()
     descrip.data_name = 'voltage'
     descrip.add_axis(DataAxis("sample", range(self.samps_per_trig)))
     descrip.add_axis(DataAxis("amplitude", self.amplitudes))
     descrip.add_axis(DataAxis("repeat", range(self.repeats)))
     self.voltage.set_descriptor(descrip)
예제 #16
0
 def init_streams(self):
     descrip = DataStreamDescriptor()
     descrip.add_axis(
         DataAxis("samples", 2e-9 * np.arange(self.num_samples)))
     descrip.add_axis(DataAxis("delay", self.delays))
     descrip.add_axis(DataAxis("round_robins",
                               np.arange(self.round_robins)))
     self.voltage.set_descriptor(descrip)
예제 #17
0
 def get_descriptor(self, stream_selector, receiver_channel):
     """Get the axis descriptor corresponding to this stream selector. If it's an integrated stream,
     then the time axis has already been eliminated. Otherswise, add the time axis."""
     descrip = DataStreamDescriptor()
     if stream_selector.stream_type == 'raw':
         samp_time = 4.0e-9
         descrip.add_axis(
             DataAxis(
                 "time",
                 samp_time *
                 np.arange(receiver_channel.receiver.record_length // 4)))
         descrip.dtype = np.float64
     elif stream_selector.stream_type == 'demodulated':
         samp_time = 32.0e-9
         descrip.add_axis(
             DataAxis(
                 "time",
                 samp_time *
                 np.arange(receiver_channel.receiver.record_length // 32)))
         descrip.dtype = np.complex128
     else:  # Integrated
         descrip.dtype = np.complex128
     return descrip
예제 #18
0
    def refine_func(sweep_axis):
        points, mean = sw.load_switching_data(wr.filename)
        new_points = refine.refine_scalar_field(points,
                                                mean,
                                                all_points=False,
                                                criterion="integral",
                                                threshold="one_sigma")
        if len(points) + len(new_points) > max_points:
            print("Reached maximum points ({}).".format(max_points))
            return False
        print("Reached {} points.".format(len(points) + len(new_points)))
        sweep_axis.add_points(new_points)

        # Plot previous mesh
        x = [list(el) for el in points[mesh.simplices, 0]]
        y = [list(el) for el in points[mesh.simplices, 1]]
        val = [np.mean(vals) for vals in mean[mesh.simplices]]

        desc = DataStreamDescriptor()
        desc.add_axis(sweep_axis)
        exp.push_to_plot(fig1, desc, points)

        time.sleep(1)
        return True
예제 #19
0
 def init_streams(self):
     descrip = DataStreamDescriptor()
     descrip.data_name='voltage'
     descrip.add_axis(DataAxis("sample", range(int(self.meas_duration*self.ai_clock))))
     descrip.add_axis(DataAxis("attempt", range(self.attempts)))
     self.voltage.set_descriptor(descrip)