Exemplo n.º 1
0
    def test_keys_path_is_supplied___correct_instance_is_created_with_correct_model_info_and_keys_path(
            self, supplier, model, version):
        with TemporaryDirectory() as d:
            keys_path = os.path.join(d, 'keys')
            os.mkdir(keys_path)

            version_path = os.path.join(d, 'version.csv')
            self.write_version_file(supplier, model, version, version_path)

            module_path = os.path.join(d, '{}_lookup.py'.format(model))
            self.write_py_module(model, module_path)

            _, instance = OasisLookupFactory.create(
                model_keys_data_path=keys_path,
                model_version_file_path=version_path,
                lookup_package_path=module_path,
            )

            self.assertEqual(
                type(instance).__name__, '{}KeysLookup'.format(model))
            self.assertEqual(instance.supplier, supplier)
            self.assertEqual(instance.model_name, model)
            self.assertEqual(instance.model_version, version)
            self.assertEqual(instance.keys_data_directory, keys_path)
Exemplo n.º 2
0
from shapely.geometry import Point, Polygon, MultiPolygon, box

from oasislmf.utils.data import get_dataframe
from oasislmf.utils.peril import PerilAreasIndex, DEFAULT_RTREE_INDEX_PROPS

from oasislmf.keys.lookup import OasisLookupFactory as olf

# Create a copy of the default Rtree properties dict and set
# leaf capacity and fill factor to create as small an index as possible
props = copy.deepcopy(DEFAULT_RTREE_INDEX_PROPS)
props['leaf_capacity'] = 1000
props['fill_factor'] = 0.9

# Create an EUWS lookup (combines peril and vulnerability lookup) using the
# Oasis lookup factory
info, meeq = olf.create(lookup_config_fp='lookup_meeq.json')
print('\nmodel info: {}'.format(info))
print('\ncombined lookup (peril + vuln): {}'.format(meeq))

# Get the config dict from the lookup (loaded in from the file path you
# provided to create the lookup)
config = meeq.config
#print('lookup config: {}'.format(config))

# Check that keys data path look correct
keys_data_path = config.get('keys_data_path')
print('\nkeys data path: {}'.format(keys_data_path), end='')
print('; exists: {}'.format(os.path.exists(keys_data_path)))

# Check that the peril and vulnerability configs look OK
print('\nperil config: {}'.format(config.get('peril')))
Exemplo n.º 3
0
from shapely.geometry import Point, Polygon, MultiPolygon, box

from oasislmf.utils.data import get_dataframe
from oasislmf.utils.peril import PerilAreasIndex, DEFAULT_RTREE_INDEX_PROPS

from oasislmf.keys.lookup import OasisLookupFactory as olf

# Create a copy of the default Rtree properties dict and set
# leaf capacity and fill factor to create as small an index as possible
props = copy.deepcopy(DEFAULT_RTREE_INDEX_PROPS)
props['leaf_capacity'] = 1000
props['fill_factor'] = 0.9

# Create an EUWS lookup (combines peril and vulnerability lookup) using the
# Oasis lookup factory
info, euws = olf.create(lookup_config_fp='lookup.json')
print('\nEUWS model info: {}'.format(info))
print('\nCombined EUWS lookup (peril + vuln): {}'.format(euws))

# Get the config dict from the lookup (loaded in from the file path you
# provided to create the lookup)
config = euws.config
#print('lookup config: {}'.format(config))

# Check that keys data path look correct
keys_data_path = config.get('keys_data_path')
print('\nkeys data path: {}'.format(keys_data_path), end='')
print('; exists: {}'.format(os.path.exists(keys_data_path)))

# Check that the peril and vulnerability configs look OK
print('\nperil config: {}'.format(config.get('peril')))