Example #1
0
def getPriceData(filePath, timestamps, offset, constantPrice):
    with open(filePath, "r", encoding="utf-8") as dataFile:
        data = pd.read_csv(
            dataFile,
            parse_dates=["DateTime"],
            index_col="DateTime",
            sep=";",
            decimal=",",
        )
        data = data.loc[timestamps[0] + offset:timestamps[-1] + offset +
                        getStepsize(timestamps)]
        origStepsize = getStepsize(data.index)
        assert origStepsize == timedelta(hours=1)
        wantedStepsize = getStepsize(timestamps)
        if origStepsize > wantedStepsize:
            assert (origStepsize / wantedStepsize).is_integer()
            data = data.resample(wantedStepsize).asfreq()
            _applyOppositeOfResampleSum(data, timestamps,
                                        origStepsize / wantedStepsize)
        elif origStepsize < wantedStepsize:
            data = _dropUnfittingValuesAtEndForDownSampling(
                origStepsize, wantedStepsize, timestamps, data)
            data = data.resample(wantedStepsize).sum()
        assert data.shape[1] <= 2

        data = data.loc[timestamps[0] + offset:timestamps[-1] + offset]
        return data.iloc[:,
                         0] / FROM_MEGAWATTHOURS_TO_KILOWATTHOURS + constantPrice / (
                             origStepsize / wantedStepsize)
Example #2
0
def resampleData(data, timestamps, offset=timedelta(days=0)):
    origStepsize = getStepsize(data.index)
    wantedStepsize = getStepsize(timestamps)
    if origStepsize > wantedStepsize:
        assert (origStepsize / wantedStepsize).is_integer()
        data = data.resample(wantedStepsize).ffill()
    elif origStepsize < wantedStepsize:
        data = _dropUnfittingValuesAtEndForDownSampling(
            origStepsize, wantedStepsize, timestamps, data)
        data = data.resample(wantedStepsize).first()
    data = data.loc[timestamps[0] + offset:timestamps[-1] + offset]
    return data
Example #3
0
def getNinja(filePath, timestamps, offset=timedelta(days=0)):
    with open(filePath, "r", encoding="utf-8") as dataFile:
        [dataFile.readline() for i in range(3)]
        data = pd.read_csv(dataFile,
                           parse_dates=["time", "local_time"],
                           index_col="local_time")
        data = data.loc[timestamps[0] + offset:timestamps[-1] + offset +
                        getStepsize(timestamps)]
        origStepsize = getStepsize(data.index)
        wantedStepsize = getStepsize(timestamps)
        if origStepsize > wantedStepsize:
            assert (origStepsize / wantedStepsize).is_integer()
            data = data.resample(wantedStepsize).ffill()
        elif origStepsize < wantedStepsize:
            data = _dropUnfittingValuesAtEndForDownSampling(
                origStepsize, wantedStepsize, timestamps, data)
            data = data.resample(wantedStepsize).mean()
        data = data.loc[timestamps[0] + offset:timestamps[-1] + offset]

        return data["electricity"]
Example #4
0
def getLoadsData(filePath, timestamps):
    with open(filePath, "r", encoding="utf-8") as dataFile:
        data = pd.read_csv(
            dataFile,
            parse_dates=["DateTime"],
            index_col="DateTime",
            sep=";",
            decimal=",",
        )
        data = data.loc[timestamps[0]:timestamps[-1] + getStepsize(timestamps)]
        data = resampleData(data, timestamps)
        data = data.iloc[:, 0]
        data.loc[data <= 0] = 0
        return data
Example #5
0
def getPecanstreetData(
        filePath,
        timeHeader,
        dataid,
        column,
        timestamps,
        offset=timedelta(days=0),
        nb_rows=20000,
):
    with open(filePath, "r", encoding="utf-8") as dataFile:
        # TODO: read more rows or split dataid into files
        data = pd.read_csv(
            dataFile,
            parse_dates=[timeHeader],
            date_parser=dateparserWithoutUTC,
            nrows=nb_rows,
        )

        data = data[data["dataid"] == int(dataid)]
        pd.to_datetime(data[timeHeader])
        data = data.set_index(timeHeader)
        data = data.sort_index()
        if column == "grid":
            ev = data.loc[:, ["car1"]]
            ev *= -1
            data = data.loc[:, [column, "solar", "solar2"]]
            data = pd.concat([data, ev], axis=1)
        else:
            data = data.loc[:, [column]]
        stepsize = getStepsize(timestamps)
        if stepsize < timedelta(minutes=15):
            stepsize = timedelta(hours=0)

        data = data.loc[timestamps[0] + offset:timestamps[-1] + offset +
                        stepsize]
        data = resampleData(data, timestamps, offset)
        data = data.sum(axis=1)
        min_data_value = min(data)
        for idx, value in enumerate(data):
            if value < 0:
                data[idx] = 0.0

        if min_data_value < 0:
            print(
                "(non-negativity of data) Values in range [{},0) were set to 0"
                .format(min_data_value))
        assert all(i >= 0.0 for i in data)
        return data
Example #6
0
def get_timestamps_per_day(config):
    timestamps_per_day = timedelta(hours=24) / getStepsize(config.TIMESTAMPS)
    assert timestamps_per_day.is_integer()
    return int(timestamps_per_day)
Example #7
0
    def __init__(self, config):
        # Global
        self.goal = Goal(config["GLOBAL"]["goal"])
        self.loc_flag = "yes" == config["GLOBAL"]["loc"]
        self.loc_lat = float(config["GLOBAL"]["lat"])
        self.loc_lon = float(config["GLOBAL"]["lon"])
        self.loadResFlag = "yes" == config["GLOBAL"]["loadResFlag"]
        self.overwrite = "yes" == config["GLOBAL"]["overwrite"]
        self.calcAllFlag = "yes" == config["GLOBAL"]["calcAllFlag"]

        # Battery init (to be moved to a initialization file)
        self.SOC_bat_min = float(config["BAT"]["SOC_bat_min"])
        self.SOC_bat_init = float(config["BAT"]["SOC_bat_init"])
        self.SOC_bat_max = float(config["BAT"]["SOC_bat_max"])
        self.E_bat_max = float(config["BAT"]["E_bat_max"])
        self.eta_bat = float(config["BAT"]["eta_bat"])
        self.P_bat_max = float(config["BAT"]["P_bat_max"])
        self.ChargeConvertLoss = float(config["BAT"]["ConvertLoss"])

        # EV init
        self.SOC_ev_min = float(config["EV"]["SOC_ev_min"])
        self.SOC_ev_init = float(config["EV"]["SOC_ev_init"])
        self.SOC_ev_max = float(config["EV"]["SOC_ev_max"])
        self.P_ev_max = float(config["EV"]["P_ev_max"])
        self.E_ev_max = float(config["EV"]["E_ev_max"])
        self.eta_ev = float(config["EV"]["eta_ev"])
        self.t_a_ev = datetime.strptime(config["EV"]["t_a_ev"], "%H:%M:%S")
        self.t_b_ev = datetime.strptime(config["EV"]["t_b_ev"], "%H:%M:%S")
        self.t_goal_ev = datetime.strptime(config["EV"]["t_goal_ev"],
                                           "%H:%M:%S")

        # verify we have enough day to build the set for the prediction
        assert (
            datetime.strptime(config["TIME"]["start"], "20%y-%m-%d %H:%M:%S") -
            datetime.strptime(config["TIME"]["startPred"],
                              "20%y-%m-%d %H:%M:%S")
        ).days >= 1, "a delay of at least 1 day is needed to predict"
        # Time frame of optimization
        self.timestamps = constructTimeStamps(
            datetime.strptime(config["TIME"]["start"], "20%y-%m-%d %H:%M:%S"),
            datetime.strptime(config["TIME"]["end"], "20%y-%m-%d %H:%M:%S"),
            datetime.strptime(config["TIME"]["stepsize"], "%H:%M:%S") -
            datetime.strptime("00:00:00", "%H:%M:%S"),
        )
        self.timestampsPredPV = constructTimeStamps(
            datetime.strptime(config["TIME"]["startPred"],
                              "20%y-%m-%d %H:%M:%S"),
            datetime.strptime(config["TIME"]["end"], "20%y-%m-%d %H:%M:%S"),
            datetime.strptime(config["TIME"]["stepsizePredPV"], "%H:%M:%S") -
            datetime.strptime("00:00:00", "%H:%M:%S"),
        )
        self.timestampsPredLoad = constructTimeStamps(
            datetime.strptime(config["TIME"]["startPred"],
                              "20%y-%m-%d %H:%M:%S"),
            datetime.strptime(config["TIME"]["end"], "20%y-%m-%d %H:%M:%S"),
            datetime.strptime(config["TIME"]["stepsizePredLoad"], "%H:%M:%S") -
            datetime.strptime("00:00:00", "%H:%M:%S"),
        )
        self.stepsize = getStepsize(self.timestamps)
        self.stepsizeHour = self.stepsize.total_seconds() / 3600
        self.stepsizeMinute = self.stepsize.total_seconds() / 60
        # we add +1 because we are between 00:00 and 23:45 so < 1 day
        self.nbDay = (datetime.strptime(
            config["TIME"]["end"], "20%y-%m-%d %H:%M:%S") - datetime.strptime(
                config["TIME"]["start"], "20%y-%m-%d %H:%M:%S")).days + 1

        # Generators
        self.P_dg_max = float(config["DIESEL"]["P_dg_max"])
        self.P_dg_min = float(config["DIESEL"]["P_dg_min"])
        self.dieselQuadraticCof = float(config["DIESEL"]["a_dg"])
        self.dieselLinearCof = float(config["DIESEL"]["b_dg"])
        self.dieselConstantCof = float(config["DIESEL"]["c_dg"])
        self.dieselFuelPrice = float(config["DIESEL"]["c_gen"])
        self.startUpCost = float(config["DIESEL"]["StartUpCost"])
        self.dieselLeastRunHour = datetime.strptime(
            config["DIESEL"]["LeastRunningTime"], "%H:%M:%S").hour
        self.dieselLeastPauseHour = datetime.strptime(
            config["DIESEL"]["LeastPauseTime"], "%H:%M:%S").hour
        self.dieselLeastRunTimestepNumber = int(
            math.ceil(self.dieselLeastRunHour / self.stepsizeHour))
        self.dieselLeastPauseTimestepNumber = int(
            math.ceil(self.dieselLeastPauseHour / self.stepsizeHour))

        self.startUpHour = datetime.strptime(config["DIESEL"]["StartUpTime"],
                                             "%H:%M:%S").hour
        self.shutDownHour = datetime.strptime(config["DIESEL"]["ShutDownTime"],
                                              "%H:%M:%S").hour
        self.shutDownTimestepNumber = int(
            math.ceil(self.shutDownHour / self.stepsizeHour))
        self.startUpTimestepNumber = int(
            math.ceil(self.startUpHour / self.stepsizeHour))
        self.deltaShutDown = self.P_dg_min / self.shutDownHour * self.stepsizeHour
        self.deltaStartUp = self.P_dg_min / self.startUpHour * self.stepsizeHour

        self.pvFile = config["PV"]["file"]
        self.pvPdct = "yes" == config["PV"]["usePredicted"]
        self.showErr = "yes" == config["GLOBAL"]["showErr"]
        self.pvScale = float(config["PV"]["scale"])
        self.windFile = config["WIND"]["file"]
        self.windScale = float(config["WIND"]["scale"])
        self.windStart = datetime.strptime(config["WIND"]["windStart"],
                                           "20%y-%m-%d %H:%M:%S")
        self.windDelta = self.windStart - datetime.strptime(
            config["TIME"]["start"], "20%y-%m-%d %H:%M:%S")
        self.pvStart = datetime.strptime(config["PV"]["pvStart"],
                                         "20%y-%m-%d %H:%M:%S")
        self.pvDelta = self.pvStart - datetime.strptime(
            config["TIME"]["start"], "20%y-%m-%d %H:%M:%S")
        self.loadsFile = config["LOADS"]["file"]
        self.loadsPdct = "yes" == config["LOADS"]["usePredicted"]
        self.loadsScale = float(config["LOADS"]["scale"])
        self.dataFile = config["DATA_PS"]["file"]
        self.dataPSLoads = "yes" == config["DATA_PS"]["loads"]
        self.dataPSPv = "yes" == config["DATA_PS"]["pv"]
        self.timeHeader = config["DATA_PS"]["timeHeader"]
        self.dataid = config["DATA_PS"]["dataid"]
        self.dataStart = datetime.strptime(config["DATA_PS"]["dataStart"],
                                           "20%y-%m-%d %H:%M:%S")
        self.dataDelta = self.dataStart - datetime.strptime(
            config["TIME"]["start"], "20%y-%m-%d %H:%M:%S")
        self.costFileGrid = config["COST"]["file_grid"]
        self.constantPrice = float(config["COST"]["constant_price"])
        self.priceDataStart = datetime.strptime(
            config["COST"]["priceDataStart"], "20%y-%m-%d %H:%M:%S")
        self.priceDataDelta = self.priceDataStart - datetime.strptime(
            config["TIME"]["start"], "20%y-%m-%d %H:%M:%S")
        self.co2Grid = float(config["CO2"]["grid_CO2"])
        self.co2Diesel = float(config["CO2"]["diesel_CO2"])