Coverage for C: \ Users \ peaco \ OneDrive \ Documents \ GitHub \ mt_metadata \ mt_metadata \ common \ declination.py: 100%

15 statements  

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

1# ===================================================== 

2# Imports 

3# ===================================================== 

4from typing import Annotated 

5 

6from pydantic import Field, field_validator, ValidationInfo 

7 

8from mt_metadata.base import MetadataBase 

9from mt_metadata.common import Comment, GeomagneticModelEnum 

10 

11 

12# ===================================================== 

13 

14 

15class Declination(MetadataBase): 

16 comments: Annotated[ 

17 Comment, 

18 Field( 

19 default_factory=lambda: Comment(), 

20 description="any comments on declination", 

21 alias=None, 

22 json_schema_extra={ 

23 "units": None, 

24 "required": False, 

25 "examples": ["estimated from WMM 2016"], 

26 }, 

27 ), 

28 ] 

29 

30 model: Annotated[ 

31 GeomagneticModelEnum, 

32 Field( 

33 default="IGRF", 

34 description="geomagnetic reference model used to calculate declination", 

35 json_schema_extra={ 

36 "units": None, 

37 "required": True, 

38 "examples": ["WMM"], 

39 }, 

40 ), 

41 ] 

42 

43 epoch: Annotated[ 

44 str | None, 

45 Field( 

46 default=None, 

47 description="Epoch for which declination was approximated in.", 

48 json_schema_extra={ 

49 "units": None, 

50 "required": False, 

51 "examples": ["2020"], 

52 }, 

53 ), 

54 ] 

55 

56 value: Annotated[ 

57 float, 

58 Field( 

59 default=0.0, 

60 description="declination angle relative to geographic north positive clockwise", 

61 json_schema_extra={ 

62 "units": "degrees", 

63 "required": True, 

64 "examples": ["12.5"], 

65 }, 

66 ), 

67 ] 

68 

69 @field_validator("comments", mode="before") 

70 @classmethod 

71 def validate_comments(cls, value, info: ValidationInfo) -> Comment: 

72 """ 

73 Validate that the value is a valid comment. 

74 """ 

75 if isinstance(value, str): 

76 return Comment(value=value) 

77 return value