Python tables.Float64Col() Examples

The following are 3 code examples of tables.Float64Col(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tables , or try the search function .
Example #1
Source File: test_simulation.py    From pyMARS with MIT License 5 votes vote down vote up
def test_clean(self):
        """Test successful cleaning up of data.
        """
        table_def = {
            'time': tables.Float64Col(pos=0),
            'temperature': tables.Float64Col(pos=1),
            'pressure': tables.Float64Col(pos=2),
            'mass_fractions': tables.Float64Col(pos=3, shape=(2))
            }
        with TemporaryDirectory() as temp_dir:
            sim = Simulation(0, None, 'gri30.cti', path=temp_dir)
            sim.save_file = os.path.join(sim.path, str(sim.idx) + '.h5')

            with tables.open_file(sim.save_file, mode='w', title='0') as h5file:

                table = h5file.create_table(where=h5file.root, name='simulation',
                                            description=table_def
                                            )
                # Row instance to save timestep information to
                timestep = table.row
                timestep['time'] = 1.0
                timestep['temperature'] = 1.0
                timestep['pressure'] = 1.0
                timestep['mass_fractions'] = np.ones(2)
                timestep.append()
                
                table.flush()
            
            sim.clean()
            assert not os.path.isfile(sim.save_file) 
Example #2
Source File: test_simulation.py    From pyMARS with MIT License 4 votes vote down vote up
def test_process_results(self):
        """Test processing of ignition results using artificial data.
        """
        table_def = {
            'time': tables.Float64Col(pos=0),
            'temperature': tables.Float64Col(pos=1),
            'pressure': tables.Float64Col(pos=2),
            'mass_fractions': tables.Float64Col(pos=3, shape=(2))
            }
        with TemporaryDirectory() as temp_dir:
            sim = Simulation(0, None, 'gri30.cti', path=temp_dir)
            
            sim.save_file = os.path.join(sim.path, str(sim.idx) + '.h5')

            time_initial = np.arange(0, 10, 0.02)
            temp_initial = 200 * np.ones(len(time_initial))

            # ignition delay (temp = 600) will be at 10.5 s
            time_ramp = np.arange(10, 11.001, 0.005)
            temp_ramp = 200 + 800 * (time_ramp - 10)

            time_flat = np.arange(11.005, 15, 0.01)
            temp_flat = 1000 * np.ones(len(time_flat))
            
            times = np.concatenate((time_initial, time_ramp, time_flat))
            temps = np.concatenate((temp_initial, temp_ramp, temp_flat))

            # add a very small number to account for floating-point roundoff error
            idx = len(temp_initial) + int((len(time_ramp) - 1) / 2)
            temps[idx] += 1e-9

            with tables.open_file(sim.save_file, mode='w', title='0') as h5file:

                table = h5file.create_table(where=h5file.root, name='simulation',
                                            description=table_def
                                            )
                # Row instance to save timestep information to
                timestep = table.row

                for time, temp in zip(times, temps):
                    timestep['time'] = time
                    timestep['temperature'] = temp
                    timestep['pressure'] = 1.0
                    timestep['mass_fractions'] = np.ones(2)
                    timestep.append()
                
                table.flush()
            
            ignition_delay, sampled_data = sim.process_results()

            assert np.allclose(ignition_delay, 10.5)

            initial_temp = 200.
            delta = 40.
            for idx in range(20):
                assert np.allclose(sampled_data[idx], [initial_temp + delta, 1, 1, 1])
                delta += 40. 
Example #3
Source File: test_simulation.py    From pyMARS with MIT License 4 votes vote down vote up
def test_process_results_skip_data(self):
        """Test processing of ignition results, skipping data sampling, using artificial data.
        """
        table_def = {
            'time': tables.Float64Col(pos=0),
            'temperature': tables.Float64Col(pos=1),
            'pressure': tables.Float64Col(pos=2),
            'mass_fractions': tables.Float64Col(pos=3, shape=(2))
            }
        with TemporaryDirectory() as temp_dir:
            sim = Simulation(0, None, 'gri30.cti', path=temp_dir)
            
            sim.save_file = os.path.join(sim.path, str(sim.idx) + '.h5')

            with tables.open_file(sim.save_file, mode='w', title='0') as h5file:

                table = h5file.create_table(where=h5file.root, name='simulation',
                                            description=table_def
                                            )
                # Row instance to save timestep information to
                timestep = table.row

                time_initial = np.arange(0, 10, 0.02)
                temp_initial = 200 * np.ones(len(time_initial))

                # ignition delay (temp = 600) will be at 10.5 s
                time_ramp = np.arange(10, 11.02, 0.02)
                temp_ramp = 200 + 800 * (time_ramp - 10)

                time_flat = np.arange(11.02, 15, 0.02)
                temp_flat = 1000 * np.ones(len(time_flat))
                
                times = np.concatenate((time_initial, time_ramp, time_flat))
                temps = np.concatenate((temp_initial, temp_ramp, temp_flat))

                # add a very small number to account for floating-point roundoff error
                idx = len(temp_initial) + 25
                temps[idx] += 1e-8

                for time, temp in zip(times, temps):
                    timestep['time'] = time
                    timestep['temperature'] = temp
                    timestep['pressure'] = 1.0
                    timestep['mass_fractions'] = np.ones(2)
                    timestep.append()
                
                table.flush()
            
            sim.process_results(skip_data=True)

            assert np.allclose(sim.ignition_delay, 10.5)
            assert not hasattr(sim, 'sampled_data')