Skip to content

Commit

Permalink
Rerun black: hug simple power operators
Browse files Browse the repository at this point in the history
After psf/black#2726 Black hugs simple power operators.
  • Loading branch information
santisoler committed Apr 4, 2022
1 parent aabb5c2 commit e2b6a16
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion examples/forward/prism_layer.py
Expand Up @@ -31,7 +31,7 @@
region = (0, 100e3, -40e3, 40e3)
spacing = 2e3
(easting, northing) = vd.grid_coordinates(region=region, spacing=spacing)
surface = 100 * np.exp(-((easting - 50e3) ** 2 + northing ** 2) / 1e9)
surface = 100 * np.exp(-((easting - 50e3) ** 2 + northing**2) / 1e9)
density = 2670.0 * np.ones_like(surface)
prisms = hm.prism_layer(
coordinates=(easting[0, :], northing[:, 0]),
Expand Down
4 changes: 2 additions & 2 deletions harmonica/equivalent_sources/gradient_boosted.py
Expand Up @@ -233,7 +233,7 @@ def _gradient_boosting(self, coordinates, data, weights):
# Get number of windows
n_windows = len(point_windows)
# Initialize RMSE array
errors = [np.sqrt(np.mean(data ** 2))]
errors = [np.sqrt(np.mean(data**2))]
# Set weights_chunk to None (will be changed unless weights is None)
weights_chunk = None
# Initialized the predicted and residue arrays
Expand Down Expand Up @@ -270,7 +270,7 @@ def _gradient_boosting(self, coordinates, data, weights):
# Update the residue
residue -= predicted
# Add RMS of the residue to the RMSE
errors.append(np.sqrt(np.mean(residue ** 2)))
errors.append(np.sqrt(np.mean(residue**2)))
# Update source coefficients
self.coefs_[point_window] += coeffs_chunk
self.rmse_per_iteration_ = np.array(errors)
Expand Down
2 changes: 1 addition & 1 deletion harmonica/forward/_tesseroid_utils.py
Expand Up @@ -87,7 +87,7 @@ def gauss_legendre_quadrature(
# Get the radius of the point mass
radius_p = 0.5 * (top - bottom) * rad_node + 0.5 * (top + bottom)
# Get kappa constant for the point mass
kappa = radius_p ** 2 * cosphi_p
kappa = radius_p**2 * cosphi_p
for i, lon_node in enumerate(lon_nodes):
# Get the longitude of the point mass
longitude_p = np.radians(0.5 * (e - w) * lon_node + 0.5 * (e + w))
Expand Down
2 changes: 1 addition & 1 deletion harmonica/forward/_tesseroid_variable_density.py
Expand Up @@ -88,7 +88,7 @@ def gauss_legendre_quadrature_variable_density(
radius_p = 0.5 * (top - bottom) * rad_node + 0.5 * (top + bottom)
density_p = density(radius_p)
# Get kappa constant for the point mass
kappa = radius_p ** 2 * cosphi_p
kappa = radius_p**2 * cosphi_p
for i, lon_node in enumerate(lon_nodes):
# Get the longitude of the point mass
longitude_p = np.radians(0.5 * (e - w) * lon_node + 0.5 * (e + w))
Expand Down
8 changes: 4 additions & 4 deletions harmonica/forward/point.py
Expand Up @@ -316,7 +316,7 @@ def kernel_g_z_cartesian(easting, northing, upward, easting_p, northing_p, upwar
# gravitational acceleration. As a consequence, it is multiplied by -1.
# Notice that the ``g_z`` does not have the minus signal observed at the
# compoents ``g_northing`` and ``g_easting``.
return (upward - upward_p) / distance ** 3
return (upward - upward_p) / distance**3


@jit(nopython=True)
Expand All @@ -330,7 +330,7 @@ def kernel_g_northing_cartesian(
distance = distance_cartesian(
(easting, northing, upward), (easting_p, northing_p, upward_p)
)
return -(northing - northing_p) / distance ** 3
return -(northing - northing_p) / distance**3


@jit(nopython=True)
Expand All @@ -344,7 +344,7 @@ def kernel_g_easting_cartesian(
distance = distance_cartesian(
(easting, northing, upward), (easting_p, northing_p, upward_p)
)
return -(easting - easting_p) / distance ** 3
return -(easting - easting_p) / distance**3


@jit(nopython=True)
Expand All @@ -371,7 +371,7 @@ def kernel_g_z_spherical(
longitude, cosphi, sinphi, radius, longitude_p, cosphi_p, sinphi_p, radius_p
)
delta_z = radius - radius_p * cospsi
return delta_z / distance ** 3
return delta_z / distance**3


def point_mass_cartesian(
Expand Down
10 changes: 5 additions & 5 deletions harmonica/forward/prism.py
Expand Up @@ -240,14 +240,14 @@ def kernel_potential(easting, northing, upward):
"""
Kernel function for potential gravitational field generated by a prism
"""
radius = np.sqrt(easting ** 2 + northing ** 2 + upward ** 2)
radius = np.sqrt(easting**2 + northing**2 + upward**2)
kernel = (
easting * northing * safe_log(upward + radius)
+ northing * upward * safe_log(easting + radius)
+ easting * upward * safe_log(northing + radius)
- 0.5 * easting ** 2 * safe_atan2(upward * northing, easting * radius)
- 0.5 * northing ** 2 * safe_atan2(upward * easting, northing * radius)
- 0.5 * upward ** 2 * safe_atan2(easting * northing, upward * radius)
- 0.5 * easting**2 * safe_atan2(upward * northing, easting * radius)
- 0.5 * northing**2 * safe_atan2(upward * easting, northing * radius)
- 0.5 * upward**2 * safe_atan2(easting * northing, upward * radius)
)
return kernel

Expand All @@ -257,7 +257,7 @@ def kernel_g_z(easting, northing, upward):
"""
Kernel for downward component of gravitational acceleration of a prism
"""
radius = np.sqrt(easting ** 2 + northing ** 2 + upward ** 2)
radius = np.sqrt(easting**2 + northing**2 + upward**2)
kernel = (
easting * safe_log(northing + radius)
+ northing * safe_log(easting + radius)
Expand Down
10 changes: 5 additions & 5 deletions harmonica/forward/utils.py
Expand Up @@ -265,7 +265,7 @@ def distance_geodetic(point_p, point_q, ellipsoid):
coslambda,
prime_vertical_radius,
prime_vertical_radius_p,
ellipsoid.first_eccentricity ** 2,
ellipsoid.first_eccentricity**2,
)


Expand Down Expand Up @@ -311,11 +311,11 @@ def geodetic_distance_core(
upward_sum = prime_vertical_radius + height
upward_sum_p = prime_vertical_radius_p + height_p
dist = np.sqrt(
upward_sum_p ** 2 * cosphi_p ** 2
+ upward_sum ** 2 * cosphi ** 2
upward_sum_p**2 * cosphi_p**2
+ upward_sum**2 * cosphi**2
- 2 * upward_sum * upward_sum_p * cosphi * cosphi_p * coslambda
+ (upward_sum_p - ecc_sq * prime_vertical_radius_p) ** 2 * sinphi_p ** 2
+ (upward_sum - ecc_sq * prime_vertical_radius) ** 2 * sinphi ** 2
+ (upward_sum_p - ecc_sq * prime_vertical_radius_p) ** 2 * sinphi_p**2
+ (upward_sum - ecc_sq * prime_vertical_radius) ** 2 * sinphi**2
- (
2
* (upward_sum_p - ecc_sq * prime_vertical_radius_p)
Expand Down
2 changes: 1 addition & 1 deletion harmonica/tests/test_forward_utils.py
Expand Up @@ -87,7 +87,7 @@ def test_geodetic_distance_equator_poles():
ellipsoid = bl.WGS84
# Compute the expected distance between the two points
expected_distance = np.sqrt(
ellipsoid.semimajor_axis ** 2 + ellipsoid.semiminor_axis ** 2
ellipsoid.semimajor_axis**2 + ellipsoid.semiminor_axis**2
)
# Compute distance for different longitudes and alternate between points on
# both poles
Expand Down
4 changes: 2 additions & 2 deletions harmonica/tests/test_point_gravity.py
Expand Up @@ -440,7 +440,7 @@ def test_point_mass_on_origin():
# eotvos)
analytical = {
"potential": GRAVITATIONAL_CONST * mass / radius,
"g_z": GRAVITATIONAL_CONST * mass / radius ** 2 * 1e5,
"g_z": GRAVITATIONAL_CONST * mass / radius**2 * 1e5,
}
# Compare results with analytical solutions
for field, solution in analytical.items():
Expand Down Expand Up @@ -472,7 +472,7 @@ def test_point_mass_same_radial_direction():
# (accelerations are in mgal and tensor components in eotvos)
analytical = {
"potential": GRAVITATIONAL_CONST * mass / height,
"g_z": GRAVITATIONAL_CONST * mass / height ** 2 * 1e5,
"g_z": GRAVITATIONAL_CONST * mass / height**2 * 1e5,
}
# Compare results with analytical solutions
for field, solution in analytical.items():
Expand Down
6 changes: 3 additions & 3 deletions harmonica/tests/test_tesseroid.py
Expand Up @@ -362,7 +362,7 @@ def test_split_tesseroid():
tesseroid, n_lon=2, n_lat=2, n_rad=2, stack=stack, stack_top=stack_top
)
splitted = np.array([tess for tess in stack if not np.all(tess == 0)])
assert splitted.shape[0] == 2 ** 3
assert splitted.shape[0] == 2**3
assert splitted.shape[0] == stack_top + 1
# Check if the tesseroid hasn't been split on each direction
assert not (splitted[0, lon_indexes] == splitted[:, lon_indexes]).all()
Expand Down Expand Up @@ -460,7 +460,7 @@ def test_split_tesseroid_only_horizontal():
tesseroid, n_lon=2, n_lat=2, n_rad=1, stack=stack, stack_top=stack_top
)
splitted = np.array([tess for tess in stack if not np.all(tess == 0)])
assert splitted.shape[0] == 2 ** 2
assert splitted.shape[0] == 2**2
assert splitted.shape[0] == stack_top + 1
# Check if the tesseroid hasn't been split on radial direction
assert (splitted[0, radial_indexes] == splitted[:, radial_indexes]).all()
Expand Down Expand Up @@ -558,7 +558,7 @@ def spherical_shell_analytical(top, bottom, density, radius):
* np.pi
* GRAVITATIONAL_CONST
* density
* (top ** 3 - bottom ** 3)
* (top**3 - bottom**3)
/ radius
)
analytical = {
Expand Down
8 changes: 4 additions & 4 deletions harmonica/tests/test_tesseroid_variable_density.py
Expand Up @@ -351,8 +351,8 @@ def analytical_spherical_shell_linear(radius, bottom, top, slope, constant_term)
Analytical solutions of a spherical shell with linear density
"""
constant = np.pi * GRAVITATIONAL_CONST * slope * (
top ** 4 - bottom ** 4
) + 4 / 3.0 * np.pi * GRAVITATIONAL_CONST * constant_term * (top ** 3 - bottom ** 3)
top**4 - bottom**4
) + 4 / 3.0 * np.pi * GRAVITATIONAL_CONST * constant_term * (top**3 - bottom**3)
potential = constant / radius
data = {
"potential": potential,
Expand All @@ -377,7 +377,7 @@ def analytical_spherical_shell_exponential(
* np.pi
* GRAVITATIONAL_CONST
* a_factor
/ k ** 3
/ k**3
/ radius
* (
((bottom * k) ** 2 + 2 * bottom * k + 2)
Expand All @@ -388,7 +388,7 @@ def analytical_spherical_shell_exponential(
* np.pi
* GRAVITATIONAL_CONST
* constant_term
* (top ** 3 - bottom ** 3)
* (top**3 - bottom**3)
/ radius
)
data = {
Expand Down

0 comments on commit e2b6a16

Please sign in to comment.