예제 #1
0
파일: prepare.py 프로젝트: nens/threedigrid
    def prepare(h5py_file, threedi_datasource, extra_attrs=None):
        # Step 1: Set optional extra attrs like epsg code,
        # model_name, revision_number, revision_hash
        # and possible other meta data..
        if extra_attrs:
            for key, value in six.iteritems(extra_attrs):
                if isinstance(value, six.string_types):
                    value = np.string_(value)
                h5py_file.attrs[key] = value

        # Step 3: prepare the ID mapper
        IdMapper.prepare_mapper(h5py_file, threedi_datasource)

        # Step 4: Prepare nodes/lines
        GridAdminH5Prepare.prepare_nodes(h5py_file, threedi_datasource)
        GridAdminH5Prepare.prepare_lines(h5py_file, threedi_datasource)

        # Step 5: Prepare onedee lines/nodes/pumps
        GridAdminH5Prepare.prepare_onedee_lines(h5py_file, threedi_datasource)
        GridAdminH5Prepare.prepare_onedee_nodes(h5py_file, threedi_datasource)
        GridAdminH5Prepare.prepare_pumps(h5py_file, threedi_datasource)

        # Step 6: prepare levees
        GridAdminH5Prepare.prepare_levees(h5py_file, threedi_datasource)

        # Step 7: prepare breaches
        GridAdminH5Prepare.prepare_breaches(h5py_file, threedi_datasource)
예제 #2
0
def test_prepare_onedee_lines(h5py_file, threedi_datasource):
    IdMapper.prepare_mapper(h5py_file, threedi_datasource)
    GridAdminH5Prepare.prepare_onedee_lines(h5py_file, threedi_datasource)
    # check some special fixed types
    assert h5py_file["lines"]["code"].dtype == "S32"
    assert h5py_file["lines"]["display_name"].dtype == "S64"
    assert is_prepared(h5py_file, "lines", "lines_prepared")
예제 #3
0
def test_prepare_mapper(mocked_id_map, h5py_file, threedi_datasource):
    mocked_id_map.return_value = simple_id_map()
    IdMapper.prepare_mapper(h5py_file, threedi_datasource)
    # now a mapping should exist on the h5py file
    mapping = h5py_file["mappings"]["id_map"]
    assert mapping
    assert mapping.dtype.names == ("obj_code", "pk", "seq_id")
    assert mapping[:].size == len(TYPE_CODE_MAP.values()) * NODE_LENGTH
예제 #4
0
def test_prepare_breaches(mocked_id_map, h5py_file, threedi_datasource):
    id_map = simple_id_map()
    id_map[13] = {0: 1, 1: 1, 2: 1}
    mocked_id_map.return_value = id_map
    IdMapper.prepare_mapper(h5py_file, threedi_datasource)
    GridAdminH5Prepare.prepare_breaches(h5py_file, threedi_datasource)
    assert is_prepared(h5py_file, "breaches", "prepared")
    breaches_field_names = {
        "id",
        "seq_ids",
        "content_pk",
        "kcu",
        "coordinates",
    }
    assert breaches_field_names.issubset(h5py_file["breaches"].keys())
예제 #5
0
def h5py_file_mapper(mocked_id_map, h5py_file, threedi_datasource):
    """Unprepared h5py file with a prepared id_mapper"""
    id_map = simple_id_map()
    mocked_id_map.return_value = id_map
    IdMapper.prepare_mapper(h5py_file, threedi_datasource)
    return h5py_file, threedi_datasource
예제 #6
0
def test_init_idMapper(mocked_id_map, h5py_file, threedi_datasource):
    mocked_id_map.return_value = simple_id_map()
    IdMapper.prepare_mapper(h5py_file, threedi_datasource)
    mapper = IdMapper(h5py_file["mappings"]["id_map"])
    assert mapper.get_by_code(TYPE_CODE_MAP["v2_channel"]).size == NODE_LENGTH
    assert mapper.get_by_name("v2_channel").size == NODE_LENGTH
예제 #7
0
def test_prepare_lines(h5py_file, threedi_datasource):
    IdMapper.prepare_mapper(h5py_file, threedi_datasource)
    GridAdminH5Prepare.prepare_lines(h5py_file, threedi_datasource)
    assert is_prepared(h5py_file, "lines", "lines_prepared")