Пример #1
0
    def test_new_expression_op(self):
        op = new_expression_op(
            OpMetaInfo('add_xy',
                       inputs={
                           'x': {
                               'data_type': float
                           },
                           'y': {
                               'data_type': float
                           },
                       },
                       outputs={'return': {
                           'data_type': float
                       }}), 'x + y')
        z = op(x=1.2, y=2.4)
        self.assertEqual(z, 1.2 + 2.4)

        op = new_expression_op(
            OpMetaInfo('add_xy', inputs={
                'x': {},
                'y': {},
            }), 'x * y')
        z = op(x=1.2, y=2.4)
        self.assertEqual(z, 1.2 * 2.4)
        self.assertIn('return', op.op_meta_info.outputs)
Пример #2
0
 def test_new_executable_op_without_ds(self):
     op = new_subprocess_op(OpMetaInfo('make_entropy',
                                       inputs={
                                           'num_steps': {'data_type': int},
                                           'period': {'data_type': float},
                                       },
                                       outputs={
                                           'return': {'data_type': int}
                                       }),
                            MAKE_ENTROPY_EXE + " {num_steps} {period}")
     exit_code = op(num_steps=5, period=0.05)
     self.assertEqual(exit_code, 0)
Пример #3
0
    def test_new_expression_op(self):
        op = new_expression_op(OpMetaInfo('add_xy',
                                          inputs={
                                              'x': {'data_type': float},
                                              'y': {'data_type': float},
                                          },
                                          outputs={
                                              'return': {'data_type': float}
                                          }),
                               'x + y')
        z = op(x=1.2, y=2.4)
        self.assertEqual(z, 1.2 + 2.4)

        op = new_expression_op(OpMetaInfo('add_xy',
                                          inputs={
                                              'x': {},
                                              'y': {},
                                          }),
                               'x * y')
        z = op(x=1.2, y=2.4)
        self.assertEqual(z, 1.2 * 2.4)
        self.assertIn('return', op.op_meta_info.outputs)
Пример #4
0
 def test_new_executable_op_with_ds_file(self):
     op = new_subprocess_op(OpMetaInfo('filter_ds',
                                       inputs={
                                           'ifile': {'data_type': FileLike},
                                           'ofile': {'data_type': FileLike},
                                           'var': {'data_type': VarName},
                                       },
                                       outputs={
                                           'return': {'data_type': int}
                                       }),
                            FILTER_DS_EXE + " {ifile} {ofile} {var}")
     ofile = os.path.join(DIR, 'test_data', 'filter_ds.nc')
     if os.path.isfile(ofile):
         os.remove(ofile)
     exit_code = op(ifile=SOILMOISTURE_NC, ofile=ofile, var='sm')
     self.assertEqual(exit_code, 0)
     self.assertTrue(os.path.isfile(ofile))
     os.remove(ofile)
Пример #5
0
 def test_new_executable_op_with_ds_in_mem(self):
     op = new_subprocess_op(
         OpMetaInfo('filter_ds',
                    inputs={
                        'ds': {
                            'data_type': xr.Dataset,
                            'write_to': 'ifile'
                        },
                        'var': {
                            'data_type': VarName
                        },
                    },
                    outputs={
                        'return': {
                            'data_type': xr.Dataset,
                            'read_from': 'ofile'
                        }
                    }), FILTER_DS_EXE + " {ifile} {ofile} {var}")
     ds = xr.open_dataset(SOILMOISTURE_NC)
     ds_out = op(ds=ds, var='sm')
     self.assertIsNotNone(ds_out)
     self.assertIsNotNone('sm' in ds_out)
Пример #6
0
 def test_new_executable_op_with_ds_in_mem(self):
     op = new_subprocess_op(OpMetaInfo('filter_ds',
                                       inputs={
                                           'ds': {
                                               'data_type': xr.Dataset,
                                               'write_to': 'ifile'
                                           },
                                           'var': {
                                               'data_type': VarName
                                           },
                                       },
                                       outputs={
                                           'return': {
                                               'data_type': xr.Dataset,
                                               'read_from': 'ofile'
                                           }
                                       }),
                            FILTER_DS_EXE + " {ifile} {ofile} {var}")
     ds = xr.open_dataset(SOILMOISTURE_NC)
     ds_out = op(ds=ds, var='sm')
     self.assertIsNotNone(ds_out)
     self.assertIsNotNone('sm' in ds_out)