本文整理汇总了Python中anuga.file.netcdf.NetCDFFile.close方法的典型用法代码示例。如果您正苦于以下问题:Python NetCDFFile.close方法的具体用法?Python NetCDFFile.close怎么用?Python NetCDFFile.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anuga.file.netcdf.NetCDFFile
的用法示例。
在下文中一共展示了NetCDFFile.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import close [as 别名]
def __init__(self, *args, **kwargs):
Visualiser.__init__(self, *args, **kwargs)
fin = NetCDFFile(self.vis_source, 'r')
self.xPoints = array(fin.variables['x'], Float)
self.yPoints = array(fin.variables['y'], Float)
self.quantityCache = {}
fin.close()
示例2: test_ferret2sww_nz_origin
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import close [as 别名]
def test_ferret2sww_nz_origin(self):
from anuga.coordinate_transforms.redfearn import redfearn
#Call conversion (with nonzero origin)
ferret2sww(self.test_MOST_file, verbose=self.verbose,
origin = (56, 100000, 200000))
#Work out the UTM coordinates for first point
zone, e, n = redfearn(-34.5, 150.66667)
#Read output file 'small.sww'
#fid = NetCDFFile('small.sww', netcdf_mode_r)
fid = NetCDFFile(self.test_MOST_file + '.sww')
x = fid.variables['x'][:]
y = fid.variables['y'][:]
#Check that first coordinate is correctly represented
assert num.allclose(x[0], e-100000)
assert num.allclose(y[0], n-200000)
fid.close()
#Cleanup
os.remove(self.test_MOST_file + '.sww')
示例3: test_ferret2sww_lat_longII
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import close [as 别名]
def test_ferret2sww_lat_longII(self):
# Test that min lat long works
#The test file has
# LON = 150.66667, 150.83334, 151, 151.16667
# LAT = -34.5, -34.33333, -34.16667, -34 ;
#Read
from anuga.coordinate_transforms.redfearn import redfearn
fid = NetCDFFile(self.test_MOST_file + '_ha.nc')
first_value = fid.variables['HA'][:][0,0,0]
fourth_value = fid.variables['HA'][:][0,0,3]
fid.close()
#Call conversion (with zero origin)
#ferret2sww('small', verbose=self.verbose,
# origin = (56, 0, 0))
try:
ferret2sww(self.test_MOST_file, verbose=self.verbose,
origin = (56, 0, 0), minlat=-34.5, maxlat=-35)
except AssertionError:
pass
else:
self.assertTrue(0 ==1, 'Bad input did not throw exception error!')
示例4: test_sww_header
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import close [as 别名]
def test_sww_header(self):
"""Test that constant sww information can be written correctly
(non smooth)
"""
self.domain.set_name('datatest' + str(id(self)))
self.domain.format = 'sww' #Remove??
self.domain.smooth = False
sww = SWW_file(self.domain)
sww.store_connectivity()
# Check contents
# Get NetCDF
fid = NetCDFFile(sww.filename, netcdf_mode_r) # Open existing file for append
# Get the variables
sww_revision = fid.revision_number
try:
revision_number = get_revision_number()
except:
revision_number = None
assert str(revision_number) == sww_revision
fid.close()
#print "sww.filename", sww.filename
os.remove(sww.filename)
示例5: __init__
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import close [as 别名]
def __init__(self, source, frameDelay=100, frameStep=1):
"""The source parameter is assumed to be a NetCDF sww file.
The frameDelay parameter is the number of milliseconds waited between frames.
"""
Visualiser.__init__(self, source)
self.frameNumber = 0
fin = NetCDFFile(self.source, 'r')
self.maxFrameNumber = fin.variables['time'].shape[0] - 1
fin.close()
#self.frameNumberTkVariable = StringVar()
#self.frameNumberTkVariable.set('Frame - %05g'%self.framNumber)
self.frameDelay = frameDelay
self.xmin = None
self.xmax = None
self.ymin = None
self.ymax = None
self.zmin = None
self.zmax = None
self.frameStep= frameStep
self.vtk_heightQuantityCache = []
for i in range(self.maxFrameNumber + 1): # maxFrameNumber is zero indexed.
self.vtk_heightQuantityCache.append({})
self.paused = False
self.movie = False
示例6: test_sww_constant
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import close [as 别名]
def test_sww_constant(self):
"""Test that constant sww information can be written correctly
(non smooth)
"""
self.domain.set_name('datatest' + str(id(self)))
self.domain.format = 'sww' #Remove??
self.domain.smooth = False
sww = SWW_file(self.domain)
sww.store_connectivity()
fid = NetCDFFile(sww.filename, netcdf_mode_r) # Open existing file for append
# Get the variables
x = fid.variables['x']
y = fid.variables['y']
z = fid.variables['elevation']
V = fid.variables['volumes']
assert num.allclose (x[:], self.X.flatten())
assert num.allclose (y[:], self.Y.flatten())
assert num.allclose (z[:], self.F.flatten())
P = len(self.domain)
for k in range(P):
assert V[k, 0] == 3*k
assert V[k, 1] == 3*k+1
assert V[k, 2] == 3*k+2
fid.close()
os.remove(sww.filename)
示例7: test_triangulation_points_georeference
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import close [as 别名]
def test_triangulation_points_georeference(self):
#
#
filename = tempfile.mktemp("_data_manager.sww")
outfile = NetCDFFile(filename, netcdf_mode_w)
points_utm = num.array([[0.,0.],[1.,1.], [0.,1.]])
volumes = [[0,1,2]]
elevation = [0,1,2]
new_origin = None
points_georeference = Geo_reference(56, 1, 554354)
points_utm = points_georeference.change_points_geo_ref(points_utm)
times = [0, 10]
number_of_volumes = len(volumes)
number_of_points = len(points_utm)
sww = Write_sww(['elevation'], ['stage', 'xmomentum', 'ymomentum'])
sww.store_header(outfile, times, number_of_volumes,
number_of_points, description='fully sick testing',
verbose=self.verbose,sww_precision=netcdf_float)
sww.store_triangulation(outfile, points_utm, volumes,
elevation, new_origin=new_origin,
points_georeference=points_georeference,
verbose=self.verbose)
outfile.close()
fid = NetCDFFile(filename)
x = fid.variables['x'][:]
y = fid.variables['y'][:]
results_georef = Geo_reference()
results_georef.read_NetCDF(fid)
assert results_georef == points_georeference
fid.close()
assert num.allclose(num.array(map(None, x,y)), points_utm)
os.remove(filename)
示例8: test_ferret2sww_2
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import close [as 别名]
def test_ferret2sww_2(self):
"""Test that georeferencing etc works when converting from
ferret format (lat/lon) to sww format (UTM)
"""
#The test file has
# LON = 150.66667, 150.83334, 151, 151.16667
# LAT = -34.5, -34.33333, -34.16667, -34 ;
# TIME = 0, 0.1, 0.6, 1.1, 1.6, 2.1 ;
#
# First value (index=0) in small_ha.nc is 0.3400644 cm,
# Fourth value (index==3) is -6.50198 cm
from anuga.coordinate_transforms.redfearn import redfearn
#fid = NetCDFFile('small_ha.nc')
fid = NetCDFFile(self.test_MOST_file + '_ha.nc')
#Pick a coordinate and a value
time_index = 1
lat_index = 0
lon_index = 2
test_value = fid.variables['HA'][:][time_index, lat_index, lon_index]
test_time = fid.variables['TIME'][:][time_index]
test_lat = fid.variables['LAT'][:][lat_index]
test_lon = fid.variables['LON'][:][lon_index]
linear_point_index = lat_index*4 + lon_index
fid.close()
#Call conversion (with zero origin)
ferret2sww(self.test_MOST_file, verbose=self.verbose,
origin = (56, 0, 0))
#Work out the UTM coordinates for test point
zone, e, n = redfearn(test_lat, test_lon)
#Read output file 'small.sww'
fid = NetCDFFile(self.test_MOST_file + '.sww')
x = fid.variables['x'][:]
y = fid.variables['y'][:]
#Check that test coordinate is correctly represented
assert num.allclose(x[linear_point_index], e)
assert num.allclose(y[linear_point_index], n)
#Check test value
stage = fid.variables['stage'][:]
assert num.allclose(stage[time_index, linear_point_index], test_value/100)
fid.close()
#Cleanup
import os
os.remove(self.test_MOST_file + '.sww')
示例9: test_boundary_timeII_1_5
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import close [as 别名]
def test_boundary_timeII_1_5(self):
"""
test_boundary_timeII(self):
Test that starttime can be set in the middle of a boundary condition
"""
boundary_starttime = 0
boundary_filename = self.create_sww_boundary(boundary_starttime)
# print "boundary_filename",boundary_filename
filename = tempfile.mktemp(".sww")
# print "filename",filename
dir, base = os.path.split(filename)
senario_name = base[:-4]
mesh = Mesh()
mesh.add_region_from_polygon([[10, 10], [90, 10], [90, 90], [10, 90]])
mesh.generate_mesh(verbose=False)
domain = pmesh_to_domain_instance(mesh, anuga.Domain)
domain.set_name(senario_name)
domain.set_datadir(dir)
domain.set_flow_algorithm("1_5")
new_starttime = 0.0
domain.set_starttime(new_starttime)
# Setup initial conditions
domain.set_quantity("elevation", 0.0)
domain.set_quantity("stage", 0.0)
Bf = anuga.File_boundary(boundary_filename, domain, use_cache=False, verbose=False)
# Setup boundary conditions
domain.set_boundary({"exterior": Bf})
for t in domain.evolve(yieldstep=5, finaltime=9.0):
pass
# print domain.boundary_statistics()
# domain.write_time()
# print "domain.time", domain.time
# do an assertion on the time of the produced sww file
fid = NetCDFFile(filename, netcdf_mode_r) # Open existing file for read
times = fid.variables["time"][:]
stage = fid.variables["stage"][:]
# print stage
# print "times", times
# print "fid.starttime", fid.starttime
assert num.allclose(fid.starttime, new_starttime)
fid.close()
# print "stage[2,0]", stage[2,0]
msg = "This test is a bit hand crafted, based on the output file. "
msg += "Not logic. "
msg += "It's testing that starttime is working"
assert num.allclose(stage[2, 0], 4.88601), msg
# clean up
os.remove(boundary_filename)
os.remove(filename)
示例10: test_georef_types
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import close [as 别名]
def test_georef_types(self):
'''Ensure that attributes of a georeference are of correct type.
zone int
false_easting int
false_northing int
xllcorner float
yllcorner float
'''
from anuga.file.netcdf import NetCDFFile
# ensure that basic instance attributes are correct
g = Geo_reference(56, 1.8, 1.8)
self.assertTrue(isinstance(g.zone, int),
"geo_ref .zone should be 'int' type, "
"was '%s' type" % type(g.zone))
self.assertTrue(isinstance(g.false_easting, int),
"geo_ref .false_easting should be int type, "
"was '%s' type" % type(g.false_easting))
self.assertTrue(isinstance(g.false_northing, int),
"geo_ref .false_northing should be int type, "
"was '%s' type" % type(g.false_northing))
self.assertTrue(isinstance(g.xllcorner, float),
"geo_ref .xllcorner should be float type, "
"was '%s' type" % type(g.xllcorner))
self.assertTrue(isinstance(g.yllcorner, float),
"geo_ref .yllcorner should be float type, "
"was '%s' type" % type(g.yllcorner))
# now write fikle, read back and check types again
file_name = tempfile.mktemp(".geo_referenceTest")
out_file = NetCDFFile(file_name, netcdf_mode_w)
g.write_NetCDF(out_file)
out_file.close()
in_file = NetCDFFile(file_name, netcdf_mode_r)
new_g = Geo_reference(NetCDFObject=in_file)
in_file.close()
os.remove(file_name)
self.assertTrue(isinstance(new_g.zone, int),
"geo_ref .zone should be 'int' type, "
"was '%s' type" % type(new_g.zone))
self.assertTrue(isinstance(new_g.false_easting, int),
"geo_ref .false_easting should be int type, "
"was '%s' type" % type(new_g.false_easting))
self.assertTrue(isinstance(new_g.false_northing, int),
"geo_ref .false_northing should be int type, "
"was '%s' type" % type(new_g.false_northing))
self.assertTrue(isinstance(new_g.xllcorner, float),
"geo_ref .xllcorner should be float type, "
"was '%s' type" % type(new_g.xllcorner))
self.assertTrue(isinstance(new_g.yllcorner, float),
"geo_ref .yllcorner should be float type, "
"was '%s' type" % type(new_g.yllcorner))
示例11: setup_grid
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import close [as 别名]
def setup_grid(self):
fin = NetCDFFile(self.source, 'r')
self.vtk_cells = vtkCellArray()
N_tri = fin.variables['volumes'].shape[0]
for v in range(N_tri):
self.vtk_cells.InsertNextCell(3)
for i in range(3):
self.vtk_cells.InsertCellPoint(fin.variables['volumes'][v][i])
fin.close()
示例12: build_quantity_dict
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import close [as 别名]
def build_quantity_dict(self):
quantities = {}
fin = NetCDFFile(self.source, 'r')
for q in filter(lambda n:n != 'x' and n != 'y' and n != 'z' and n != 'time' and n != 'volumes', fin.variables.keys()):
if len(fin.variables[q].shape) == 1: # Not a time-varying quantity
quantities[q] = num.ravel(num.array(fin.variables[q], num.float))
else: # Time-varying, get the current timestep data
quantities[q] = num.array(fin.variables[q][self.frameNumber], num.float)
fin.close()
return quantities
示例13: helper_read_msh_file
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import close [as 别名]
def helper_read_msh_file(self, filename):
fid = NetCDFFile(filename, netcdf_mode_r)
mesh = {}
# Get the 'strings' variable
strings = fid.variables['strings'][:]
fid.close()
return char_to_string(strings)
示例14: test_sww_range
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import close [as 别名]
def test_sww_range(self):
"""Test that constant sww information can be written correctly
Use non-smooth to be able to compare to quantity values.
"""
self.domain.set_name('datatest' + str(id(self)))
self.domain.format = 'sww'
self.domain.set_store_vertices_uniquely(True)
sww = SWW_file(self.domain)
dqs = self.domain.get_quantity('stage')
dqx = self.domain.get_quantity('xmomentum')
dqy = self.domain.get_quantity('ymomentum')
xmom_min = ymom_min = stage_min = sys.maxint
xmom_max = ymom_max = stage_max = -stage_min
for t in self.domain.evolve(yieldstep = 1, finaltime = 1):
wmax = max(dqs.get_values().flatten())
if wmax > stage_max: stage_max = wmax
wmin = min(dqs.get_values().flatten())
if wmin < stage_min: stage_min = wmin
uhmax = max(dqx.get_values().flatten())
if uhmax > xmom_max: xmom_max = uhmax
uhmin = min(dqx.get_values().flatten())
if uhmin < xmom_min: xmom_min = uhmin
vhmax = max(dqy.get_values().flatten())
if vhmax > ymom_max: ymom_max = vhmax
vhmin = min(dqy.get_values().flatten())
if vhmin < ymom_min: ymom_min = vhmin
# Get NetCDF
fid = NetCDFFile(sww.filename, netcdf_mode_r) # Open existing file for append
# Get the variables
range = fid.variables['stage_range'][:]
assert num.allclose(range,[stage_min, stage_max])
range = fid.variables['xmomentum_range'][:]
#print range
assert num.allclose(range, [xmom_min, xmom_max])
range = fid.variables['ymomentum_range'][:]
#print range
assert num.allclose(range, [ymom_min, ymom_max])
fid.close()
os.remove(sww.filename)
示例15: setupGrid
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import close [as 别名]
def setupGrid(self):
fin = NetCDFFile(self.vis_source, 'r')
nTri = fin.variables['volumes'].shape[0]
insertNextCell = vtkCellArray.InsertNextCell
insertCellPoint = vtkCellArray.InsertCellPoint
for v in range(nTri):
insertNextCell(self.vtk_cells, 3)
for i in range(3):
insertCellPoint(self.vtk_cells, fin.variables['volumes'][v][i])
fin.close()