本文整理汇总了Python中file.File.append_variable方法的典型用法代码示例。如果您正苦于以下问题:Python File.append_variable方法的具体用法?Python File.append_variable怎么用?Python File.append_variable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类file.File
的用法示例。
在下文中一共展示了File.append_variable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_netcdf_compare
# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import append_variable [as 别名]
def test_netcdf_compare(self):
# self.T = EasyTest(s, l, refdirectory=self.refdir, output_directory = output_directory)
nx = 10
ny = 20
variables = ["var1", "var2", "var3"]
f1 = tempfile.mktemp(suffix=".nc")
f2 = tempfile.mktemp(suffix=".nc")
f3 = tempfile.mktemp(suffix=".nc")
f4 = tempfile.mktemp(suffix=".nc")
F1 = File(f1, "x", "y", mode="w")
F1.create_dimension("x", nx)
F1.create_dimension("y", ny)
F2 = File(f2, "x", "y", mode="w")
F2.create_dimension("x", nx)
F2.create_dimension("y", ny)
F3 = File(f3, "x", "y", mode="w")
F3.create_dimension("x", nx)
F3.create_dimension("y", ny)
F4 = File(f4, "x", "y", mode="w")
F4.create_dimension("x", nx)
F4.create_dimension("y", ny)
cnt = 1
for k in variables:
x = np.random.random((ny, nx))
x = np.ma.array(x, mask=x != x)
F1.append_variable(k, x)
F2.append_variable(k, x) # ... two same files
y = np.random.random((ny, nx))
y = np.ma.array(y, mask=y != y)
F3.append_variable(k, y) # ... and one different
if cnt == 1:
F4.append_variable(k, x) # one file with different number of variables
cnt += 1
F1.close()
F2.close()
F3.close()
F4.close()
T = self.T
self.assertTrue(T._compare_netcdf(f1, f2, compare_variables=True, compare_values=False))
self.assertTrue(T._compare_netcdf(f1, f2, compare_variables=False, compare_values=True))
self.assertTrue(T._compare_netcdf(f1, f2, compare_variables=True, compare_values=True))
self.assertTrue(T._compare_netcdf(f1, f3, compare_variables=True, compare_values=False))
self.assertFalse(T._compare_netcdf(f1, f3, compare_variables=False, compare_values=True))
self.assertFalse(T._compare_netcdf(f1, f3, compare_variables=True, compare_values=True))
self.assertFalse(T._compare_netcdf(f1, f4, compare_variables=True, compare_values=False))