示例#1
0
    def test_system_changing_field_name(self):
        path1 = self.get_temporary_file_path('foo1.nc')
        path2 = self.get_temporary_file_path('foo2.nc')

        vc1 = VariableCollection(name='vc1')
        var1 = Variable('var1',
                        value=[1, 2, 3],
                        dimensions='three',
                        parent=vc1)

        vc2 = VariableCollection(name='vc2')
        vc1.add_child(vc2)
        var2 = Variable('var2',
                        value=[4, 5, 6, 7],
                        dimensions='four',
                        parent=vc2)

        vc1.write(path1)

        rd = RequestDataset(path1)
        # rd.inspect()
        nvc = rd.get_variable_collection()
        nvc2 = nvc.children['vc2']
        self.assertIsNone(nvc2['var2']._value)
        self.assertEqual(nvc2.name, 'vc2')
        nvc2.set_name('extraordinary')
        self.assertIsNotNone(nvc2['var2'].get_value())
        self.assertEqual(nvc2['var2'].get_value().tolist(), [4, 5, 6, 7])

        nvc.write(path2)
        rd2 = RequestDataset(path2)
        # rd2.inspect()
        n2vc = rd2.get_variable_collection()
        self.assertEqual(n2vc.children[nvc2.name].name, nvc2.name)
示例#2
0
 def test_init(self):
     path = self.get_temporary_file_path('foo.nc')
     with self.nc_scope(path, 'w') as ds:
         ds.createDimension('a', 2)
     rd = RequestDataset(uri=path, driver='netcdf')
     self.assertIsInstance(rd.driver, DriverNetcdf)
     vc = rd.get_variable_collection()
     self.assertEqual(len(vc), 0)
示例#3
0
 def test_open(self):
     # Test with a multi-file dataset.
     path1 = self.get_temporary_file_path('foo1.nc')
     path2 = self.get_temporary_file_path('foo2.nc')
     for idx, path in enumerate([path1, path2]):
         with self.nc_scope(path, 'w', format='NETCDF4_CLASSIC') as ds:
             ds.createDimension('a', None)
             b = ds.createVariable('b', np.int32, ('a', ))
             b[:] = idx
     uri = [path1, path2]
     rd = RequestDataset(uri=uri, driver=DriverNetcdf)
     field = rd.get_variable_collection()
     self.assertEqual(field['b'].get_value().tolist(), [0, 1])
示例#4
0
    def test(self):
        path = self.get_path_to_template_csv()
        path_out = self.get_temporary_file_path('foo_out.csv')

        rd = RequestDataset(uri=path)
        vc = rd.get_variable_collection()

        for v in list(vc.values()):
            self.assertIsNotNone(v.get_value())

        field = rd.get()
        self.assertIsInstance(field, Field)

        vc.write(path_out, driver=DriverCSV)

        self.assertCSVFilesEqual(path, path_out)
示例#5
0
    def test_system_parallel_write(self):
        if MPI_RANK == 0:
            in_path = self.get_path_to_template_csv()
            out_path = self.get_temporary_file_path('foo_out.csv')
        else:
            in_path, out_path = [None] * 2

        in_path = MPI_COMM.bcast(in_path)
        out_path = MPI_COMM.bcast(out_path)

        rd = RequestDataset(in_path)
        list(rd.metadata['dimensions'].values())[0]['dist'] = True
        vc = rd.get_variable_collection()

        with vm.scoped_by_emptyable('vc.write', vc):
            if not vm.is_null:
                vc.write(out_path, driver=DriverCSV)

        if MPI_RANK == 0:
            self.assertCSVFilesEqual(in_path, out_path)