Coverage for C:\src\imod-python\imod\mf6\out\disu.py: 30%
46 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-08 14:15 +0200
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-08 14:15 +0200
1import struct
2from typing import Any, BinaryIO, Dict, List, Optional
4import numpy as np
5import xarray as xr
6import xugrid as xu
8from . import cbc
9from .common import FilePath, _grb_text
12def read_grb(f: BinaryIO, ntxt: int, lentxt: int) -> Dict[str, Any]:
13 read_vertices = lentxt > 10
15 if read_vertices:
16 f.seek(10 * lentxt, 1)
17 nvert = int(_grb_text(f).split()[-1])
18 f.seek(3 * lentxt, 1)
19 njavert = int(_grb_text(f).split()[-1])
20 else:
21 # we don't need any information from the the text lines that follow,
22 # they are definitions that aim to make the file more portable,
23 # so let's skip straight to the binary data
24 f.seek(ntxt * lentxt, 1)
26 ncells = struct.unpack("i", f.read(4))[0]
27 nja = struct.unpack("i", f.read(4))[0]
28 _ = struct.unpack("d", f.read(8))[0] # xorigion
29 _ = struct.unpack("d", f.read(8))[0] # yorigin
30 f.seek(8, 1) # skip angrot
31 top_np = np.fromfile(f, np.float64, ncells)
32 bottom_np = np.fromfile(f, np.float64, ncells)
33 ia = np.fromfile(f, np.int32, ncells + 1)
34 ja = np.fromfile(f, np.int32, nja)
35 idomain_np = np.fromfile(f, np.int32, ncells)
36 icelltype_np = np.fromfile(f, np.int32, ncells)
38 out = {
39 "distype": "disu",
40 "top": top_np,
41 "bottom": bottom_np,
42 "ncells": ncells,
43 "nja": nja,
44 "ia": ia,
45 "ja": ja,
46 "idomain": idomain_np,
47 "icelltype": icelltype_np,
48 }
50 if read_vertices:
51 out["vertices"] = np.reshape(np.fromfile(f, np.float64, nvert * 2), (nvert, 2))
52 out["cellx"] = np.fromfile(f, np.float64, ncells)
53 out["celly"] = np.fromfile(f, np.float64, ncells)
54 out["iavert"] = np.fromfile(f, np.int32, ncells + 1)
55 out["javert"] = np.fromfile(f, np.int32, njavert)
57 return out
60def read_times(path: FilePath, ntime: int, ncell: int):
61 raise NotImplementedError
64def read_hds_timestep(
65 path: FilePath, nlayer: int, ncell_per_layer: int, dry_nan: bool, pos: int
66):
67 raise NotImplementedError
70def open_hds(
71 path: FilePath,
72 grid_info: Dict[str, Any],
73 dry_nan: bool,
74 simulation_start_time: Optional[np.datetime64] = None,
75 time_unit: Optional[str] = "d",
76) -> xr.DataArray:
77 raise NotImplementedError
80def open_imeth1_budgets(
81 cbc_path: FilePath, grb_content: dict, header_list: List[cbc.Imeth1Header]
82) -> xr.DataArray:
83 raise NotImplementedError
86def open_imeth6_budgets(
87 cbc_path: FilePath, grb_content: dict, header_list: List[cbc.Imeth6Header]
88) -> xr.DataArray:
89 raise NotImplementedError
92def open_cbc(
93 cbc_path: FilePath, grb_content: Dict[str, Any]
94) -> Dict[str, xu.UgridDataArray]:
95 raise NotImplementedError