def test_simple_build(self):
     pool = field.MatlabPool(engine_count=1)
     para = simulate.Parameter()
     para.load(os.path.join(os.path.dirname(os.path.dirname(__file__)),
                            'configs', 'simple.json'))
     result = pool.parallel(simulate.SimpleWorker, task=[], args=(para,))
     self.assertTrue(result)
     self.assertEqual(result[0].shape[1], 32)
 def test_linear_array_imaging_build(self):
     pool = field.MatlabPool(engine_count=2)
     para = simulate.Parameter()
     para.load(os.path.join(os.path.dirname(os.path.dirname(__file__)),
                            'configs', 'linear_array_imaging.json'))
     task = list(range(para.line_count // 2 - 2, para.line_count // 2 + 2 + 1))
     result = pool.parallel(simulate.LinearArrayImagingWorker, task=task, args=(para,))
     self.assertTrue(isinstance(result, list))
     self.assertEqual(len(result), len(task))
    def test_matlab_pool(self):
        matlab_pool = field.MatlabPool(engine_count=2)
        for session_name in matlab_pool.session_names:
            self.assertTrue(isinstance(session_name, str))

        class FieldIIInitWorker(field.MatlabWorker):
            def run(self, *args):
                self.e.field_init()
                return self.e.session_name

        result = matlab_pool.parallel(FieldIIInitWorker, list(range(10)))
        self.assertEqual(result, matlab_pool.session_names)
Beispiel #4
0
    def simulation(para: param.Parameter):
        import field
        import simulate

        worker = getattr(simulate, para.worker + 'Worker', None)
        if worker is None:
            raise FileNotFoundError(
                "Not Found {}Worker in simulate module".format(para.worker))

        total = len(field.engine_pool.engines)
        engine_count = 1 if para.worker.endswith(
            "SyntheticAperture") else total
        pool = field.MatlabPool(engine_count=engine_count)
        task = list(range(para.line_count))

        lines = pool.parallel(worker, task=task, args=(para, ))
        with open(para.signal_path, 'wb') as f:
            for line in lines:
                f.write(np.array(line, dtype=np.float32).tobytes())
Beispiel #5
0
import sys
import field
import simulate
import numpy as np

if len(sys.argv) != 2:
    raise EnvironmentError(
        """Run this program like this:\n    python3 simu.py configs/multi_scat.json"""
    )

config_path = sys.argv[1]
if not os.path.exists(config_path):
    raise FileNotFoundError("Not Found {}".format(config_path))

para = simulate.Parameter()
para.load(config_path)

worker = getattr(simulate, para.worker + 'Worker', None)
if worker is None:
    raise FileNotFoundError("Not Found {}Worker in simulate module".format(
        para.worker))

pool = field.MatlabPool(engine_count=4)
task = list(range(para.line_count))

lines = pool.parallel(worker, task=task, args=(para, ))

with open(para.signal_path, 'wb') as f:
    for line in lines:
        f.write(np.array(line, dtype=np.float32).tobytes())