mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/SPATZ.git
synced 2025-06-10 01:55:59 +00:00
added more features get time-specific values
This commit is contained in:
parent
4bd50375d7
commit
4def93041e
@ -80,7 +80,7 @@ class Dataset(Advanceable):
|
||||
int: The computed index.
|
||||
"""
|
||||
idx = (self.__df['time'] - t).abs().idxmin()
|
||||
idx = idx if self.__df['time'].loc[idx] < t else idx - 1
|
||||
idx = idx if self.__df['time'].loc[idx] <= t else idx - 1
|
||||
|
||||
return idx
|
||||
|
||||
@ -139,7 +139,14 @@ class Dataset(Advanceable):
|
||||
"""
|
||||
return max(self.__df['time'])
|
||||
|
||||
def fetch_init_value(self, name: str) -> float:
|
||||
def get_start_time(self) -> float:
|
||||
"""
|
||||
Returns:
|
||||
float: Returns the starting time of the simulation.
|
||||
"""
|
||||
return self.fetch_start_value('time')
|
||||
|
||||
def fetch_start_value(self, name: str) -> float:
|
||||
"""Get the initial value for a given attribute from the dataframe.
|
||||
|
||||
Args:
|
||||
@ -148,7 +155,7 @@ class Dataset(Advanceable):
|
||||
Returns:
|
||||
float: Returns the requested value.
|
||||
"""
|
||||
return self.__df[name].iloc[0]
|
||||
return self.__df.at[0, name]
|
||||
|
||||
def fetch_init_values(self, names: List[str]) -> ArrayLike:
|
||||
"""Get the initial value for given attributes from the dataframe.
|
||||
@ -159,7 +166,7 @@ class Dataset(Advanceable):
|
||||
Returns:
|
||||
np.array: Returns a numpy array containing the requested values in the same order as in the input list.
|
||||
"""
|
||||
return np.asarray([self.fetch_init_value(name) for name in names])
|
||||
return np.asarray([self.fetch_start_value(name) for name in names])
|
||||
|
||||
def fetch_value(self, name: str, t: float | None = None) -> float:
|
||||
"""Get a specific value from the dataframe.
|
||||
@ -171,7 +178,7 @@ class Dataset(Advanceable):
|
||||
Returns:
|
||||
float: Returns the requested value.
|
||||
"""
|
||||
idx = idx if t is None else self._get_closest_idx(t)
|
||||
idx = self.__idx if t is None else self._get_closest_idx(t)
|
||||
|
||||
if self.__interpolation == 'linear':
|
||||
t_min = self.__df.at[idx, 'time']
|
||||
@ -211,7 +218,7 @@ class Dataset(Advanceable):
|
||||
rots = self.fetch_values(['pitch_l', 'yaw_l', 'roll_l'], t)
|
||||
pitch_l, yaw_l, roll_l = rots[0], rots[1], rots[2]
|
||||
|
||||
return self.T1(roll_l) @ self.T2(pitch_l - math.pi/2) @ self.T1(-yaw_l)
|
||||
return T1(roll_l) @ T2(pitch_l - math.pi/2) @ T1(-yaw_l)
|
||||
|
||||
def global_to_local(self, t: float | None = None) -> ArrayLike:
|
||||
"""
|
||||
@ -223,11 +230,11 @@ class Dataset(Advanceable):
|
||||
"""
|
||||
decl = self.fetch_value('declination', t)
|
||||
long = self.fetch_value('longitude', t)
|
||||
t0 = self.__df['time'].iloc[0]
|
||||
t0 = self.get_start_time()
|
||||
|
||||
omega_E = (2*math.pi) / (24*60*60)
|
||||
|
||||
return self.T2(-decl) @ self.T3(long + omega_E * t0)
|
||||
return T2(-decl) @ T3(long + omega_E * t0)
|
||||
|
||||
def global_to_launch_rail(self, t: float | None = None) -> ArrayLike:
|
||||
"""
|
||||
@ -238,10 +245,10 @@ class Dataset(Advanceable):
|
||||
Returns:
|
||||
ArrayLike: The current transformation matrix from global to launch rail coords.
|
||||
"""
|
||||
init_long = self.__df['longitude'].iloc[0]
|
||||
init_lat = self.__df['latitude'].iloc[0]
|
||||
init_long = self.fetch_start_value('longitude')
|
||||
init_lat = self.fetch_start_value('latitude')
|
||||
|
||||
return self.T2(-math.pi/2 - init_lat) @ self.T3(init_long)
|
||||
return T2(-math.pi/2 - init_lat) @ T3(init_long)
|
||||
|
||||
def local_to_launch_rail(self, t: float | None = None) -> ArrayLike:
|
||||
"""
|
||||
@ -348,6 +355,16 @@ class Dataset(Advanceable):
|
||||
|
||||
return vel
|
||||
|
||||
def get_altitude(self, t: float | None = None) -> float:
|
||||
"""
|
||||
Args:
|
||||
t (float | None, optional): Allows specification of a different time instead of the current time. None for current time.
|
||||
|
||||
Returns:
|
||||
float: Returns the altitude in meter at the specified time.
|
||||
"""
|
||||
return self.fetch_value('altitude', t)
|
||||
|
||||
def get_speed_of_sound(self, t: float | None = None) -> float:
|
||||
"""
|
||||
Args:
|
||||
|
@ -24,8 +24,15 @@ class Observer:
|
||||
def _log(self, name: AnyStr, value: Any):
|
||||
self._logger.write(name, value, self._get_name())
|
||||
|
||||
def __call__(self) -> ArrayLike:
|
||||
data = self._dataset.fetch_values(self.__attrs)
|
||||
def get_start_value(self) -> ArrayLike:
|
||||
"""
|
||||
Returns:
|
||||
ArrayLike: Returns the values of the observed attributes at the start of the simulation.
|
||||
"""
|
||||
return self(t=self._dataset.get_start_time())
|
||||
|
||||
def __call__(self, t: float | None = None) -> ArrayLike:
|
||||
data = self._dataset.fetch_values(self.__attrs, t)
|
||||
|
||||
for attrib, value in zip(self.__attrs, data):
|
||||
self._log(attrib, value)
|
||||
|
@ -37,14 +37,14 @@ class Sensor:
|
||||
raise NotImplementedError()
|
||||
|
||||
@abstractmethod
|
||||
def _get_data(self, t: float = None) -> ArrayLike | float:
|
||||
def _get_data(self) -> ArrayLike | float:
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_init_data() -> ArrayLike:
|
||||
pass
|
||||
|
||||
def __call__(self, t: float = None) -> ArrayLike | float:
|
||||
out = self._get_data(t = t)
|
||||
def __call__(self) -> ArrayLike | float:
|
||||
out = self._get_data()
|
||||
out = self._sensor_specific_effects(out)
|
||||
|
||||
for transform in self._transforms:
|
||||
|
Loading…
x
Reference in New Issue
Block a user