本文整理汇总了Python中anuga.file.netcdf.NetCDFFile.variables['time'][i]方法的典型用法代码示例。如果您正苦于以下问题:Python NetCDFFile.variables['time'][i]方法的具体用法?Python NetCDFFile.variables['time'][i]怎么用?Python NetCDFFile.variables['time'][i]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anuga.file.netcdf.NetCDFFile
的用法示例。
在下文中一共展示了NetCDFFile.variables['time'][i]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _sww_merge_parallel_non_smooth
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import variables['time'][i] [as 别名]
#.........这里部分代码省略.........
fid.close()
#---------------------------
# Write out the SWW file
#---------------------------
if verbose:
print 'Writing file ', output, ':'
fido = NetCDFFile(output, netcdf_mode_w)
sww = Write_sww(static_quantities, dynamic_quantities, static_c_quantities, dynamic_c_quantities)
sww.store_header(fido, starttime,
number_of_global_triangles,
number_of_global_triangles*3,
description=description,
sww_precision=netcdf_float32)
from anuga.coordinate_transforms.geo_reference import Geo_reference
geo_reference = Geo_reference()
sww.store_triangulation(fido, g_points, g_volumes, points_georeference=geo_reference)
fido.order = order
fido.xllcorner = xllcorner;
fido.yllcorner = yllcorner ;
fido.zone = zone;
fido.false_easting = false_easting;
fido.false_northing = false_northing;
fido.datum = datum;
fido.projection = projection;
sww.store_static_quantities(fido, verbose=verbose, **out_s_quantities)
sww.store_static_quantities_centroid(fido, verbose=verbose, **out_s_c_quantities)
# Write out all the dynamic quantities for each timestep
for i in range(n_steps):
fido.variables['time'][i] = times[i]
for q in (dynamic_quantities + dynamic_c_quantities):
if verbose:
print ' Writing quantity: ',q
# Initialise q_values with zeros
if q in dynamic_quantities:
q_values = num.zeros((n_steps, 3*number_of_global_triangles), num.float32)
elif q in dynamic_c_quantities:
q_values = num.zeros((n_steps, number_of_global_triangles), num.float32)
# Read the quantities one at a time, to reduce memory usage
for filename in swwfiles:
fid = NetCDFFile(filename, netcdf_mode_r)
# Index information
tri_l2g = fid.variables['tri_l2g'][:]
node_l2g = fid.variables['node_l2g'][:]
tri_full_flag = fid.variables['tri_full_flag'][:]
f_ids = num.argwhere(tri_full_flag==1).reshape(-1,)
f_gids = tri_l2g[f_ids]
g_vids = (3*f_gids.reshape(-1,1) + num.array([0,1,2])).reshape(-1,)
l_vids = (3*f_ids.reshape(-1,1) + num.array([0,1,2])).reshape(-1,)
for i in range(n_steps):
# Different indices for vertex and centroid quantities
if q in dynamic_quantities:
q_values[i][g_vids] = \
num.array(fid.variables[q][i], dtype=num.float32)[l_vids]
elif q in dynamic_c_quantities:
q_values[i][f_gids] = \
num.array(fid.variables[q][i], dtype=num.float32)[f_ids]
fid.close()
# Write to the file
for i in range(n_steps):
fido.variables[q][i] = q_values[i]
if q in dynamic_quantities:
# This updates the _range values
q_range = fido.variables[q + Write_sww.RANGE][:]
q_values_min = num.min(q_values)
if q_values_min < q_range[0]:
fido.variables[q + Write_sww.RANGE][0] = q_values_min
q_values_max = num.max(q_values)
if q_values_max > q_range[1]:
fido.variables[q + Write_sww.RANGE][1] = q_values_max
fido.close()
if delete_old:
import os
for filename in swwfiles:
if verbose:
print 'Deleting file ', filename, ':'
os.remove(filename)
示例2: _sww_merge_parallel_smooth
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import variables['time'][i] [as 别名]
#.........这里部分代码省略.........
#Collate all dynamic c quantities according to their timestep
for quantity in dynamic_c_quantities:
q = fid.variables[quantity]
#print q.shape
for i in range(n_steps):
out_d_c_quantities[quantity][i][ftri_l2g] = \
num.array(q[i]).astype(num.float32)[ftri_ids]
fid.close()
#---------------------------
# Write out the SWW file
#---------------------------
#print g_points.shape
#print number_of_global_triangles
#print number_of_global_nodes
if verbose:
print 'Writing file ', output, ':'
fido = NetCDFFile(output, netcdf_mode_w)
sww = Write_sww(static_quantities, dynamic_quantities, static_c_quantities, dynamic_c_quantities)
sww.store_header(fido, starttime,
number_of_global_triangles,
number_of_global_nodes,
description=description,
sww_precision=netcdf_float32)
from anuga.coordinate_transforms.geo_reference import Geo_reference
geo_reference = Geo_reference()
sww.store_triangulation(fido, g_points, g_volumes, points_georeference=geo_reference)
fido.order = order
fido.xllcorner = xllcorner;
fido.yllcorner = yllcorner ;
fido.zone = zone;
fido.false_easting = false_easting;
fido.false_northing = false_northing;
fido.datum = datum;
fido.projection = projection;
sww.store_static_quantities(fido, verbose=verbose, **out_s_quantities)
sww.store_static_quantities_centroid(fido, verbose=verbose, **out_s_c_quantities)
# Write out all the dynamic quantities for each timestep
for i in range(n_steps):
fido.variables['time'][i] = times[i]
for q in dynamic_quantities:
q_values = out_d_quantities[q]
if verbose:
print ' Writing quantity: ',q
for i in range(n_steps):
fido.variables[q][i] = q_values[i]
# This updates the _range values
q_range = fido.variables[q + Write_sww.RANGE][:]
q_values_min = num.min(q_values)
if q_values_min < q_range[0]:
fido.variables[q + Write_sww.RANGE][0] = q_values_min
q_values_max = num.max(q_values)
if q_values_max > q_range[1]:
fido.variables[q + Write_sww.RANGE][1] = q_values_max
for q in dynamic_c_quantities:
if verbose:
print ' Writing quantity: ',q
q_values = out_d_c_quantities[q]
for i in range(n_steps):
fido.variables[q][i] = q_values[i]
#print out_s_quantities
#print out_d_quantities
#print g_x
#print g_y
#print g_volumes
fido.close()
if delete_old:
import os
for filename in swwfiles:
if verbose:
print 'Deleting file ', filename, ':'
os.remove(filename)