本文整理汇总了Python中Utilities.config.ConfigParser.geteval方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser.geteval方法的具体用法?Python ConfigParser.geteval怎么用?Python ConfigParser.geteval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utilities.config.ConfigParser
的用法示例。
在下文中一共展示了ConfigParser.geteval方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Utilities.config import ConfigParser [as 别名]
# 或者: from Utilities.config.ConfigParser import geteval [as 别名]
def __init__(self, configFile, autoCalc_gridLimit=None,
progressbar=None):
"""
Initialize the data and variables required for the interface
"""
self.configFile = configFile
config = ConfigParser()
config.read(configFile)
self.progressbar = progressbar
log.info("Initialising StatInterface")
self.kdeType = config.get('StatInterface', 'kdeType')
self.kde2DType = config.get('StatInterface','kde2DType')
minSamplesCell = config.getint('StatInterface', 'minSamplesCell')
self.kdeStep = config.getfloat('StatInterface', 'kdeStep')
self.outputPath = config.get('Output', 'Path')
self.processPath = pjoin(self.outputPath, 'process')
missingValue = cnfGetIniValue(self.configFile, 'StatInterface',
'MissingValue', sys.maxint)
gridLimitStr = cnfGetIniValue(self.configFile, 'StatInterface',
'gridLimit', '')
if gridLimitStr is not '':
try:
self.gridLimit = eval(gridLimitStr)
except SyntaxError:
log.exception('Error! gridLimit is not a dictionary')
else:
self.gridLimit = autoCalc_gridLimit
log.info('No gridLimit specified - using automatic' +
' selection: ' + str(self.gridLimit))
try:
gridSpace = config.geteval('Region', 'gridSpace')
gridInc = config.geteval('Region', 'gridInc')
except SyntaxError:
log.exception('Error! gridSpace or gridInc not dictionaries')
raise
self.generateDist = GenerateDistributions(self.configFile,
self.gridLimit,
gridSpace, gridInc,
self.kdeType,
minSamplesCell,
missingValue)
self.gridSpace = gridSpace
self.gridInc = gridInc
示例2: __init__
# 需要导入模块: from Utilities.config import ConfigParser [as 别名]
# 或者: from Utilities.config.ConfigParser import geteval [as 别名]
def __init__(self, configFile):
"""
Calculate density of TC positions on a grid
:param str configFile: path to a TCRM configuration file.
"""
config = ConfigParser()
config.read(configFile)
self.configFile = configFile
# Define the grid:
gridLimit = config.geteval('Region', 'gridLimit')
gridSpace = config.geteval('Region', 'GridSpace')
self.lon_range = np.arange(gridLimit['xMin'],
gridLimit['xMax'] + 0.1,
gridSpace['x'])
self.lat_range = np.arange(gridLimit['yMin'],
gridLimit['yMax'] + 0.1,
gridSpace['y'])
outputPath = config.get('Output', 'Path')
self.trackPath = pjoin(outputPath, 'tracks')
self.plotPath = pjoin(outputPath, 'plots', 'stats')
self.dataPath = pjoin(outputPath, 'process')
# Determine TCRM input directory
tcrm_dir = pathLocator.getRootDirectory()
self.inputPath = pjoin(tcrm_dir, 'input')
self.synNumYears = config.getint('TrackGenerator',
'yearspersimulation')
示例3: __init__
# 需要导入模块: from Utilities.config import ConfigParser [as 别名]
# 或者: from Utilities.config.ConfigParser import geteval [as 别名]
def __init__(self, configFile):
"""
:param str configFile: Path to configuration file.
"""
config = ConfigParser()
config.read(configFile)
self.outputPath = config.get('Output', 'Path')
self.wf_domain = config.geteval('Region', 'gridLimit')
示例4: __init__
# 需要导入模块: from Utilities.config import ConfigParser [as 别名]
# 或者: from Utilities.config.ConfigParser import geteval [as 别名]
def __init__(self, configFile, tilegrid, numSim, minRecords, yrsPerSim,
calcCI=False):
"""
Initialise HazardCalculator object.
:param str configFile: path to TCRM configuration file.
:param tilegrid: :class:`TileGrid` instance
:param int numSim: number of simulations created.
:param int minRecords: minimum number of valid wind speed values required
to do fitting.
:param int yrsPerSim:
"""
config = ConfigParser()
config.read(configFile)
self.nodata = -9999.
self.years = np.array(config.get('Hazard',
'Years').split(',')).astype('f')
self.outputPath = pjoin(config.get('Output', 'Path'), 'hazard')
self.inputPath = pjoin(config.get('Output', 'Path'), 'windfield')
gridLimit = config.geteval('Region', 'gridLimit')
self.numSim = numSim
self.minRecords = minRecords
self.yrsPerSim = yrsPerSim
self.calcCI = calcCI
if self.calcCI:
log.debug("Bootstrap confidence intervals will be calculated")
self.sample_size = config.getint('Hazard', 'SampleSize')
self.prange = config.getint('Hazard', 'PercentileRange')
self.tilegrid = tilegrid
lon, lat = self.tilegrid.getDomainExtent()
# Create arrays for storing output data:
self.loc = np.zeros((len(lat), len(lon)), dtype='f')
self.shp = np.zeros((len(lat), len(lon)), dtype='f')
self.scale = np.zeros((len(lat), len(lon)), dtype='f')
self.Rp = np.zeros((len(self.years), len(lat), len(lon)), dtype='f')
self.RPupper = np.zeros((len(self.years), len(lat), len(lon)), dtype='f')
self.RPlower = np.zeros((len(self.years), len(lat), len(lon)), dtype='f')
self.global_atts = {'history': ('TCRM hazard simulation - '
'return period wind speeds'),
'version': flProgramVersion(),
'Python_ver': sys.version}
# Add configuration settings to global attributes:
for section in config.sections():
for option in config.options(section):
key = "{0}_{1}".format(section, option)
value = config.get(section, option)
self.global_atts[key] = value
示例5: run
# 需要导入模块: from Utilities.config import ConfigParser [as 别名]
# 或者: from Utilities.config.ConfigParser import geteval [as 别名]
def run(configFile, callback=None):
"""
Run the hazard calculations.
This will attempt to run the calculation in parallel by tiling the
domain, but also provides a sane fallback mechanism to execute
in serial.
:param configFile: str
"""
log.info("Loading hazard calculation settings")
config = ConfigParser()
config.read(configFile)
outputPath = config.get('Output', 'Path')
inputPath = pjoin(outputPath, 'windfield')
gridLimit = config.geteval('Region', 'gridLimit')
numsimulations = config.getint('TrackGenerator', 'NumSimulations')
yrsPerSim = config.getint('TrackGenerator', 'YearsPerSimulation')
minRecords = config.getint('Hazard', 'MinimumRecords')
calculate_confidence = config.getboolean('Hazard', 'CalculateCI')
wf_lon, wf_lat = setDomain(inputPath)
global pp
pp = attemptParallel()
log.info("Running hazard calculations")
TG = TileGrid(gridLimit, wf_lon, wf_lat)
tiles = getTiles(TG)
#def progress(i):
# callback(i, len(tiles))
pp.barrier()
hc = HazardCalculator(configFile, TG,
numsimulations,
minRecords,
yrsPerSim,
calculate_confidence)
hc.dumpHazardFromTiles(tiles)
pp.barrier()
hc.saveHazard()
log.info("Completed hazard calculation")
示例6: doWindfieldPlotting
# 需要导入模块: from Utilities.config import ConfigParser [as 别名]
# 或者: from Utilities.config.ConfigParser import geteval [as 别名]
def doWindfieldPlotting(configFile):
"""
Plot the wind field on a map.
:param str configFile: Path to the configuration file.
:Note: the file name is assumed to be 'gust.interp.nc'
"""
from netCDF4 import Dataset
import numpy as np
config = ConfigParser()
config.read(configFile)
outputPath = config.get('Output', 'Path')
windfieldPath = pjoin(outputPath, 'windfield')
# Note the assumption about the file name!
outputWindFile = pjoin(windfieldPath, 'gust.interp.nc')
plotPath = pjoin(outputPath, 'plots', 'maxwind.png')
f = Dataset(outputWindFile, 'r')
xdata = f.variables['lon'][:]
ydata = f.variables['lat'][:]
vdata = f.variables['vmax'][:]
gridLimit = None
if config.has_option('Region','gridLimit'):
gridLimit = config.geteval('Region', 'gridLimit')
ii = np.where((xdata >= gridLimit['xMin']) &
(xdata <= gridLimit['xMax']))
jj = np.where((ydata >= gridLimit['yMin']) &
(ydata <= gridLimit['yMax']))
[xgrid, ygrid] = np.meshgrid(xdata[ii], ydata[jj])
ig, jg = np.meshgrid(ii, jj)
vdata = vdata[jg, ig]
else:
[xgrid, ygrid] = np.meshgrid(xdata, ydata)
map_kwargs = dict(llcrnrlon=xgrid.min(),
llcrnrlat=ygrid.min(),
urcrnrlon=xgrid.max(),
urcrnrlat=ygrid.max(),
projection='merc',
resolution='i')
title = "Maximum wind speed"
cbarlabel = "Wind speed ({0})".format(f.variables['vmax'].units)
levels = np.arange(30, 101., 5.)
saveWindfieldMap(vdata, xgrid, ygrid, title, levels,
cbarlabel, map_kwargs, plotPath)
示例7: __init__
# 需要导入模块: from Utilities.config import ConfigParser [as 别名]
# 或者: from Utilities.config.ConfigParser import geteval [as 别名]
def __init__(self, configFile):
"""
Calculate density of TC genesis positions on a grid
:param str configFile: path to a TCRM configuration file.
"""
config = ConfigParser()
config.read(configFile)
self.configFile = configFile
# Define the grid:
gridLimit = config.geteval('Region', 'gridLimit')
gridSpace = config.geteval('Region', 'GridSpace')
self.lon_range = np.arange(gridLimit['xMin'],
gridLimit['xMax'] + 0.1,
0.1)
self.lat_range = np.arange(gridLimit['yMin'],
gridLimit['yMax'] + 0.1,
0.1)
self.X, self.Y = np.meshgrid(self.lon_range, self.lat_range)
outputPath = config.get('Output', 'Path')
self.trackPath = pjoin(outputPath, 'tracks')
self.plotPath = pjoin(outputPath, 'plots', 'stats')
self.dataPath = pjoin(outputPath, 'process')
# Determine TCRM input directory
tcrm_dir = pathLocator.getRootDirectory()
self.inputPath = pjoin(tcrm_dir, 'input')
self.synNumYears = config.getint('TrackGenerator',
'yearspersimulation')
cellnumber = 0
self.gridCells = []
for k in xrange(len(self.lon_range) - 1):
for l in xrange(len(self.lat_range) - 1):
ymin = self.lat_range[l]
ymax = self.lat_range[l] + gridSpace['y']
xmin = self.lon_range[k]
xmax = self.lon_range[k] + gridSpace['x']
self.gridCells.append(gridCell(xmin, ymin, xmax, ymax,
cellnumber, (k, l)))
cellnumber += 1
示例8: __init__
# 需要导入模块: from Utilities.config import ConfigParser [as 别名]
# 或者: from Utilities.config.ConfigParser import geteval [as 别名]
def __init__(self, configFile):
config = ConfigParser()
config.read(configFile)
self.configFile = configFile
# Define the grid:
gridLimit = config.geteval('Region', 'gridLimit')
gridSpace = config.geteval('Region', 'GridSpace')
self.lon_range = np.arange(gridLimit['xMin'],
gridLimit['xMax'] + 0.1,
gridSpace['x'])
self.lat_range = np.arange(gridLimit['yMin'],
gridLimit['yMax'] + 0.1,
gridSpace['y'])
outputPath = config.get('Output', 'Path')
self.trackPath = pjoin(outputPath, 'tracks')
self.plotPath = pjoin(outputPath, 'plots', 'stats')
self.dataPath = pjoin(outputPath, 'process')
# Determine TCRM input directory
tcrm_dir = pathLocator.getRootDirectory()
self.inputPath = pjoin(tcrm_dir, 'input')
self.synNumYears = config.getint('TrackGenerator',
'yearspersimulation')
# Longitude crossing gates:
self.gateLons = np.arange(self.lon_range.min(),
self.lon_range.max() + 0.5, 10.)
self.gateLats = np.arange(self.lat_range.min(),
self.lat_range.max() + 0.5, 2.)
# Add configuration settings to global attributes:
self.gatts = {'history': "Longitude crossing rates for TCRM simulation",
'version': flProgramVersion() }
for section in config.sections():
for option in config.options(section):
key = "{0}_{1}".format(section, option)
value = config.get(section, option)
self.gatts[key] = value
示例9: main
# 需要导入模块: from Utilities.config import ConfigParser [as 别名]
# 或者: from Utilities.config.ConfigParser import geteval [as 别名]
def main(configFile):
from Utilities.loadData import loadTrackFile
from Utilities.config import ConfigParser
from os.path import join as pjoin, normpath, dirname
baseDir = normpath(pjoin(dirname(__file__), '..'))
inputPath = pjoin(baseDir, 'input')
config = ConfigParser()
config.read(configFile)
inputFile = config.get('DataProcess', 'InputFile')
source = config.get('DataProcess', 'Source')
gridLimit = config.geteval('Region', 'gridLimit')
xx = np.arange(gridLimit['xMin'], gridLimit['xMax'] + .1, 0.1)
yy = np.arange(gridLimit['yMin'], gridLimit['yMax'] + .1, 0.1)
xgrid, ygrid = np.meshgrid(xx, yy)
if len(dirname(inputFile)) == 0:
inputFile = pjoin(inputPath, inputFile)
try:
tracks = loadTrackFile(configFile, inputFile, source)
except (TypeError, IOError, ValueError):
log.critical("Cannot load historical track file: {0}".format(inputFile))
raise
title = source
outputPath = config.get('Output', 'Path')
outputPath = pjoin(outputPath, 'plots','stats')
outputFile = pjoin(outputPath, 'tctracks.png')
map_kwargs = dict(llcrnrlon=xgrid.min(),
llcrnrlat=ygrid.min(),
urcrnrlon=xgrid.max(),
urcrnrlat=ygrid.max(),
projection='merc',
resolution='i')
figure = TrackMapFigure()
figure.add(tracks, xgrid, ygrid, title, map_kwargs)
figure.plot()
saveFigure(figure, outputFile)
示例10: __init__
# 需要导入模块: from Utilities.config import ConfigParser [as 别名]
# 或者: from Utilities.config.ConfigParser import geteval [as 别名]
def __init__(self, configFile):
"""
Calculate density of TC genesis positions on a grid
:param str configFile: path to a TCRM configuration file.
"""
config = ConfigParser()
config.read(configFile)
self.configFile = configFile
# Define the grid:
self.gridLimit = config.geteval("Region", "gridLimit")
self.gridSpace = config.geteval("Region", "GridSpace")
self.lon_range = np.arange(self.gridLimit["xMin"], self.gridLimit["xMax"] + 0.1, 0.1)
self.lat_range = np.arange(self.gridLimit["yMin"], self.gridLimit["yMax"] + 0.1, 0.1)
self.X, self.Y = np.meshgrid(self.lon_range, self.lat_range)
outputPath = config.get("Output", "Path")
self.trackPath = pjoin(outputPath, "tracks")
self.plotPath = pjoin(outputPath, "plots", "stats")
self.dataPath = pjoin(outputPath, "process")
# Determine TCRM input directory
tcrm_dir = pathLocator.getRootDirectory()
self.inputPath = pjoin(tcrm_dir, "input")
self.synNumYears = config.getint("TrackGenerator", "yearspersimulation")
cellnumber = 0
self.gridCells = []
for k in xrange(len(self.lon_range) - 1):
for l in xrange(len(self.lat_range) - 1):
ymin = self.lat_range[l]
ymax = self.lat_range[l] + self.gridSpace["y"]
xmin = self.lon_range[k]
xmax = self.lon_range[k] + self.gridSpace["x"]
self.gridCells.append(gridCell(xmin, ymin, xmax, ymax, cellnumber, (k, l)))
cellnumber += 1
示例11: __init__
# 需要导入模块: from Utilities.config import ConfigParser [as 别名]
# 或者: from Utilities.config.ConfigParser import geteval [as 别名]
def __init__(self, configFile, auto_calc_grid_limit):
"""
:type configFile: string
:param configFile: Configuration file name
:type auto_calc_grid_limit: :class:`dict`
:param auto_calc_grid_limit: the domain where the frequency will be calculated.
The :class:`dict` should contain the keys
:attr:`xMin`, :attr:`xMax`, :attr:`yMin`
and :attr:`yMax`. The *x* variable bounds the
longitude and the *y* variable bounds
the latitude.
"""
config = ConfigParser()
config.read(configFile)
if config.has_option('TrackGenerator', 'gridLimit'):
self.tg_domain = config.geteval('TrackGenerator', 'gridLimit')
else:
self.tg_domain = auto_calc_grid_limit
self.outputPath = config.get('Output', 'Path')
示例12: __init__
# 需要导入模块: from Utilities.config import ConfigParser [as 别名]
# 或者: from Utilities.config.ConfigParser import geteval [as 别名]
def __init__(self, configFile):
config = ConfigParser()
config.read(configFile)
self.configFile = configFile
# Define the grid:
gridLimit = config.geteval("Region", "gridLimit")
gridSpace = config.geteval("Region", "GridSpace")
self.lon_range = np.arange(gridLimit["xMin"], gridLimit["xMax"] + 0.1, gridSpace["x"])
self.lat_range = np.arange(gridLimit["yMin"], gridLimit["yMax"] + 0.1, gridSpace["y"])
outputPath = config.get("Output", "Path")
self.trackPath = pjoin(outputPath, "tracks")
self.plotPath = pjoin(outputPath, "plots", "stats")
self.dataPath = pjoin(outputPath, "process")
# Determine TCRM input directory
tcrm_dir = pathLocator.getRootDirectory()
self.inputPath = pjoin(tcrm_dir, "input")
self.synNumYears = config.getint("TrackGenerator", "yearspersimulation")
# Longitude crossing gates:
self.gateLons = np.arange(self.lon_range.min(), self.lon_range.max() + 0.5, 10.0)
self.gateLats = np.arange(self.lat_range.min(), self.lat_range.max() + 0.5, 2.0)
# Add configuration settings to global attributes:
self.gatts = {"history": "Longitude crossing rates for TCRM simulation", "version": flProgramVersion()}
for section in config.sections():
for option in config.options(section):
key = "{0}_{1}".format(section, option)
value = config.get(section, option)
self.gatts[key] = value
示例13: __init__
# 需要导入模块: from Utilities.config import ConfigParser [as 别名]
# 或者: from Utilities.config.ConfigParser import geteval [as 别名]
def __init__(self, configFile):
config = ConfigParser()
config.read(configFile)
self.outputPath = config.get('Output', 'Path')
self.wf_domain = config.geteval('Region', 'gridLimit')
示例14: run
# 需要导入模块: from Utilities.config import ConfigParser [as 别名]
# 或者: from Utilities.config.ConfigParser import geteval [as 别名]
def run(configFile, callback=None):
"""
Run the wind field calculations.
:param str configFile: path to a configuration file.
:param func callback: optional callback function to track progress.
"""
log.info('Loading wind field calculation settings')
# Get configuration
config = ConfigParser()
config.read(configFile)
outputPath = config.get('Output', 'Path')
profileType = config.get('WindfieldInterface', 'profileType')
windFieldType = config.get('WindfieldInterface', 'windFieldType')
beta = config.getfloat('WindfieldInterface', 'beta')
beta1 = config.getfloat('WindfieldInterface', 'beta1')
beta2 = config.getfloat('WindfieldInterface', 'beta2')
thetaMax = config.getfloat('WindfieldInterface', 'thetaMax')
margin = config.getfloat('WindfieldInterface', 'Margin')
resolution = config.getfloat('WindfieldInterface', 'Resolution')
domain = config.get('WindfieldInterface', 'Domain')
windfieldPath = pjoin(outputPath, 'windfield')
trackPath = pjoin(outputPath, 'tracks')
windfieldFormat = 'gust-%i-%04d.nc'
gridLimit = None
if config.has_option('Region','gridLimit'):
gridLimit = config.geteval('Region', 'gridLimit')
if config.has_option('WindfieldInterface', 'gridLimit'):
gridLimit = config.geteval('WindfieldInterface', 'gridLimit')
if config.has_section('Timeseries'):
if config.has_option('Timeseries', 'Extract'):
if config.getboolean('Timeseries', 'Extract'):
from Utilities.timeseries import Timeseries
log.debug("Timeseries data will be extracted")
ts = Timeseries(configFile)
timestepCallback = ts.extract
else:
def timestepCallback(*args):
"""Dummy timestepCallback function"""
pass
thetaMax = math.radians(thetaMax)
# Attempt to start the track generator in parallel
global pp
pp = attemptParallel()
log.info('Running windfield generator')
wfg = WindfieldGenerator(config=config,
margin=margin,
resolution=resolution,
profileType=profileType,
windFieldType=windFieldType,
beta=beta,
beta1=beta1,
beta2=beta2,
thetaMax=thetaMax,
gridLimit=gridLimit,
domain=domain)
msg = 'Dumping gusts to %s' % windfieldPath
log.info(msg)
# Get the trackfile names and count
files = os.listdir(trackPath)
trackfiles = [pjoin(trackPath, f) for f in files if f.startswith('tracks')]
nfiles = len(trackfiles)
def progressCallback(i):
"""Define the callback function"""
callback(i, nfiles)
msg = 'Processing %d track files in %s' % (nfiles, trackPath)
log.info(msg)
# Do the work
pp.barrier()
wfg.dumpGustsFromTrackfiles(trackfiles, windfieldPath, windfieldFormat,
progressCallback, timestepCallback)
try:
ts.shutdown()
except NameError:
pass
pp.barrier()
#.........这里部分代码省略.........