Esempio n. 1
0
 def test_full_example(self):
     with test.temp_workspace():
         shutil.copytree(test.data_item_path('spec_data'), 'spec_data')
         with open(test.data_item_path('spec.yml')) as sf:
             spec = yaml.safe_load(sf)
         gen.make_layout(spec['datasets'], spec['pages'], spec['equations'])
         tp.export.save_png('test.png')
         self.assertTrue(exists('test.png'))
Esempio n. 2
0
 def test_generate(self):
     ''' Make sure generate command works '''
     with test.temp_workspace():
         shutil.copytree(test.data_item_path('spec_data'), 'spec_data')
         main([
             'generate', '--layout_file=layout.lay',
             test.data_item_path('spec.yml')
         ])
         self.assertTrue(exists('layout.lay'))
Esempio n. 3
0
 def test_basic_function(self):
     with test.temp_workspace():
         tec_util.interpolate_dataset(
             test.data_item_path("interp_src.dat"),
             test.data_item_path("interp_tgt.dat"),
             "interp_out.plt",
         )
         ds = load_and_replace("interp_out.plt")
         vrange = ds.variable("r").values(0).minmax()
         self.assertAlmostEqual(max(vrange), 6.39408e-01, delta=1e-6)
         self.assertAlmostEqual(min(vrange), 5.10930e-01, delta=1e-6)
Esempio n. 4
0
 def test_interp(self):
     ''' Make sure interp command works '''
     with test.temp_workspace():
         main([
             'interp',
             test.data_item_path('interp_src.dat'),
             test.data_item_path('interp_tgt.dat'),
         ])
         ds = load_and_replace("interp.plt")
         vrange = ds.variable("r").values(0).minmax()
         self.assertAlmostEqual(max(vrange), 6.39408e-01, delta=1e-6)
         self.assertAlmostEqual(min(vrange), 5.10930e-01, delta=1e-6)
Esempio n. 5
0
 def test_extract(self):
     with test.temp_workspace():
         ds = load_and_replace(test.data_item_path("sphere.dat"))
         self.assertEqual(ds.num_variables, 3)
         self.assertEqual(ds.num_zones, 6)
         tec_util.extract(
             test.data_item_path("sphere.dat"),
             "extract.dat",
             var_patterns=['x', 'y'],
             zone_patterns=['*:[246]'],
         )
         ds = load_and_replace("extract.dat")
         self.assertEqual(ds.num_variables, 2)
         self.assertEqual(ds.num_zones, 3)
Esempio n. 6
0
 def test_variable_filter(self):
     ''' Test that we can select variables for differencing '''
     # Compute delta on just z; keep x as grid variable
     with test.temp_workspace():
         tec_util.difference_datasets(
             test.data_item_path("cube.dat"),
             test.data_item_path("cube.dat"),
             "diff.dat",
             nskip=1,
             var_patterns="z",
         )
         ds = load_and_replace("diff.dat")
         self.assertEqual(ds.num_variables, 2)
         self.assertEqual(ds.variable(0).name, "x")
         self.assertEqual(ds.variable(1).name, "delta_z")
Esempio n. 7
0
 def test_revolve(self):
     ''' Make sure revolve command works '''
     with test.temp_workspace():
         main([
             'revolve',
             test.data_item_path('axi_sphere_surf.plt'),
             '-o',
             'axi_sphere_rev.dat',
             '-n',
             '25',
             '-a',
             '90.0',
             '-r',
             'v1',
             '-v',
             'v2:v2y,v2z',
             '-v',
             'q2',
         ]),
         ds = load_and_replace('axi_sphere_rev.dat')
         vs = [v.name for v in ds.variables()]
         self.assertEqual(vs, [
             'x',
             'y',
             'q1',
             'q2',
             'q2_cos',
             'q2_sin',
             'v1',
             'z',
             'v2',
             'v2y',
             'v2z',
         ])
         self.assertEqual(ds.zone(0).dimensions, (11, 25, 1))
Esempio n. 8
0
 def test_zone_filter(self):
     ''' Test that we can select zones for differencing '''
     # Compute delta on just the even zones
     with test.temp_workspace():
         tec_util.difference_datasets(
             test.data_item_path("cube.dat"),
             test.data_item_path("cube.dat"),
             "diff.dat",
             nskip=1,
             zone_patterns="*:[246]",
         )
         ds = load_and_replace("diff.dat")
         self.assertEqual(ds.num_zones, 3)
         self.assertTrue(ds.zone(0).name.endswith(":2"))
         self.assertTrue(ds.zone(1).name.endswith(":4"))
         self.assertTrue(ds.zone(2).name.endswith(":6"))
Esempio n. 9
0
    def test_vector_vars(self):
        ''' Verify we can specify variable to treat as vector quantities '''
        with test.temp_workspace():
            tec_util.revolve_dataset(
                test.data_item_path("axi_sphere.plt"),
                "sphere.plt",
                planes=13,
                angle=90.0,
                vector_vars=['v1', 'v2'],
            )
            ds = load_and_replace("sphere.plt")
            vars = [v.name for v in ds.variables()]
            self.assertEqual(vars, [
                'x', 'y', 'z', 'q1', 'q2', 'v1', 'v1_cos', 'v1_sin', 'v2',
                'v2_cos', 'v2_sin'
            ])
            z0 = ds.zone(0)
            self.assertEqual(
                z0.values('v1').minmax(),
                z0.values('v1_cos').minmax())
            self.assertEqual(
                z0.values('v1').minmax(),
                z0.values('v1_sin').minmax())

            tec_util.revolve_dataset(
                test.data_item_path("axi_sphere.plt"),
                "sphere.plt",
                planes=13,
                angle=90.0,
                vector_vars={
                    'v1': ('v1y', 'v1z'),
                    'v2': ('v2y', 'v2z'),
                },
            )
            ds = load_and_replace("sphere.plt")
            vars = [v.name for v in ds.variables()]
            self.assertEqual(vars, [
                'x', 'y', 'z', 'q1', 'q2', 'v1', 'v1y', 'v1z', 'v2', 'v2y',
                'v2z'
            ])
            z0 = ds.zone(0)
            self.assertEqual(
                z0.values('v1').minmax(),
                z0.values('v1y').minmax())
            self.assertEqual(
                z0.values('v1').minmax(),
                z0.values('v1z').minmax())
Esempio n. 10
0
 def test_extract(self):
     ''' Make sure extract command works '''
     with test.temp_workspace():
         main([
             'extract', '--variables=x,y', '--zones="*:[1-4]"',
             test.data_item_path('sphere.dat')
         ])
         ds = load_and_replace("extract.plt")
         self.assertEqual(ds.num_variables, 2)
         self.assertEqual(ds.num_zones, 4)
Esempio n. 11
0
    def test_revolve_quotes(self):
        ''' Make sure we can read arguments in quoted strings '''
        with test.temp_workspace():

            # Support various kinds of quoting
            main([
                'revolve',
                test.data_item_path('axi_sphere_surf.plt'),
                '-o', 'axi_sphere_rev.dat',
                '-n', '25',
                '-a', '90.0',
                '-r', 'v1',
                '-v', '"v2":\'v2y\',v2z',
                '-v', 'q2',
            ]),
            ds = load_and_replace('axi_sphere_rev.dat')
            vs = [v.name for v in ds.variables()]
            self.assertEqual(vs,[
                'x', 'y', 'q1',
                'q2', 'q2_cos', 'q2_sin',
                'v1', 'z',
                'v2', 'v2y', 'v2z',
            ])

            # Support quoting the full argument
            main([
                'revolve',
                test.data_item_path('axi_sphere_surf.plt'),
                '-o', 'axi_sphere_rev.dat',
                '-n', '25',
                '-a', '90.0',
                '-r', 'v1',
                '-v', '"v2:v2y,v2z"',
                '-v', 'q2',
            ]),
            ds = load_and_replace('axi_sphere_rev.dat')
            vs = [v.name for v in ds.variables()]
            self.assertEqual(vs,[
                'x', 'y', 'q1',
                'q2', 'q2_cos', 'q2_sin',
                'v1', 'z',
                'v2', 'v2y', 'v2z',
            ])
Esempio n. 12
0
 def test_basic_rename(self):
     ''' Test that we can rename specific zones in the dataset '''
     with test.temp_workspace():
         tec_util.rename_zones(test.data_item_path("cube.dat"), "cube.dat",
                               {
                                   'cube.x:1': 'front',
                                   'cube.x:6': 'bottom',
                               })
         ds = load_and_replace("cube.dat")
         self.assertEqual(ds.zone(0).name, "front")
         self.assertEqual(ds.zone(5).name, "bottom")
Esempio n. 13
0
 def test_basic_rename(self):
     ''' Test that we can rename specific variable in the dataset '''
     with test.temp_workspace():
         tec_util.rename_variables(test.data_item_path("cube.dat"),
                                   "cube.dat", {
                                       "x": "xx",
                                       "z": "zz"
                                   })
         ds = load_and_replace("cube.dat")
         self.assertEqual(ds.variable(0).name, "xx")
         self.assertEqual(ds.variable(1).name, "y")
         self.assertEqual(ds.variable(2).name, "zz")
Esempio n. 14
0
    def test_basic_generators(self):
        with test.temp_workspace():
            tp.new_layout()
            tp.data.load_tecplot([
                test.data_item_path('spec_data/ds1.dat'),
                test.data_item_path('spec_data/ds2.dat'),
            ])
            default_page = tp.active_page()
            page = gen.add_page()
            default_frame = page.active_frame()
            frame = gen.add_frame(
                position=[2., 1.],
                width=7,
                height=5,
            )
            plot = frame.plot(tpc.PlotType.XYLine)
            plot.activate()
            plot.delete_linemaps()
            gen.add_xylinemap(
                name='T (ds1)',
                zone='stag[0]',
                x_variable='x',
                y_variable='T',
            )
            gen.add_xylinemap(
                name='T (ds2)',
                zone='stag[1]',
                x_variable='x',
                y_variable='T',
            )
            tp.delete_page(default_page)
            page.delete_frame(default_frame)
            tp.save_layout('test.lay')

            # Note: we can't really test for much more than simple success
            # creating the layout file. The fine details of the layout will
            # depend on whether the user has a tecplot.cfg file available
            # and we can't force factory settings in PyTecplot at this time.
            # Therefore, trying to establish a "reference output" is
            self.assertTrue(exists('test.lay'))
Esempio n. 15
0
    def test_nskip(self):
        ''' Check behavior of the nskip option '''
        # default nskip: no variables should be diff'd
        with test.temp_workspace():
            tec_util.difference_datasets(
                test.data_item_path("cube.dat"),
                test.data_item_path("cube.dat"),
                "diff.dat",
            )
            ds = load_and_replace("diff.dat")
            self.assertEqual(
                [v.name for v in ds.variables()],
                ["x", "y", "z"],
            )
            for v in ds.variables():
                zone_maxima = [v.values(i).max() for i in range(v.num_zones)]
                self.assertAlmostEqual(max(zone_maxima), 0.5, delta=1e-6)

        # nskip = 1: two variables should be diff'd
        with test.temp_workspace():
            tec_util.difference_datasets(
                test.data_item_path("sphere.dat"),
                test.data_item_path("sphere.dat"),
                "diff.dat",
                nskip=1,
            )
            ds = load_and_replace("diff.dat")
            max_vals = {
                "x": 1.00,
                "delta_y": 0.00,
                "delta_z": 0.00,
            }
            for v in ds.variables():
                zone_maxima = [v.values(i).max() for i in range(v.num_zones)]
                self.assertAlmostEqual(max(zone_maxima),
                                       max_vals[v.name],
                                       delta=1e-6)
Esempio n. 16
0
    def test_radial_coord(self):
        ''' Verify ability to select the radial coordinate '''
        with test.temp_workspace():
            tec_util.revolve_dataset(
                test.data_item_path("axi_sphere.plt"),
                "sphere.plt",
                radial_coord='v2',
                planes=13,
                angle=90.0,
            )
            ds = load_and_replace("sphere.plt")
            vars = [v.name for v in ds.variables()]
            self.assertEqual(vars, ['x', 'y', 'q1', 'q2', 'v1', 'v2', 'z'])
            self.assertEqual(
                ds.zone(0).values('v2').minmax(),
                ds.zone(0).values('z').minmax(),
            )

            tec_util.revolve_dataset(
                test.data_item_path("axi_sphere.plt"),
                "sphere.plt",
                radial_coord={'v2': ('ry', 'rz')},
                planes=13,
                angle=90.0,
            )
            ds = load_and_replace("sphere.plt")
            vars = [v.name for v in ds.variables()]
            self.assertEqual(vars,
                             ['x', 'y', 'q1', 'q2', 'v1', 'v2', 'ry', 'rz'])
            self.assertEqual(
                ds.zone(0).values('v2').minmax(),
                ds.zone(0).values('ry').minmax(),
            )
            self.assertEqual(
                ds.zone(0).values('v2').minmax(),
                ds.zone(0).values('rz').minmax(),
            )
Esempio n. 17
0
 def test_basic_useage(self):
     ''' Test that we can revolve a dataset and get the correct file out '''
     with test.temp_workspace():
         tec_util.revolve_dataset(
             test.data_item_path("axi_sphere.plt"),
             "sphere.plt",
             planes=13,
             angle=90.0,
         )
         ds = load_and_replace("sphere.plt")
         vars = [v.name for v in ds.variables()]
         self.assertEqual(vars, ['x', 'y', 'z', 'q1', 'q2', 'v1', 'v2'])
         self.assertEqual(ds.zone(0).dimensions, (11, 9, 13))
         self.assertEqual(
             ds.zone(0).values('y').minmax(),
             ds.zone(0).values('z').minmax())
Esempio n. 18
0
 def test_surface_grid(self):
     ''' Verify we can create a surface by revoling a 1D generatrix '''
     with test.temp_workspace():
         tec_util.revolve_dataset(
             test.data_item_path("axi_sphere_surf.plt"),
             "sphere.plt",
             planes=13,
             angle=90.0,
         )
         ds = load_and_replace("sphere.plt")
         vars = [v.name for v in ds.variables()]
         self.assertEqual(vars, ['x', 'y', 'z', 'q1', 'q2', 'v1', 'v2'])
         self.assertEqual(ds.zone(0).dimensions, (11, 13, 1))
         self.assertEqual(
             ds.zone(0).values('y').minmax(),
             ds.zone(0).values('z').minmax())
Esempio n. 19
0
 def test_export_yaml(self):
     ''' Test export command with YAML input file '''
     with test.temp_workspace():
         shutil.copytree(test.data_item_path('spec_data'), 'spec_data')
         main(['export', test.data_item_path('spec.yml')])
         self.assertTrue(exists('combo_plot.png'))