def load_bridge_data(): """Preload bridge damage data from external files.""" global ClassificationDamageParams, EQCoefficients # check dictionaries - if empty, load from file if ClassificationDamageParams is None: eqrm_dir = determine_eqrm_path(__file__) path = os.path.join(eqrm_dir, DataFilePath, ClassificationDamageParamsCSVFile) ClassificationDamageParams = csvi.csv2rowdict(path, columns=['CLASS', 'K3D', 'Ishape', 'Slight', 'Moderate', 'Extensive', 'Complete'], convert={'Ishape': int, 'Slight': float, 'Moderate': float, 'Extensive': float, 'Complete': float}) if EQCoefficients is None: eqrm_dir = determine_eqrm_path(__file__) path = os.path.join(eqrm_dir, DataFilePath, EQCoefficientsCSVFile) EQCoefficients = csvi.csv2rowdict(path, columns=['Equation','A','B'], convert={'A': float, 'B': int})
def load_external_data(fp): """Load mean and sigma values from an external file. Data is placed in a numpy array where row number is the state number and the columns are the ppf() function for each pf value That is, if the source data file contains: State,StateIndex,Mean,Sigma none,0,0.0,0.00001 slight,1,0.6,0.6 moderate,2,2.5,2.7 extensive,3,75.0,42.0 complete,4,230.0,110.0 and the fp value is [10, 20] then the resulting array will be: fp(10) fp(20) vvv vvv [[ 0 0 ] <- state 0 (none) [ 1 1 ] <- state 1 (slight) [ 1 2 ] <- state 2 (moderate) [ 40 53 ] <- state 3 (extensive) [ 138 173 ]] <- state 4 (complete) All 'none' state days will be 0 days. All other states have values computed with ceil() and if less than 1 changed to 1. """ eqrm_dir = determine_eqrm_path(__file__) path = os.path.join(eqrm_dir, eqrm_filesystem.Resources_Data_Path, MeanSigmaValuesCSVFile) dict = csvi.csv2rowdict(path, columns=['StateIndex', 'Mean', 'Sigma'], convert={'StateIndex': int, 'Mean': float, 'Sigma': float }) data = [] for i in range(5): (mean, sigma) = dict[str(i)] data.append(scipy.stats.norm.ppf(fp, mean, sigma)) data = numpy.array(data) # 'normalise' results # if value < 0, convert to 1 # if value < 1 and > 0, convert to 1 result = data.clip(1.0, 99999999999.0) result = numpy.ceil(numpy.array(result)) result[0,:] = 0.0 # force all 'none' times to 0 return result
def load_external_data(fp): """Load mean and sigma values from an external file. Data is placed in a numpy array where row number is the state number and the columns are the ppf() function for each pf value That is, if the source data file contains: State,StateIndex,Mean,Sigma none,0,0.0,0.00001 slight,1,0.6,0.6 moderate,2,2.5,2.7 extensive,3,75.0,42.0 complete,4,230.0,110.0 and the fp value is [10, 20] then the resulting array will be: fp(10) fp(20) vvv vvv [[ 0 0 ] <- state 0 (none) [ 1 1 ] <- state 1 (slight) [ 1 2 ] <- state 2 (moderate) [ 40 53 ] <- state 3 (extensive) [ 138 173 ]] <- state 4 (complete) All 'none' state days will be 0 days. All other states have values computed with ceil() and if less than 1 changed to 1. """ eqrm_dir = determine_eqrm_path(__file__) path = os.path.join(eqrm_dir, eqrm_filesystem.Resources_Data_Path, MeanSigmaValuesCSVFile) dict = csvi.csv2rowdict(path, columns=['StateIndex', 'Mean', 'Sigma'], convert={ 'StateIndex': int, 'Mean': float, 'Sigma': float }) data = [] for i in range(5): (mean, sigma) = dict[str(i)] data.append(scipy.stats.norm.ppf(fp, mean, sigma)) data = numpy.array(data) # 'normalise' results # if value < 0, convert to 1 # if value < 1 and > 0, convert to 1 result = data.clip(1.0, 99999999999.0) result = numpy.ceil(numpy.array(result)) result[0, :] = 0.0 # force all 'none' times to 0 return result