示例#1
0
class TestParameters(DataSet):
    """
    DataSet test
    The following text is the DataSet 'comment': <br>Plain text or
    <b>rich text<sup>2</sup></b> are both supported,
    as well as special characters (α, β, γ, δ, ...)
    """
    files = SubDataSetItem("files")
    string = StringItem("String")
    text = TextItem("Text")
    _bg = BeginGroup("A sub group")
    float_slider = FloatItem("Float (with slider)",
                             default=0.5,
                             min=0,
                             max=1,
                             step=0.01,
                             slider=True)
    fl1 = FloatItem("Current",
                    default=10.,
                    min=1,
                    max=30,
                    unit="mA",
                    help="Threshold current")
    fl2 = FloatItem("Float (col=1)",
                    default=1.,
                    min=1,
                    max=1,
                    help="Help on float item").set_pos(col=1)
    fl3 = FloatItem("Not checked float").set_prop('data', check_value=False)
    bool1 = BoolItem("Boolean option without label")
    bool2 = BoolItem("Boolean option with label", "Label").set_pos(col=1,
                                                                   colspan=2)
    color = ColorItem("Color", default="red")
    choice = ChoiceItem("Single choice",
                        [(16, "first choice"), (32, "second choice"),
                         (64, "third choice")]).set_pos(col=1, colspan=2)
    _eg = EndGroup("A sub group")
    floatarray = FloatArrayItem("Float array",
                                default=np.ones((50, 5), float),
                                format=" %.2e ").set_pos(col=1)
    g0 = BeginTabGroup("group")
    mchoice1 = MultipleChoiceItem(
        "MC type 1",
        ["first choice", "second choice", "third choice"]).vertical(2)
    mchoice2 = ImageChoiceItem("MC type 2",
                               [("rect", "first choice", "gif.png" ),
                                ("ell", "second choice", "txt.png" ),
                                ("qcq", "third choice", "file.png" )]
                               ).set_pos(col=1) \
                                .set_prop("display", icon="file.png")
    mchoice3 = MultipleChoiceItem("MC type 3",
                                  [str(i) for i in range(10)]).horizontal(2)
    eg0 = EndTabGroup("group")
    integer_slider = IntItem("Integer (with slider)",
                             default=5,
                             min=0,
                             max=100,
                             slider=True)
    integer = IntItem("Integer", default=5, min=3, max=6).set_pos(col=1)
示例#2
0
class ImageParam(DataSet):
    _hide_data = False
    _hide_size = True
    title = StringItem(_("Title"), default=_("Untitled"))
    data = FloatArrayItem(_("Data")).set_prop("display", hide=GetAttrProp("_hide_data"))
    width = IntItem(
        _("Width"), help=_("Image width (pixels)"), min=1, default=100
    ).set_prop("display", hide=GetAttrProp("_hide_size"))
    height = IntItem(
        _("Height"), help=_("Image height (pixels)"), min=1, default=100
    ).set_prop("display", hide=GetAttrProp("_hide_size"))
示例#3
0
class ArrayParam(DataSet):
    _hide_data = False
    _hide_size = True
    title = StringItem(_("Name"), default=_(" array name "))
    data = FloatArrayItem(_("Data")).set_prop("display",
                                              hide=GetAttrProp("_hide_data"))
    width = IntItem(_("Width(個數)"), help=_("總共幾個array"), min=1,
                    default=100).set_prop("display",
                                          hide=GetAttrProp("_hide_size"))
    height = IntItem(_("Height(長度)"), help=_("一個array的長度"), min=1,
                     default=1).set_prop("display",
                                         hide=GetAttrProp("_hide_size"))
示例#4
0
class TestParameters(DataSet):
    """
    DataSet test
    The following text is the DataSet 'comment': <br>Plain text or
    <b>rich text<sup>2</sup></b> are both supported,
    as well as special characters (α, β, γ, δ, ...)
    """
    dir = DirectoryItem("Directory", TEMPDIR)
    fname = FileOpenItem("Open file", ("csv", "eta"), FILE_CSV.name)
    fnames = FilesOpenItem("Open files", "csv", FILE_CSV.name)
    fname_s = FileSaveItem("Save file", "eta", FILE_ETA.name)
    string = StringItem("String")
    text = TextItem("Text")
    float_slider = FloatItem("Float (with slider)",
                             default=0.5,
                             min=0,
                             max=1,
                             step=0.01,
                             slider=True)
    integer = IntItem("Integer", default=5, min=3, max=16,
                      slider=True).set_pos(col=1)
    dtime = DateTimeItem("Date/time", default=datetime.datetime(2010, 10, 10))
    date = DateItem("Date", default=datetime.date(2010, 10, 10)).set_pos(col=1)
    bool1 = BoolItem("Boolean option without label")
    bool2 = BoolItem("Boolean option with label", "Label")
    _bg = BeginGroup("A sub group")
    color = ColorItem("Color", default="red")
    choice = ChoiceItem("Single choice 1", [('16', "first choice"),
                                            ('32', "second choice"),
                                            ('64', "third choice")])
    mchoice2 = ImageChoiceItem("Single choice 2",
                               [("rect", "first choice", "gif.png"),
                                ("ell", "second choice", "txt.png"),
                                ("qcq", "third choice", "file.png")])
    _eg = EndGroup("A sub group")
    floatarray = FloatArrayItem("Float array",
                                default=np.ones((50, 5), float),
                                format=" %.2e ").set_pos(col=1)
    mchoice3 = MultipleChoiceItem("MC type 1",
                                  [str(i) for i in range(12)]).horizontal(4)
    mchoice1 = MultipleChoiceItem(
        "MC type 2", ["first choice", "second choice", "third choice"
                      ]).vertical(1).set_pos(col=1)
示例#5
0
class Measurement(DataSet):
    """Measurement"""
    """"
       This object store the data and physical informations
       about the scanning probe measurement. It also has function to process
       the data.

       Data are stored in the data member in a numpy matrix.
       Info are stored in a DataSet parameter class derived from guidata.
    """

    rawdata = FloatArrayItem(_("Raw measured data"),
                             default=ndarray(0),
                             format=" %.2e ")
    param = ScanningParamItem(_('Scanning parameters'))

    def __init__(self,
                 rawdata=None,
                 param=None,
                 title=None,
                 comment=None,
                 icon=''):
        """\arg rawdata a numpy.ndarray
           \arg param a ScanningParam object
        """
        DataSet.__init__(self, title=title, comment=comment, icon=icon)
        if rawdata is not None:
            self.set_rawdata(rawdata)
        if param is not None:
            self.set_param(param)

    def copy(self, source):
        """Copy a the data and the parameter from a Measurement object."""
        if isinstance(source, Measurement):
            self.copy_param(source.param)
            self.copy_rawdata(source.rawdata)

    def get_rawdata(self):
        """Return the raw data measured in physical, unit according to
        parameter"""
        return self.rawdata

    def set_rawdata(self, source):
        """Set the data from a source (without copying)
        \arg source can be either a Measurement object or data.
        """
        if isinstance(source, Measurement):
            source = source.rawdata
        assert isinstance(source, ndarray), _('Wrong data type')
        self.rawdata = source

    def set_param(self, source):
        """Set the parameter (without copying) from a source.
        \arg source can be either a Measurement object or ScanningParam.
        """
        if isinstance(source, Measurement):
            source = source.param
        assert isinstance(source, ScanningParam), _('Wrong parameter type')
        self.param = source

    def copy_param(self, source):
        """Copy the parameter from a source.
        \arg source can be either a Measurement object or ScanningParam.
        """
        if isinstance(source, Measurement):
            source = source.param
        self.set_param(deepcopy(source))

    def copy_rawdata(self, source):
        """Copy the data from a source.
        \arg source can be either a Measurement object or data.
        """
        if isinstance(source, Measurement):
            source = source.rawdata
        self.set_rawdata(array(source, copy=True))

    def get_dimension(self):
        """Return the dimension of the data"""
        return len(self.rawdata.shape)

    def get_shape(self):
        return self.rawdata.shape

    def get_scale(self):
        """Return the scale as a list along the axis corresponding to the
        type of the measurement."""
        dimension = self.get_dimension()

        if 1 == dimension:
            return self.param.axis1.get_scale()
        elif 2 == dimension:
            return self.param.axis2.get_scale()
        elif 3 == dimension:
            return self.param.axis3.get_scale()

    def __add__(self, a):
        new_param = self.param.copy()
        if isinstance(a, (int, float)):
            new_param.processing += _('add %2.3g') % (a, ) + '\n'
            new_data = self.rawdata + a
        elif isinstance(a, Measurement):
            if self.rawdata.shape != a.rawdata.shape:
                raise ValueError, _('Can only add measurement with same shape')
            new_param.processing += _('%s added') % (a.param.filename, ) + '\n'
            new_data = self.rawdata + a.rawdata
        else:
            raise TypeError, _('Unsupported operand type')

        return Measurement(new_data, new_param)

    def __mul__(self, a):
        if not isinstance(a, (int, float)):
            raise TypeError, _('Unsupported operand type')
        new_param = self.param.copy()
        new_param.processing += _('scaled by %2.3g') % (a, ) + '\n'
        new_data = self.rawdata * a
        return Measurement(new_data, new_param)

    def __div__(self, a):
        if not isinstance(a, (int, float)):
            raise TypeError, _('Unsupported operand type')
        new_param = self.param.copy()
        new_param.processing += _('divided by %2.3g') % (a, ) + '\n'
        new_data = self.rawdata / a
        return Measurement(new_data, new_param)

    def __truediv__(self, a):
        if not isinstance(a, (int, float)):
            raise TypeError, _('Unsupported operand type')
        new_param = self.param.copy()
        new_param.processing += _('divided by %2.3g') % (a, ) + '\n'
        new_data = self.rawdata / a
        return Measurement(new_data, new_param)

    def __floordiv__(self, a):
        if not isinstance(a, (int, float)):
            raise TypeError, _('Unsupported operand type')
        new_param = self.param.copy()
        new_param.processing += _('divided by %2.3g') % (a, ) + '\n'
        new_data = self.rawdata // a
        return Measurement(new_data, new_param)

    def __getitem__(self, key):
        if key == 'rawdata':
            return self.get_rawdata()
        elif key == 'shape':
            return self.get_shape()
        elif key == 'scale':
            return self.get_scale()
        else:
            try:
                return getattr(self.param, key)
            except AttributeError:
                raise KeyError, _("They are no such attributes %s.") % key

    def __setitem__(self, key, value):
        if key == 'rawdata':
            self.set_rawdata(value)
        else:
            setattr(self.param, key, value)

    def __len__(self):
        if self.get_dimension() in (1, 3):
            return self.get_shape()[-1]
        else:
            x, y = self.get_shape()
            return x * y