How to use the pelicun.db.convert_Series_to_dict function in pelicun

To help you get started, we’ve selected a few pelicun examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NHERI-SimCenter / pelicun / pelicun / file_io.py View on Github external
if os.path.isdir(path_CMP):

        CMP_dir = Path(path_CMP).resolve()

        for c_id in s_cmp_keys:
            with open(CMP_dir / f'{c_id}.json', 'r') as f:
                DL_data_dict.update({c_id: json.load(f)})

    # else if an HDF5 file is provided we assume it contains the DL data
    elif path_CMP.endswith('hdf'):

        store = pd.HDFStore(path_CMP)
        store.open()
        CMP_table = store.select('data', where=f'index in {s_cmp_keys}')
        for c_id in s_cmp_keys:
            DL_data_dict.update({c_id: convert_Series_to_dict(CMP_table.loc[c_id, :])})
        store.close()

    else:
        raise ValueError(
            "Component data source not recognized. Please provide "
            "either a folder with DL json files or an HDF5 table.")

    # for each component
    for c_id in s_cmp_keys:
        c_data = data[c_id]

        DL_data = DL_data_dict[c_id]

        DL_GI = DL_data['GeneralInformation']
        DL_EDP = DL_data['EDP']
        DL_DSG = DL_data['DSGroups']
github NHERI-SimCenter / pelicun / pelicun / file_io.py View on Github external
# Load the population data

    # If a json file is provided:
    if path_POP.endswith('json'):
        with open(path_POP, 'r') as f:
            jd = json.load(f)

        data = jd[occupancy]

    # else if an HDF5 file is provided
    elif path_POP.endswith('hdf'):

        store = pd.HDFStore(path_POP)
        store.open()
        pop_table = store.select('pop', where = f'index in {[occupancy,]}')
        data = convert_Series_to_dict(pop_table.loc[occupancy,:])
        store.close()

    # convert peak population to persons/m2
    if 'peak' in data.keys():
        data['peak'] = data['peak'] / (1000. * ft2)

    if verbose: # pragma: no cover
        pp.pprint(data)

    return data

pelicun

Probabilistic Estimation of Losses, Injuries, and Community resilience Under Natural hazard events

BSD-2-Clause
Latest version published 22 days ago

Package Health Score

63 / 100
Full package analysis