Пример #1
0
 def _side_effect(self, *args):
     self.assertEqual(int(args[0]), self.ndata)
     self.assertEqual(ffi.string(args[1]), b"xdata")
     self.assertEqual(args[2],
                      ffi.cast("double*", self.curve.data[0].ctypes.data))
     self.assertEqual(ffi.string(args[3]), b"ydata")
     self.assertEqual(args[4],
                      ffi.cast("double*", self.curve.data[1].ctypes.data))
     self.assertEqual(ffi.string(args[5]), b"description")
     self.assertEqual(ffi.string(args[6]), self.description.encode('utf-8'))
     self.assertEqual(ffi.string(args[7]), b"type")
     self.assertEqual(int(args[8]), self.curve.meta['type'])
     self.assertEqual(ffi.string(args[9]), b"point_type")
     self.assertEqual(int(args[10]), self.curve.meta['point_type'])
     self.assertEqual(ffi.string(args[11]), b"line_style")
     self.assertEqual(int(args[12]), self.curve.meta['line_style'])
     self.assertEqual(ffi.string(args[13]), b"point_size")
     self.assertEqual(int(args[14]), self.curve.meta['point_size'])
     self.assertEqual(ffi.string(args[15]), b"line_size")
     self.assertEqual(int(args[16]), self.curve.meta['line_size'])
     self.assertEqual(ffi.string(args[17]), b"color.red")
     self.assertAlmostEqual(float(args[18]), self.curve.meta['color.red'])
     self.assertEqual(ffi.string(args[19]), b"color.green")
     self.assertAlmostEqual(float(args[20]), self.curve.meta['color.green'])
     self.assertEqual(ffi.string(args[21]), b"color.blue")
     self.assertAlmostEqual(float(args[22]), self.curve.meta['color.blue'])
     self.assertEqual(args[-1], ffi.NULL)
     return self.gwycurve
Пример #2
0
    def _returned_value_side_effect(self, *args):
        """
        Write self.xdata and self.ydata as C arrays to 'xdata' and 'ydata'
        and return True
        """
        # combine fields names and fields pointers in one dictionary
        arg_keys = [ffi.string(key).decode('utf-8') for key in args[2:-1:2]]
        arg_pointers = [pointer for pointer in args[3:-1:2]]
        arg_dict = dict(zip(arg_keys, arg_pointers))

        arg_dict['xdata'][0] = ffi.cast("double*", self.xdata.ctypes.data)
        arg_dict['ydata'][0] = ffi.cast("double*", self.ydata.ctypes.data)

        # C func returns true if the graphcurvemodel object loock acceptable
        truep = ffi.new("bool*", True)
        return truep[0]
Пример #3
0
def new_gwyitem_double(item_key, value):
    """ Create a new double GWY file item

    Args:
        item_key (string): GWY file item name
        value (double): item value

    Returns:
        gwyitem (<cdata GwyfileItem*>): new GWY file item
    """
    cfunc = lib.gwyfile_item_new_double
    cvalue = ffi.cast("double", value)
    gwyitem = _new_gwyitem(cfunc, item_key, cvalue)
    return gwyitem
Пример #4
0
def new_gwyitem_int32(item_key, value):
    """ Create a new 32bit integer GWY file item

    Args:
        item_key (string): GWY file item name
        value (int): item value

    Returns:
        gwyitem (<cdata GwyfileItem*>): new GWY file item
    """
    cfunc = lib.gwyfile_item_new_int32
    cvalue = ffi.cast("int32_t", value)
    gwyitem = _new_gwyitem(cfunc, item_key, cvalue)
    return gwyitem
Пример #5
0
def new_gwyitem_bool(item_key, value):
    """ Create a new boolean GWY file item

    Args:
        item_key (string): GWY file item name
        value (boolean): GWY file item value

    Returns:
        gwyitem (<cdata GwyfileItem*>): new GWY file item
    """
    cvalue = ffi.cast("bool", value)
    cfunc = lib.gwyfile_item_new_bool
    gwyitem = _new_gwyitem(cfunc, item_key, cvalue)
    return gwyitem
Пример #6
0
    def to_gwy(self):
        """Get C representation of GwyDataField instance

        Returns:
            gwydatafield (<cdata GwyfileObject*>):
                A new GWY file GwyDataField object

        """
        args = []

        xres, yres = self.data.shape
        xres = ffi.cast("int32_t", xres)
        yres = ffi.cast("int32_t", yres)
        args.append(xres)
        args.append(yres)

        xreal = self.meta['xreal']
        yreal = self.meta['yreal']
        xreal = ffi.cast("double", xreal)
        yreal = ffi.cast("double", yreal)
        args.append(xreal)
        args.append(yreal)

        args.append(ffi.new("char[]", b"data(copy)"))
        datap = ffi.cast("double*", self.data.ctypes.data)
        args.append(datap)

        if self.meta['xoff'] is not None:
            args.append(ffi.new("char[]", b"xoff"))
            args.append(ffi.cast("double", self.meta['xoff']))

        if self.meta['yoff'] is not None:
            args.append(ffi.new("char[]", b"yoff"))
            args.append(ffi.cast("double", self.meta['yoff']))

        if self.meta['si_unit_xy'] is not None:
            args.append(ffi.new("char[]", b"si_unit_xy"))
            args.append(
                ffi.new("char[]", self.meta['si_unit_xy'].encode('utf-8')))

        if self.meta['si_unit_z'] is not None:
            args.append(ffi.new("char[]", b"si_unit_z"))
            args.append(
                ffi.new("char[]", self.meta['si_unit_z'].encode('utf-8')))

        args.append(ffi.NULL)

        gwydatafield = lib.gwyfile_object_new_datafield(*args)
        return gwydatafield
 def _side_effect(self, *args):
     self.assertEqual(int(args[0]), self.gwydatafield.meta['xres'])
     self.assertEqual(int(args[1]), self.gwydatafield.meta['yres'])
     self.assertEqual(float(args[2]), self.gwydatafield.meta['xreal'])
     self.assertEqual(float(args[3]), self.gwydatafield.meta['yreal'])
     self.assertEqual(ffi.string(args[4]), b'data(copy)')
     self.assertEqual(
         args[5], ffi.cast("double*", self.gwydatafield.data.ctypes.data))
     self.assertEqual(ffi.string(args[6]), b"xoff")
     self.assertEqual(float(args[7]), self.gwydatafield.meta['xoff'])
     self.assertEqual(ffi.string(args[8]), b"yoff")
     self.assertEqual(float(args[9]), self.gwydatafield.meta['yoff'])
     self.assertEqual(ffi.string(args[10]), b"si_unit_xy")
     self.assertEqual(ffi.string(args[11]),
                      self.gwydatafield.meta['si_unit_xy'].encode('utf-8'))
     self.assertEqual(ffi.string(args[12]), b"si_unit_z")
     self.assertEqual(ffi.string(args[13]),
                      self.gwydatafield.meta['si_unit_z'].encode('utf-8'))
     self.assertEqual(args[-1], ffi.NULL)
     return self.expected_return
    def _side_effect(self, *args):

        # first arg is GwyDatafield object from Libgwyfile
        self.assertEqual(args[0], self.cgwydf)

        # second arg is GwyfileError**
        assert ffi.typeof(args[1]) == ffi.typeof(self.errorp)

        # last arg in NULL
        self.assertEqual(args[-1], ffi.NULL)

        # create dict from names and types of pointers in args
        arg_keys = [ffi.string(key).decode('utf-8') for key in args[2:-1:2]]
        arg_pointers = [pointer for pointer in args[3:-1:2]]
        arg_dict = dict(zip(arg_keys, arg_pointers))

        datap = arg_dict['data']
        datap[0] = ffi.cast("double*", self.data.ctypes.data)

        return self.truep[0]
 def setUp(self):
     self.point_pairs = [((0., 0.), (1., 1.)), ((2., 2.), (3., 3.))]
     self.cdata = ffi.cast(
         "double*", ffi.new("double[]", [0., 0., 1., 1., 2., 2., 3., 3.]))
     self.ellipsesel = GwyEllipseSelection(point_pairs=self.point_pairs)
 def setUp(self):
     self.points = [(0., 0.), (1., 1.)]
     self.cdata = ffi.cast("double*", ffi.new("double[]", [0., 0., 1., 1.]))
     self.pointersel = GwyPointerSelection(points=self.points)
Пример #11
0
    def to_gwy(self):
        """ Create a new GWY file GwyGraphModel object."""
        args = []

        gwycurves = ffi.new('GwyfileObject*[]',
                            [curve.to_gwy() for curve in self.curves])
        ncurves = ffi.cast("int32_t", len(self.curves))
        args.append(ncurves)

        args.append(ffi.new("char[]", b"curves"))
        args.append(gwycurves)

        if self.meta['title'] is not None:
            args.append(ffi.new("char[]", b"title"))
            args.append(ffi.new("char[]", self.meta['title'].encode('utf-8')))

        if self.meta['top_label'] is not None:
            args.append(ffi.new("char[]", b'top_label'))
            args.append(
                ffi.new("char[]", self.meta['top_label'].encode('utf-8')))

        if self.meta['left_label'] is not None:
            args.append(ffi.new("char[]", b'left_label'))
            args.append(
                ffi.new("char[]", self.meta['left_label'].encode('utf-8')))

        if self.meta['right_label'] is not None:
            args.append(ffi.new("char[]", b'right_label'))
            args.append(
                ffi.new("char[]", self.meta['right_label'].encode('utf-8')))

        if self.meta['bottom_label'] is not None:
            args.append(ffi.new("char[]", b'bottom_label'))
            args.append(
                ffi.new("char[]", self.meta['bottom_label'].encode('utf-8')))

        if self.meta['x_unit'] is not None:
            args.append(ffi.new("char[]", b'x_unit'))
            args.append(ffi.new("char[]", self.meta['x_unit'].encode('utf-8')))

        if self.meta['y_unit'] is not None:
            args.append(ffi.new("char[]", b'y_unit'))
            args.append(ffi.new("char[]", self.meta['y_unit'].encode('utf-8')))

        if self.meta['x_min'] is not None:
            args.append(ffi.new("char[]", b'x_min'))
            args.append(ffi.cast("double", self.meta['x_min']))

        if self.meta['x_min_set'] is not None:
            args.append(ffi.new("char[]", b'x_min_set'))
            args.append(ffi.cast("bool", self.meta['x_min_set']))

        if self.meta['x_max'] is not None:
            args.append(ffi.new("char[]", b'x_max'))
            args.append(ffi.cast("double", self.meta['x_max']))

        if self.meta['x_max_set'] is not None:
            args.append(ffi.new("char[]", b'x_max_set'))
            args.append(ffi.cast("bool", self.meta['x_max_set']))

        if self.meta['x_is_logarithmic'] is not None:
            args.append(ffi.new("char[]", b'x_is_logarithmic'))
            args.append(ffi.cast("bool", self.meta['x_is_logarithmic']))

        if self.meta['y_is_logarithmic'] is not None:
            args.append(ffi.new("char[]", b'y_is_logarithmic'))
            args.append(ffi.cast("bool", self.meta['y_is_logarithmic']))

        if self.meta['label.visible'] is not None:
            args.append(ffi.new("char[]", b'label.visible'))
            args.append(ffi.cast("bool", self.meta['label.visible']))

        if self.meta['label.has_frame'] is not None:
            args.append(ffi.new("char[]", b'label.has_frame'))
            args.append(ffi.cast("bool", self.meta['label.has_frame']))

        if self.meta['label.reverse'] is not None:
            args.append(ffi.new("char[]", b'label.reverse'))
            args.append(ffi.cast("bool", self.meta['label.reverse']))

        if self.meta['label.frame_thickness'] is not None:
            args.append(ffi.new("char[]", b'label.frame_thickness'))
            args.append(ffi.cast("int32_t",
                                 self.meta['label.frame_thickness']))

        if self.meta['label.position'] is not None:
            args.append(ffi.new("char[]", b'label.position'))
            args.append(ffi.cast("int32_t", self.meta['label.position']))

        if self.meta['grid-type'] is not None:
            args.append(ffi.new("char[]", b'grid-type'))
            args.append(ffi.cast("int32_t", self.meta['grid-type']))

        args.append(ffi.NULL)
        gwygraphmodel = lib.gwyfile_object_new_graphmodel(*args)

        # gwygraphmodel object keeps alive gwycurves objects
        _graph_curves_dict[gwygraphmodel] = gwycurves

        return gwygraphmodel
Пример #12
0
    def to_gwy(self):
        """ Get a new GWY file GwyGraphCurveModel object

        Returns:
            <GwyfileObject*>: GwyGraphCurveModel object

        """
        args = []

        ndata = ffi.cast("int32_t", self.meta['ndata'])
        args.append(ndata)

        xdata = self.data[0]
        xdatap = ffi.cast("double*", xdata.ctypes.data)
        args.append(ffi.new("char[]", b"xdata"))
        args.append(xdatap)

        ydata = self.data[1]
        ydatap = ffi.cast("double*", ydata.ctypes.data)
        args.append(ffi.new("char[]", b"ydata"))
        args.append(ydatap)

        if self.meta['description'] is not None:
            args.append(ffi.new("char[]", b'description'))
            args.append(
                ffi.new("char[]", self.meta['description'].encode('utf-8')))

        if self.meta['type'] is not None:
            args.append(ffi.new("char[]", b'type'))
            args.append(ffi.cast("int32_t", self.meta['type']))

        if self.meta['point_type'] is not None:
            args.append(ffi.new("char[]", b'point_type'))
            args.append(ffi.cast("int32_t", self.meta['point_type']))

        if self.meta['line_style'] is not None:
            args.append(ffi.new("char[]", b'line_style'))
            args.append(ffi.cast("int32_t", self.meta['line_style']))

        if self.meta['point_size'] is not None:
            args.append(ffi.new("char[]", b'point_size'))
            args.append(ffi.cast("int32_t", self.meta['point_size']))

        if self.meta['line_size'] is not None:
            args.append(ffi.new("char[]", b'line_size'))
            args.append(ffi.cast("int32_t", self.meta['line_size']))

        if self.meta['color.red'] is not None:
            args.append(ffi.new("char[]", b'color.red'))
            args.append(ffi.cast("double", self.meta['color.red']))

        if self.meta['color.green'] is not None:
            args.append(ffi.new("char[]", b'color.green'))
            args.append(ffi.cast("double", self.meta['color.green']))

        if self.meta['color.blue'] is not None:
            args.append(ffi.new("char[]", b'color.blue'))
            args.append(ffi.cast("double", self.meta['color.blue']))

        args.append(ffi.NULL)

        gwycurve = lib.gwyfile_object_new_graphcurvemodel(*args)
        return gwycurve