Example #1
0
def test_manual_calcs():
    # where is this script?
    homedir = os.path.dirname(os.path.abspath(__file__))
    popfile = os.path.join(homedir, '..', 'data', 'eventdata', 'northridge',
                           'northridge_gpw.flt')
    urbfile = os.path.join(homedir, '..', 'data', 'eventdata', 'northridge',
                           'northridge_urban.bil')
    isofile = os.path.join(homedir, '..', 'data', 'eventdata', 'northridge',
                           'northridge_isogrid.bil')
    ccode = 'ID'
    timeofday = 'day'
    density = URBAN
    pop = 100000
    mmi = 8.5
    popyear = 2016
    semi = SemiEmpiricalFatality.fromDefault()
    semi.setGlobalFiles(popfile, popyear, urbfile, isofile)

    # let's do the calculations "manually" by getting all of the data and doing our own multiplications
    workforce = semi.getWorkforce(ccode)
    res, nonres, outside = pop_dist(pop, workforce, timeofday, density)
    resinv, nonresinv = semi.getInventories(ccode, density)
    res_collapse = semi.getCollapse(ccode, mmi, resinv)
    nonres_collapse = semi.getCollapse(ccode, mmi, nonresinv)
    res_fat_rates = semi.getFatalityRates(ccode, timeofday, resinv)
    nonres_fat_rates = semi.getFatalityRates(ccode, timeofday, nonresinv)
    res_fats = res * resinv * res_collapse * res_fat_rates
    nonres_fats = nonres * nonresinv * nonres_collapse * nonres_fat_rates
    # print(res_fats)
    # print(nonres_fats)
    fatsum = int(res_fats.sum() + nonres_fats.sum())
    print('Testing that "manual" calculations achieve tested result...')
    assert fatsum == 383
    print('Passed.')
Example #2
0
def test_work():
    popi = 2000
    wforce = pd.Series({'WorkForceTotal': 0.5,
                        'WorkForceAgricultural': 0.5,
                        'WorkForceIndustrial': 0.25,
                        'WorkForceServices': 0.25})
    timeofday = 'day'
    dclass = URBAN
    res, nonres, outdoor = pop_dist(popi, wforce, timeofday, dclass)
    np.testing.assert_almost_equal(res, 410)
    np.testing.assert_almost_equal(nonres, 865)
    np.testing.assert_almost_equal(outdoor, 725)
Example #3
0
def work_tests():
    popi = 2000
    fwf = 0.5
    f_ind = 0.25
    fser = 0.25
    fagr = 0.5
    timeofday = 'day'
    dclass = URBAN
    res, nonres, outdoor = pop_dist(popi, fwf, f_ind, fser, fagr, timeofday,
                                    dclass)
    np.testing.assert_almost_equal(res, 410)
    np.testing.assert_almost_equal(nonres, 865)
    np.testing.assert_almost_equal(outdoor, 725)
Example #4
0
def model_test_single():
    homedir = os.path.dirname(
        os.path.abspath(__file__))  #where is this script?
    invfile = os.path.join(homedir, '..', 'data', 'semi_inventory.hdf')
    colfile = os.path.join(homedir, '..', 'data', 'semi_collapse_mmi.hdf')
    fatfile = os.path.join(homedir, '..', 'data', 'semi_casualty.hdf')
    workfile = os.path.join(homedir, '..', 'data', 'semi_workforce.hdf')
    growthfile = os.path.join(homedir, '..', 'data',
                              'WPP2015_POP_F02_POPULATION_GROWTH_RATE.xls')
    popfile = os.path.join(homedir, '..', 'data', 'eventdata', 'northridge',
                           'northridge_gpw.flt')
    urbfile = os.path.join(homedir, '..', 'data', 'eventdata', 'northridge',
                           'northridge_urban.bil')
    isofile = os.path.join(homedir, '..', 'data', 'eventdata', 'northridge',
                           'northridge_isogrid.bil')
    ccode = 'ID'
    timeofday = 'day'
    density = URBAN
    pop = 100000
    mmi = 8.5
    popyear = 2016
    semi = SemiEmpiricalFatality.fromDefault()
    semi.setGlobalFiles(popfile, popyear, urbfile, isofile)

    #let's do the calculations "manually" by getting all of the data and doing our own multiplications
    workforce = semi.getWorkforce(ccode)
    res, nonres, outside = pop_dist(pop, workforce, timeofday, density)
    resinv, nonresinv = semi.getInventories(ccode, density)
    res_collapse = semi.getCollapse(ccode, mmi, resinv)
    nonres_collapse = semi.getCollapse(ccode, mmi, nonresinv)
    res_fat_rates = semi.getFatalityRates(ccode, timeofday, resinv)
    nonres_fat_rates = semi.getFatalityRates(ccode, timeofday, nonresinv)
    res_fats = res * resinv * res_collapse * res_fat_rates
    nonres_fats = nonres * nonresinv * nonres_collapse * nonres_fat_rates
    #print(res_fats)
    #print(nonres_fats)
    fatsum = int(res_fats.sum() + nonres_fats.sum())
    print('Testing that "manual" calculations achieve tested result...')
    assert fatsum == 383
    print('Passed.')

    loss, resfat, nresfat = make_test_semi_model(ccode, timeofday, density,
                                                 pop, mmi)
    print(
        'Testing that "manual" calculations achieve same results as grid calculations...'
    )
    assert fatsum == loss
    print('Passed.')