Skip to content

Commit

Permalink
STY: Applies black and isort
Browse files Browse the repository at this point in the history
  • Loading branch information
LUCKIN13 committed Sep 15, 2024
1 parent 09659a1 commit 1ed8a9e
Show file tree
Hide file tree
Showing 48 changed files with 380 additions and 357 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][

Check warning on line 894 in rocketpy/environment/environment_analysis.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/environment_analysis.py#L894

Added line #L894 was not covered by tests
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

Check warning on line 2043 in rocketpy/environment/environment_analysis.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/environment_analysis.py#L2043

Added line #L2043 was not covered by tests

# 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)

Check warning on line 138 in rocketpy/environment/fetchers.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/fetchers.py#L138

Added line #L138 was not covered by tests

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)

Check warning on line 185 in rocketpy/environment/fetchers.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/fetchers.py#L185

Added line #L185 was not covered by tests

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)

Check warning on line 230 in rocketpy/environment/fetchers.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/fetchers.py#L230

Added line #L230 was not covered by tests

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)

Check warning on line 284 in rocketpy/environment/fetchers.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/fetchers.py#L284

Added line #L284 was not covered by tests

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)

Check warning on line 388 in rocketpy/environment/fetchers.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/fetchers.py#L388

Added line #L388 was not covered by tests
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)

Check warning on line 430 in rocketpy/environment/fetchers.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/fetchers.py#L430

Added line #L430 was not covered by tests
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
64 changes: 32 additions & 32 deletions rocketpy/mathutils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def akima_interpolation(
x_interval = bisect_left(x_data, x)
x_interval = x_interval if x_interval != 0 else 1
a = coeffs[4 * x_interval - 4 : 4 * x_interval]
return a[3] * x**3 + a[2] * x**2 + a[1] * x + a[0]
return a[3] * x ** 3 + a[2] * x ** 2 + a[1] * x + a[0]

self._interpolation_func = akima_interpolation

Expand All @@ -379,7 +379,7 @@ def spline_interpolation(
x_interval = max(x_interval, 1)
a = coeffs[:, x_interval - 1]
x = x - x_data[x_interval - 1]
return a[3] * x**3 + a[2] * x**2 + a[1] * x + a[0]
return a[3] * x ** 3 + a[2] * x ** 2 + a[1] * x + a[0]

self._interpolation_func = spline_interpolation

Expand Down Expand Up @@ -430,7 +430,7 @@ def natural_extrapolation(
x, x_min, x_max, x_data, y_data, coeffs
): # pylint: disable=unused-argument
a = coeffs[:4] if x < x_min else coeffs[-4:]
return a[3] * x**3 + a[2] * x**2 + a[1] * x + a[0]
return a[3] * x ** 3 + a[2] * x ** 2 + a[1] * x + a[0]

elif interpolation == 3: # spline

Expand All @@ -443,7 +443,7 @@ def natural_extrapolation(
else:
a = coeffs[:, -1]
x = x - x_data[-2]
return a[3] * x**3 + a[2] * x**2 + a[1] * x + a[0]
return a[3] * x ** 3 + a[2] * x ** 2 + a[1] * x + a[0]

self._extrapolation_func = natural_extrapolation
elif extrapolation == 2: # constant
Expand Down Expand Up @@ -1705,7 +1705,7 @@ def __interpolate_polynomial__(self):
# Create coefficient matrix1
sys_coeffs = np.zeros((degree + 1, degree + 1))
for i in range(degree + 1):
sys_coeffs[:, i] = x**i
sys_coeffs[:, i] = x ** i
# Solve the system and store the resultant coefficients
self.__polynomial_coefficients__ = np.linalg.solve(sys_coeffs, y)

Expand Down Expand Up @@ -1755,10 +1755,10 @@ def __interpolate_akima__(self):
dl, dr = d[i], d[i + 1]
matrix = np.array(
[
[1, xl, xl**2, xl**3],
[1, xr, xr**2, xr**3],
[0, 1, 2 * xl, 3 * xl**2],
[0, 1, 2 * xr, 3 * xr**2],
[1, xl, xl ** 2, xl ** 3],
[1, xr, xr ** 2, xr ** 3],
[0, 1, 2 * xl, 3 * xl ** 2],
[0, 1, 2 * xr, 3 * xr ** 2],
]
)
result = np.array([yl, yr, dl, dr]).T
Expand Down Expand Up @@ -1791,7 +1791,7 @@ def __interpolate_shepard__(self, args):
x = arg_stack.reshape(arg_qty, 1, arg_dim)

sub_matrix = x_data - x
distances_squared = np.sum(sub_matrix**2, axis=2)
distances_squared = np.sum(sub_matrix ** 2, axis=2)

# Remove zero distances from further calculations
zero_distances = np.where(distances_squared == 0)
Expand Down Expand Up @@ -2335,7 +2335,7 @@ def __pow__(self, other): # pylint: disable=too-many-statements
and np.array_equal(self.x_array, other.x_array)
):
# Operate on grid values
ys = self.y_array**other.y_array
ys = self.y_array ** other.y_array

Check warning on line 2338 in rocketpy/mathutils/function.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/mathutils/function.py#L2338

Added line #L2338 was not covered by tests
xs = self.x_array
source = np.concatenate(([xs], [ys])).transpose()
# Retrieve inputs, outputs and interpolation
Expand All @@ -2356,7 +2356,7 @@ def __pow__(self, other): # pylint: disable=too-many-statements
# Check if Function object source is array or callable
if isinstance(self.source, np.ndarray):
# Operate on grid values
ys = self.y_array**other
ys = self.y_array ** other
xs = self.x_array
source = np.concatenate(([xs], [ys])).transpose()
# Retrieve inputs, outputs and interpolation
Expand Down Expand Up @@ -2394,7 +2394,7 @@ def __rpow__(self, other):
if isinstance(other, NUMERICAL_TYPES) or self.__is_single_element_array(other):
if isinstance(self.source, np.ndarray):
# Operate on grid values
ys = other**self.y_array
ys = other ** self.y_array
xs = self.x_array
source = np.concatenate(([xs], [ys])).transpose()
# Retrieve inputs, outputs and interpolation
Expand Down Expand Up @@ -2489,15 +2489,15 @@ def integral(self, a, b, numerical=False): # pylint: disable=too-many-statement
sub_b = a - x_data[0]
sub_a = min(b, x_data[0]) - x_data[0]
ans += (
(c[3] * sub_a**4) / 4
+ (c[2] * sub_a**3 / 3)
+ (c[1] * sub_a**2 / 2)
(c[3] * sub_a ** 4) / 4
+ (c[2] * sub_a ** 3 / 3)
+ (c[1] * sub_a ** 2 / 2)
+ c[0] * sub_a
)
ans -= (
(c[3] * sub_b**4) / 4
+ (c[2] * sub_b**3 / 3)
+ (c[1] * sub_b**2 / 2)
(c[3] * sub_b ** 4) / 4
+ (c[2] * sub_b ** 3 / 3)
+ (c[1] * sub_b ** 2 / 2)
+ c[0] * sub_b
)
else:
Expand All @@ -2521,15 +2521,15 @@ def integral(self, a, b, numerical=False): # pylint: disable=too-many-statement
sub_b = x_data[i + 1] - x_data[i]
c = coeffs[:, i]
ans += (
(c[3] * sub_b**4) / 4
+ (c[2] * sub_b**3 / 3)
+ (c[1] * sub_b**2 / 2)
(c[3] * sub_b ** 4) / 4
+ (c[2] * sub_b ** 3 / 3)
+ (c[1] * sub_b ** 2 / 2)
+ c[0] * sub_b
)
ans -= (
(c[3] * sub_a**4) / 4
+ (c[2] * sub_a**3 / 3)
+ (c[1] * sub_a**2 / 2)
(c[3] * sub_a ** 4) / 4
+ (c[2] * sub_a ** 3 / 3)
+ (c[1] * sub_a ** 2 / 2)
+ c[0] * sub_a
)
i += 1
Expand All @@ -2542,15 +2542,15 @@ def integral(self, a, b, numerical=False): # pylint: disable=too-many-statement
sub_a = max(x_data[-1], a) - x_data[-2]
sub_b = b - x_data[-2]
ans -= (
(c[3] * sub_a**4) / 4
+ (c[2] * sub_a**3 / 3)
+ (c[1] * sub_a**2 / 2)
(c[3] * sub_a ** 4) / 4
+ (c[2] * sub_a ** 3 / 3)
+ (c[1] * sub_a ** 2 / 2)
+ c[0] * sub_a
)
ans += (
(c[3] * sub_b**4) / 4
+ (c[2] * sub_b**3 / 3)
+ (c[1] * sub_b**2 / 2)
(c[3] * sub_b ** 4) / 4
+ (c[2] * sub_b ** 3 / 3)
+ (c[1] * sub_b ** 2 / 2)
+ c[0] * sub_b
)
else:
Expand Down Expand Up @@ -2606,7 +2606,7 @@ def differentiate(self, x, dx=1e-6, order=1):
self.get_value_opt(x + dx)
- 2 * self.get_value_opt(x)
+ self.get_value_opt(x - dx)
) / dx**2
) / dx ** 2

def differentiate_complex_step(self, x, dx=1e-200, order=1):
"""Differentiate a Function object at a given point using the complex
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
Loading

0 comments on commit 1ed8a9e

Please sign in to comment.