diff --git a/examples/forward/prism_layer.py b/examples/forward/prism_layer.py index fa4d0259f..73e9b76c2 100644 --- a/examples/forward/prism_layer.py +++ b/examples/forward/prism_layer.py @@ -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]), diff --git a/harmonica/equivalent_sources/gradient_boosted.py b/harmonica/equivalent_sources/gradient_boosted.py index 7bd8c76d1..7800add12 100644 --- a/harmonica/equivalent_sources/gradient_boosted.py +++ b/harmonica/equivalent_sources/gradient_boosted.py @@ -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 @@ -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) diff --git a/harmonica/forward/_tesseroid_utils.py b/harmonica/forward/_tesseroid_utils.py index ae274ab6f..f9e89143d 100644 --- a/harmonica/forward/_tesseroid_utils.py +++ b/harmonica/forward/_tesseroid_utils.py @@ -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)) diff --git a/harmonica/forward/_tesseroid_variable_density.py b/harmonica/forward/_tesseroid_variable_density.py index 1429f8089..d2be1c8fe 100644 --- a/harmonica/forward/_tesseroid_variable_density.py +++ b/harmonica/forward/_tesseroid_variable_density.py @@ -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)) diff --git a/harmonica/forward/point.py b/harmonica/forward/point.py index add0bea32..4bc2991be 100644 --- a/harmonica/forward/point.py +++ b/harmonica/forward/point.py @@ -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) @@ -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) @@ -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) @@ -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( diff --git a/harmonica/forward/prism.py b/harmonica/forward/prism.py index 25553087f..baac487dc 100644 --- a/harmonica/forward/prism.py +++ b/harmonica/forward/prism.py @@ -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 @@ -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) diff --git a/harmonica/forward/utils.py b/harmonica/forward/utils.py index f707f6e06..ea2117d82 100644 --- a/harmonica/forward/utils.py +++ b/harmonica/forward/utils.py @@ -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, ) @@ -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) diff --git a/harmonica/tests/test_forward_utils.py b/harmonica/tests/test_forward_utils.py index 6110e5bc7..ef77cd480 100644 --- a/harmonica/tests/test_forward_utils.py +++ b/harmonica/tests/test_forward_utils.py @@ -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 diff --git a/harmonica/tests/test_point_gravity.py b/harmonica/tests/test_point_gravity.py index 2f66c8b6c..a71883a8e 100644 --- a/harmonica/tests/test_point_gravity.py +++ b/harmonica/tests/test_point_gravity.py @@ -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(): @@ -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(): diff --git a/harmonica/tests/test_tesseroid.py b/harmonica/tests/test_tesseroid.py index 17fd8e230..9db9533dd 100644 --- a/harmonica/tests/test_tesseroid.py +++ b/harmonica/tests/test_tesseroid.py @@ -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() @@ -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() @@ -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 = { diff --git a/harmonica/tests/test_tesseroid_variable_density.py b/harmonica/tests/test_tesseroid_variable_density.py index 3531f9ca2..6eff3e312 100644 --- a/harmonica/tests/test_tesseroid_variable_density.py +++ b/harmonica/tests/test_tesseroid_variable_density.py @@ -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, @@ -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) @@ -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 = {