Beispiel #1
0
    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
Beispiel #2
0
    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')
        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.maxsize)

        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
Beispiel #3
0
def main(argv):
    """
    Main part of the program

    :param list argv: List of command line arguments.

    """
    gConfigFile = flConfigFile()
    #logFile = flConfigFile(".log")
    #verbose = False
    logger = logging.getLogger()

    try:
        opts, args = getopt.getopt(argv, "hc:l:v",
                                   ["help", "config=", "logfile=", "verbose"])
    except getopt.GetoptError:
        ShowSyntax(2)

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            ShowSyntax()
            sys.exit(2)
        elif opt in ("-c", "--config"):
            gConfigFile = arg
        elif opt in ("-l", "--logfile"):
            logFile = arg
        elif opt in ("-v", "--verbose"):
            verbose = True

    flStartLog(
        cnfGetIniValue(gConfigFile, 'Logging', 'LogFile',
                       flConfigFile('.log')),
        cnfGetIniValue(gConfigFile, 'Logging', 'LogLevel', 'INFO'),
        cnfGetIniValue(gConfigFile, 'Logging', 'Verbose', False))

    inputFile = cnfGetIniValue(gConfigFile, 'Input', 'File')
    logger.info("Processing {0}".format(inputFile))
    source = cnfGetIniValue(gConfigFile, 'Input', 'Source')
    delta = cnfGetIniValue(gConfigFile, 'Output', 'Delta', 0.1)

    nid, newtime, newdates, nLon, nLat, nthetaFm, \
        nvFm, npCentre, npEnv, nrMax = \
                    interpolateTrack(gConfigFile, inputFile, source, delta)
    #header = ''
    outputFile = cnfGetIniValue(gConfigFile, 'Output', 'File')
    logger.info("Saving interpolated data to {0}".format(outputFile))
    fh = open(outputFile, 'w')
    for i in xrange(len(newtime)):
        fh.write("%d,%5.1f,%s,%6.2f,%6.2f,%6.2f,%6.2f,%7.2f,%7.2f,%5.1f\n" %
                 (nid[i], newtime[i], newdates[i].strftime("%Y-%m-%d %H:%M"),
                  nLon[i], nLat[i], nthetaFm[i], nvFm[i], npCentre[i],
                  npEnv[i], nrMax[i]))
    fh.close()
    logger.info("Completed {0}".format(sys.argv[0]))
Beispiel #4
0
    def __init__(self, configFile, gridLimit, gridSpace, gridInc, kdeType,
                 minSamplesCell=40, missingValue=sys.maxsize):
        """
        Initialise required fields
        """
        self.logger = logging.getLogger()

        self.logger.info("Initialising GenerateDistributions")
        self.gridSpace = gridSpace
        self.gridLimit = gridLimit
        self.gridInc = gridInc
        self.kdeType = kdeType
        self.minSamplesCell = minSamplesCell
        self.outputPath = cnfGetIniValue(configFile, 'Output', 'Path')
        self.kdeParameter = KDEParameters.KDEParameters(kdeType)

        self.missingValue = missingValue
Beispiel #5
0
    def __init__(self, configFile, gridLimit, gridSpace, gridInc, kdeType,
                 minSamplesCell=40, missingValue=sys.maxint):
        """
        Initialise required fields
        """
        self.logger = logging.getLogger()
        
        self.logger.info("Initialising GenerateDistributions")
        self.gridSpace = gridSpace
        self.gridLimit = gridLimit
        self.gridInc = gridInc
        self.kdeType = kdeType
        self.minSamplesCell = minSamplesCell
        self.outputPath = cnfGetIniValue(configFile, 'Output', 'Path')
        self.kdeParameter = KDEParameters.KDEParameters(kdeType)

        self.missingValue = missingValue
Beispiel #6
0
if __name__ == "__main__":
    try:
        configFile = sys.argv[1]
    except IndexError:
        # Try loading config file with same name as python script
        configFile = __file__.rstrip('.py') + '.ini'
        # If no filename is specified and default filename doesn't exist => raise error
        if not os.path.exists(configFile):
            error_msg = "No configuration file specified, please type: python main.py {config filename}.ini"
            raise IOError, error_msg
    # If config file doesn't exist => raise error
    if not os.path.exists(configFile):
        error_msg = "Configuration file '" + configFile +"' not found"
        raise IOError, error_msg

    flStartLog(cnfGetIniValue(configFile, 'Logging', 'LogFile', __file__.rstrip('.py') + '.log'),
               cnfGetIniValue(configFile, 'Logging', 'LogLevel', 'DEBUG'),
               cnfGetIniValue(configFile, 'Logging', 'Verbose', True))
    path = cnfGetIniValue(configFile, 'Output', 'Path')

    gridLimit = eval(cnfGetIniValue(configFile, 'Region', 'gridLimit'))
    gridSpace = eval(cnfGetIniValue(configFile, 'Region', 'gridSpace'))
    gridInc = eval(cnfGetIniValue(configFile, 'Region', 'gridInc'))
    kdeType = cnfGetIniValue(configFile, 'StatInterface', 'kdeType')
    kdeStep = cnfGetIniValue(configFile, 'StatInterface', 'kdeStep', 0.1)
    minSamplesCell = cnfGetIniValue(configFile, 'StatInterface',
                                    'minSamplesCell', 100)
    missingValue = cnfGetIniValue(configFile, 'StatInterface',
                                  'MissingValue', sys.maxint)
    gDist = GenerateDistributions(configFile, gridLimit, gridSpace, gridInc, kdeType,
                                  minSamplesCell, missingValue)
Beispiel #7
0
def loadTrackFile(configFile, trackFile, source, missingValue=0,
                  calculateWindSpeed=True):
    """
    Load TC track data from the given input file, from a specified source.
    The configFile is a configuration file that contains a section called
    'source' that describes the data.
    This returns a collection of :class:`Track` objects that contains
    the details of the TC tracks in the input file.

    :param str configFile: Configuration file with a section ``source``.
    :param str trackFile: Path to a csv-formatted file containing TC data.
    :pararm str source: Name of the source format of the TC data. There
                        *must* be a section in ``configFile`` matching
                        this string, containing the details of the format
                        of the data.
    :param missingValue: Replace all null values in the input data with
                         this value (default=0).
    :param boolean calculateWindSpeed: Calculate maximum wind speed using
                                       a pressure-wind relation described
                                       in :func:`maxWindSpeed`

    :returns: A collection of :class:`Track` objects. 
              If any of the variables are not present in the input
              dataset, they are (where possible) calculated
              (date/time/windspeed), sampled from default datasets
              (e.g. environmental pressure) or set to the missing value.

    Example::

      >>> tracks = loadTrackFile('tcrm.ini', 'IBTRaCS.csv', 'IBTrACS' )

    """
    
    logger.info("Loading %s" % trackFile)
    inputData = colReadCSV(configFile, trackFile, source) #,
                          #nullValue=missingValue)

    config = ConfigParser()
    config.read(configFile)

    inputSpeedUnits = config.get(source, 'SpeedUnits')
    inputPressureUnits = config.get(source, 'PressureUnits')
    inputLengthUnits = config.get(source, 'LengthUnits')
    inputDateFormat = config.get(source, 'DateFormat')
    
    if config.getboolean('DataProcess', 'FilterSeasons'):
        startSeason = config.getint('DataProcess', 'StartSeason')        
        idx = np.where(inputData['season'] >= startSeason)[0]
        inputData = inputData[idx]
        
    # Determine the initial TC positions...
    indicator = getInitialPositions(inputData)


    # Sort date/time information
    if 'age' in inputData.dtype.names:
        year, month, day, hour, minute, datetimes = parseAge(inputData, indicator)
        timeElapsed = inputData['age']
    else:
        year, month, day, hour, minute, datetimes = parseDates(inputData, indicator,
                                                    inputDateFormat)
        timeElapsed = getTimeElapsed(indicator, year, month, day, hour, minute)
        
    # Time between observations:
    dt = getTimeDelta(year, month, day, hour, minute)

    # Calculate julian days
    jdays = julianDays(year, month, day, hour, minute)

    lat = np.array(inputData['lat'], 'd')
    lon = np.mod(np.array(inputData['lon'], 'd'), 360)
    delta_lon = np.diff(lon)
    delta_lat = np.diff(lat)

    # Split into separate tracks if large jump occurs (delta_lon > 10 degrees
    # or delta_lat > 5 degrees)
    # This avoids two tracks being accidentally combined when seasons and track
    # numbers match but basins are different as occurs in the IBTrACS dataset.
    # This problem can also be prevented if the 'tcserialno' column is
    # specified.
    indicator[np.where(delta_lon > 10)[0] + 1] = 1
    indicator[np.where(delta_lat > 5)[0] + 1] = 1

    pressure = filterPressure(np.array(inputData['pressure'], 'd'),
                              inputPressureUnits, missingValue)
    try:
        windspeed = np.array(inputData['vmax'], 'd')
        novalue_index = np.where(windspeed == sys.maxint)
        windspeed = metutils.convert(windspeed, inputSpeedUnits, "mps")
        windspeed[novalue_index] = missingValue
    except (ValueError,KeyError):
        logger.debug("No max wind speed data - all values will be zero")
        windspeed = np.zeros(indicator.size, 'f')
    assert lat.size == indicator.size
    assert lon.size == indicator.size
    assert pressure.size == indicator.size

    try:
        rmax = np.array(inputData['rmax'])
        novalue_index = np.where(rmax == missingValue)
        rmax = metutils.convert(rmax, inputLengthUnits, "km")
        rmax[novalue_index] = missingValue

    except (ValueError, KeyError):
        logger.debug("No radius to max wind data - all values will be zero")
        rmax = np.zeros(indicator.size, 'f')

    if 'penv' in inputData.dtype.names:
        penv = np.array(inputData['penv'], 'd')
    else:
        logger.debug("No ambient MSLP data in this input file")
        logger.debug("Sampling data from MSLP data defined in "
                    "configuration file")
        # Warning: using sampled data will likely lead to some odd behaviour
        # near the boundary of the MSLP grid boundaries - higher resolution
        # MSLP data will decrease this unusual behaviour.

        try:
            ncfile = cnfGetIniValue(configFile, 'Input', 'MSLPFile')
        except:
            logger.exception("No input MSLP file specified in configuration")
            raise
        time = getTime(year, month, day, hour, minute)
        penv = ltmPressure(jdays, time, lon, lat, ncfile)

    speed, bearing = getSpeedBearing(indicator, lon, lat, dt,
                                     missingValue=missingValue)

    if calculateWindSpeed:
        windspeed = maxWindSpeed(indicator, dt, lon, lat, pressure, penv)

    TCID = np.cumsum(indicator)

    data = np.empty(len(indicator), 
                        dtype={
                               'names': trackFields,
                               'formats': trackTypes
                               } )
    for key, value in zip(trackFields, [indicator, TCID, year, month,
                                           day, hour, minute, timeElapsed, datetimes,
                                           lon, lat, speed, bearing,
                                           pressure, windspeed, rmax, penv]):
        data[key] = value
        
    tracks = []
    n = np.max(TCID)
    for i in range(1, n + 1):
        track = Track(data[TCID == i])
        track.trackId = (i, n)
        track.trackfile = trackFile
        getMinPressure(track, missingValue)
        getMaxWind(track, missingValue)
        tracks.append(track)

    return tracks
Beispiel #8
0
if __name__ == "__main__":
    try:
        configFile = sys.argv[1]
    except IndexError:
        # Try loading config file with same name as python script
        configFile = __file__.rstrip('.py') + '.ini'
        # If no filename is specified and default filename doesn't exist => raise error
        if not os.path.exists(configFile):
            error_msg = "No configuration file specified, please type: python main.py {config filename}.ini"
            raise IOError, error_msg
    # If config file doesn't exist => raise error
    if not os.path.exists(configFile):
        error_msg = "Configuration file '" + configFile +"' not found"
        raise IOError, error_msg

    logging.basicConfig(level=logging.getattr(cnfGetIniValue(configFile, 'Logging', 'LogLevel', 'DEBUG')),
                        format='%(asctime)s %(name)-12s: %(levelname)-8s %(message)s',
                        filename=cnfGetIniValue(configFile, 'Logging', 'LogFile', __file__.rstrip('.py') + '.log'),
                        filemode='w')

    path = cnfGetIniValue(configFile, 'Output', 'Path')

#    init_bearing = path+'init_bearing'
#    kde_init_bearing = path+'kde_init_bearing'
#    cdf_init_bearing = cpath+'cdf_init_bearing'
#    all_bearing = path+'all_bearing'
#    kde_all_bearing = path+'kde_all_bearing'
#    cdf_all_bearing = path+'cdf_all_bearing'
#    bearing_no_init = path+'bearing_no_init'
#    kde_no_init_bearing = path+'kde_no_init_bearing'
#    cdf_no_init_bearing = path+'cdf_no_init_bearing'
Beispiel #9
0
    except IndexError:
        # Try loading config file with same name as python script
        configFile = __file__.rstrip('.py') + '.ini'
        # If no filename is specified and default filename doesn't exist => raise error
        if not os.path.exists(configFile):
            error_msg = ("No configuration file specified, please type: "
                         "python main.py {config filename}.ini")
            raise IOError(error_msg)
    # If config file doesn't exist => raise error
    if not os.path.exists(configFile):
        error_msg = "Configuration file '" + configFile + "' not found"
        raise IOError(error_msg)

    logging.basicConfig(
        level=logging.getattr(
            cnfGetIniValue(configFile, 'Logging', 'LogLevel', 'DEBUG')),
        format='%(asctime)s %(name)-12s: %(levelname)-8s %(message)s',
        filename=cnfGetIniValue(configFile, 'Logging', 'LogFile',
                                __file__.rstrip('.py') + '.log'),
        filemode='w')

    path = cnfGetIniValue(configFile, 'Output', 'Path')

    #    init_bearing = path+'init_bearing'
    #    kde_init_bearing = path+'kde_init_bearing'
    #    cdf_init_bearing = cpath+'cdf_init_bearing'
    #    all_bearing = path+'all_bearing'
    #    kde_all_bearing = path+'kde_all_bearing'
    #    cdf_all_bearing = path+'cdf_all_bearing'
    #    bearing_no_init = path+'bearing_no_init'
    #    kde_no_init_bearing = path+'kde_no_init_bearing'
Beispiel #10
0
def loadTrackFile(configFile,
                  trackFile,
                  source,
                  missingValue=0,
                  calculateWindSpeed=True):
    """
    Load TC track data from the given input file, from a specified source.
    The configFile is a configuration file that contains a section called
    'source' that describes the data.
    This returns a collection of :class:`Track` objects that contains
    the details of the TC tracks in the input file.

    :param str configFile: Configuration file with a section ``source``.
    :param str trackFile: Path to a csv-formatted file containing TC data.
    :pararm str source: Name of the source format of the TC data. There
                        *must* be a section in ``configFile`` matching
                        this string, containing the details of the format
                        of the data.
    :param missingValue: Replace all null values in the input data with
                         this value (default=0).
    :param boolean calculateWindSpeed: Calculate maximum wind speed using
                                       a pressure-wind relation described
                                       in :func:`maxWindSpeed`

    :returns: A collection of :class:`Track` objects.
              If any of the variables are not present in the input
              dataset, they are (where possible) calculated
              (date/time/windspeed), sampled from default datasets
              (e.g. environmental pressure) or set to the missing value.

    Example::

      >>> tracks = loadTrackFile('tcrm.ini', 'IBTRaCS.csv', 'IBTrACS' )

    """

    LOG.info("Loading %s" % trackFile)
    inputData = colReadCSV(configFile, trackFile, source)  #,
    #nullValue=missingValue)

    config = ConfigParser()
    config.read(configFile)

    inputSpeedUnits = config.get(source, 'SpeedUnits')
    inputPressureUnits = config.get(source, 'PressureUnits')
    inputLengthUnits = config.get(source, 'LengthUnits')
    inputDateFormat = config.get(source, 'DateFormat')

    if config.getboolean('DataProcess', 'FilterSeasons'):
        startSeason = config.getint('DataProcess', 'StartSeason')
        idx = np.where(inputData['season'] >= startSeason)[0]
        inputData = inputData[idx]

    # Determine the initial TC positions...
    indicator = getInitialPositions(inputData)

    # Sort date/time information
    if 'age' in inputData.dtype.names:
        year, month, day, hour, minute, datetimes = parseAge(
            inputData, indicator)
        timeElapsed = inputData['age']
    else:
        year, month, day, hour, minute, datetimes = parseDates(
            inputData, indicator, inputDateFormat)
        timeElapsed = getTimeElapsed(indicator, year, month, day, hour, minute)

    # Time between observations:
    dt = getTimeDelta(year, month, day, hour, minute)

    # Calculate julian days
    jdays = julianDays(year, month, day, hour, minute)

    lat = np.array(inputData['lat'], 'd')
    lon = np.mod(np.array(inputData['lon'], 'd'), 360)
    delta_lon = np.diff(lon)
    delta_lat = np.diff(lat)

    # Split into separate tracks if large jump occurs (delta_lon > 10 degrees
    # or delta_lat > 5 degrees)
    # This avoids two tracks being accidentally combined when seasons and track
    # numbers match but basins are different as occurs in the IBTrACS dataset.
    # This problem can also be prevented if the 'tcserialno' column is
    # specified.
    indicator[np.where(delta_lon > 10)[0] + 1] = 1
    indicator[np.where(delta_lat > 5)[0] + 1] = 1

    pressure = filterPressure(np.array(inputData['pressure'], 'd'),
                              inputPressureUnits, missingValue)
    try:
        windspeed = np.array(inputData['vmax'], 'd')
        novalue_index = np.where(windspeed == sys.maxint)
        windspeed = metutils.convert(windspeed, inputSpeedUnits, "mps")
        windspeed[novalue_index] = missingValue
    except (ValueError, KeyError):
        LOG.debug("No max wind speed data - all values will be zero")
        windspeed = np.zeros(indicator.size, 'f')
    assert lat.size == indicator.size
    assert lon.size == indicator.size
    assert pressure.size == indicator.size

    try:
        rmax = np.array(inputData['rmax'])
        novalue_index = np.where(rmax == missingValue)
        rmax = metutils.convert(rmax, inputLengthUnits, "km")
        rmax[novalue_index] = missingValue

    except (ValueError, KeyError):
        LOG.debug("No radius to max wind data - all values will be zero")
        rmax = np.zeros(indicator.size, 'f')

    if 'penv' in inputData.dtype.names:
        penv = np.array(inputData['penv'], 'd')
    else:
        LOG.debug("No ambient MSLP data in this input file")
        LOG.debug("Sampling data from MSLP data defined in "
                  "configuration file")
        # Warning: using sampled data will likely lead to some odd behaviour
        # near the boundary of the MSLP grid boundaries - higher resolution
        # MSLP data will decrease this unusual behaviour.

        try:
            ncfile = cnfGetIniValue(configFile, 'Input', 'MSLPFile')
        except:
            LOG.exception("No input MSLP file specified in configuration")
            raise
        time = getTime(year, month, day, hour, minute)
        penv = ltmPressure(jdays, time, lon, lat, ncfile)

    if 'poci' in inputData.dtype.names:
        poci = np.array(inputData['poci'], 'd')
    else:
        LOG.debug("Determining poci")
        eps = np.random.normal(0, scale=2.5717)
        poci = getPoci(penv, pressure, lat, jdays, eps)

    speed, bearing = getSpeedBearing(indicator,
                                     lon,
                                     lat,
                                     dt,
                                     missingValue=missingValue)

    if calculateWindSpeed:
        windspeed = maxWindSpeed(indicator, dt, lon, lat, pressure, poci)

    TCID = np.cumsum(indicator)

    data = np.empty(len(indicator),
                    dtype={
                        'names': trackFields,
                        'formats': trackTypes
                    })
    for key, value in zip(trackFields, [
            indicator, TCID, year, month, day, hour, minute, timeElapsed,
            datetimes, lon, lat, speed, bearing, pressure, windspeed, rmax,
            poci
    ]):
        data[key] = value

    tracks = []
    n = np.max(TCID)
    for i in range(1, n + 1):
        track = Track(data[TCID == i])
        track.trackId = (i, n)
        track.trackfile = trackFile
        getMinPressure(track, missingValue)
        getMaxWind(track, missingValue)
        tracks.append(track)

    return tracks
Beispiel #11
0
 def test_returnDefaultMissingOption(self):
     self.assertEqual(config.cnfGetIniValue(self.configFile, 'Integer', 'Option3', 1), 1)
     self.assertEqual(config.cnfGetIniValue(self.configFile, 'String', 'Option2', 'otherstring'), 'otherstring')
Beispiel #12
0
 def test_cnfReadIniValue(self):
     self.assertEqual(config.cnfGetIniValue(self.configFile, 'Integer', 'Option1'), 1)
     self.assertEqual(config.cnfGetIniValue(self.configFile, 'Integer', 'Option2'), 10)
     self.assertEqual(config.cnfGetIniValue(self.configFile, 'Boolean', 'Option1'), True)
     self.assertEqual(config.cnfGetIniValue(self.configFile, 'Boolean', 'Option2'), False)
     self.assertEqual(config.cnfGetIniValue(self.configFile, 'Float', 'Option1'), 0.5)
     self.assertEqual(config.cnfGetIniValue(self.configFile, 'Float', 'Option2'), 2.5)
     self.assertEqual(config.cnfGetIniValue(self.configFile, 'List', 'Option1'), "A,B,C,D,E")
     self.assertEqual(config.cnfGetIniValue(self.configFile, 'List', 'Option2'), "A")
     self.assertEqual(config.cnfGetIniValue(self.configFile, 'String', 'Option'), 'randomstring')
     self.assertEqual(config.cnfGetIniValue(self.configFile, 'String', 'Option1'), '/path/string')
     self.assertEqual(config.cnfGetIniValue(self.configFile, 'Evaluate', 'Option'), {'x':1.0,'y':0.5})
Beispiel #13
0
if __name__ == "__main__":
    try:
        configFile = sys.argv[1]
    except IndexError:
        # Try loading config file with same name as python script
        configFile = __file__.rstrip('.py') + '.ini'
        # If no filename is specified and default filename doesn't exist => raise error
        if not os.path.exists(configFile):
            error_msg = "No configuration file specified, please type: python main.py {config filename}.ini"
            raise IOError, error_msg
    # If config file doesn't exist => raise error
    if not os.path.exists(configFile):
        error_msg = "Configuration file '" + configFile +"' not found"
        raise IOError, error_msg

    logging.basicConfig(level=logging.DEBUG,
                        format='%(asctime)s %(name)-12s: %(levelname)-8s %(message)s',
                        filename=cnfGetIniValue(configFile, 'Logging', 'LogFile', __file__.rstrip('.py') + '.log'),
                        filemode='w')

    path = cnfGetIniValue(configFile, 'Output','Path')

    cdfParameters = os.path.join(path,'all_cell_cdf_pressure_rate')

    sp = SamplingParameters(cdfParameters)

    #pdb.set_trace()
    os = sp.generateOneSample()
    s = sp.generateSamples(cnfGetIniValue(configFile, 'Parameters',
                                          'Samples'))
if __name__ == "__main__":
    try:
        configFile = sys.argv[1]
    except IndexError:
        # Try loading config file with same name as python script
        configFile = __file__.rstrip('.py') + '.ini'
        # If no filename is specified and default filename doesn't exist => raise error
        if not os.path.exists(configFile):
            error_msg = "No configuration file specified, please type: python main.py {config filename}.ini"
            raise IOError, error_msg
    # If config file doesn't exist => raise error
    if not os.path.exists(configFile):
        error_msg = "Configuration file '" + configFile + "' not found"
        raise IOError, error_msg

    logging.basicConfig(
        level=logging.DEBUG,
        format='%(asctime)s %(name)-12s: %(levelname)-8s %(message)s',
        filename=cnfGetIniValue(configFile, 'Logging', 'LogFile',
                                __file__.rstrip('.py') + '.log'),
        filemode='w')

    path = cnfGetIniValue(configFile, 'Output', 'Path')

    cdfParameters = os.path.join(path, 'all_cell_cdf_pressure_rate')

    sp = SamplingParameters(cdfParameters)

    os = sp.generateOneSample()
    s = sp.generateSamples(cnfGetIniValue(configFile, 'Parameters', 'Samples'))
Beispiel #15
0
        #pyplot.xlabel("Normal")
        pyplot.ylabel(parameterName)
        pyplot.title("Q-Q plot - %s" % parameterName)
        pyplot.xlim((-5, 5))
        pyplot.ylim((-5, 5))
        pos = (2, -4.8)
        pyplot.text(2, -4.9, r"$r^2=%1.4f$" % r, fontsize=12)

        self.savefig('qqplot_%s' % parameterName)
        #pyplot.rcdefaults()

if __name__=="__main__":
    from os.path import join as pjoin

    configFile = sys.argv[1]
    dataPath = config.cnfGetIniValue(configFile, 'Output', 'Path', os.getcwd())
    inputPath = pjoin(dataPath, 'process')
    outputPath = pjoin(dataPath, 'plots')
    pyplot.rcParams['figure.figsize'] = (7, 12)

    pRateData = files.flLoadFile(pjoin(inputPath, 'pressure_rate'))
    pAllData = files.flLoadFile(pjoin(inputPath, 'all_pressure'))
    bRateData = files.flLoadFile(pjoin(inputPath, 'bearing_rate'))
    bAllData = files.flLoadFile(pjoin(inputPath, 'all_bearing'))
    sRateData = files.flLoadFile(pjoin(inputPath, 'speed_rate'))
    sAllData = files.flLoadFile(pjoin(inputPath, 'all_speed'))
    freq = files.flLoadFile(pjoin(inputPath, 'frequency'))
    years = freq[:, 0]
    frequency = freq[:, 1]

    plotting = PlotData(outputPath, "png")
Beispiel #16
0
    try:
        configFile = sys.argv[1]
    except IndexError:
        # Try loading config file with same name as python script
        configFile = __file__.rstrip(".py") + ".ini"
        # If no filename is specified and default filename doesn't exist => raise error
        if not os.path.exists(configFile):
            error_msg = "No configuration file specified, please type: python main.py {config filename}.ini"
            raise IOError, error_msg
    # If config file doesn't exist => raise error
    if not os.path.exists(configFile):
        error_msg = "Configuration file '" + configFile + "' not found"
        raise IOError, error_msg

    logging.basicConfig(
        level=logging.DEBUG,
        format="%(asctime)s %(name)-12s: %(levelname)-8s %(message)s",
        filename=cnfGetIniValue(configFile, "Logging", "LogFile", __file__.rstrip(".py") + ".log"),
        filemode="w",
    )

    path = cnfGetIniValue(configFile, "Output", "Path")

    cdfParameters = os.path.join(path, "all_cell_cdf_pressure_rate")

    sp = SamplingParameters(cdfParameters)

    # pdb.set_trace()
    os = sp.generateOneSample()
    s = sp.generateSamples(cnfGetIniValue(configFile, "Parameters", "Samples"))
Beispiel #17
0
 def test_returnDefaultMissingSection(self):
     self.assertEqual(config.cnfGetIniValue(self.configFile, 'Missing', 'Option', 'Default'), 'Default')
Beispiel #18
0
    try:
        configFile = sys.argv[1]
    except IndexError:
        # Try loading config file with same name as python script
        configfile = __file__.rstrip('.py') + '.ini'
        # If no filename is specified and default filename doesn't exist => raise error
        if not os.path.exists(configFile):
            error_msg = ("No configuration file specified. "
                         "please type: python main.py {config filename}.ini")
            raise IOError(error_msg)
    # If config file doesn't exist => raise error
    if not os.path.exists(configFile):
        error_msg = "Configuration file '" + configFile +"' not found"
        raise IOError(error_msg)

    flStartLog(cnfGetIniValue(configFile, 'Logging',
                              'LogFile', __file__.rstrip('.py') + '.log'),
               cnfGetIniValue(configFile, 'Logging', 'LogLevel', 'DEBUG'),
               cnfGetIniValue(configFile, 'Logging', 'Verbose', True))
    path = cnfGetIniValue(configFile, 'Output', 'Path')

    gridLim = eval(cnfGetIniValue(configFile, 'Region', 'gridLimit'))
    gridSp = eval(cnfGetIniValue(configFile, 'Region', 'gridSpace'))
    gridinc = eval(cnfGetIniValue(configFile, 'Region', 'gridInc'))
    kdetype = cnfGetIniValue(configFile, 'StatInterface', 'kdeType')
    kdestep = cnfGetIniValue(configFile, 'StatInterface', 'kdeStep', 0.1)
    minSamples = cnfGetIniValue(configFile, 'StatInterface',
                                'minSamplesCell', 100)
    mv = cnfGetIniValue(configFile, 'StatInterface',
                        'MissingValue', sys.maxsize)
    gDist = GenerateDistributions(configFile, gridLim, gridSp,
                                  gridinc, kdetype,