-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathenvironment.py
More file actions
68 lines (54 loc) · 1.89 KB
/
environment.py
File metadata and controls
68 lines (54 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from typing import Self
import dill
from rocketpy.environment.environment import Environment as RocketPyEnvironment
from rocketpy.utilities import get_instance_attributes
from src.models.environment import EnvironmentModel
from src.views.environment import EnvironmentSimulation
class EnvironmentService:
_environment: RocketPyEnvironment
def __init__(self, environment: RocketPyEnvironment = None):
self._environment = environment
@classmethod
def from_env_model(cls, env: EnvironmentModel) -> Self:
"""
Get the rocketpy env object.
Returns:
RocketPyEnvironment
"""
rocketpy_env = RocketPyEnvironment(
latitude=env.latitude,
longitude=env.longitude,
elevation=env.elevation,
date=env.date,
)
rocketpy_env.set_atmospheric_model(
type=env.atmospheric_model_type,
file=env.atmospheric_model_file,
pressure=env.pressure,
temperature=env.temperature,
wind_u=env.wind_u,
wind_v=env.wind_v,
)
return cls(environment=rocketpy_env)
@property
def environment(self) -> RocketPyEnvironment:
return self._environment
@environment.setter
def environment(self, environment: RocketPyEnvironment):
self._environment = environment
def get_environment_simulation(self) -> EnvironmentSimulation:
"""
Get the simulation of the environment.
Returns:
EnvironmentSimulation
"""
attributes = get_instance_attributes(self.environment)
env_simulation = EnvironmentSimulation(**attributes)
return env_simulation
def get_environment_binary(self) -> bytes:
"""
Get the binary representation of the environment.
Returns:
bytes
"""
return dill.dumps(self.environment)