<commit_before>''' Implementation of the BC Hydro model'''
import numpy as np
import itertools
import model

def interpolateSpectra(spectra1 , spectra2 , period1, period2):
    return spectra1

def fixPeriods(augmentedSpectra, periods, augmentedPeriods):
    fixedSpectra = np.zeros((augmentedSpectra.shape[0], periods.shape[0]))
    for i, per in enumerate(periods):
        if per in augmentedPeriods:
            fixedSpectra[:, i] = augmentedSpectra[:, 0]
            fixedSpectra[:, i] = augmentedSpectra[:, np.nonzero(augmentedPeriods == per)[0][0]]
        else:
            idxLow = np.nonzero(augmentedPeriods < per)[0][-1]
            idxHigh = np.nonzero(augmentedPeriods > per)[0][0]
            fixedSpectra[:, i] = interpolateSpectra(augmentedSpectra[:, idxLow] , augmentedSpectra[:, idxHigh] , augmentedPeriods[idxLow] , augmentedPeriods[idxHigh])
    return fixedSpectra

def augmentPeriods(periods):
    availablePeriods = np.array([0.01, 0.02, 0.05, 0.075, 0.1, 0.15, 0.2, 0.250, 0.3, 0.4, 0.5, 0.6, 0.75, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 6.0, 7.5, 10.0])
    modifiedPeriods = []
    for period in periods:
        if period in availablePeriods:
            modifiedPeriods.append(period)
        else:
            idxLow = np.nonzero(availablePeriods < period)[0][-1]
            modifiedPeriods.append(availablePeriods[idxLow])
            idxHigh = np.nonzero(availablePeriods > period)[0][0]
            modifiedPeriods.append(availablePeriods[idxHigh])
    return modifiedPeriods

def spectra(M, Rrup, Rhyp, eventType, Z, Faba, Vs30, periods):
    periods = np.array(periods)
    idx = np.nonzero(periods <= 0.01)[0]
    periods[idx] = 0.01 # Periods less than eq to 0.01 are essentially pga. Setting this allows us to avoid errors while interpolating in log-log scale.
    augmentedPeriods = augmentPeriods(periods)

    nRow = len(M)
    nCol = len(augmentedPeriods)

    M = np.array([M] * nCol).transpose()
    Rrup = np.array([Rrup] * nCol).transpose()
    Rhyp = np.array([Rhyp] * nCol).transpose()
    eventType = np.array([eventType] * nCol).transpose()
    Z = np.array([Z] * nCol).transpose()
    Faba = np.array([Faba] * nCol).transpose()
    Vs30 = np.array([Vs30] * nCol).transpose()
    augmentedPeriods = np.array([augmentedPeriods] * nRow)

    augmentedSpectra = np.array([[model.computeSpectra(mag, rrup, rhyp, evt, z, faba, vs, per) for mag, rrup, rhyp, evt, z, faba, vs, per in itertools.izip(mags, rrups, rhyps, evts, zs, fabas, vss, pers)] for mags, rrups, rhyps, evts, zs, fabas, vss, pers in itertools.izip(M, Rrup, Rhyp, eventType, Z, Faba, Vs30, augmentedPeriods)])

    return fixPeriods(augmentedSpectra, periods, augmentedPeriods[0]).tolist()<commit_msg>compute R based on event type<commit_after>''' Implementation of the BC Hydro model'''
import numpy as np
import itertools
import model

def interpolateSpectra(spectra1 , spectra2 , period1, period2):
    return spectra1

def fixPeriods(augmentedSpectra, periods, augmentedPeriods):
    fixedSpectra = np.zeros((augmentedSpectra.shape[0], periods.shape[0]))
    for i, per in enumerate(periods):
        if per in augmentedPeriods:
            fixedSpectra[:, i] = augmentedSpectra[:, 0]
            fixedSpectra[:, i] = augmentedSpectra[:, np.nonzero(augmentedPeriods == per)[0][0]]
        else:
            idxLow = np.nonzero(augmentedPeriods < per)[0][-1]
            idxHigh = np.nonzero(augmentedPeriods > per)[0][0]
            fixedSpectra[:, i] = interpolateSpectra(augmentedSpectra[:, idxLow] , augmentedSpectra[:, idxHigh] , augmentedPeriods[idxLow] , augmentedPeriods[idxHigh])
    return fixedSpectra

def augmentPeriods(periods):
    availablePeriods = np.array([0.01, 0.02, 0.05, 0.075, 0.1, 0.15, 0.2, 0.250, 0.3, 0.4, 0.5, 0.6, 0.75, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 6.0, 7.5, 10.0])
    modifiedPeriods = []
    for period in periods:
        if period in availablePeriods:
            modifiedPeriods.append(period)
        else:
            idxLow = np.nonzero(availablePeriods < period)[0][-1]
            modifiedPeriods.append(availablePeriods[idxLow])
            idxHigh = np.nonzero(availablePeriods > period)[0][0]
            modifiedPeriods.append(availablePeriods[idxHigh])
    return modifiedPeriods

def spectra(M, Rrup, Rhyp, eventType, Z, Faba, Vs30, periods):
    periods = np.array(periods)
    idx = np.nonzero(periods <= 0.01)[0]
    periods[idx] = 0.01 # Periods less than eq to 0.01 are essentially pga. Setting this allows us to avoid errors while interpolating in log-log scale.
    augmentedPeriods = augmentPeriods(periods)

    # compute R based on event type
    R = [rrup if ev == 0 else rhyp for rrup, rhyp, ev in itertools.izip(Rrup, Rhyp, eventType)]

    nRow = len(M)
    nCol = len(augmentedPeriods)

    M = np.array([M] * nCol).transpose()
    R = np.array([R] * nCol).transpose()
    eventType = np.array([eventType] * nCol).transpose()
    Z = np.array([Z] * nCol).transpose()
    Faba = np.array([Faba] * nCol).transpose()
    Vs30 = np.array([Vs30] * nCol).transpose()
    augmentedPeriods = np.array([augmentedPeriods] * nRow)

    augmentedSpectra = np.array([[model.computeSpectra(mag, r, evt, z, faba, vs, per) for mag, r, evt, z, faba, vs, per in itertools.izip(mags, rs, evts, zs, fabas, vss, pers)] for mags, rs, evts, zs, fabas, vss, pers in itertools.izip(M, R, eventType, Z, Faba, Vs30, augmentedPeriods)])

    return fixPeriods(augmentedSpectra, periods, augmentedPeriods[0]).tolist()
{'fraction_non_alphanumeric': 0.13791841960856047, 'fraction_numerical': 0.03420523138832998, 'mean_word_length': 3.51900826446281, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5645892', 'n_tokens_mistral': 2063, 'n_tokens_neox': 1910, 'n_words': 471}