Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an overall climate change index #2

Open
DSSG-DFKI-Testuser opened this issue Sep 7, 2023 · 0 comments
Open

Add an overall climate change index #2

DSSG-DFKI-Testuser opened this issue Sep 7, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@DSSG-DFKI-Testuser
Copy link
Contributor

DSSG-DFKI-Testuser commented Sep 7, 2023

Add an overall climate change index that takes as input the information from various weather features and calculates for a certain location for a certain point in time the climate change index. To illustrate this, here a simple example implementation:

import pandas as pd
import pytest
from sklearn.preprocessing import MinMaxScaler

def create_climate_change_index(
    df: pd.DataFrame, cols_and_weights_to_calculate_index: dict
) -> pd.DataFrame:
    # Normalize each column
    for key in cols_and_weights_to_calculate_index:
        scaler = MinMaxScaler()
        df[f"{key}_transformed"] = scaler.fit_transform(df[key].values.reshape(-1, 1))

    # Calculate the climate change index
    df["climate_change_index"] = 0
    for key in cols_and_weights_to_calculate_index:
        df["climate_change_index"] += (
            df[f"{key}_transformed"] * cols_and_weights_to_calculate_index[key]
        )

    return df

@pytest.fixture(scope="session")
def example_survey_weather_data():
    example_df = pd.DataFrame(
        {
            "lat": [2.75, 2.91, 3.07, 3.24],
            "lon": [4.25, 4.25, 4.25, 4.25],
            "date": ["2009-01-01", "2009-01-01", "2009-01-01", "2009-01-01"],
            "precipitation": [0.001, 0.002, 0.003, 0.004],
            "temperature": [34, 42, 28, 35],
            "heavy_rainfall_ranking": [0.2, 0.4, 0.6, 0.8],
            "heatwave_ranking": [0.4, 0.2, 0.6, 0.1],
            "spi": [-2.1, 1.2, 0.3, -0.4],
        }
    )

    return example_df


@pytest.fixture(scope="session")
def example_climate_indicator_weights_dict():
    cols_and_weights_to_calculate_index = {
        "precipitation": 0.2,
        "temperature": 0.3,
        "heavy_rainfall_ranking": 0.1,
        "heatwave_ranking": 0.1,
        "spi": 0.3,
    }

    return cols_and_weights_to_calculate_index
@DSSG-DFKI-Testuser DSSG-DFKI-Testuser added the enhancement New feature or request label Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant