def __init__(self, configFile, tilegrid, numSim, minRecords, yrsPerSim, calcCI=False, evd='GEV'): """ 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: :param boolean calcCI: :param str extreme_value_distribution: evd to use. Options so far are GEV and GPD. """ 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.evd = evd 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 = {'title': ('TCRM hazard simulation - ' 'return period wind speeds'), 'tcrm_version': flProgramVersion(), 'python_version': 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
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
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): 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 saveGustToFile(self, trackfile, result, filename): """ Save gusts to a file. """ lat, lon, speed, Vx, Vy, P = result trackfileDate = flModDate(trackfile) gatts = { 'title': 'TCRM hazard simulation - synthetic event wind field', 'tcrm_version': flProgramVersion(), 'python_version': sys.version, 'track_file': trackfile, 'track_file_date': trackfileDate, 'radial_profile': self.profileType, 'boundary_layer': self.windFieldType, 'beta': self.beta } # Add configuration settings to global attributes: for section in self.config.sections(): for option in self.config.options(section): key = "{0}_{1}".format(section, option) value = self.config.get(section, option) gatts[key] = value dimensions = { 0: { 'name': 'lat', 'values': lat, 'dtype': 'float64', 'atts': { 'long_name': 'Latitude', 'standard_name': 'latitude', 'units': 'degrees_north', 'axis': 'Y' } }, 1: { 'name': 'lon', 'values': lon, 'dtype': 'float64', 'atts': { 'long_name': 'Longitude', 'standard_name': 'longitude', 'units': 'degrees_east', 'axis': 'X' } } } variables = { 0: { 'name': 'vmax', 'dims': ('lat', 'lon'), 'values': speed, 'dtype': 'float32', 'atts': { 'long_name': 'Maximum 0.2-second gust wind speed', 'standard_name': 'wind_speed_of_gust', 'units': 'm/s', 'actual_range': (np.min(speed), np.max(speed)), 'valid_range': (0.0, 200.), 'cell_methods': ('time: maximum ', 'time: maximum (interval: 0.2 seconds)'), 'grid_mapping': 'crs' } }, 1: { 'name': 'ua', 'dims': ('lat', 'lon'), 'values': Vx, 'dtype': 'float32', 'atts': { 'long_name': 'Eastward component of maximum wind speed', 'standard_name': 'eastward_wind', 'units': 'm/s', 'actual_range': (np.min(Vx), np.max(Vx)), 'valid_range': (-200., 200.), 'grid_mapping': 'crs' } }, 2: { 'name': 'va', 'dims': ('lat', 'lon'), 'values': Vy, 'dtype': 'float32', 'atts': { 'long_name': 'Northward component of maximim wind speed', 'standard_name': 'northward_wind', 'units': 'm/s', 'actual_range': (np.min(Vy), np.max(Vy)), 'valid_range': (-200., 200.), 'grid_mapping': 'crs' } }, 3: { 'name': 'slp', 'dims': ('lat', 'lon'), 'values': P, 'dtype': 'float32', 'atts': { 'long_name': 'Minimum air pressure at sea level', 'standard_name': 'air_pressure_at_sea_level', 'units': 'Pa', 'actual_range': (np.min(P), np.max(P)), 'valid_range': (70000., 115000.), 'cell_methods': 'time: minimum', 'grid_mapping': 'crs' } }, 4: { 'name': 'crs', 'dims': (), 'values': None, 'dtype': 'i', 'atts': { 'grid_mapping_name': 'latitude_longitude', 'semi_major_axis': 6378137.0, 'inverse_flattening': 298.257222101, 'longitude_of_prime_meridian': 0.0 } } } nctools.ncSaveGrid(filename, dimensions, variables, gatts=gatts)
def _saveGustToFile(self, trackfile, result, filename): """ Save gusts to a file. """ lat, lon, speed, Vx, Vy, P = result trackfileDate = flModDate(trackfile) gatts = { 'title': 'TCRM hazard simulation - synthetic event wind field', 'tcrm_version': flProgramVersion(), 'python_version': sys.version, 'track_file': trackfile, 'track_file_date': trackfileDate, 'radial_profile': self.profileType, 'boundary_layer': self.windFieldType, 'beta': self.beta} # Add configuration settings to global attributes: for section in self.config.sections(): for option in self.config.options(section): key = "{0}_{1}".format(section, option) value = self.config.get(section, option) gatts[key] = value dimensions = { 0: { 'name': 'lat', 'values': lat, 'dtype': 'f', 'atts': { 'long_name': 'Latitude', 'standard_name': 'latitude', 'units': 'degrees_north', 'axis': 'Y' } }, 1: { 'name': 'lon', 'values': lon, 'dtype': 'f', 'atts': { 'long_name': 'Longitude', 'standard_name': 'longitude', 'units': 'degrees_east', 'axis': 'X' } } } variables = { 0: { 'name': 'vmax', 'dims': ('lat', 'lon'), 'values': speed, 'dtype': 'f', 'atts': { 'long_name': 'Maximum 3-second gust wind speed', 'standard_name': 'wind_speed_of_gust', 'units': 'm/s', 'actual_range': (np.min(speed), np.max(speed)), 'valid_range': (0.0, 200.), 'cell_methods': ('time: maximum ' 'time: maximum (interval: 3 seconds)'), 'grid_mapping': 'crs' } }, 1: { 'name': 'ua', 'dims': ('lat', 'lon'), 'values': Vx, 'dtype': 'f', 'atts': { 'long_name': 'Eastward component of maximum wind speed', 'standard_name': 'eastward_wind', 'units': 'm/s', 'actual_range': (np.min(Vx), np.max(Vx)), 'valid_range': (-200., 200.), 'grid_mapping': 'crs' } }, 2: { 'name': 'va', 'dims': ('lat', 'lon'), 'values': Vy, 'dtype': 'f', 'atts': { 'long_name': 'Northward component of maximim wind speed', 'standard_name': 'northward_wind', 'units': 'm/s', 'actual_range': (np.min(Vy), np.max(Vy)), 'valid_range': (-200., 200.), 'grid_mapping': 'crs' } }, 3: { 'name': 'slp', 'dims': ('lat', 'lon'), 'values': P, 'dtype': 'f', 'atts': { 'long_name': 'Minimum air pressure at sea level', 'standard_name': 'air_pressure_at_sea_level', 'units': 'Pa', 'actual_range': (np.min(P), np.max(P)), 'valid_range': (70000., 115000.), 'cell_methods': 'time: minimum', 'grid_mapping': 'crs' } }, 4: { 'name': 'crs', 'dims': (), 'values': None, 'dtype': 'i', 'atts': { 'grid_mapping_name': 'latitude_longitude', 'semi_major_axis': 6378137.0, 'inverse_flattening': 298.257222101, 'longitude_of_prime_meridian': 0.0 } } } nctools.ncSaveGrid(filename, dimensions, variables, gatts=gatts)
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