-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathenvironment.py
More file actions
66 lines (52 loc) · 1.81 KB
/
Copy pathenvironment.py
File metadata and controls
66 lines (52 loc) · 1.81 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
from typing import Self
import dill
from rocketpy.environment.environment import Environment as RocketPyEnvironment
from src.models.environment import EnvironmentModel
from src.views.environment import EnvironmentSimulation
from src.utils import rocketpy_encoder, DiscretizeConfig
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,
)
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 = rocketpy_encoder(
self.environment, DiscretizeConfig.for_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)