Skip to content

Feature/quake - #201

Open
chahank wants to merge 34 commits into
developfrom
feature/quake
Open

Feature/quake#201
chahank wants to merge 34 commits into
developfrom
feature/quake

Redo Earthquake tests.

9b4e7e1
Select commit
Loading
Failed to load commit list.
Sign in for the full log view
GitHub Actions / Petals / Unit Test Results (3.11) failed Jul 16, 2026 in 0s

1 fail, 4 skipped, 351 pass in 5m 52s

356 tests  +355   351 ✅ +351   5m 52s ⏱️ + 5m 30s
  1 suites ±  0     4 💤 +  4 
  1 files   ±  0     1 ❌ +  1 

Results for commit 9b4e7e1. ± Comparison against earlier commit 5a71bae.

Annotations

Check warning on line 0 in climada_petals.hazard.test.test_earthquake.TestEarthquake

See this annotation in the file changed.

@github-actions github-actions / Petals / Unit Test Results (3.11)

test_uniform_random_events (climada_petals.hazard.test.test_earthquake.TestEarthquake) failed

climada_petals/tests_xml/tests.xml [took 0s]
Raw output
AssertionError: 
Not equal to tolerance rtol=1e-07, atol=0

Mismatched elements: 2 / 4 (50%)
Max absolute difference among violations: 0.1
Max relative difference among violations: 0.00055648
 ACTUAL: array([-179.7, -179.8, -179.7, -179.8])
 DESIRED: array(-179.7)
self = <climada_petals.hazard.test.test_earthquake.TestEarthquake object at 0x7f1e74412c90>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f1e526c0190>

    def test_uniform_random_events(self, monkeypatch):
        """Apply deterministic location, magnitude, depth, and date changes."""
        centroids = Centroids.from_lat_lon([89.8], [179.8])
        catalogue = pd.DataFrame(
            {
                "lat": [89.8, 89.7, 0.0],
                "lon": [179.8, 179.7, 0.0],
                "mw": [6.0, 7.0, 8.0],
                "depth": [10.0, 20.0, 30.0],
                "eventid": [10, 20, 30],
                "date": [
                    "2000-02-29 00:00:00.000000",
                    "2010-01-01 00:00:00.000000",
                    "1990-01-01 00:00:00.000000",
                ],
            }
        )
    
        random_values = iter(
            [
                np.full(4, 0.5),
                np.full(4, 0.5),
                np.full(4, 0.25),
                np.full(4, 0.1),
            ]
        )
        monkeypatch.setattr(
            np.random,
            "uniform",
            lambda low, high, size: next(random_values),
        )
    
        captured = {}
    
        def capture_hazard(cls, df, centroids, orig=True):
            captured["df"] = df
            captured["orig"] = orig
            return "hazard"
    
        monkeypatch.setattr(
            Earthquake,
            "from_Mw_depth",
            classmethod(capture_hazard),
        )
    
        result = Earthquake.uniform_random_events(
            catalogue,
            centroids,
            n=2,
        )
    
        assert result == "hazard"
        assert captured["orig"] is False
    
        generated = captured["df"]
        np.testing.assert_allclose(generated["lat"], 90.0)
>       np.testing.assert_allclose(generated["lon"], -179.7)
E       AssertionError: 
E       Not equal to tolerance rtol=1e-07, atol=0
E       
E       Mismatched elements: 2 / 4 (50%)
E       Max absolute difference among violations: 0.1
E       Max relative difference among violations: 0.00055648
E        ACTUAL: array([-179.7, -179.8, -179.7, -179.8])
E        DESIRED: array(-179.7)

climada_petals/hazard/test/test_earthquake.py:187: AssertionError