Пример #1
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")
Пример #2
0
    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)
Пример #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
class TestIdMapperByName(unittest.TestCase):
    def setUp(self):
        h5py_file = h5py.File(grid_file, "r")
        self.id_mapper = IdMapper(H5pyGroup(h5py_file, "mappings")["id_map"])

    def test_get_channels_by_code(self):
        tc = TYPE_CODE_MAP["v2_channel"]
        qs = self.id_mapper.get_by_name("v2_channel")
        assert np.all(qs["obj_code"] == tc)

    def test_get_culvert_by_code(self):
        tc = TYPE_CODE_MAP["v2_culvert"]
        qs = self.id_mapper.get_by_name("v2_culvert")
        assert np.all(qs["obj_code"] == tc)
Пример #5
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())
Пример #6
0
    def prepare_breaches(h5py_file, threedi_datasource, overwrite=True):
        if skip_prepare(h5py_file, 'breaches', 'prepared', overwrite):
            return

        if not is_prepared(h5py_file, 'lines', 'line_prepared'):
            # Line data is missing, prepare line data first.
            GridAdminH5Prepare.prepare_lines(h5py_file, threedi_datasource)

        if not is_prepared(h5py_file, 'levees', 'prepared'):
            # Levee data is missing, prepare levee data first.
            GridAdminH5Prepare.prepare_levees(h5py_file, threedi_datasource)

        has_breaches = h5py_file.attrs.get('has_breaches', 0) == 1
        levees = None
        if 'levees' in h5py_file:
            levees = Levees(H5pyGroup(h5py_file, 'levees'))

        id_mapper = IdMapper(H5pyGroup(h5py_file, 'mappings')['id_map'])
        line_group = H5pyGroup(h5py_file, 'lines')

        # Prepare breaches
        if has_breaches:
            PrepareBreaches.prepare_datasource(
                H5pyGroup(h5py_file, 'breaches',
                          required=True), line_group['kcu'], id_mapper, levees,
                line_group['line_coords'])

            h5py_file['breaches'].attrs['prepared'] = 1
Пример #7
0
    def prepare_lines(h5py_file, threedi_datasource, overwrite=False):
        # Prepare lines
        if skip_prepare(h5py_file, 'lines', 'lines_prepared', overwrite):
            return

        has_1d = h5py_file.attrs.get('has_1d', 0) == 1

        line_group = H5pyGroup(h5py_file, 'lines')
        node_group = H5pyGroup(h5py_file, 'nodes')

        id_mapper = IdMapper(H5pyGroup(h5py_file, 'mappings')['id_map'])

        PrepareLines.prepare_datasource(
            line_group,
            id_mapper,
            threedi_datasource,
            [node_group['x_coordinate'], node_group['y_coordinate']],
            has_1d=has_1d)

        h5py_file['lines'].attrs['lines_prepared'] = 1
Пример #8
0
    def prepare_nodes(h5py_file, threedi_datasource, overwrite=False):
        if skip_prepare(h5py_file, 'nodes', 'prepared', overwrite):
            return

        has_1d = h5py_file.attrs.get('has_1d', 0) == 1

        if has_1d:
            mapping1d = H5pyGroup(h5py_file, 'mapping1d')
        else:
            mapping1d = None

        id_mapper = IdMapper(H5pyGroup(h5py_file, 'mappings')['id_map'])

        # Prepare nodes
        node_group = H5pyGroup(h5py_file, 'nodes')
        PrepareNodes.prepare_datasource(node_group,
                                        mapping1d,
                                        id_mapper,
                                        has_1d=has_1d)

        PrepareCells.prepare_datasource(h5py_file, threedi_datasource)

        h5py_file['nodes'].attrs['prepared'] = 1
Пример #9
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
Пример #10
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
Пример #11
0
 def setUp(self):
     h5py_file = h5py.File(grid_file, "r")
     self.id_mapper = IdMapper(H5pyGroup(h5py_file, "mappings")["id_map"])
Пример #12
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")