本文整理汇总了Python中anuga.file.netcdf.NetCDFFile.starttime方法的典型用法代码示例。如果您正苦于以下问题:Python NetCDFFile.starttime方法的具体用法?Python NetCDFFile.starttime怎么用?Python NetCDFFile.starttime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anuga.file.netcdf.NetCDFFile
的用法示例。
在下文中一共展示了NetCDFFile.starttime方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prepare_timeboundary
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import starttime [as 别名]
def prepare_timeboundary(filename, verbose = False):
"""Convert benchmark 2 time series to NetCDF tms file.
This is a 'throw-away' code taylor made for files like
'Benchmark_2_input.txt' from the LWRU2 benchmark
"""
from anuga.file.netcdf import NetCDFFile
if verbose: print 'Creating', filename
# Read the ascii (.txt) version of this file
fid = open(filename[:-4] + '.txt')
# Skip first line
line = fid.readline()
# Read remaining lines
lines = fid.readlines()
fid.close()
N = len(lines)
T = num.zeros(N, num.float) #Time
Q = num.zeros(N, num.float) #Values
for i, line in enumerate(lines):
fields = line.split()
T[i] = float(fields[0])
Q[i] = float(fields[1])
# Create tms NetCDF file
fid = NetCDFFile(filename, 'w')
fid.institution = 'Geoscience Australia'
fid.description = 'Input wave for Benchmark 2'
fid.starttime = 0.0
fid.createDimension('number_of_timesteps', len(T))
fid.createVariable('time', netcdf_float, ('number_of_timesteps',))
fid.variables['time'][:] = T
fid.createVariable('stage', netcdf_float, ('number_of_timesteps',))
fid.variables['stage'][:] = Q[:]
fid.createVariable('xmomentum', netcdf_float, ('number_of_timesteps',))
fid.variables['xmomentum'][:] = 0.0
fid.createVariable('ymomentum', netcdf_float, ('number_of_timesteps',))
fid.variables['ymomentum'][:] = 0.0
fid.close()
示例2: timefile2netcdf
# 需要导入模块: from anuga.file.netcdf import NetCDFFile [as 别名]
# 或者: from anuga.file.netcdf.NetCDFFile import starttime [as 别名]
def timefile2netcdf(file_text, file_out = None, quantity_names=None, \
time_as_seconds=False):
"""Template for converting typical text files with time series to
NetCDF tms file.
The file format is assumed to be either two fields separated by a comma:
time [DD/MM/YY hh:mm:ss], value0 value1 value2 ...
E.g
31/08/04 00:00:00, 1.328223 0 0
31/08/04 00:15:00, 1.292912 0 0
or time (seconds), value0 value1 value2 ...
0.0, 1.328223 0 0
0.1, 1.292912 0 0
will provide a time dependent function f(t) with three attributes
filename is assumed to be the rootname with extensions .txt/.tms and .sww
"""
import time, calendar
from anuga.config import time_format
from anuga.utilities.numerical_tools import ensure_numeric
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)
#.........这里部分代码省略.........