本文整理汇总了Python中pthelma.timeseries.Timeseries.write_file方法的典型用法代码示例。如果您正苦于以下问题:Python Timeseries.write_file方法的具体用法?Python Timeseries.write_file怎么用?Python Timeseries.write_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pthelma.timeseries.Timeseries
的用法示例。
在下文中一共展示了Timeseries.write_file方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute_point
# 需要导入模块: from pthelma.timeseries import Timeseries [as 别名]
# 或者: from pthelma.timeseries.Timeseries import write_file [as 别名]
#.........这里部分代码省略.........
raise InvalidOptionError(
'elevation should only be specified in the configuration file '
'in spatial calculation')
# Read input time series
input_timeseries = {}
for name in ('temperature_min', 'temperature_max', 'temperature',
'humidity', 'humidity_min', 'humidity_max', 'wind_speed',
'pressure', 'solar_radiation', 'sunshine_duration'):
filename = self.config['General'][name + '_prefix'] + '.hts'
if not os.path.exists(filename):
continue
t = Timeseries()
with open(filename, 'r') as f:
t.read_file(f)
input_timeseries[name] = t
# Make sure all are in the same location and timezone
first = True
for index in input_timeseries:
t = input_timeseries[index]
if first:
abscissa = t.location['abscissa']
ordinate = t.location['ordinate']
srid = t.location['srid']
altitude = t.location['altitude']
timezone = t.timezone
first = False
continue
if abs(abscissa - t.location['abscissa']) > 1e-7 or \
abs(ordinate - t.location['ordinate']) > 1e-7 or \
srid != t.location['srid'] or \
abs(altitude - t.location['altitude']) > 1e-2 or \
timezone != t.timezone:
raise ValueError('Incorrect or unspecified or inconsistent '
'locations or time zones in the time series '
'files.')
# Convert location to WGS84
source_projection = osr.SpatialReference()
source_projection.ImportFromEPSG(srid)
wgs84 = osr.SpatialReference()
wgs84.ImportFromEPSG(4326)
transform = osr.CoordinateTransformation(source_projection, wgs84)
apoint = ogr.Geometry(ogr.wkbPoint)
apoint.AddPoint(abscissa, ordinate)
apoint.Transform(transform)
latitude, longitude = apoint.GetY(), apoint.GetY()
# Prepare the Penman Monteith method
nsrr = self.nighttime_solar_radiation_ratio
self.penman_monteith = PenmanMonteith(
albedo=self.albedo,
nighttime_solar_radiation_ratio=nsrr,
elevation=altitude,
latitude=latitude,
longitude=longitude,
step_length=self.step,
unit_converters=self.unit_converters)
# Create output timeseries object
precision = 2 if self.step == timedelta(hours=1) else 1
pet = Timeseries(
time_step=TimeStep(length_minutes=self.step.total_seconds() / 60),
unit='mm',
timezone=timezone,
variable='Potential Evapotranspiration',
precision=precision,
location={'abscissa': abscissa, 'ordinate': ordinate,
'srid': srid, 'altitude': altitude})
# Let's see what variables we are going to use in the calculation,
# based mainly on the step.
if self.step == timedelta(hours=1):
variables = ('temperature', 'humidity', 'wind_speed',
'solar_radiation')
elif self.step == timedelta(days=1):
variables = (
'temperature_max', 'temperature_min', 'humidity_max',
'humidity_min', 'wind_speed',
'solar_radiation' if 'solar_radiation' in input_timeseries
else 'sunshine_duration')
else:
raise Exception(
'Internal error: step should have been checked already')
# Calculate evaporation
for adatetime in input_timeseries['wind_speed']:
try:
kwargs = {v: input_timeseries[v][adatetime]
for v in variables}
except (IndexError, KeyError):
continue
kwargs['adatetime'] = adatetime
pet[adatetime] = self.penman_monteith.calculate(**kwargs)
# Save result
outfilename = self.config['General']['evaporation_prefix'] + '.hts'
with open(outfilename, 'w') as f:
pet.write_file(f)