Coverage for C: \ Users \ peaco \ OneDrive \ Documents \ GitHub \ mt_metadata \ mt_metadata \ base \ __init__.py: 100%

3 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-10 00:11 -0800

1""" 

2Base classes for holding metadata and schema objects 

3 

4MetadataBase Overview 

5===================== 

6 

7MetadataBase is the foundational class for all metadata objects in mt_metadata, 

8providing robust, validated data structures with extensive serialization capabilities. 

9 

10Built on Pydantic 

11----------------- 

12MetadataBase inherits from Pydantic's BaseModel, leveraging the powerful benefits 

13of Pydantic for data validation and management: 

14 

15* **Automatic Type Validation**: All attributes are validated against their defined 

16 types at assignment time, catching errors early 

17* **Data Parsing**: Automatically converts and coerces input data to the correct 

18 types (e.g., strings to floats, lists to arrays) 

19* **IDE Support**: Full autocomplete and type hints for enhanced developer experience 

20* **Performance**: Fast validation using compiled Rust code (via pydantic-core) 

21* **Serialization**: Built-in support for converting to/from dictionaries and JSON 

22 

23Extended Functionality 

24---------------------- 

25MetadataBase extends Pydantic's BaseModel with specialized features: 

26 

27* **Dot-Separated Attribute Names**: Set nested attributes using dot notation 

28 (e.g., `survey.id = "MT001"` or `station.location.latitude = 45.0`) 

29* **Default Values**: Accepts default values from schemas and validates them to 

30 proper types automatically 

31* **Flexible I/O Methods**: 

32 - `to_dict()` / `from_dict()` - Dictionary conversion 

33 - `to_json()` / `from_json()` - JSON string/file handling 

34 - `to_xml()` / `from_xml()` - XML element handling 

35 - `to_series()` / `from_series()` - Pandas Series integration 

36* **Attribute Introspection**: 

37 - `get_attribute_list()` - Get all attribute names 

38 - `attribute_information` - Detailed metadata about each field 

39 - `update_attribute()` - Programmatically update attributes with validation 

40 - `add_new_field()` - Dynamically add new fields with validation rules 

41* **Standards Compliance**: Integrates with metadata standards and schemas for 

42 consistent, validated magnetotelluric data interchange 

43 

44This design ensures that metadata objects are always in a valid state, with type 

45safety, comprehensive validation, and flexible data exchange formats. 

46 

47""" 

48 

49from .metadata import MetadataBase 

50from .schema import BaseDict 

51 

52__all__ = ["MetadataBase", "BaseDict"]