Coverage for C:\src\imod-python\imod\mf6\utilities\schemata.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-08 13:27 +0200

1from typing import Tuple 

2 

3from imod.schemata import BaseSchema 

4 

5 

6def filter_schemata_dict( 

7 schemata_dict: dict[str, list[BaseSchema] | Tuple[BaseSchema, ...]], 

8 schema_types: tuple[type[BaseSchema], ...], 

9) -> dict[str, list[BaseSchema]]: 

10 """ 

11 Filter schemata dict with a tuple of schema types. Keys which do not have 

12 provided types in their corresponding schema list are dropped. The schema 

13 list in the values is reduced to contain the schema_types only. 

14 

15 Example 

16 ------- 

17 >>> _write_schemata = { 

18 "stage": [ 

19 AllValueSchema(">=", "bottom_elevation"), 

20 OtherCoordsSchema("idomain"), 

21 AllNoDataSchema(), # Check for all nan, can occur while clipping 

22 AllInsideNoDataSchema(other="idomain", is_other_notnull=(">", 0)), 

23 ], 

24 "conductance": [IdentityNoDataSchema("stage"), AllValueSchema(">", 0.0)], 

25 } 

26 

27 >>> print(filter_schemata_dict(write_schemata, (AllNoDataSchema()))) 

28 

29 Prints ``{'stage': [<imod.schemata.AllNoDataSchema at 0x1b152b12aa0>]}`` 

30 """ 

31 

32 dict = {} 

33 for key, schema_ls in schemata_dict.items(): 

34 schema_match = [ 

35 schema for schema in schema_ls if isinstance(schema, schema_types) 

36 ] 

37 if schema_match: 

38 dict[key] = schema_match 

39 return dict