Coverage for physioblocks / library / functions / trigonometric.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-09 16:40 +0100

1# SPDX-FileCopyrightText: Copyright INRIA 

2# 

3# SPDX-License-Identifier: LGPL-3.0-only 

4# 

5# Copyright INRIA 

6# 

7# This file is part of PhysioBlocks, a library mostly developed by the 

8# [Ananke project-team](https://team.inria.fr/ananke) at INRIA. 

9# 

10# Authors: 

11# - Colin Drieu 

12# - Dominique Chapelle 

13# - François Kimmig 

14# - Philippe Moireau 

15# 

16# PhysioBlocks is free software: you can redistribute it and/or modify it under the 

17# terms of the GNU Lesser General Public License as published by the Free Software 

18# Foundation, version 3 of the License. 

19# 

20# PhysioBlocks is distributed in the hope that it will be useful, but WITHOUT ANY 

21# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 

22# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 

23# 

24# You should have received a copy of the GNU Lesser General Public License along with 

25# PhysioBlocks. If not, see <https://www.gnu.org/licenses/>. 

26 

27""" 

28Declare configuration function to set parameter with trigonometric function. 

29""" 

30 

31from dataclasses import dataclass 

32from typing import Any 

33 

34import numpy as np 

35 

36from physioblocks.registers.type_register import register_type 

37from physioblocks.simulation import AbstractFunction 

38 

39# sinus with offset function id 

40SINUS_OFFSET_NAME = "sinus_offset" 

41 

42 

43@register_type(SINUS_OFFSET_NAME) 

44@dataclass 

45class SinusOffset(AbstractFunction): 

46 """ 

47 Defines an evaluation method to get the value of a offset sinus 

48 function. 

49 """ 

50 

51 offset_value: float 

52 """Offset value of the function""" 

53 

54 amplitude: float 

55 """Peak amplitude of the function""" 

56 

57 frequency: float 

58 """Frequency of the function""" 

59 

60 phase_shift: float 

61 """Phase shift of the function""" 

62 

63 def eval(self, time: float) -> Any: 

64 """ 

65 Evaluate function value at the given time. 

66 

67 :param time: evaluation time 

68 :type time: float 

69 

70 :return: the function value 

71 :rtype: np.float64 

72 """ 

73 

74 output = self.offset_value + self.amplitude * np.sin( 

75 2 * np.pi * self.frequency * time + self.phase_shift 

76 ) 

77 

78 return output