本文整理汇总了Python中anuga.file.netcdf.NetCDFFile.variables['test_array'][:]方法的典型用法代码示例。如果您正苦于以下问题:Python NetCDFFile.variables['test_array'][:]方法的具体用法?Python NetCDFFile.variables['test_array'][:]怎么用?Python NetCDFFile.variables['test_array'][:]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anuga.file.netcdf.NetCDFFile
的用法示例。
在下文中一共展示了NetCDFFile.variables['test_array'][:]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_compute_checksum
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import variables['test_array'][:] [as 别名]
def test_compute_checksum(self):
"""test_compute_checksum(self):
Check that checksums on files are OK
"""
from tempfile import mkstemp, mktemp
# Generate a text file
tmp_fd , tmp_name = mkstemp(suffix='.tmp', dir='.')
fid = os.fdopen(tmp_fd, 'w+b')
string = 'My temp file with textual content. AAAABBBBCCCC1234'
fid.write(string)
fid.close()
# Have to apply the 64 bit fix here since we aren't comparing two
# files, but rather a string and a file.
ref_crc = safe_crc(string)
checksum = compute_checksum(tmp_name)
assert checksum == ref_crc
os.remove(tmp_name)
# Binary file
tmp_fd , tmp_name = mkstemp(suffix='.tmp', dir='.')
fid = os.fdopen(tmp_fd, 'w+b')
string = 'My temp file with binary content. AAAABBBBCCCC1234'
fid.write(string)
fid.close()
ref_crc = safe_crc(string)
checksum = compute_checksum(tmp_name)
assert checksum == ref_crc
os.remove(tmp_name)
# Binary NetCDF File X 2 (use mktemp's name)
try:
from anuga.file.netcdf import NetCDFFile
except ImportError:
# This code is also used by EQRM which does not require NetCDF
pass
else:
test_array = num.array([[7.0, 3.14], [-31.333, 0.0]])
# First file
filename1 = mktemp(suffix='.nc', dir='.')
fid = NetCDFFile(filename1, netcdf_mode_w)
fid.createDimension('two', 2)
fid.createVariable('test_array', netcdf_float,
('two', 'two'))
fid.variables['test_array'][:] = test_array
fid.close()
# Second file
filename2 = mktemp(suffix='.nc', dir='.')
fid = NetCDFFile(filename2, netcdf_mode_w)
fid.createDimension('two', 2)
fid.createVariable('test_array', netcdf_float,
('two', 'two'))
fid.variables['test_array'][:] = test_array
fid.close()
checksum1 = compute_checksum(filename1)
checksum2 = compute_checksum(filename2)
assert checksum1 == checksum2
os.remove(filename1)
os.remove(filename2)