Ejemplo n.º 1
0
    def test_write_mixed(self):
        print("----- ovf test writing")
        with ovf.ovf_file("testfile_py_mixed.ovf") as ovf_file:
            data = np.zeros((2, 2, 1, 3), dtype='d')
            data[0,1,0,:] = [3.0, 2.0, 1.0]
            segment = ovf.ovf_segment(
                title="python write test",
                comment="more details in this comment...",
                valuedim=3,
                n_cells=[2,2,1])
            success = ovf_file.write_segment(segment, data, fileformat=ovf.FILEFORMAT_BIN)
            if success != ovf.OK:
                print("write_segment failed: ", ovf_file.get_latest_message())
            self.assertTrue( success == ovf.OK )
            data[0,1,0,:] = [4.0, 5.0, 6.0]
            segment.title = "python append test".encode('utf-8')
            success = ovf_file.append_segment(segment, data, fileformat=ovf.FILEFORMAT_CSV)
            if success != ovf.OK:
                print("append_segment failed: ", ovf_file.get_latest_message())
            self.assertTrue( success == ovf.OK )
        print("----- ovf test writing done")

        print("----- ovf test reading")
        with ovf.ovf_file("testfile_py_mixed.ovf") as ovf_file:
            print("found:      ", ovf_file.found)
            print("is_ovf:     ", ovf_file.is_ovf)
            print("n_segments: ", ovf_file.n_segments)
            segment = ovf.ovf_segment()
            success = ovf_file.read_segment_header(0, segment)
            if success != ovf.OK:
                print("read_segment_header failed: ", ovf_file.get_latest_message())
            self.assertTrue( success == ovf.OK )
            data_shape = (segment.n_cells[0], segment.n_cells[1], segment.n_cells[2], 3)
            data = np.zeros(data_shape, dtype='f')
            print("data shape: ", data_shape)
            success = ovf_file.read_segment_data(0, segment, data)
            if success != ovf.OK:
                print("read_segment_data failed: ", ovf_file.get_latest_message())
            print("first segment:  ", data[0,1,0,:])
            self.assertTrue( success == ovf.OK )

            success = ovf_file.read_segment_header(1, segment)
            if success != ovf.OK:
                print("read_segment_header failed: ", ovf_file.get_latest_message())
            self.assertTrue( success == ovf.OK )
            data_shape = (segment.n_cells[0], segment.n_cells[1], segment.n_cells[2], 3)
            data = np.zeros(data_shape, dtype='d')
            success = ovf_file.read_segment_data(1, segment, data)
            if success != ovf.OK:
                print("read_segment_data failed: ", ovf_file.get_latest_message())
            print("second segment: ", data[0,1,0,:])
            self.assertTrue( success == ovf.OK )
        print("----- ovf test reading done")
Ejemplo n.º 2
0
    def test_write(self):
        print("----- ovf test writing")
        with ovf.ovf_file("testfile_py.ovf") as ovf_file:
            data = np.zeros((2, 2, 1, 3), dtype='d')
            data[0, 1, 0, :] = [3.0, 2.0, 1.0]
            segment = ovf.ovf_segment(n_cells=[2, 2, 1], valuedim=3)
            success = ovf_file.write_segment(segment, data)
            if success != ovf.OK:
                print("write_segment failed: ", ovf_file.get_latest_message())
            self.assertTrue(success == ovf.OK)
            data[0, 1, 0, :] = [4.0, 5.0, 6.0]
            success = ovf_file.append_segment(segment, data)
            if success != ovf.OK:
                print("append_segment failed: ", ovf_file.get_latest_message())
            self.assertTrue(success == ovf.OK)
        print("----- ovf test writing done")

        print("----- ovf test reading")
        with ovf.ovf_file("testfile_py.ovf") as ovf_file:
            print("found:      ", ovf_file.found)
            print("is_ovf:     ", ovf_file.is_ovf)
            print("n_segments: ", ovf_file.n_segments)
            segment = ovf.ovf_segment()
            success = ovf_file.read_segment_header(0, segment)
            if success != ovf.OK:
                print("read_segment_header failed: ",
                      ovf_file.get_latest_message())
            data_shape = (segment.n_cells[0], segment.n_cells[1],
                          segment.n_cells[2], 3)
            print("data shape: ", data_shape)
            self.assertTrue(success == ovf.OK)
            data = np.zeros(data_shape, dtype='f')
            success = ovf_file.read_segment_data(0, segment, data)
            if success != ovf.OK:
                print("read_segment_data failed: ",
                      ovf_file.get_latest_message())
            print("first segment:  ", data[0, 1, 0, :])
            self.assertTrue(success == ovf.OK)
            success = ovf_file.read_segment_data(1, segment, data)
            if success != ovf.OK:
                print("read_segment_data failed: ",
                      ovf_file.get_latest_message())
            print("second segment: ", data[0, 1, 0, :])
            self.assertTrue(success == ovf.OK)
        print("----- ovf test reading done")
Ejemplo n.º 3
0
 def test_nonexistent(self):
     print("----- ovf test nonexistent")
     with ovf.ovf_file("nonexistent.ovf") as ovf_file:
         print("found:      ", ovf_file.found)
         print("is_ovf:     ", ovf_file.is_ovf)
         print("n_segments: ", ovf_file.n_segments)
         segment = ovf.ovf_segment()
         success = ovf_file.read_segment_header(0, segment)
         if success != ovf.OK:
             print("read_segment_header failed: ",
                   ovf_file.get_latest_message())
         self.assertFalse(success == ovf.OK)
     print("----- ovf test nonexistent done")
Ejemplo n.º 4
0
def func2(filename, dim, show_plot):
    with ovf.ovf_file(filename) as ovf_file:
        some_segment = ovf.ovf_segment()
        n = ovf_file.n_segments
        print("the number of segments are ", n)
        #
        for i in range(n):
            ovf_file.read_segment_header(i, some_segment)
            data_shape = (some_segment.n_cells[0], some_segment.n_cells[1],
                          some_segment.n_cells[2], 3)
            #
            record_data = np.zeros(data_shape, dtype='f')
            ovf_file.read_segment_data(i, some_segment, record_data)

            #
            visualise(record_data, i, show_plot)
        return
Ejemplo n.º 5
0
    def __init__(self, parent):
        super(GLWidget, self).__init__(parent)

        # Set the size to be equal to Screen
        self.setSize(parent.size())

        # self.system_dimensions = np.array([3, 5, 4])
        # self.nx = self.system_dimensions[0]
        # self.ny = self.system_dimensions[1]
        # self.nz = self.system_dimensions[2]

        # # Create the VFR.geometry
        # n_cells = self.system_dimensions
        # self.geometry = vfr.Geometry.rectilinearGeometry(
        # range(n_cells[0]), range(n_cells[1]), range(n_cells[2]))

        # # Initialize directions
        # directions = []
        # for iz in range(n_cells[2]):
        # for iy in range(n_cells[1]):
        # for ix in range(n_cells[0]):
        # directions.append([0, 0, 0.5])
        # self.directions = np.array(directions)

        testfile = "img_out.ovf"

        with ovf.ovf_file(testfile) as ovf_file:
            print("found:      ", ovf_file.found)
            print("is_ovf:     ", ovf_file.is_ovf)
            print("n_segments: ", ovf_file.n_segments)
            segment = ovf.ovf_segment()
            success = ovf_file.read_segment_header(0, segment)

            self.system_dimensions = (segment.n_cells[0], segment.n_cells[1],
                                      segment.n_cells[2], 3)

            self.nx = segment.n_cells[0]
            self.ny = segment.n_cells[1]
            self.nz = segment.n_cells[2]
            self.nos = self.nx * self.ny * self.nz
            # Create the VFR.geometry
            n_cells = self.system_dimensions
            self.geometry = vfr.Geometry.rectilinearGeometry(
                range(n_cells[0]), range(n_cells[1]), range(n_cells[2]))

            print("data shape: ", self.system_dimensions)
            self.directions = np.zeros(self.system_dimensions, dtype='f')
            success = ovf_file.read_segment_data(0, segment, self.directions)
        print("----- ovf test reading done")

        # Create the VFR.view
        self.view = vfr.View()
        self.view.setFramebufferSize(parent.size()[0] * parent.pixelRatio(),
                                     parent.size()[1] * parent.pixelRatio())

        # Create/Init VFR.vf
        self.vf = vfr.VectorField(self.geometry,
                                  self.directions.reshape((self.nos, 3)))

        # Renderers
        self.arrows = ArrowsRenderer(self.view, self.vf)
        self.dots = DotsRenderer(self.view, self.vf)
        self.neighbors = NeighborsRenderer(self.view, self.geometry,
                                           self.system_dimensions)
        self.coordinate = CoordinateSystemRenderer(self.view)
        self.cubes = CubesRenderer(self.view, self.vf)
        self.bounding_box = BoundingBoxRenderer(self.view, self.geometry,
                                                self.system_dimensions)
        # self.streamtubes = StreamTubeRenderer(self.view, self.vf, self.system_dimensions)

        # Switch on initial renderers
        self.arrows.switch()
        self.coordinate.switch()
        self.bounding_box.switch()

        self.updateRenderers()

        # Options
        self.options = vfr.Options()
        self.options.setBackgroundColor([0.5, 0.5, 0.5])
        self.options.setColormapImplementation(
            vfr.getColormapImplementation(vfr.Colormap.hsv))
        self.options.setSystemCenter(
            (self.geometry.min() + self.geometry.max()) * 0.5)
        self.options.setCameraPosition([0, 0, 30])
        self.options.setCenterPosition(
            (self.geometry.min() + self.geometry.max()) * 0.5)
        self.options.setUpVector([0, 1, 0])
        self.view.updateOptions(self.options)

        # For mouse movement events
        self.previous_mouse_position = [0, 0]