def test_SolarElevAngle(sample_input_data):
    ct0 = pp.TemporalHour(variable=config.TEMPORAL_HOUR, ref_feature=config.DATETIME_INDEX)
    ct1 = pp.TemporalDayofYear(variable=config.TEMPORAL_DAY, ref_feature=config.DATETIME_INDEX)
    ct2 = pp.SolarElevAngle(var_name=config.SOLAR_ANGLE, day=config.TEMPORAL_DAY, hour=config.TEMPORAL_HOUR)
    data_t = ct0.transform(sample_input_data)
    data_t = ct1.transform(data_t)
    data_t = ct2.transform(data_t)
    var = config.SOLAR_ANGLE

    assert data_t[var] is not None
    #in summer it doesn't go over 53 degrees
    #in winter doesn't drop below -53 degrees
    assert (data_t[var].max()  > 50) & (data_t[var].max()  < 55)
    assert (data_t[var].min()  < -50) & (data_t[var].min()  > -55)
    assert type(data_t) == pd.core.frame.DataFrame
def test_SunAzimuth(sample_input_data):
    ct0 = pp.TemporalHour(variable=config.TEMPORAL_HOUR, ref_feature=config.DATETIME_INDEX)
    ct1 = pp.TemporalDayofYear(variable=config.TEMPORAL_DAY, ref_feature=config.DATETIME_INDEX)
    ct2 = pp.SolarElevAngle(var_name=config.SOLAR_ANGLE, day=config.TEMPORAL_DAY, hour=config.TEMPORAL_HOUR)
    ct3 = pp.SunAzimuth(var_name=config.SUN_AZIMUTH, day=config.TEMPORAL_DAY, hour=config.TEMPORAL_HOUR)
    data_t = ct0.transform(sample_input_data)
    data_t = ct1.transform(data_t)
    data_t = ct2.transform(data_t)
    data_t = ct3.transform(data_t)
    var = config.SUN_AZIMUTH

    assert data_t[var] is not None
    assert data_t[var].max()  <= 180
    assert data_t[var].min() >= -180
    assert type(data_t) == pd.core.frame.DataFrame
def test_DropFeatures(sample_input_data):
    ct0 = pp.TemporalHour(variable=config.TEMPORAL_HOUR, ref_feature=config.DATETIME_INDEX)
    ct1 = pp.TemporalDayofYear(variable=config.TEMPORAL_DAY, ref_feature=config.DATETIME_INDEX)
    ct2 = pp.SolarElevAngle(var_name=config.SOLAR_ANGLE, day=config.TEMPORAL_DAY, hour=config.TEMPORAL_HOUR)
    ct3 = pp.SunAzimuth(var_name=config.SUN_AZIMUTH, day=config.TEMPORAL_DAY, hour=config.TEMPORAL_HOUR)
    ct4 = pp.TheoreticalRadiation(var_name=config.THEOR_SRAD, day=config.TEMPORAL_DAY, hour=config.TEMPORAL_HOUR)
    ct5 = pp.DropUnnecessaryFeatures(variables_to_drop=config.DROP_FEATURES)
    data_t = ct0.transform(sample_input_data)
    data_t = ct1.transform(data_t)
    data_t = ct2.transform(data_t)
    data_t = ct3.transform(data_t)
    data_t = ct4.transform(data_t)
    data_t = ct5.transform(data_t)
    assert config.DROP_FEATURES not in data_t.columns.to_list()
    assert type(data_t) == pd.core.frame.DataFrame
def test_TheoreticalIrradiance(sample_input_data):
    ct0 = pp.TemporalHour(variable=config.TEMPORAL_HOUR, ref_feature=config.DATETIME_INDEX)
    ct1 = pp.TemporalDayofYear(variable=config.TEMPORAL_DAY, ref_feature=config.DATETIME_INDEX)
    ct2 = pp.SolarElevAngle(var_name=config.SOLAR_ANGLE, day=config.TEMPORAL_DAY, hour=config.TEMPORAL_HOUR)
    ct3 = pp.SunAzimuth(var_name=config.SUN_AZIMUTH, day=config.TEMPORAL_DAY, hour=config.TEMPORAL_HOUR)
    ct4 = pp.TheoreticalRadiation(var_name=config.THEOR_SRAD, day=config.TEMPORAL_DAY, hour=config.TEMPORAL_HOUR)
    data_t = ct0.transform(sample_input_data)
    data_t = ct1.transform(data_t)
    data_t = ct2.transform(data_t)
    data_t = ct3.transform(data_t)
    data_t = ct4.transform(data_t)
    var = config.THEOR_SRAD

    assert data_t[var] is not None
    assert len(sample_input_data) == len(data_t[var])
    assert type(data_t) == pd.core.frame.DataFrame
from sklearn.pipeline import Pipeline
from sklearn.ensemble import RandomForestRegressor
from sklearn.preprocessing import StandardScaler
# from sklearn.preprocessing import MinMaxScaler #select  one of the two

from regression_model.processing import preprocessors as pp
from regression_model.config import config
# from regression_model.processing import features

import logging

_logger = logging.getLogger(__name__)

energy_pipe = Pipeline(
    [
        ('wind_disc', pp.WindDiscretizer(variables=config.WIND_DISCRETE)),
        ('num_to_binary', pp.DiscretizerNumericalIntoBinary(boundaries=config.BINARY_BOUNDARIES, variables=config.NUM_TO_BINARY)),
        ('temporal_hour', pp.TemporalHour(variable=config.TEMPORAL_HOUR, ref_feature=config.DATETIME_INDEX)),
        ('temporal_dayofyear', pp.TemporalDayofYear(variable=config.TEMPORAL_DAY, ref_feature=config.DATETIME_INDEX)),
        ('solar_angle', pp.SolarElevAngle(var_name=config.SOLAR_ANGLE, day=config.TEMPORAL_DAY, hour=config.TEMPORAL_HOUR)),
        ('sun_azimuth', pp.SunAzimuth(var_name=config.SUN_AZIMUTH, day=config.TEMPORAL_DAY, hour=config.TEMPORAL_HOUR)),
        ('theor_solar_radiation', pp.TheoreticalRadiation(var_name=config.THEOR_SRAD, day=config.TEMPORAL_DAY, hour=config.TEMPORAL_HOUR)),
        ('drop_features', pp.DropUnnecessaryFeatures(variables_to_drop=config.DROP_FEATURES)),
        ("scaler", StandardScaler()),
        ("random_forest", RandomForestRegressor(n_estimators=300, min_samples_split=5, min_samples_leaf=1, max_features='sqrt',max_depth=30, bootstrap=False, n_jobs= -1, random_state=config.RANDOM_STATE))
    ]
)