mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/SPATZ.git
synced 2025-06-10 01:55:59 +00:00
Performance increases by replacing "df.loc" by "df.at"
This commit is contained in:
parent
f5f30953ca
commit
58d362c8f9
@ -8,4 +8,4 @@ import spatz.transforms as transforms
|
||||
from spatz.transforms import *
|
||||
|
||||
from spatz.dataset import *
|
||||
from spatz.simulation import *
|
||||
from spatz.simulation import *
|
@ -0,0 +1 @@
|
||||
from spatz.connections.serial import *
|
@ -199,18 +199,18 @@ class Dataset(Advanceable):
|
||||
float: Returns the requested value.
|
||||
"""
|
||||
if self.__interpolation == 'linear':
|
||||
t_min = self.__df['time'].iloc[self.__idx]
|
||||
t_max = self.__df['time'].iloc[self.__idx + 1]
|
||||
t_min = self.__df.at[self.__idx, 'time']
|
||||
t_max = self.__df.at[self.__idx + 1, 'time']
|
||||
|
||||
# Sometimes no time passes in-between two samples.
|
||||
if t_max == t_min:
|
||||
return self.__df[name].iloc[self.__idx]
|
||||
return self.__df.at[name, self.__idx]
|
||||
|
||||
# Compute the weight for interpolation.
|
||||
alpha = (self.get_time() - t_min) / (t_max - t_min)
|
||||
|
||||
# Interpolate linearly between the two data points.
|
||||
return (1 - alpha) * self.__df[name].iloc[self.__idx] + alpha * self.__df[name].iloc[self.__idx + 1]
|
||||
return (1 - alpha) * self.__df.at[self.__idx, name] + alpha * self.__df.at[self.__idx + 1, name]
|
||||
|
||||
def fetch_values(self, names: List[str]) -> np.array:
|
||||
"""Get specific values from the dataframe.
|
||||
|
@ -49,9 +49,9 @@ class Logger(Advanceable):
|
||||
self.__idx = -1
|
||||
|
||||
def _on_step(self, _: float):
|
||||
self.__df = pd.concat([self.__df, pd.DataFrame()], ignore_index=True)
|
||||
self.__df = pd.concat([pd.DataFrame(), self.__df], ignore_index=True, copy=False)
|
||||
self.__idx += 1
|
||||
self.__df.loc[self.__idx, 'time'] = self.get_time()
|
||||
self.__df.at[self.__idx, 'time'] = self.get_time()
|
||||
|
||||
def _on_reset(self):
|
||||
self.__df = pd.DataFrame.from_dict({'time': [self.get_time()]}).astype(np.float64)
|
||||
@ -64,12 +64,12 @@ class Logger(Advanceable):
|
||||
value (Any): The value to log.
|
||||
domain (str, optional): The domain the value belongs to. Defaults to 'any'.
|
||||
"""
|
||||
name = domain + '/' + attrib
|
||||
name = f'{domain}/{attrib}'
|
||||
|
||||
if name not in self.__df.columns:
|
||||
self.__df[name] = pd.Series([pd.NA] * len(self.__df))
|
||||
|
||||
self.__df.loc[self.__idx, name] = value
|
||||
self.__df.at[self.__idx, name] = value
|
||||
|
||||
def get_dataframe(self) -> pd.DataFrame:
|
||||
return self.__df
|
@ -2,7 +2,4 @@ from spatz.sensors.sensor import Sensor
|
||||
from spatz.sensors.gps import GPS
|
||||
from spatz.sensors.imu import Accelerometer, Gyroscope, IMU
|
||||
from spatz.sensors.pressure import PressureSensor
|
||||
from spatz.sensors.compound import CompoundSensor
|
||||
|
||||
|
||||
from pandas import NA
|
||||
from spatz.sensors.compound import CompoundSensor
|
0
spatz/simulations/__init__.py
Normal file
0
spatz/simulations/__init__.py
Normal file
0
spatz/simulations/astos/__init__.py
Normal file
0
spatz/simulations/astos/__init__.py
Normal file
0
spatz/simulations/rocketpy/__init__.py
Normal file
0
spatz/simulations/rocketpy/__init__.py
Normal file
Loading…
x
Reference in New Issue
Block a user