Skip to content

Commit

Permalink
MNT: black
Browse files Browse the repository at this point in the history
  • Loading branch information
MateusStano committed Sep 16, 2024
1 parent a317e26 commit 24dbc1d
Show file tree
Hide file tree
Showing 37 changed files with 261 additions and 281 deletions.
10 changes: 5 additions & 5 deletions rocketpy/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def __init__(

def __initialize_constants(self):
"""Sets some important constants and atmospheric variables."""
self.earth_radius = 6.3781 * (10 ** 6)
self.earth_radius = 6.3781 * (10**6)
self.air_gas_constant = 287.05287 # in J/K/kg
self.standard_g = 9.80665
self.__weather_model_map = WeatherModelMapping()
Expand Down Expand Up @@ -563,7 +563,7 @@ def __reset_barometric_height_function(self):

def __reset_wind_speed_function(self):
# NOTE: assume wind_velocity_x and wind_velocity_y as Function objects
self.wind_speed = (self.wind_velocity_x ** 2 + self.wind_velocity_y ** 2) ** 0.5
self.wind_speed = (self.wind_velocity_x**2 + self.wind_velocity_y**2) ** 0.5
self.wind_speed.set_inputs("Height Above Sea Level (m)")
self.wind_speed.set_outputs("Wind Speed (m/s)")
self.wind_speed.set_title("Wind Speed Profile")
Expand Down Expand Up @@ -850,7 +850,7 @@ def somigliana_gravity(self, height):
height_correction = (
1
- height * 2 / a * (1 + f + m_rot - 2 * f * sin_lat_sqrd)
+ 3 * height ** 2 / a ** 2
+ 3 * height**2 / a**2
)

return height_correction * gravity_somgl
Expand Down Expand Up @@ -2802,8 +2802,8 @@ def calculate_earth_radius(
# Calculate the Earth Radius in meters
e_radius = np.sqrt(
(
(np.cos(lat) * (semi_major_axis ** 2)) ** 2
+ (np.sin(lat) * (semi_minor_axis ** 2)) ** 2
(np.cos(lat) * (semi_major_axis**2)) ** 2
+ (np.sin(lat) * (semi_minor_axis**2)) ** 2
)
/ (
(np.cos(lat) * semi_major_axis) ** 2
Expand Down
10 changes: 5 additions & 5 deletions rocketpy/environment/environment_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,10 +891,10 @@ def __parse_surface_data(self): # pylint: disable=too-many-statements
# Extract data from weather file
indices = (time_index, lon_index, lat_index)
for key, value in surface_file_dict.items():
dictionary[date_string][hour_string][
key
] = self.__extract_surface_data_value(
surface_data, value, indices, lon_array, lat_array
dictionary[date_string][hour_string][key] = (
self.__extract_surface_data_value(
surface_data, value, indices, lon_array, lat_array
)
)

# Get elevation, time index does not matter, use last one
Expand Down Expand Up @@ -2040,7 +2040,7 @@ def __process_surface_wind_data(self):
vy = self.converted_surface_data[day][str(hour)][
"surface10m_wind_velocity_y"
]
wind_speed[hour][index] = (vx ** 2 + vy ** 2) ** 0.5
wind_speed[hour][index] = (vx**2 + vy**2) ** 0.5

# Wind direction means where the wind is blowing from, 180 deg opposite from wind heading
direction = (180 + (np.arctan2(vy, vx) * 180 / np.pi)) % 360
Expand Down
12 changes: 6 additions & 6 deletions rocketpy/environment/fetchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def fetch_gfs_file_return_dataset(max_attempts=10, base_delay=2):
return dataset
except OSError:
attempt_count += 1
time.sleep(base_delay ** attempt_count)
time.sleep(base_delay**attempt_count)

if dataset is None:
raise RuntimeError(
Expand Down Expand Up @@ -182,7 +182,7 @@ def fetch_nam_file_return_dataset(max_attempts=10, base_delay=2):
return dataset
except OSError:
attempt_count += 1
time.sleep(base_delay ** attempt_count)
time.sleep(base_delay**attempt_count)

if dataset is None:
raise RuntimeError("Unable to load latest weather data for NAM through " + file)
Expand Down Expand Up @@ -227,7 +227,7 @@ def fetch_rap_file_return_dataset(max_attempts=10, base_delay=2):
return dataset
except OSError:
attempt_count += 1
time.sleep(base_delay ** attempt_count)
time.sleep(base_delay**attempt_count)

if dataset is None:
raise RuntimeError("Unable to load latest weather data for RAP through " + file)
Expand Down Expand Up @@ -281,7 +281,7 @@ def fetch_hiresw_file_return_dataset(max_attempts=10, base_delay=2):
return dataset
except OSError:
attempt_count += 1
time.sleep(base_delay ** attempt_count)
time.sleep(base_delay**attempt_count)

if dataset is None:
raise RuntimeError(
Expand Down Expand Up @@ -385,7 +385,7 @@ def fetch_gefs_ensemble():
return dataset
except OSError:
attempt_count += 1
time.sleep(2 ** attempt_count)
time.sleep(2**attempt_count)
if not success:
raise RuntimeError(
"Unable to load latest weather data for GEFS through " + file
Expand Down Expand Up @@ -427,6 +427,6 @@ def fetch_cmc_ensemble():
return dataset
except OSError:
attempt_count += 1
time.sleep(2 ** attempt_count)
time.sleep(2**attempt_count)
if not success:
raise RuntimeError("Unable to load latest weather data for CMC through " + file)
16 changes: 8 additions & 8 deletions rocketpy/environment/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def calculate_wind_speed(u, v, w=0.0):
>>> calculate_wind_speed(3, 4, 0)
np.float64(5.0)
"""
return np.sqrt(u ** 2 + v ** 2 + w ** 2)
return np.sqrt(u**2 + v**2 + w**2)


## These functions are meant to be used with netcdf4 datasets
Expand Down Expand Up @@ -482,7 +482,7 @@ def geodesic_to_utm(

# Evaluate reference parameters
K0 = 1 - 1 / 2500
e2 = 2 * flattening - flattening ** 2
e2 = 2 * flattening - flattening**2
e2lin = e2 / (1 - e2)

# Evaluate auxiliary parameters
Expand All @@ -505,9 +505,9 @@ def geodesic_to_utm(

# Evaluate new auxiliary parameters
J = (1 - t + c) * ag * ag * ag / 6
K = (5 - 18 * t + t * t + 72 * c - 58 * e2lin) * (ag ** 5) / 120
K = (5 - 18 * t + t * t + 72 * c - 58 * e2lin) * (ag**5) / 120
L = (5 - t + 9 * c + 4 * c * c) * ag * ag * ag * ag / 24
M = (61 - 58 * t + t * t + 600 * c - 330 * e2lin) * (ag ** 6) / 720
M = (61 - 58 * t + t * t + 600 * c - 330 * e2lin) * (ag**6) / 720

# Evaluate the final coordinates
x = 500000 + K0 * n * (ag + J + K)
Expand Down Expand Up @@ -542,7 +542,7 @@ def utm_to_geodesic( # pylint: disable=too-many-locals,too-many-statements

# Calculate reference values
K0 = 1 - 1 / 2500
e2 = 2 * flattening - flattening ** 2
e2 = 2 * flattening - flattening**2
e2lin = e2 / (1 - e2)
e1 = (1 - (1 - e2) ** 0.5) / (1 + (1 - e2) ** 0.5)

Expand All @@ -566,18 +566,18 @@ def utm_to_geodesic( # pylint: disable=too-many-locals,too-many-statements
t1 = np.tan(lat1) ** 2
n1 = semi_major_axis / ((1 - e2 * (np.sin(lat1) ** 2)) ** 0.5)
quoc = (1 - e2 * np.sin(lat1) * np.sin(lat1)) ** 3
r1 = semi_major_axis * (1 - e2) / (quoc ** 0.5)
r1 = semi_major_axis * (1 - e2) / (quoc**0.5)
d = (x - 500000) / (n1 * K0)

# Calculate other auxiliary values
aux_i = (5 + 3 * t1 + 10 * c1 - 4 * c1 * c1 - 9 * e2lin) * d * d * d * d / 24
J = (
(61 + 90 * t1 + 298 * c1 + 45 * t1 * t1 - 252 * e2lin - 3 * c1 * c1)
* (d ** 6)
* (d**6)
/ 720
)
K = d - (1 + 2 * t1 + c1) * d * d * d / 6
L = (5 - 2 * c1 + 28 * t1 - 3 * c1 * c1 + 8 * e2lin + 24 * t1 * t1) * (d ** 5) / 120
L = (5 - 2 * c1 + 28 * t1 - 3 * c1 * c1 + 8 * e2lin + 24 * t1 * t1) * (d**5) / 120

# Finally calculate the coordinates in lat/lot
lat = lat1 - (n1 * np.tan(lat1) / r1) * (d * d / 2 - aux_i + J)
Expand Down
8 changes: 4 additions & 4 deletions rocketpy/mathutils/vector_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def cross_matrix(self):

def __abs__(self):
"""R3 vector norm, magnitude or absolute value."""
return (self.x ** 2 + self.y ** 2 + self.z ** 2) ** 0.5
return (self.x**2 + self.y**2 + self.z**2) ** 0.5

def __neg__(self):
"""-1 times R3 vector self."""
Expand Down Expand Up @@ -1033,9 +1033,9 @@ def transformation(quaternion):
q_w, q_x, q_y, q_z = normalize_quaternions(quaternion)

# pre-compute common terms
q_x2 = q_x ** 2
q_y2 = q_y ** 2
q_z2 = q_z ** 2
q_x2 = q_x**2
q_y2 = q_y**2
q_z2 = q_z**2
q_wx = q_w * q_x
q_wy = q_w * q_y
q_wz = q_w * q_z
Expand Down
4 changes: 2 additions & 2 deletions rocketpy/motors/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ def propellant_I_11(self):
"""
return (
self.propellant_mass
* (3 * self.chamber_radius ** 2 + self.chamber_height ** 2)
* (3 * self.chamber_radius**2 + self.chamber_height**2)
/ 12
)

Expand Down Expand Up @@ -1333,7 +1333,7 @@ def propellant_I_33(self):
----------
https://en.wikipedia.org/wiki/Moment_of_inertia#Inertia_tensor
"""
return self.propellant_mass * self.chamber_radius ** 2 / 2
return self.propellant_mass * self.chamber_radius**2 / 2

@funcify_method("Time (s)", "Inertia I_12 (kg m²)")
def propellant_I_12(self):
Expand Down
26 changes: 13 additions & 13 deletions rocketpy/motors/solid_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ class Function. Thrust units are Newtons.
)
# Nozzle parameters
self.throat_radius = throat_radius
self.throat_area = np.pi * throat_radius ** 2
self.throat_area = np.pi * throat_radius**2

# Grain parameters
self.grains_center_of_mass_position = grains_center_of_mass_position
Expand All @@ -331,7 +331,7 @@ class Function. Thrust units are Newtons.
self.grain_initial_volume = (
self.grain_initial_height
* np.pi
* (self.grain_outer_radius ** 2 - self.grain_initial_inner_radius ** 2)
* (self.grain_outer_radius**2 - self.grain_initial_inner_radius**2)
)
self.grain_initial_mass = self.grain_density * self.grain_initial_volume

Expand Down Expand Up @@ -364,7 +364,7 @@ def grain_volume(self):
Propellant volume as a function of time.
"""
cross_section_area = np.pi * (
self.grain_outer_radius ** 2 - self.grain_inner_radius ** 2
self.grain_outer_radius**2 - self.grain_inner_radius**2
)
return cross_section_area * self.grain_height

Expand Down Expand Up @@ -481,8 +481,8 @@ def geometry_dot(t, y):
2
* np.pi
* (
grain_outer_radius ** 2
- grain_inner_radius ** 2
grain_outer_radius**2
- grain_inner_radius**2
+ grain_inner_radius * grain_height
)
)
Expand All @@ -502,8 +502,8 @@ def geometry_jacobian(t, y):
2
* np.pi
* (
grain_outer_radius ** 2
- grain_inner_radius ** 2
grain_outer_radius**2
- grain_inner_radius**2
+ grain_inner_radius * grain_height
)
** 2
Expand Down Expand Up @@ -578,8 +578,8 @@ def burn_area(self):
2
* np.pi
* (
self.grain_outer_radius ** 2
- self.grain_inner_radius ** 2
self.grain_outer_radius**2
- self.grain_inner_radius**2
+ self.grain_inner_radius * self.grain_height
)
* self.grain_number
Expand Down Expand Up @@ -649,8 +649,8 @@ def propellant_I_11(self):
grain_mass = self.propellant_mass / self.grain_number
grain_number = self.grain_number
grain_inertia11 = grain_mass * (
(1 / 4) * (self.grain_outer_radius ** 2 + self.grain_inner_radius ** 2)
+ (1 / 12) * self.grain_height ** 2
(1 / 4) * (self.grain_outer_radius**2 + self.grain_inner_radius**2)
+ (1 / 12) * self.grain_height**2
)

# Calculate each grain's distance d to propellant center of mass
Expand All @@ -660,7 +660,7 @@ def propellant_I_11(self):
d = d * (self.grain_initial_height + self.grain_separation)

# Calculate inertia for all grains
I_11 = grain_number * grain_inertia11 + grain_mass * np.sum(d ** 2)
I_11 = grain_number * grain_inertia11 + grain_mass * np.sum(d**2)

return I_11

Expand Down Expand Up @@ -709,7 +709,7 @@ def propellant_I_33(self):
I_33 = (
(1 / 2.0)
* self.propellant_mass
* (self.grain_outer_radius ** 2 + self.grain_inner_radius ** 2)
* (self.grain_outer_radius**2 + self.grain_inner_radius**2)
)
return I_33

Expand Down
4 changes: 2 additions & 2 deletions rocketpy/motors/tank.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def liquid_inertia(self):
Ix_volume = Ix_volume @ self.liquid_height

# Steiner theorem to account for center of mass
Ix_volume -= self.liquid_volume * self.liquid_center_of_mass ** 2
Ix_volume -= self.liquid_volume * self.liquid_center_of_mass**2
Ix_volume += (
self.liquid_volume * (self.liquid_center_of_mass - self.center_of_mass) ** 2
)
Expand All @@ -380,7 +380,7 @@ def gas_inertia(self):
inertia_volume = upper_inertia_volume - lower_inertia_volume

# Steiner theorem to account for center of mass
inertia_volume -= self.gas_volume * self.gas_center_of_mass ** 2
inertia_volume -= self.gas_volume * self.gas_center_of_mass**2
inertia_volume += (
self.gas_volume * (self.gas_center_of_mass - self.center_of_mass) ** 2
)
Expand Down
14 changes: 7 additions & 7 deletions rocketpy/motors/tank_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def area(self):
Function
Tank cross sectional area as a function of height.
"""
return np.pi * self.radius ** 2
return np.pi * self.radius**2

@funcify_method("Height (m)", "Volume (m³)", extrapolation="zero")
def volume(self):
Expand Down Expand Up @@ -212,7 +212,7 @@ def inverse_volume(self):
Tank height as a function of volume.
"""
return self.volume.inverse_function(
lambda v: v / (np.pi * self.average_radius ** 2),
lambda v: v / (np.pi * self.average_radius**2),
)

@cache
Expand Down Expand Up @@ -278,7 +278,7 @@ def Ix_volume(self, lower, upper):
# Tolerance of 1e-8 is used to avoid numerical errors
upper = upper + 1e-12 if upper - lower < 1e-8 else upper

inertia = (self.area * (height2 + self.radius ** 2 / 4)).integral_function(
inertia = (self.area * (height2 + self.radius**2 / 4)).integral_function(
lower, upper
)

Expand Down Expand Up @@ -325,7 +325,7 @@ def Iz_volume(self, lower, upper):
# Tolerance of 1e-8 is used to avoid numerical errors
upper = upper + 1e-12 if upper - lower < 1e-8 else upper

inertia = (self.area * self.radius ** 2).integral_function(lower, upper) / 2
inertia = (self.area * self.radius**2).integral_function(lower, upper) / 2

return inertia

Expand Down Expand Up @@ -402,10 +402,10 @@ def add_spherical_caps(self):
upper_cap_range = (height / 2 - radius, height / 2)

def bottom_cap_radius(h):
return abs(radius ** 2 - (h + (height / 2 - radius)) ** 2) ** 0.5
return abs(radius**2 - (h + (height / 2 - radius)) ** 2) ** 0.5

def upper_cap_radius(h):
return abs(radius ** 2 - (h - (height / 2 - radius)) ** 2) ** 0.5
return abs(radius**2 - (h - (height / 2 - radius)) ** 2) ** 0.5

self.add_geometry(bottom_cap_range, bottom_cap_radius)
self.add_geometry(upper_cap_range, upper_cap_radius)
Expand Down Expand Up @@ -434,4 +434,4 @@ def __init__(self, radius, geometry_dict=None):
"""
geometry_dict = geometry_dict or {}
super().__init__(geometry_dict)
self.add_geometry((-radius, radius), lambda h: (radius ** 2 - h ** 2) ** 0.5)
self.add_geometry((-radius, radius), lambda h: (radius**2 - h**2) ** 0.5)
4 changes: 2 additions & 2 deletions rocketpy/plots/aero_surface_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ def draw(self):
/ (3 * (self.aero_surface.root_chord + self.aero_surface.tip_chord))
)
yma_end = (
2 * self.aero_surface.root_chord ** 2
2 * self.aero_surface.root_chord**2
+ self.aero_surface.root_chord * self.aero_surface.sweep_length
+ 2 * self.aero_surface.root_chord * self.aero_surface.tip_chord
+ 2 * self.aero_surface.sweep_length * self.aero_surface.tip_chord
+ 2 * self.aero_surface.tip_chord ** 2
+ 2 * self.aero_surface.tip_chord**2
) / (3 * (self.aero_surface.root_chord + self.aero_surface.tip_chord))
yma_line = plt.Line2D(
(yma_start, yma_end),
Expand Down
Loading

0 comments on commit 24dbc1d

Please sign in to comment.