本文整理汇总了Python中Utilities.config.ConfigParser类的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser类的具体用法?Python ConfigParser怎么用?Python ConfigParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: doDataDownload
def doDataDownload(configFile):
"""
Check and download the data files.
:param str configFile: Name of configuration file.
"""
log.info('Checking availability of input data sets')
config = ConfigParser()
config.read(configFile)
showProgressBar = config.get('Logging', 'ProgressBar')
for dataset in datasets.DATASETS:
if not dataset.isDownloaded():
log.info('Input file %s is not available', dataset.filename)
try:
log.info('Attempting to download %s', dataset.filename)
pbar = ProgressBar('Downloading file %s: ' % dataset.filename,
showProgressBar)
def status(fn, done, size):
pbar.update(float(done)/size)
dataset.download(status)
log.info('Download successful')
except IOError:
log.error('Unable to download %s. Maybe a proxy problem?',
dataset.filename)
sys.exit(1)
示例2: doTrackGeneration
def doTrackGeneration(configFile):
"""
Do the tropical cyclone track generation.
The track generation settings are read from *configFile*.
:param str configFile: Name of configuration file.
"""
log.info('Starting track generation')
config = ConfigParser()
config.read(configFile)
showProgressBar = config.get('Logging', 'ProgressBar')
pbar = ProgressBar('Simulating cyclone tracks: ', showProgressBar)
def status(done, total):
pbar.update(float(done)/total)
import TrackGenerator
TrackGenerator.run(configFile, status)
pbar.update(1.0)
log.info('Completed track generation')
示例3: doHazard
def doHazard(configFile):
"""
Do the hazard calculations (extreme value distribution fitting)
using the :mod:`hazard` module.
:param str configFile: Name of configuration file.
"""
log.info('Running HazardInterface')
config = ConfigParser()
config.read(configFile)
showProgressBar = config.get('Logging', 'ProgressBar')
pbar = ProgressBar('Performing hazard calculations: ', showProgressBar)
def status(done, total):
pbar.update(float(done)/total)
import hazard
hazard.run(configFile)
log.info('Completed HazardInterface')
pbar.update(1.0)
示例4: doHazardPlotting
def doHazardPlotting(configFile):
"""
Do the hazard plots (hazard maps and curves for all locations within
the model domain). Plotting is performed by the
:mod:`PlotInterface.AutoPlotHazard` module.
:param str configFile: Name of configuration file.
"""
import matplotlib
matplotlib.use('Agg') # Use matplotlib backend
config = ConfigParser()
config.read(configFile)
log.info('Plotting Hazard Maps')
showProgressBar = config.get('Logging', 'ProgressBar')
pbar = ProgressBar('Plotting hazard maps: ', showProgressBar)
pbar.update(0.0)
from PlotInterface.AutoPlotHazard import AutoPlotHazard
plotter = AutoPlotHazard(configFile, progressbar=pbar)
plotter.plotMap()
plotter.plotCurves()
pbar.update(1.0)
示例5: historic
def historic(self):
"""Load historic data and calculate histogram"""
config = ConfigParser()
config.read(self.configFile)
inputFile = config.get('DataProcess', 'InputFile')
if len(os.path.dirname(inputFile)) == 0:
inputFile = pjoin(self.inputPath, inputFile)
source = config.get('DataProcess', 'Source')
try:
tracks = loadTrackFile(self.configFile, inputFile,source)
except (TypeError, IOError, ValueError):
log.critical("Cannot load historical track file: {0}".format(inputFile))
raise
else:
startYr = 9999
endYr = 0
for t in tracks:
startYr = min(startYr, min(t.Year))
endYr = max(endYr, max(t.Year))
numYears = endYr - startYr
log.info("Range of years: %d - %d" % (startYr, endYr))
self.hist = self._calculate(tracks) / numYears
示例6: doHazardPlotting
def doHazardPlotting(configFile):
"""
Do the hazard plots.
:param str configFile: Name of configuration file.
"""
import matplotlib
matplotlib.use('Agg') # Use matplotlib backend
config = ConfigParser()
config.read(configFile)
log.info('Plotting Hazard Maps')
showProgressBar = config.get('Logging', 'ProgressBar')
pbar = ProgressBar('Plotting hazard maps: ', showProgressBar)
pbar.update(0.0)
from PlotInterface.AutoPlotHazard import AutoPlotHazard
plotter = AutoPlotHazard(configFile, progressbar=pbar)
plotter.plotMap()
plotter.plotCurves()
pbar.update(1.0)
示例7: doOutputDirectoryCreation
def doOutputDirectoryCreation(configFile):
"""
Create all the necessary output folders.
:param str configFile: Name of configuration file.
:raises OSError: If the directory tree cannot be created.
"""
config = ConfigParser()
config.read(configFile)
outputPath = config.get('Output', 'Path')
log.info('Output will be stored under %s', outputPath)
subdirs = ['tracks', 'windfield', 'plots', 'plots/timeseries',
'log', 'process', 'process/timeseries']
if not isdir(outputPath):
try:
os.makedirs(outputPath)
except OSError:
raise
for subdir in subdirs:
if not isdir(realpath(pjoin(outputPath, subdir))):
try:
os.makedirs(realpath(pjoin(outputPath, subdir)))
except OSError:
raise
示例8: __init__
def __init__(self, configFile, kdeType, gridLimit, kdeStep, lonLat=None, progressbar=None):
"""
"""
self.logger = logging.getLogger()
self.progressbar = progressbar
if self.progressbar:
KPDF.set_callback(self.updateProgressBar)
self.logger.info("Initialising KDEOrigins")
self.configFile = configFile
self.x = numpy.arange(gridLimit['xMin'], gridLimit['xMax'], kdeStep)
self.y = numpy.arange(gridLimit['yMax'], gridLimit['yMin'], -kdeStep)
self.kdeType = kdeType
self.kdeStep = kdeStep
config = ConfigParser()
config.read(configFile)
if lonLat is None:
self.outputPath = config.get('Output', 'Path')
self.processPath = os.path.join(self.outputPath, 'process')
self.logger.debug("Loading "+os.path.join(self.processPath,
'init_lon_lat'))
ll = flLoadFile(os.path.join(self.processPath, 'init_lon_lat'),
'%', ',')
self.lonLat = ll[:,0:2]
else:
self.lonLat = lonLat[:,0:2]
self.bw = KPDF.MPDFOptimumBandwidth(self.lonLat)
self.logger.debug("Optimal bandwidth: %f"%self.bw)
示例9: doWindfieldCalculations
def doWindfieldCalculations(configFile):
"""
Do the wind field calculations. The wind field settings are read
from *configFile*.
:param str configFile: Name of configuration file.
"""
log.info('Starting wind field calculations')
config = ConfigParser()
config.read(configFile)
showProgressBar = config.get('Logging', 'ProgressBar')
pbar = ProgressBar('Calculating wind fields: ', showProgressBar)
def status(done, total):
pbar.update(float(done)/total)
import wind
wind.run(configFile, status)
pbar.update(1.0)
log.info('Completed wind field calculations')
示例10: __init__
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')
示例11: doDataDownload
def doDataDownload(configFile):
"""
Check and download the data files listed in the configuration file.
Datasets are listed in the `Input` section of the configuration
file, with the option `Datasets`. There must also be a corresponding
section in the configuration file that inlcudes the url, path where
the dataset will be stored and the filename that will be stored, e.g.::
[Input]
Datasets=IBTRACS
[IBTRACS]
URL=ftp://eclipse.ncdc.noaa.gov/pub/ibtracs/v03r05/wmo/csv/Allstorms.ibtracs_wmo.v03r05.csv.gz
filename=Allstorms.ibtracs_wmo.v03r05.csv
path=input
This will attempt to download the gzipped csv file from the given URL
and save it to the given filename, in the 'input' folder under the current
directory. Gzipped files are automatically unzipped.
:param str configFile: Name of configuration file.
:raises IOError: If the data cannot be downloaded.
"""
log.info('Checking availability of input data sets')
config = ConfigParser()
config.read(configFile)
showProgressBar = config.get('Logging', 'ProgressBar')
datasets.loadDatasets(configFile)
for dataset in datasets.DATASETS:
if not dataset.isDownloaded():
log.info('Input file %s is not available', dataset.filename)
try:
log.info('Attempting to download %s', dataset.filename)
pbar = ProgressBar('Downloading file %s: ' % dataset.filename,
showProgressBar)
def status(fn, done, size):
pbar.update(float(done)/size)
dataset.download(status)
log.info('Download successful')
except IOError:
log.error('Unable to download %s. Maybe a proxy problem?',
dataset.filename)
sys.exit(1)
示例12: doTimeseriesPlotting
def doTimeseriesPlotting(configFile):
"""
Run functions to plot time series output
"""
config = ConfigParser()
config.read(configFile)
outputPath = config.get('Output', 'Path')
timeseriesPath = pjoin(outputPath, 'process', 'timeseries')
plotPath = pjoin(outputPath, 'plots', 'timeseries')
log.info("Plotting time series data to %s" % plotPath)
from PlotInterface.plotTimeseries import plotTimeseries
plotTimeseries(timeseriesPath, plotPath)
示例13: doStatistics
def doStatistics(configFile):
"""
Calibrate the model.
:param str configFile: Name of configuration file.
"""
from DataProcess.CalcTrackDomain import CalcTrackDomain
config = ConfigParser()
config.read(configFile)
showProgressBar = config.get('Logging', 'ProgressBar')
getRMWDistFromInputData = config.getboolean('RMW',
'GetRMWDistFromInputData')
log.info('Running StatInterface')
pbar = ProgressBar('Calibrating model: ', showProgressBar)
# Auto-calculate track generator domain
CalcTD = CalcTrackDomain(configFile)
domain = CalcTD.calcDomainFromFile()
pbar.update(0.05)
from StatInterface import StatInterface
statInterface = StatInterface.StatInterface(configFile,
autoCalc_gridLimit=domain)
statInterface.kdeGenesisDate()
pbar.update(0.4)
statInterface.kdeOrigin()
pbar.update(0.5)
statInterface.cdfCellBearing()
pbar.update(0.6)
statInterface.cdfCellSpeed()
pbar.update(0.7)
statInterface.cdfCellPressure()
pbar.update(0.8)
statInterface.calcCellStatistics()
if getRMWDistFromInputData:
statInterface.cdfCellSize()
pbar.update(1.0)
log.info('Completed StatInterface')
示例14: __init__
def __init__(self, configFile, dt):
"""
Initialise required fields
"""
self.configFile = configFile
config = ConfigParser()
config.read(configFile)
landMaskFile = config.get('Input', 'LandMask')
self.landMask = SampleGrid(landMaskFile)
self.tol = 0 # Time over land
self.dt = dt
示例15: __init__
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