Coverage for src/aquasense/hydroscat/calibrate.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2026-04-20 10:23 +0000

1""" 

2HydroScat calibration functions. 

3""" 

4 

5def seconds_since_posix_epoch_to_excel_days(seconds: float) -> float: 

6 """Convert seconds since January 1 1970 (POSIX epoch) 

7 to days since January 1 1900 (Excel epoch). 

8 

9 Args: 

10 seconds: seconds since POSIX epoch 

11 

12 Returns: 

13 The decimal days since Excel epoch. 

14 """ 

15 seconds_per_day = 86400 

16 days_since_1970 = seconds/seconds_per_day 

17 excel_day_1970_01_01 = 25569 

18 return days_since_1970 + excel_day_1970_01_01 

19 

20 

21def temperature(raw_temperature: int) -> float: 

22 """Convert the raw temperature to temperature in degrees C. 

23 See section 9.2.9 of HydroScat manual Rev J, TempRaw 

24 

25 Args: 

26 raw_temperature: raw integer temperature from a D or T packet 

27 

28 Returns: 

29 The converted, actual temperature. 

30 """ 

31 return raw_temperature / 5.0 - 10 

32 

33 

34def depth(raw_depth: int, depth_cal: float, depth_off: float) -> float: 

35 """Convert the raw depth to depth in metres. 

36 See section 9.2.8 of HydroScat manual Rev J, DepthRaw 

37 

38 Args: 

39 raw_depth: raw integer depth from a D or T packet. 

40 depth_cal: depth calibration value. 

41 depth_off: depth offset calibration value 

42 

43 Returns: 

44 The converted, actual depth. 

45 """ 

46 return raw_depth * depth_cal - depth_off 

47 

48 

49def voltage(raw_voltage: int) -> float: 

50 """Convert the raw voltage to a decimal voltage value. 

51 See section 9.4.5 of HydroScat manual Rev J, VsupA, VsupB, Vback 

52 

53 Args: 

54 raw_voltage: raw integer voltage value from a H packet. 

55 

56 Returns: 

57 The decimal voltage value. 

58 """ 

59 return raw_voltage / 10 

60 

61 

62def beta(s_norm: int, mu: float, 

63 temp_coeff: float, instr_temp: float, cal_temp: float, 

64 gain_ratio: float, r_nom: float) -> float: 

65 """Convert the raw signal to the value of the volume scattering function. 

66 See section 9.5 of HydroScat manual Rev J, Calculating beta and bb 

67 

68 Args: 

69 s_norm: raw normalized backscatter value from HydroScat 

70 mu: mu value from .cal file 

71 temp_coeff: temperature coefficient (TempCoeff) in .cal file 

72 instr_temp: instrument temperature from temperature function 

73 cal_temp: temperature calibration value (CalTemp) in .cal file 

74 gain_ratio: gain ratio for gain_g (Gain1 - Gain5) in .cal file 

75 r_nom: nominal reference value (Rnom) in .cal file 

76 

77 Returns: 

78 value of the volume scattering function, beta(140 degrees) 

79 """ 

80 return s_norm * mu / \ 

81 ((1.0 + temp_coeff*(instr_temp - cal_temp)) * gain_ratio * r_nom)