Esempio n. 1
0
def test_base_validation(task):
    """Test simply validating the evaluation.

    """
    task.feval = '2*{Loop_val}'
    val, res, msg = validators.Feval().check(task, 'feval')
    assert val == 2
    assert res
    assert not msg

    task.feval = '2-*{Loop_val}'
    val, res, msg = validators.Feval().check(task, 'feval')
    assert val is None
    assert not res
    assert msg
Esempio n. 2
0
def test_warn_on_error(task):
    """Test simply warning on error.

    """
    task.feval = '2-*{test_val}'
    val, res, msg = validators.Feval(warn=True).check(task, 'feval')
    assert val is None
    assert res
    assert msg
class OscilloGetTraceTask(InstrumentTask):
    """ Get the trace displayed on the oscilloscope.

    """
    #: Trace to collect from the oscilloscope
    trace = Enum('1', '2', '3', '4', 'TA', 'TB', 'TC', 'TD').tag(pref=True)

    #: Number of time the instrument should average.
    average_nb = Str().tag(pref=True,
                           feval=validators.Feval(types=numbers.Integral))

    #: Should hid=gh resolution be used.
    highres = Bool(True).tag(pref=True)

    database_entries = set_default({
        'trace_data': np.array([1.0]),
        'oscillo_config': ''
    })

    def perform(self):
        """Get the data from the instrument.

        """
        if self.driver.owner != self.name:
            self.driver.owner = self.name

        channel = self.driver.get_channel(self.trace)
        data = channel.read_data_complete(self.highres)

        msg = 'Coupling {}, Average number {}'
        oscillo_config = msg.format(channel.sweep, data['VERT_COUPLING'])
        self.write_in_database('oscillo_config', oscillo_config)

        # if the TrigArray lentgh is null, it's a simple single sweep waveform
        if data['TRIGTIME_ARRAY'][0] == 0:
            arr = np.rec.fromarrays([
                data['SingleSweepTimesValuesArray'], data['Volt_Value_array']
            ],
                                    names=['Time (s)', 'Voltage (V)'])
            self.write_in_database('trace_data', arr)
        else:
            arr = np.rec.fromarrays([
                data['SEQNCEWaveformTimesValuesArray'],
                data['Volt_Value_array']
            ],
                                    names=['Time (s)', 'Voltage (V)'])
            self.write_in_database('trace_data', )
Esempio n. 4
0
def test_type_validation(task):
    """Test type validating an entry.

    """
    validator = validators.Feval(types=numbers.Real)

    task.feval = '2*{Loop_val}'
    val, res, msg = validator.check(task, 'feval')
    assert val == 2
    assert res
    assert not msg

    task.feval = '2j*{Loop_val}'
    val, res, msg = validator.check(task, 'feval')
    assert val is None
    assert not res
    assert msg
Esempio n. 5
0
# -----------------------------------------------------------------------------
"""Task perform measurements the SPDevices digitizers.

"""
from __future__ import (division, unicode_literals, print_function,
                        absolute_import)

import numbers
import numpy as np
from inspect import cleandoc

from atom.api import (Bool, Str, Enum, set_default)

from exopy.tasks.api import InstrumentTask, validators

VAL_REAL = validators.Feval(types=numbers.Real)

VAL_INT = validators.Feval(types=numbers.Integral)

import psutil  #used in the RAM estimation


class DemodAlazarTask(InstrumentTask):
    """ Get the raw or averaged quadratures of the signal.
        Can also get raw or averaged traces of the signal.
        Custom shape for demodulation can be used.
    """
    freq = Str('50').tag(pref=True)

    freqB = Str('50').tag(pref=True)
Esempio n. 6
0
import numbers
import numpy as np
import textwrap
import time
from inspect import cleandoc
from collections import OrderedDict
import os
from operator import mul
from functools import reduce

from atom.api import (Bool, Str, Enum, set_default,Typed)

from exopy.tasks.api import InstrumentTask, validators
from exopy.utils.atom_util import ordered_dict_from_pref, ordered_dict_to_pref

VAL_REAL = validators.Feval(types=numbers.Real)

VAL_INT = validators.Feval(types=numbers.Integral)# -*- coding: utf-8 -*-

def eval_with_units(task,evaluee):
    value = task.format_and_eval_string(evaluee[0])
    unit = str(evaluee[1])
    unitlist = ['','none', 'ns', 'GHz', 'MHz' ,'clock_samples', 's', 'µs','ns_to_clck'] #from views
    multlist  = [1,1,1e-9,1e9,1e6,1,1,1e-6,1/3.33] #corresponding to above list
    unitdict = dict(zip(unitlist,multlist))

    clckrate_command = '/%s/system/clocks/sampleclock/freq' %task.driver.device
    unitdict['ns_to_clck'] = float(task.driver.daq.get(clckrate_command, True, 0)[clckrate_command]['value'])*1e-9/8 # the HDAWG clockrate is 8 times slower than the sample rate

    multiplier = unitdict[unit]
    value = value * multiplier
Esempio n. 7
0
    def create_dataset(self, name, shape, maximumshape, datatype, compress):
        f = super(_HDF5File, self)
        if compress != 'None':
            f.create_dataset(name,
                             shape,
                             maxshape=maximumshape,
                             dtype=datatype,
                             compression=compress)
        else:
            f.create_dataset(name,
                             shape,
                             maxshape=maximumshape,
                             dtype=datatype)


VAL_REAL = validators.Feval(types=numbers.Real)


class SaveFileHDF5Task(SimpleTask):
    """ Save the specified entries in a HDF5 file.

    Wait for any parallel operation before execution.

    """
    #: Folder in which to save the data.
    folder = Str('{default_path}').tag(pref=True, fmt=True)

    #: Name of the file in which to write the data.
    filename = Str().tag(pref=True, fmt=True)

    #: Currently opened file object. (File mode)
Esempio n. 8
0
class ArrayFindValueTask(SimpleTask):
    """ Store the index of the first occurence of a value in an array.

    Wait for any parallel operation before execution.

    """
    #: Name of the target in the database.
    target_array = Str().tag(pref=True, feval=ARR_VAL)

    #: Name of the column into which the extrema should be looked for.
    column_name = Str().tag(pref=True)

    #: Value which should be looked for in the array.
    value = Str().tag(pref=True, feval=validators.Feval())

    database_entries = set_default({'index': 0})

    wait = set_default({'activated': True})  # Wait on all pools by default.

    def perform(self):
        """ Find index of value array and store index in database.

        """
        array = self.format_and_eval_string(self.target_array)
        if self.column_name:
            array = array[self.column_name]

        val = self.format_and_eval_string(self.value)

        try:
            ind = np.where(np.abs(array - val) < 1e-12)[0][0]
        except IndexError as e:
            msg = 'Could not find {} in array {} ({})'
            raise ValueError(msg.format(val, self.target_array, array)) from e
        self.write_in_database('index', ind)

    def check(self, *args, **kwargs):
        """ Check the target array can be found and has the right column.

        """
        test, traceback = super(ArrayFindValueTask, self).check(*args,
                                                                **kwargs)

        if not test:
            return test, traceback

        err_path = self.get_error_path()

        array = self.format_and_eval_string(self.target_array)

        if self.column_name:
            if array.dtype.names:
                names = array.dtype.names
                if self.column_name not in names:
                    msg = 'No column named {} in array. (column are : {})'
                    traceback[err_path] = msg.format(self.column_name, names)
                    return False, traceback
            else:
                traceback[err_path] = 'Array has no named columns'
                return False, traceback

        else:
            if array.dtype.names:
                msg = 'The target array has names columns : {}. Choose one'
                traceback[err_path] = msg.format(array.dtype.names)
                return False, traceback
            elif len(array.shape) > 1:
                msg = 'Must use 1d array when using non record arrays.'
                traceback[err_path] = msg
                return False, traceback

        return test, traceback
Esempio n. 9
0
# -----------------------------------------------------------------------------
# Copyright 2015-2018 by ExopyHqcLegacy Authors, see AUTHORS for more details.
#
# Distributed under the terms of the BSD license.
#
# The full license is in the file LICENCE, distributed with this software.
# -----------------------------------------------------------------------------
"""Tasks to operate on numpy.arrays.

"""
import numpy as np
from atom.api import (Enum, Str, set_default)
from exopy.tasks.api import SimpleTask, validators


ARR_VAL = validators.Feval(types=np.ndarray)


class ArrayExtremaTask(SimpleTask):
    """ Store the pair(s) of index/value for the extrema(s) of an array.

    Wait for any parallel operation before execution.

    """
    #: Name of the target in the database.
    target_array = Str().tag(pref=True, feval=ARR_VAL)

    #: Name of the column into which the extrema should be looked for.
    column_name = Str().tag(pref=True)

    #: Flag indicating which extremum shiul be lookd for.