1
1
"""
2
- Subclassing BaseObj - Simple Pendulum
2
+ Subclassing ObjBase - Simple Pendulum
3
3
=====================================
4
- This example shows how to subclass :class:`easyscience.Objects.Base.BaseObj ` with parameters from
5
- :class:`EasyScience.Objects.Base .Parameter`. For this example a simple pendulum will be modeled.
4
+ This example shows how to subclass :class:`easyscience.base_classes.ObjBase ` with parameters from
5
+ :class:`EasyScience.variable .Parameter`. For this example a simple pendulum will be modeled.
6
6
7
7
.. math::
8
8
y = A \sin (2 \pi f t + \phi )
17
17
import matplotlib .pyplot as plt
18
18
import numpy as np
19
19
20
- from easyscience .Objects . ObjectClasses import BaseObj
21
- from easyscience .Objects . ObjectClasses import Parameter
20
+ from easyscience .base_classes import ObjBase
21
+ from easyscience .variable import Parameter
22
22
23
23
# %%
24
24
# Subclassing
29
29
# embedded rST text block:
30
30
31
31
32
- class Pendulum (BaseObj ):
32
+ class Pendulum (ObjBase ):
33
33
def __init__ (self , A : Parameter , f : Parameter , p : Parameter ):
34
34
super (Pendulum , self ).__init__ ('SimplePendulum' , A = A , f = f , p = p )
35
35
@@ -41,13 +41,13 @@ def from_pars(cls, A: float = 1, f: float = 1, p: float = 0):
41
41
return cls (A , f , p )
42
42
43
43
def __call__ (self , t ):
44
- return self .A .raw_value * np .sin (2 * np .pi * self .f .raw_value * t + self .p .raw_value )
44
+ return self .A .value * np .sin (2 * np .pi * self .f .value * t + self .p .value )
45
45
46
46
def plot (self , time , axis = None , ** kwargs ):
47
47
if axis is None :
48
48
axis = plt
49
49
else :
50
- axis .set_title (f'A={ self .A .raw_value } , F={ self .f .raw_value } , P={ self .p .raw_value } ' )
50
+ axis .set_title (f'A={ self .A .value } , F={ self .f .value } , P={ self .p .value } ' )
51
51
p = axis .plot (time , self (time ), ** kwargs )
52
52
return p
53
53
0 commit comments