Exemplo n.º 1
0
    def test_fit(self, tmp_path):
        data_path = _create_dummy_precip_data(tmp_path,
                                              start_date='2000-01-01',
                                              end_date='2010-01-01')
        czi = ChinaZIndex(data_path / 'chirps_kenya.nc')
        variable = 'precip'
        czi.fit(variable=variable)

        coords = [c for c in czi.index.coords]
        vars_ = [v for v in czi.index.variables if v not in coords]
        assert "CZI" in vars_, f"Expecting `CZI` variable in `self.index`"
        assert np.isclose(czi.index.CZI.median().values, 0, atol=0.1), "" \
            "Because values are normally distributed expect CZI median to be" \
            "close to 0"
Exemplo n.º 2
0
    def test_fit_modified(self, tmp_path):
        data_path = _create_dummy_precip_data(tmp_path,
                                              start_date="2000-01-01",
                                              end_date="2010-01-01")
        czi = ChinaZIndex(data_path / "chirps_kenya.nc")
        variable = "precip"
        czi.fit(variable=variable, modified=True)

        coords = [c for c in czi.index.coords]
        vars_ = [v for v in czi.index.variables if v not in coords]
        assert "MCZI" in vars_, f"Expecting `CZI` variable in `self.index`"

        assert np.isclose(czi.index.MCZI.median().values, 0, atol=0.1), (
            ""
            "Because values are normally distributed expect CZI median to be"
            "close to 0")
Exemplo n.º 3
0
    def test_initialisation(self, tmp_path):
        data_path = _create_dummy_precip_data(tmp_path)
        czi = ChinaZIndex(data_path / 'chirps_kenya.nc')
        assert czi.name == 'china_z_index', f"Expected name"\
            f"to be `china_z_index` got: {czi.name}"

        with pytest.raises(AttributeError):
            # assert error raised because haven't fit
            czi.index
# -------------------------------------------------------------
# fit HDSI
# -------------------------------------------------------------
from src.analysis.indices.drought_severity_index import DroughtSeverityIndex

h = DroughtSeverityIndex(data_path)
variable = 'precip'
h.fit(variable=variable)

# -------------------------------------------------------------
# fit China Z index
# -------------------------------------------------------------
from src.analysis.indices.china_z_index import ChinaZIndex

c = ChinaZIndex(data_path)
variable = 'precip'
c.fit(variable=variable)

# -------------------------------------------------------------
# fit Decile Index
# -------------------------------------------------------------
from src.analysis.indices.decile_index import DecileIndex
d= DecileIndex(data_path)
variable = 'precip'
d.fit(variable=variable)

# -------------------------------------------------------------
# fit AnomalyIndex
# -------------------------------------------------------------
from src.analysis.indices.anomaly_index import AnomalyIndex