Skip to content

Commit c445e37

Browse files
committed
ENH: add berkeley data
1 parent 7c33fbf commit c445e37

22 files changed

+5905
-1
lines changed

docs/notebooks/time_post_process.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import timeit
2+
from unittest.mock import patch
3+
4+
import numpy as np
5+
6+
from rocketpy import Environment, SolidMotor, Rocket, Flight
7+
8+
Env = Environment(
9+
railLength=5.2, latitude=32.990254, longitude=-106.974998, elevation=1400
10+
)
11+
Pro75M1670 = SolidMotor(
12+
thrustSource="../../data/motors/Cesaroni_M1670.eng",
13+
burnOut=3.9,
14+
grainNumber=5,
15+
grainSeparation=5 / 1000,
16+
grainDensity=1815,
17+
grainOuterRadius=33 / 1000,
18+
grainInitialInnerRadius=15 / 1000,
19+
grainInitialHeight=120 / 1000,
20+
nozzleRadius=33 / 1000,
21+
throatRadius=11 / 1000,
22+
interpolationMethod="linear",
23+
)
24+
Calisto = Rocket(
25+
motor=Pro75M1670,
26+
radius=127 / 2000,
27+
mass=19.197 - 2.956,
28+
inertiaI=6.60,
29+
inertiaZ=0.0351,
30+
distanceRocketNozzle=-1.255,
31+
distanceRocketPropellant=-0.85704,
32+
powerOffDrag="../../data/calisto/powerOffDragCurve.csv",
33+
powerOnDrag="../../data/calisto/powerOnDragCurve.csv",
34+
)
35+
36+
Calisto.setRailButtons([0.2, -0.5])
37+
NoseCone = Calisto.addNose(length=0.55829, kind="vonKarman", distanceToCM=0.71971)
38+
39+
FinSet = Calisto.addTrapezoidalFins(
40+
n=4,
41+
rootChord=0.120,
42+
tipChord=0.040,
43+
span=0.100,
44+
distanceToCM=-1.04956,
45+
cantAngle=0,
46+
radius=None,
47+
airfoil=None,
48+
)
49+
50+
Tail = Calisto.addTail(
51+
topRadius=0.0635, bottomRadius=0.0435, length=0.060, distanceToCM=-1.194656
52+
)
53+
54+
55+
def drogueTrigger(p, y):
56+
# p = pressure
57+
# y = [x, y, z, vx, vy, vz, e0, e1, e2, e3, w1, w2, w3]
58+
# activate drogue when vz < 0 m/s.
59+
return True if y[5] < 0 else False
60+
61+
62+
def mainTrigger(p, y):
63+
# p = pressure
64+
# y = [x, y, z, vx, vy, vz, e0, e1, e2, e3, w1, w2, w3]
65+
# activate main when vz < 0 m/s and z < 800 + 1400 m (+1400 due to surface elevation).
66+
return True if y[5] < 0 and y[2] < 800 + 1400 else False
67+
68+
69+
Main = Calisto.addParachute(
70+
"Main",
71+
CdS=10.0,
72+
trigger=mainTrigger,
73+
samplingRate=105,
74+
lag=1.5,
75+
noise=(0, 8.3, 0.5),
76+
)
77+
78+
Drogue = Calisto.addParachute(
79+
"Drogue",
80+
CdS=1.0,
81+
trigger=drogueTrigger,
82+
samplingRate=105,
83+
lag=1.5,
84+
noise=(0, 8.3, 0.5),
85+
)
86+
87+
result = timeit.repeat(
88+
"TestFlight = Flight(rocket=Calisto, environment=Env, inclination=85, heading=0)",
89+
globals=globals(),
90+
number=1,
91+
repeat=15,
92+
)
93+
result = np.array(result)
94+
print("Mean: ", result.mean())
95+
print("Std: ", result.std())
96+
print("Min: ", np.min(result))
97+
print("Max: ", np.max(result))
98+
99+
TestFlight = Flight(rocket=Calisto, environment=Env, inclination=85, heading=0)
100+
result = timeit.repeat(
101+
"""with patch('matplotlib.pyplot.show') as p, patch('matplotlib.pyplot.figure') as p, patch('matplotlib.pyplot.plot') as p, patch('builtins.print') as pp:
102+
TestFlight.allInfo()""",
103+
globals=globals(),
104+
number=1,
105+
repeat=15,
106+
)
107+
result = np.array(result)
108+
print("Mean: ", result.mean())
109+
print("Std: ", result.std())
110+
print("Min: ", np.min(result))
111+
print("Max: ", np.max(result))

rocketpy/Function.py

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,52 @@ def reset(
626626

627627
return self
628628

629+
# Define transformation methods
630+
def crop(self, domain):
631+
"""This method allows the user to crop a Function object, i.e. to define
632+
a new Function object with a smaller domain.
633+
634+
Parameters
635+
----------
636+
domain : list of tuples
637+
List of tuples containing the lower and upper bounds of the domain
638+
to be cropped. The length of the list must be equal to the domain
639+
dimension of the Function object.
640+
641+
Examples
642+
--------
643+
>>> from rocketpy import Function
644+
>>> f = Function(lambda x: x**2, inputs='x', outputs='y')
645+
>>> f
646+
Function from R1 to R1 : (x) → (y)
647+
>>> f.crop([(-1, 1)])
648+
649+
Returns
650+
-------
651+
self : Function
652+
"""
653+
if not isinstance(domain, list):
654+
raise TypeError("domain must be a list of tuples.")
655+
if len(domain) != self.__domDim__:
656+
raise ValueError(
657+
"domain must have the same length as the domain dimension."
658+
)
659+
660+
if self.__domDim__ == 1:
661+
self.source = self.source[
662+
(self.source[:, 0] >= domain[0][0])
663+
& (self.source[:, 0] <= domain[0][1])
664+
]
665+
elif self.__domDim__ == 2:
666+
self.source = self.source[
667+
(self.source[:, 0] >= domain[0][0])
668+
& (self.source[:, 0] <= domain[0][1])
669+
& (self.source[:, 1] >= domain[1][0])
670+
& (self.source[:, 1] <= domain[1][1])
671+
]
672+
673+
return self
674+
629675
# Define all get methods
630676
def getInputs(self):
631677
"Return tuple of inputs of the function."
@@ -2227,7 +2273,50 @@ def integral(self, a, b, numerical=False):
22272273
# self.__extrapolation__ = 'zero'
22282274
pass
22292275
elif self.__interpolation__ == "linear" and numerical is False:
2230-
return np.trapz(self.source[:, 1], x=self.source[:, 0])
2276+
# Integrate from a to b using np.trapz
2277+
xData = self.source[:, 0]
2278+
yData = self.source[:, 1]
2279+
# Get data in interval
2280+
xData = xData[(xData >= a) & (xData <= b)]
2281+
yData = yData[(xData >= a) & (xData <= b)]
2282+
# Check to see if interval starts before point data
2283+
if a < xData[0]:
2284+
if self.__extrapolation__ == "constant":
2285+
yData = np.append(yData[0], yData)
2286+
xData = np.append(a, xData)
2287+
elif self.__extrapolation__ == "natural":
2288+
# Linearly extrapolate first point
2289+
yData = np.append(
2290+
yData[0]
2291+
+ (yData[0] - yData[1])
2292+
/ (xData[1] - xData[0])
2293+
* (a - xData[0]),
2294+
yData,
2295+
)
2296+
xData = np.append(a, xData)
2297+
else:
2298+
# self.__extrapolation__ = 'zero'
2299+
pass
2300+
# Check to see if interval ends after point data
2301+
if b > xData[-1]:
2302+
if self.__extrapolation__ == "constant":
2303+
yData = np.append(yData, yData[-1])
2304+
xData = np.append(xData, b)
2305+
elif self.__extrapolation__ == "natural":
2306+
# Linearly extrapolate last point
2307+
yData = np.append(
2308+
yData,
2309+
yData[-1]
2310+
+ (yData[-1] - yData[-2])
2311+
/ (xData[-1] - xData[-2])
2312+
* (b - xData[-1]),
2313+
)
2314+
xData = np.append(xData, b)
2315+
else:
2316+
# self.__extrapolation__ = 'zero'
2317+
pass
2318+
# Integrate using np.trapz
2319+
ans = np.trapz(yData, xData)
22312320
else:
22322321
# Integrate numerically
22332322
ans, _ = integrate.quad(self, a, b, epsabs=0.1, limit=10000)
Binary file not shown.

validation/space_enterprises_at_berkeley/flight_data.ipynb

Lines changed: 917 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)