本文整理汇总了Python中anuga.file.netcdf.NetCDFFile.variables[name][:]方法的典型用法代码示例。如果您正苦于以下问题:Python NetCDFFile.variables[name][:]方法的具体用法?Python NetCDFFile.variables[name][:]怎么用?Python NetCDFFile.variables[name][:]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anuga.file.netcdf.NetCDFFile
的用法示例。
在下文中一共展示了NetCDFFile.variables[name][:]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: timefile2netcdf
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import variables[name][:] [as 别名]
#.........这里部分代码省略.........
if file_text[-4:] != '.txt':
raise IOError('Input file %s should be of type .txt.' % file_text)
if file_out is None:
file_out = file_text[:-4] + '.tms'
fid = open(file_text)
line = fid.readline()
fid.close()
fields = line.split(',')
msg = "File %s must have the format 'datetime, value0 value1 value2 ...'" \
% file_text
assert len(fields) == 2, msg
if not time_as_seconds:
try:
starttime = calendar.timegm(time.strptime(fields[0], time_format))
except ValueError:
msg = 'First field in file %s must be' % file_text
msg += ' date-time with format %s.\n' % time_format
msg += 'I got %s instead.' % fields[0]
raise DataTimeError, msg
else:
try:
starttime = float(fields[0])
except Error:
msg = "Bad time format"
raise DataTimeError, msg
# Split values
values = []
for value in fields[1].split():
values.append(float(value))
q = ensure_numeric(values)
msg = 'ERROR: File must contain at least one independent value'
assert len(q.shape) == 1, msg
# Read times proper
from anuga.config import time_format
import time, calendar
fid = open(file_text)
lines = fid.readlines()
fid.close()
N = len(lines)
d = len(q)
T = num.zeros(N, num.float) # Time
Q = num.zeros((N, d), num.float) # Values
for i, line in enumerate(lines):
fields = line.split(',')
if not time_as_seconds:
realtime = calendar.timegm(time.strptime(fields[0], time_format))
else:
realtime = float(fields[0])
T[i] = realtime - starttime
for j, value in enumerate(fields[1].split()):
Q[i, j] = float(value)
msg = 'File %s must list time as a monotonuosly ' % file_text
msg += 'increasing sequence'
assert num.alltrue(T[1:] - T[:-1] > 0), msg
#Create NetCDF file
fid = NetCDFFile(file_out, netcdf_mode_w)
fid.institution = 'Geoscience Australia'
fid.description = 'Time series'
#Reference point
#Start time in seconds since the epoch (midnight 1/1/1970)
#FIXME: Use Georef
fid.starttime = starttime
# dimension definitions
#fid.createDimension('number_of_volumes', self.number_of_volumes)
#fid.createDimension('number_of_vertices', 3)
fid.createDimension('number_of_timesteps', len(T))
fid.createVariable('time', netcdf_float, ('number_of_timesteps',))
fid.variables['time'][:] = T
for i in range(Q.shape[1]):
try:
name = quantity_names[i]
except:
name = 'Attribute%d' % i
fid.createVariable(name, netcdf_float, ('number_of_timesteps',))
fid.variables[name][:] = Q[:,i]
fid.close()
示例2: setUp
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import variables[name][:] [as 别名]
def setUp(self):
import time
self.verbose = Test_File_Conversion.verbose
# Create basic mesh
points, vertices, boundary = rectangular(2, 2)
# Create shallow water domain
domain = Domain(points, vertices, boundary)
domain.default_order = 2
# Set some field values
domain.set_quantity('elevation', lambda x,y: -x)
domain.set_quantity('friction', 0.03)
######################
# Boundary conditions
B = Transmissive_boundary(domain)
domain.set_boundary( {'left': B, 'right': B, 'top': B, 'bottom': B})
######################
#Initial condition - with jumps
bed = domain.quantities['elevation'].vertex_values
stage = num.zeros(bed.shape, num.float)
h = 0.3
for i in range(stage.shape[0]):
if i % 2 == 0:
stage[i,:] = bed[i,:] + h
else:
stage[i,:] = bed[i,:]
domain.set_quantity('stage', stage)
domain.distribute_to_vertices_and_edges()
self.initial_stage = copy.copy(domain.quantities['stage'].vertex_values)
self.domain = domain
C = domain.get_vertex_coordinates()
self.X = C[:,0:6:2].copy()
self.Y = C[:,1:6:2].copy()
self.F = bed
#Write A testfile (not realistic. Values aren't realistic)
self.test_MOST_file = 'most_small'
longitudes = [150.66667, 150.83334, 151., 151.16667]
latitudes = [-34.5, -34.33333, -34.16667, -34]
long_name = 'LON'
lat_name = 'LAT'
nx = 4
ny = 4
six = 6
for ext in ['_ha.nc', '_ua.nc', '_va.nc', '_e.nc']:
fid = NetCDFFile(self.test_MOST_file + ext, netcdf_mode_w)
fid.createDimension(long_name,nx)
fid.createVariable(long_name,netcdf_float,(long_name,))
fid.variables[long_name].point_spacing='uneven'
fid.variables[long_name].units='degrees_east'
fid.variables[long_name][:] = longitudes
fid.createDimension(lat_name,ny)
fid.createVariable(lat_name,netcdf_float,(lat_name,))
fid.variables[lat_name].point_spacing='uneven'
fid.variables[lat_name].units='degrees_north'
fid.variables[lat_name][:] = latitudes
fid.createDimension('TIME',six)
fid.createVariable('TIME',netcdf_float,('TIME',))
fid.variables['TIME'].point_spacing='uneven'
fid.variables['TIME'].units='seconds'
fid.variables['TIME'][:] = [0.0, 0.1, 0.6, 1.1, 1.6, 2.1]
name = ext[1:3].upper()
if name == 'E.': name = 'ELEVATION'
fid.createVariable(name,netcdf_float,('TIME', lat_name, long_name))
fid.variables[name].units='CENTIMETERS'
fid.variables[name].missing_value=-1.e+034
fid.variables[name][:] = [[[0.3400644, 0, -46.63519, -6.50198],
[-0.1214216, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]],
[[0.3400644, 2.291054e-005, -23.33335, -6.50198],
[-0.1213987, 4.581959e-005, -1.594838e-007, 1.421085e-012],
[2.291054e-005, 4.582107e-005, 4.581715e-005, 1.854517e-009],
[0, 2.291054e-005, 2.291054e-005, 0]],
[[0.3400644, 0.0001374632, -23.31503, -6.50198],
#.........这里部分代码省略.........