From 98c273b7d380ad7d26f5cb1f733dbd2804a8ecf1 Mon Sep 17 00:00:00 2001 From: pcain-usgs <pcain@usgs.gov> Date: Mon, 25 Jan 2021 08:42:51 -0700 Subject: [PATCH] Black reformat --- geomagio/adjusted/Transform.py | 37 +++++++--- geomagio/algorithm/AdjustedAlgorithm.py | 4 +- test/adjusted_test/adjusted_test.py | 70 ++++++++++++++----- test/algorithm_test/AdjustedAlgorithm_test.py | 7 +- 4 files changed, 90 insertions(+), 28 deletions(-) diff --git a/geomagio/adjusted/Transform.py b/geomagio/adjusted/Transform.py index 0e2dcd58f..9937cb583 100644 --- a/geomagio/adjusted/Transform.py +++ b/geomagio/adjusted/Transform.py @@ -344,12 +344,16 @@ class RotationTranslation3D(SVD): # generate weighted "covariance" matrix H = np.dot( self.get_stacked_values( - values=ordinates, weighted_values=weighted_ordinates, ndims=3, + values=ordinates, + weighted_values=weighted_ordinates, + ndims=3, ), np.dot( np.diag(weights), self.get_stacked_values( - values=absolutes, weighted_values=weighted_absolutes, ndims=3, + values=absolutes, + weighted_values=weighted_absolutes, + ndims=3, ).T, ), ) @@ -533,12 +537,16 @@ class RotationTranslationXY(SVD): # generate weighted "covariance" matrix H = np.dot( self.get_stacked_values( - values=ordinates, weighted_values=weighted_ordinates, ndims=2, + values=ordinates, + weighted_values=weighted_ordinates, + ndims=2, ), np.dot( np.diag(weights), self.get_stacked_values( - values=absolutes, weighted_values=weighted_absolutes, ndims=2, + values=absolutes, + weighted_values=weighted_absolutes, + ndims=2, ).T, ), ) @@ -583,7 +591,12 @@ class QRFactorization(SVD): if weights is None: return values weights = np.sqrt(weights) - return np.array([values[0] * weights, values[1] * weights,]) + return np.array( + [ + values[0] * weights, + values[1] * weights, + ] + ) def calculate( self, @@ -601,19 +614,25 @@ class QRFactorization(SVD): # return generate_affine_9(ord_hez, abs_xyz, weights) # LHS, or dependent variables abs_stacked = self.get_stacked_values( - values=absolutes, weighted_values=weighted_absolutes, ndims=2, + values=absolutes, + weighted_values=weighted_absolutes, + ndims=2, ) # RHS, or independent variables ord_stacked = self.get_stacked_values( - values=ordinates, weighted_values=weighted_ordinates, ndims=2, + values=ordinates, + weighted_values=weighted_ordinates, + ndims=2, ) abs_stacked = self.get_weighted_values_lstsq( - values=abs_stacked, weights=weights, + values=abs_stacked, + weights=weights, ) ord_stacked = self.get_weighted_values_lstsq( - values=ord_stacked, weights=weights, + values=ord_stacked, + weights=weights, ) # regression matrix M that minimizes L2 norm diff --git a/geomagio/algorithm/AdjustedAlgorithm.py b/geomagio/algorithm/AdjustedAlgorithm.py index ef917b76f..2a5b647e3 100644 --- a/geomagio/algorithm/AdjustedAlgorithm.py +++ b/geomagio/algorithm/AdjustedAlgorithm.py @@ -26,7 +26,9 @@ class AdjustedAlgorithm(Algorithm): inchannels = inchannels or ["H", "E", "Z", "F"] outchannels = outchannels or ["X", "Y", "Z", "F"] Algorithm.__init__( - self, inchannels=inchannels, outchannels=outchannels, + self, + inchannels=inchannels, + outchannels=outchannels, ) # state variables self.matrix = matrix diff --git a/test/adjusted_test/adjusted_test.py b/test/adjusted_test/adjusted_test.py index 0e76e9725..d37c3aa04 100644 --- a/test/adjusted_test/adjusted_test.py +++ b/test/adjusted_test/adjusted_test.py @@ -68,7 +68,9 @@ def test_NoConstraints_synthetic(): ordinates, absolutes, weights = get_sythetic_variables() assert_array_almost_equal( NoConstraints().calculate( - ordinates=ordinates, absolutes=absolutes, weights=weights, + ordinates=ordinates, + absolutes=absolutes, + weights=weights, ), get_expected_synthetic_result("NoConstraints"), decimal=3, @@ -79,7 +81,9 @@ def test_ZRotationShear_synthetic(): ordinates, absolutes, weights = get_sythetic_variables() assert_array_almost_equal( ZRotationShear().calculate( - ordinates=ordinates, absolutes=absolutes, weights=weights, + ordinates=ordinates, + absolutes=absolutes, + weights=weights, ), get_expected_synthetic_result("ZRotationShear"), decimal=3, @@ -90,7 +94,9 @@ def test_ZRotationHscale_synthetic(): ordinates, absolutes, weights = get_sythetic_variables() assert_array_almost_equal( ZRotationHscale().calculate( - ordinates=ordinates, absolutes=absolutes, weights=weights, + ordinates=ordinates, + absolutes=absolutes, + weights=weights, ), get_expected_synthetic_result("ZRotationHscale"), decimal=3, @@ -101,7 +107,9 @@ def test_ZRotationHscaleZbaseline_synthetic(): ordinates, absolutes, weights = get_sythetic_variables() assert_array_almost_equal( ZRotationHscaleZbaseline().calculate( - ordinates=ordinates, absolutes=absolutes, weights=weights, + ordinates=ordinates, + absolutes=absolutes, + weights=weights, ), get_expected_synthetic_result("ZRotationHscaleZbaseline"), decimal=3, @@ -112,7 +120,9 @@ def test_RotationTranslation3D_synthetic(): ordinates, absolutes, weights = get_sythetic_variables() assert_array_almost_equal( RotationTranslation3D().calculate( - ordinates=ordinates, absolutes=absolutes, weights=weights, + ordinates=ordinates, + absolutes=absolutes, + weights=weights, ), get_expected_synthetic_result("RotationTranslation3D"), decimal=3, @@ -123,7 +133,9 @@ def test_Rescale3D_synthetic(): ordinates, absolutes, weights = get_sythetic_variables() assert_array_almost_equal( Rescale3D().calculate( - ordinates=ordinates, absolutes=absolutes, weights=weights, + ordinates=ordinates, + absolutes=absolutes, + weights=weights, ), get_expected_synthetic_result("Rescale3D"), decimal=3, @@ -134,7 +146,9 @@ def test_TranslateOrigins_synthetic(): ordinates, absolutes, weights = get_sythetic_variables() assert_array_almost_equal( TranslateOrigins().calculate( - ordinates=ordinates, absolutes=absolutes, weights=weights, + ordinates=ordinates, + absolutes=absolutes, + weights=weights, ), get_expected_synthetic_result("TranslateOrigins"), decimal=3, @@ -144,7 +158,11 @@ def test_TranslateOrigins_synthetic(): def test_ShearYZ_synthetic(): ordinates, absolutes, weights = get_sythetic_variables() assert_array_almost_equal( - ShearYZ().calculate(ordinates=ordinates, absolutes=absolutes, weights=weights,), + ShearYZ().calculate( + ordinates=ordinates, + absolutes=absolutes, + weights=weights, + ), get_expected_synthetic_result("ShearYZ"), decimal=3, ) @@ -154,7 +172,9 @@ def test_RotationTranslationXY_synthetic(): ordinates, absolutes, weights = get_sythetic_variables() assert_array_almost_equal( RotationTranslationXY().calculate( - ordinates=ordinates, absolutes=absolutes, weights=weights, + ordinates=ordinates, + absolutes=absolutes, + weights=weights, ), get_expected_synthetic_result("RotationTranslationXY"), decimal=3, @@ -165,7 +185,9 @@ def test_QRFactorization_synthetic(): ordinates, absolutes, weights = get_sythetic_variables() assert_array_almost_equal( QRFactorization().calculate( - ordinates=ordinates, absolutes=absolutes, weights=weights, + ordinates=ordinates, + absolutes=absolutes, + weights=weights, ), get_expected_synthetic_result("QRFactorization"), decimal=3, @@ -238,7 +260,9 @@ def test_BOU201911202001_short_acausal(): endtime=endtime, update_interval=update_interval, acausal=True, - ).calculate(readings=readings,) + ).calculate( + readings=readings, + ) matrices = format_result([adjusted_matrix.matrix for adjusted_matrix in result]) expected_matrices = get_excpected_matrices("BOU", "short_acausal") @@ -270,7 +294,9 @@ def test_BOU201911202001_infinite_weekly(): RotationTranslationXY(memory=np.inf), TranslateOrigins(memory=np.inf), ], - ).calculate(readings=readings,) + ).calculate( + readings=readings, + ) matrices = format_result([adjusted_matrix.matrix for adjusted_matrix in result]) expected_matrices = get_excpected_matrices("BOU", "inf_weekly") @@ -296,7 +322,9 @@ def test_BOU201911202001_infinite_one_interval(): TranslateOrigins(memory=np.inf), ], update_interval=None, - ).calculate(readings=readings,) + ).calculate( + readings=readings, + ) matrices = format_result([adjusted_matrix.matrix for adjusted_matrix in result]) expected_matrices = get_excpected_matrices("BOU", "inf_one_interval") @@ -329,7 +357,9 @@ def test_CMO2015_causal(): starttime=starttime, endtime=endtime, update_interval=update_interval, - ).calculate(readings=readings,) + ).calculate( + readings=readings, + ) matrices = format_result([adjusted_matrix.matrix for adjusted_matrix in result]) expected_matrices = get_excpected_matrices("CMO", "short_causal") @@ -363,7 +393,9 @@ def test_CMO2015_acausal(): endtime=endtime, update_interval=update_interval, acausal=True, - ).calculate(readings=readings,) + ).calculate( + readings=readings, + ) matrices = format_result([adjusted_matrix.matrix for adjusted_matrix in result]) expected_matrices = get_excpected_matrices("CMO", "short_acausal") @@ -401,7 +433,9 @@ def test_CMO2015_infinite_weekly(): ], update_interval=update_interval, acausal=True, - ).calculate(readings=readings,) + ).calculate( + readings=readings, + ) matrices = format_result([adjusted_matrix.matrix for adjusted_matrix in result]) expected_matrices = get_excpected_matrices("CMO", "inf_weekly") @@ -435,7 +469,9 @@ def test_CMO2015_infinite_one_interval(): ], acausal=True, update_interval=None, - ).calculate(readings=readings,) + ).calculate( + readings=readings, + ) matrices = format_result([adjusted_matrix.matrix for adjusted_matrix in result]) expected_matrices = get_excpected_matrices("CMO", "inf_one_interval") diff --git a/test/algorithm_test/AdjustedAlgorithm_test.py b/test/algorithm_test/AdjustedAlgorithm_test.py index de72ed3d7..d44ae09e6 100644 --- a/test/algorithm_test/AdjustedAlgorithm_test.py +++ b/test/algorithm_test/AdjustedAlgorithm_test.py @@ -80,7 +80,12 @@ def test_process_reverse_polarity_AdjustedMatrix(): # Initiate algorithm with AdjustedMatrix object a = adj( matrix=AdjustedMatrix( - matrix=[[-1, 0, 0], [0, -1, 0], [0, 0, 1],], pier_correction=-22, + matrix=[ + [-1, 0, 0], + [0, -1, 0], + [0, 0, 1], + ], + pier_correction=-22, ), inchannels=["H", "E"], outchannels=["H", "E"], -- GitLab