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, 1.) self.lat_range = np.arange(self.gridLimit['yMin'], self.gridLimit['yMax'] + 0.1, 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')
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')
def __init__(self, configFile): config = ConfigParser() config.read(configFile) self.configFile = configFile 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') try: gateFile = config.get('Input', 'CoastlineGates') except NoOptionError: log.exception(("No coastline gate file specified " "in configuration file")) raise gateData = np.genfromtxt(gateFile, delimiter=',') nGates = len(gateData) self.gates = Int.convert2vertex(gateData[:, 1], gateData[:, 2]) self.coast = list(self.gates) self.coast.append(self.gates[0])
def __init__(self, configFile): config = ConfigParser() config.read(configFile) self.configFile = configFile 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') try: gateFile = config.get('Input', 'CoastlineGates') except NoOptionError: LOG.exception(("No coastline gate file specified " "in configuration file")) raise gateData = np.genfromtxt(gateFile, delimiter=',') self.gates = Int.convert2vertex(gateData[:, 1], gateData[:, 2]) self.coast = list(self.gates) self.coast.append(self.gates[0])
def startup(): """ Parse command line arguments and call the :func:`main` function. """ parser = argparse.ArgumentParser() parser.add_argument('-c', '--config_file', help='Path to configuration file') parser.add_argument('-v', '--verbose', help='Verbose output', action='store_true') parser.add_argument('-d', '--debug', help='Allow pdb traces', action='store_true') args = parser.parse_args() configFile = args.config_file config = ConfigParser() config.read(configFile) rootdir = pathLocator.getRootDirectory() os.chdir(rootdir) logfile = config.get('Logging', 'LogFile') logdir = dirname(realpath(logfile)) # If log file directory does not exist, create it if not isdir(logdir): try: os.makedirs(logdir) except OSError: logfile = pjoin(os.getcwd(), 'processMultipliers.log') logLevel = config.get('Logging', 'LogLevel') verbose = config.getboolean('Logging', 'Verbose') datestamp = config.getboolean('Logging', 'Datestamp') debug = False if args.verbose: verbose = True if args.debug: debug = True flStartLog(logfile, logLevel, verbose, datestamp) if debug: main(configFile) else: try: modified_main(configFile) except Exception: # pylint: disable=W0703 # Catch any exceptions that occur and log them (nicely): tblines = traceback.format_exc().splitlines() for line in tblines: log.critical(line.lstrip())
def startup(): parser = argparse.ArgumentParser() parser.add_argument('-c', '--config_file', help='Path to configuration file') parser.add_argument('-v', '--verbose', help='Verbose output', action='store_true') parser.add_argument('-d', '--debug', help='Allow pdb traces', action='store_true') args = parser.parse_args() configFile = args.config_file config = ConfigParser() config.read(configFile) rootdir = pathLocator.getRootDirectory() os.chdir(rootdir) logfile = config.get('Logging','LogFile') logdir = dirname(realpath(logfile)) # If log file directory does not exist, create it if not isdir(logdir): try: os.makedirs(logdir) except OSError: logfile = pjoin(os.getcwd(), 'tcrm.log') logLevel = config.get('Logging', 'LogLevel') verbose = config.getboolean('Logging', 'Verbose') debug = False if args.verbose: verbose = True if args.debug: debug = True flStartLog(logfile, logLevel, verbose) # Switch off minor warning messages import warnings warnings.filterwarnings("ignore", category=DeprecationWarning) warnings.filterwarnings("ignore", category=UserWarning, module="pytz") warnings.filterwarnings("ignore", category=UserWarning, module="numpy") warnings.filterwarnings("ignore", category=UserWarning, module="matplotlib") warnings.filterwarnings("ignore", category=RuntimeWarning) if debug: main(configFile) else: try: main(configFile) except Exception: # pylint: disable=W0703 # Catch any exceptions that occur and log them (nicely): tblines = traceback.format_exc().splitlines() for line in tblines: log.critical(line.lstrip())
def plotCurves(self): """Plot hazard curves for speified locations""" tcrm_dir = pathLocator.getRootDirectory() localitiesDataFile = pjoin(tcrm_dir, 'input', 'localities.dat') self.sqlcon = sqlite3.connect(localitiesDataFile) self.sqlcur = self.sqlcon.cursor() self.plotHazardCurves(self.inputFile, self.plotPath) self.progressbar.update(1.0)
def startup(): """ Parse command line arguments and call the :func:`main` function. """ parser = argparse.ArgumentParser() parser.add_argument('-c', '--config_file', help='Path to configuration file') parser.add_argument('-v', '--verbose', help='Verbose output', action='store_true') parser.add_argument('-d', '--debug', help='Allow pdb traces', action='store_true') args = parser.parse_args() config_file = args.config_file config = ConfigParser() config.read(config_file) rootdir = pathLocator.getRootDirectory() os.chdir(rootdir) logfile = config.get('Logging', 'LogFile') logdir = dirname(realpath(logfile)) # If log file directory does not exist, create it if not isdir(logdir): try: os.makedirs(logdir) except OSError: logfile = pjoin(os.getcwd(), 'tsmultipliers.log') logLevel = config.get('Logging', 'LogLevel') verbose = config.getboolean('Logging', 'Verbose') datestamp = config.getboolean('Logging', 'Datestamp') debug = False if args.verbose: verbose = True if args.debug: debug = True flStartLog(logfile, logLevel, verbose, datestamp) if debug: process_timeseries(config_file) else: try: process_timeseries(config_file) except Exception: # pylint: disable=W0703 # Catch any exceptions that occur and log them (nicely): tblines = traceback.format_exc().splitlines() for line in tblines: log.critical(line.lstrip()) log.info("Completed {0}".format(sys.argv[0]))
def __init__(self, configFile, progressbar=None): """ Initialize the data include tool instance, Nan value and all full path names of the files in which data will be stored. """ #CalcTD = CalcTrackDomain(configFile) #self.domain = CalcTD.calc() self.configFile = configFile self.progressbar = progressbar self.logger = logging.getLogger(__name__) self.logger.info("Initialising DataProcess") config = ConfigParser() config.read(configFile) self.outputPath = config.get('Output', 'Path') self.processPath = pjoin(self.outputPath, 'process') # Determine TCRM input directory tcrm_dir = pathLocator.getRootDirectory() self.tcrm_input_dir = pjoin(tcrm_dir, 'input') landmask = config.get('Input', 'LandMask') self.landmask = SampleGrid(landmask) fmt = config.get('Output', 'Format') self.ncflag = False if fmt.startswith("nc"): self.logger.debug("Output format is netcdf") self.ncflag = True self.data = {} #dimensions = {records} # variables = {init_index(records), # genesis_index(records), # non_init_index(records), # lon(records), lat(records), # year(records), month(records), # day(records), hour(records), # minute(records), julianday(records), # bearing(records), speed(records), # pressure(records), lsflag(records), } # global_attributes = dict(description= # source_file=, # source_file_moddate, # landmask_file=, # version=,) elif fmt.startswith("txt"): self.logger.debug("Output format is text") self.origin_year = pjoin(self.processPath, 'origin_year')
def __init__(self, configFile, progressbar=None): #CalcTD = CalcTrackDomain(configFile) #self.domain = CalcTD.calc() self.configFile = configFile self.progressbar = progressbar self.logger = logging.getLogger(__name__) self.logger.info("Initialising DataProcess") config = ConfigParser() config.read(configFile) self.outputPath = config.get('Output', 'Path') self.processPath = pjoin(self.outputPath, 'process') # Determine TCRM input directory tcrm_dir = pathLocator.getRootDirectory() self.tcrm_input_dir = pjoin(tcrm_dir, 'input') landmask = config.get('Input', 'LandMask') self.landmask = SampleGrid(landmask) fmt = config.get('Output', 'Format') self.ncflag = False if fmt.startswith("nc"): self.logger.debug("Output format is netcdf") self.ncflag = True self.data = {} #dimensions = {records} # variables = {init_index(records), # genesis_index(records), # non_init_index(records), # lon(records), lat(records), # year(records), month(records), # day(records), hour(records), # minute(records), julianday(records), # bearing(records), speed(records), # pressure(records), lsflag(records), } # global_attributes = dict(description= # source_file=, # source_file_moddate, # landmask_file=, # version=,) elif fmt.startswith("txt"): self.logger.debug("Output format is text") self.origin_year = pjoin(self.processPath, 'origin_year')
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
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
def __init__(self, configFile): """ Calculate central pressure distributions on a grid :param str configFile: path to a TCRM configuration file. """ config = ConfigParser() config.read(configFile) self.configFile = configFile # Determine TCRM input directory tcrm_dir = pathLocator.getRootDirectory() self.inputPath = pjoin(tcrm_dir, 'input') # 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']) self.gridLimit = gridLimit outputPath = config.get('Output', 'Path') self.trackPath = pjoin(outputPath, 'tracks') self.plotPath = pjoin(outputPath, 'plots', 'stats') self.dataPath = pjoin(outputPath, 'process') 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
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
def __init__(self, selected_months, filename=''): if not os.path.isfile(filename): tcrm_dir = pathLocator.getRootDirectory() filename = os.path.join(tcrm_dir, 'MSLP', 'mslp_monthly_clim.nc') if not os.path.isfile(filename): error_msg = "MSLP data file not found" raise IOError(error_msg) selected_months = set(selected_months) ncobj = nctools.ncLoadFile(filename) mslp_all = nctools.ncGetData(ncobj, 'mslp') self.lon = nctools.ncGetDims(ncobj, 'lon') self.lat = nctools.ncGetDims(ncobj, 'lat') dim0, dim1, dim2 = np.shape(mslp_all) # Average over selected months mslp_sum = np.zeros([dim1, dim2], dtype='float32') for month in selected_months: mslp_sum = mslp_sum + mslp_all[month - 1, :, :] self.mslp_av = np.flipud(mslp_sum / len(selected_months))
def __init__(self, selected_months, filename=''): if not os.path.isfile(filename): tcrm_dir = pathLocator.getRootDirectory() filename = os.path.join(tcrm_dir, 'MSLP', 'mslp_monthly_clim.nc') if not os.path.isfile(filename): error_msg = "MSLP data file not found" raise IOError, error_msg selected_months = set(selected_months) ncobj = nctools.ncLoadFile(filename) mslp_all = nctools.ncGetData(ncobj, 'mslp') self.lon = nctools.ncGetDims(ncobj, 'lon') self.lat = nctools.ncGetDims(ncobj, 'lat') dim0,dim1,dim2 = shape(mslp_all) # Average over selected months mslp_sum = zeros([dim1,dim2],dtype='float32') for month in selected_months: mslp_sum = mslp_sum + mslp_all[month-1,:,:] self.mslp_av = flipud(mslp_sum / len(selected_months))
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
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
def startup(): """ Parse the command line arguments and call the :func:`main` function. """ parser = argparse.ArgumentParser() parser.add_argument('-c', '--config_file', help='Path to configuration file') parser.add_argument('-v', '--verbose', help='Verbose output', action='store_true') parser.add_argument('-d', '--debug', help='Allow pdb traces', action='store_true') args = parser.parse_args() configFile = args.config_file config = ConfigParser() config.read(configFile) rootdir = pathLocator.getRootDirectory() os.chdir(rootdir) logfile = config.get('Logging', 'LogFile') logdir = dirname(realpath(logfile)) # If log file directory does not exist, create it if not isdir(logdir): try: os.makedirs(logdir) except OSError: logfile = pjoin(os.getcwd(), 'tcrm.log') logLevel = config.get('Logging', 'LogLevel') verbose = config.getboolean('Logging', 'Verbose') datestamp = config.getboolean('Logging', 'Datestamp') debug = False if args.verbose: verbose = True if args.debug: debug = True flStartLog(logfile, logLevel, verbose, datestamp) # Switch off minor warning messages import warnings warnings.filterwarnings("ignore", category=DeprecationWarning) warnings.filterwarnings("ignore", category=UserWarning, module="pytz") warnings.filterwarnings("ignore", category=UserWarning, module="numpy") warnings.filterwarnings("ignore", category=UserWarning, module="matplotlib") warnings.filterwarnings("ignore", category=RuntimeWarning) if debug: main(configFile) else: try: main(configFile) except ImportError as e: log.critical("Missing module: {0}".format(e.strerror)) except Exception: # pylint: disable=W0703 # Catch any exceptions that occur and log them (nicely): tblines = traceback.format_exc().splitlines() for line in tblines: log.critical(line.lstrip())
def startup(): """ Parse command line arguments, set up logging and attempt to execute the main TCRM functions. """ parser = argparse.ArgumentParser() parser.add_argument('-c', '--config_file', help='The configuration file') parser.add_argument('-v', '--verbose', help='Verbose output', action='store_true') parser.add_argument('-d', '--debug', help='Allow pdb traces', action='store_true') args = parser.parse_args() configFile = args.config_file rootdir = pathLocator.getRootDirectory() os.chdir(rootdir) config = ConfigParser() config.read(configFile) logfile = config.get('Logging', 'LogFile') logdir = dirname(realpath(logfile)) # If log file directory does not exist, create it if not isdir(logdir): try: os.makedirs(logdir) except OSError: logfile = pjoin(os.getcwd(), 'tcrm.log') logLevel = config.get('Logging', 'LogLevel') verbose = config.getboolean('Logging', 'Verbose') datestamp = config.getboolean('Logging', 'Datestamp') debug = False if args.verbose: verbose = True if args.debug: debug = True global MPI, comm MPI = attemptParallel() import atexit atexit.register(MPI.Finalize) comm = MPI.COMM_WORLD if comm.size > 1 and comm.rank > 0: logfile += '-' + str(comm.rank) verbose = False # to stop output to console else: pass #codeStatus = status() #print __doc__ + codeStatus flStartLog(logfile, logLevel, verbose, datestamp) # Switch off minor warning messages import warnings warnings.filterwarnings("ignore", category=DeprecationWarning) warnings.filterwarnings("ignore", category=UserWarning, module="pytz") warnings.filterwarnings("ignore", category=UserWarning, module="numpy") warnings.filterwarnings("ignore", category=UserWarning, module="matplotlib") warnings.filterwarnings("ignore", category=RuntimeWarning) checkModules() if debug: main(configFile) else: try: main(configFile) except ImportError as e: log.critical("Missing module: {0}".format(e)) tblines = traceback.format_exc().splitlines() for line in tblines: log.critical(line.lstrip()) except Exception: # pylint: disable=W0703 # Catch any exceptions that occur and log them (nicely): tblines = traceback.format_exc().splitlines() for line in tblines: log.critical(line.lstrip())
from os.path import join as pjoin, realpath, isdir, dirname from functools import wraps from Utilities.progressbar import SimpleProgressBar as ProgressBar from Utilities.files import flStartLog, flLoadFile from Utilities.config import ConfigParser from Utilities.parallel import attemptParallel, disableOnWorkers from Utilities.version import version from Utilities import pathLocator import matplotlib matplotlib.use('Agg') # Use matplotlib backend # Set Basemap data path if compiled with py2exe if pathLocator.is_frozen(): os.environ['BASEMAPDATA'] = pjoin( pathLocator.getRootDirectory(), 'mpl-data', 'data') def checkModules(): """ Check that compiled extensions are available :param list moduleList: list of modules to check for :return: """ try: import Utilities.akima log.debug("Compiled modules were found.") except ImportError: log.critical("Unable to import compiled modules. " "Make sure to compile the extensions using "
def __init__(self): """ Parse command line arguments and call the :func:`main` function. """ parser = argparse.ArgumentParser() parser.add_argument('-c', '--config_file', help='Path to configuration file') parser.add_argument('-v', '--verbose', help='Verbose output', action='store_true') parser.add_argument('-d', '--debug', help='Allow pdb traces', action='store_true') args = parser.parse_args() self.configFile = args.config_file config = ConfigParser() config.read(self.configFile) logfile = config.get('Logging', 'LogFile') logdir = dirname(realpath(logfile)) # If log file directory does not exist, create it if not isdir(logdir): try: os.makedirs(logdir) except OSError: logfile = pjoin(os.getcwd(), 'processMultipliers.log') logLevel = config.get('Logging', 'LogLevel') verbose = config.getboolean('Logging', 'Verbose') datestamp = config.getboolean('Logging', 'Datestamp') if args.verbose: verbose = True flStartLog(logfile, logLevel, verbose, datestamp) # Switch off minor warning messages import warnings warnings.filterwarnings("ignore", category=DeprecationWarning) warnings.filterwarnings("ignore", category=UserWarning, module="pytz") warnings.filterwarnings("ignore", category=UserWarning, module="numpy") warnings.filterwarnings("ignore", category=UserWarning, module="matplotlib") warnings.filterwarnings("ignore", category=RuntimeWarning) self.working_dir = config.get('Output', 'Working_dir') self.gust_file = config.get('Input', 'Gust_file') tiles = config.get('Input', 'Tiles') self.tiles = [item.strip() for item in tiles.split(',')] log.debug('List of tiles to be processed: {0}'.format(self.tiles)) log.info('Multipliers will be written out to %s', self.working_dir) # Get the multipliers, and process them if need be self.type_mapping = { 'shielding': 'Ms', 'terrain': 'Mz', 'topographic': 'Mt' } self.dirns = ['e', 'n', 'ne', 'nw', 's', 'se', 'sw', 'w'] rootdir = pathLocator.getRootDirectory() os.chdir(rootdir) try: self.main() except ImportError as e: log.critical("Missing module: {0}".format(e.strerror)) except Exception: # pylint: disable=W0703 # Catch any exceptions that occur and log them (nicely): tblines = traceback.format_exc().splitlines() for line in tblines: log.critical(line.lstrip())
def startup(): """ Parse command line arguments, set up logging and attempt to execute the main TCRM functions. """ parser = argparse.ArgumentParser() parser.add_argument('-c', '--config_file', help='The configuration file') parser.add_argument('-v', '--verbose', help='Verbose output', action='store_true') parser.add_argument('-d', '--debug', help='Allow pdb traces', action='store_true') args = parser.parse_args() configFile = args.config_file rootdir = pathLocator.getRootDirectory() os.chdir(rootdir) config = ConfigParser() config.read(configFile) logfile = config.get('Logging', 'LogFile') logdir = dirname(realpath(logfile)) # If log file directory does not exist, create it if not isdir(logdir): try: os.makedirs(logdir) except OSError: logfile = pjoin(os.getcwd(), 'tcrm.log') logLevel = config.get('Logging', 'LogLevel') verbose = config.getboolean('Logging', 'Verbose') datestamp = config.getboolean('Logging', 'Datestamp') debug = False if args.verbose: verbose = True #if not verbose: # logLevel = 'ERROR' # verbose = True if args.debug: debug = True global pp pp = attemptParallel() import atexit atexit.register(pp.finalize) if pp.size() > 1 and pp.rank() > 0: logfile += '-' + str(pp.rank()) verbose = False # to stop output to console else: pass #codeStatus = status() #print __doc__ + codeStatus flStartLog(logfile, logLevel, verbose, datestamp) # Switch off minor warning messages import warnings warnings.filterwarnings("ignore", category=DeprecationWarning) warnings.filterwarnings("ignore", category=UserWarning, module="pytz") warnings.filterwarnings("ignore", category=UserWarning, module="numpy") warnings.filterwarnings("ignore", category=UserWarning, module="matplotlib") warnings.filterwarnings("ignore", category=RuntimeWarning) if debug: main(configFile) else: try: main(configFile) except Exception: # pylint: disable=W0703 # Catch any exceptions that occur and log them (nicely): tblines = traceback.format_exc().splitlines() for line in tblines: log.critical(line.lstrip())
import sys import os from os.path import join as pjoin, realpath, isdir, dirname, abspath from functools import wraps from Utilities.progressbar import SimpleProgressBar as ProgressBar from Utilities.files import flStartLog, flLoadFile, flModDate from Utilities.config import ConfigParser from Utilities.parallel import attemptParallel, disableOnWorkers from Utilities import pathLocator # Set Basemap data path if compiled with py2exe if pathLocator.is_frozen(): os.environ['BASEMAPDATA'] = pjoin( pathLocator.getRootDirectory(), 'mpl-data', 'data') UPDATE_MSG = """ ---------------------------------------------------------- Your TCRM version is not up-to-date. The last 3 things that have been fixed are: %s To update your version of TCRM, try running: git pull ---------------------------------------------------------- """
from os.path import join as pjoin, realpath, isdir, dirname from functools import wraps from Utilities.progressbar import SimpleProgressBar as ProgressBar from Utilities.files import flStartLog, flLoadFile from Utilities.config import ConfigParser from Utilities.parallel import attemptParallel, disableOnWorkers from Utilities.version import version from Utilities import pathLocator import matplotlib matplotlib.use('Agg', warn=False) # Use matplotlib backend # Set Basemap data path if compiled with py2exe if pathLocator.is_frozen(): os.environ['BASEMAPDATA'] = pjoin(pathLocator.getRootDirectory(), 'mpl-data', 'data') def timer(f): """ A simple timing decorator for the entire process. """ @wraps(f) def wrap(*args, **kwargs): t1 = time.time() res = f(*args, **kwargs) tottime = time.time() - t1 msg = "%02d:%02d:%02d " % \