本文整理汇总了Python中anuga.file.netcdf.NetCDFFile类的典型用法代码示例。如果您正苦于以下问题:Python NetCDFFile类的具体用法?Python NetCDFFile怎么用?Python NetCDFFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NetCDFFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ferret2sww_nz_origin
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')
示例2: test_ferret2sww_lat_longII
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!')
示例3: test_sww_constant
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)
示例4: __init__
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()
示例5: test_sww_header
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)
示例6: __init__
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
示例7: test_boundary_timeII_1_5
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)
示例8: setup_grid
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()
示例9: build_quantity_dict
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
示例10: helper_read_msh_file
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)
示例11: test_sww_range
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)
示例12: setupGrid
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()
示例13: test_sww_variable2
def test_sww_variable2(self):
"""Test that sww information can be written correctly
multiple timesteps. Use average as reduction operator
"""
import time, os
self.domain.set_name('datatest' + str(id(self)))
self.domain.format = 'sww'
self.domain.smooth = True
self.domain.reduction = mean
sww = SWW_file(self.domain)
sww.store_connectivity()
sww.store_timestep()
#self.domain.tight_slope_limiters = 1
self.domain.evolve_to_end(finaltime = 0.01)
sww.store_timestep()
# Check contents
# Get NetCDF
fid = NetCDFFile(sww.filename, netcdf_mode_r)
# Get the variables
x = fid.variables['x']
y = fid.variables['y']
z = fid.variables['elevation']
time = fid.variables['time']
stage = fid.variables['stage']
#Check values
Q = self.domain.quantities['stage']
Q0 = Q.vertex_values[:,0]
Q1 = Q.vertex_values[:,1]
Q2 = Q.vertex_values[:,2]
A = stage[1,:]
assert num.allclose(A[0], (Q2[0] + Q1[1])/2, rtol=1.0e-5, atol=1.0e-5)
assert num.allclose(A[1], (Q0[1] + Q1[3] + Q2[2])/3, rtol=1.0e-5, atol=1.0e-5)
assert num.allclose(A[2], Q0[3], rtol=1.0e-5, atol=1.0e-5)
assert num.allclose(A[3], (Q0[0] + Q1[5] + Q2[4])/3, rtol=1.0e-5, atol=1.0e-5)
#Center point
assert num.allclose(A[4], (Q1[0] + Q2[1] + Q0[2] +\
Q0[5] + Q2[6] + Q1[7])/6, rtol=1.0e-5, atol=1.0e-5)
fid.close()
#Cleanup
os.remove(sww.filename)
示例14: test_sww_minimum_storable_height
def test_sww_minimum_storable_height(self):
"""Test that sww information can be written correctly
multiple timesteps using a different reduction operator (min)
"""
import time, os
self.domain.set_name('datatest' + str(id(self)))
self.domain.format = 'sww'
self.domain.smooth = True
self.domain.reduction = min
self.domain.minimum_storable_height = 100
sww = SWW_file(self.domain)
sww.store_connectivity()
sww.store_timestep()
#self.domain.tight_slope_limiters = 1
self.domain.evolve_to_end(finaltime = 0.01)
sww.store_timestep()
#Check contents
#Get NetCDF
fid = NetCDFFile(sww.filename, netcdf_mode_r)
# Get the variables
x = fid.variables['x']
y = fid.variables['y']
z = fid.variables['elevation']
time = fid.variables['time']
stage = fid.variables['stage']
xmomentum = fid.variables['xmomentum']
ymomentum = fid.variables['ymomentum']
#Check values
Q = self.domain.quantities['stage']
Q0 = Q.vertex_values[:,0]
Q1 = Q.vertex_values[:,1]
Q2 = Q.vertex_values[:,2]
A = stage[1,:]
assert num.allclose(stage[1,:], z[:])
assert num.allclose(xmomentum, 0.0)
assert num.allclose(ymomentum, 0.0)
fid.close()
#Cleanup
os.remove(sww.filename)
示例15: getQuantityDict
def getQuantityDict(self):
quantities = {}
fin = NetCDFFile(self.vis_source, 'r')
names = [ k for k in fin.variables.keys()
if k != 'x'
and k != 'y'
and k != 'z'
and k != 'time'
and k != 'volumes' ]
argss = [ (name, len(fin.variables[name].shape) != 1) for name in names ]
fin.close()
for args in argss:
quantities[name] = self.getQuantityPoints(*args)
return quantities