def load_car_models(self):
        """
        Loads all car models from car_models.csv.

        Returns
        -------
        None.
        """
        cast = Cast("Car Model")
        self.car_models = dict()
        
        csv_helper = CSVHelper("data","car_models.csv")
        for row in csv_helper.data:
            uid = cast.to_positive_int(row[0], "Uid")
            cast.uid = uid
                
            car_model_name = str(row[1]).strip(" ").strip('"')
            car_consumption = cast.to_positive_float(row[2], "Car consumption")
            drag_coeff = cast.to_positive_float(row[3], "Drag coeff")
            frontal_area = cast.to_positive_float(row[4], "Frontal area")
            mass = cast.to_positive_float(row[5], "Mass")
            battery_capacity \
                = cast.to_positive_float(row[6], "Battery capacity")
            charger_capacity_ac \
                = cast.to_positive_float(row[7], "Charger capacity AC")
            charger_capacity_dc \
                = cast.to_positive_float(row[8], "Charger capacity DC")
                
            cm = CarModel(uid, car_model_name, car_consumption, drag_coeff,
                          frontal_area, mass, battery_capacity,
                          charger_capacity_ac, charger_capacity_dc)
            self.car_models[uid] = cm
Exemple #2
0
    def get_parameter(self, parameter_name, parameter_type):
        """
        Returns a parameter from self.parameter as a requested type.

        Parameters
        ----------
        parameter_name : string
            Name of the parameter requested.
        parameter_type : string
            Type the parameter is requested in. Currently    
            supported: float, positive_float, int, positive_int, string,
            boolean.

        Returns
        -------
        <Type as requested in parameter_type>
            Well the parameter request casted as the type requested

        """
        if parameter_name not in self.parameters:
            sys.exit("No parameter called " + parameter_name \
                     + " is defined in parameters.csv")
        value_str = self.parameters[parameter_name]
        
        cast = Cast("Get Parameter")
        if parameter_type == "float":
            return cast.to_float(value_str, parameter_name)
        elif parameter_type == "positive_float":
            return cast.to_positive_float(value_str, parameter_name)
        elif parameter_type == "int":
            return cast.to_int(value_str, parameter_name)
        elif parameter_type == "positive_int":
            return cast.to_positive_int(value_str, parameter_name)
        elif parameter_type == "string":
            return value_str
        elif parameter_type == "boolean":
            return cast.to_boolean(value_str, parameter_name)
        else:
            sys.exit("Type '" + parameter_type + "' for parameter " \
                     + parameter_name + " is not recognised")
 def __init__(self, clock, row):
     time_factor = 60 // clock.time_step
     time_factor_sqrt = numpy.sqrt(time_factor)
     if 60 % clock.time_step != 0:
         raise RuntimeError("time_step do not add up to full hour!")
     cast = Cast("Normed rooftop PV output fit parameters")
     self.max_output \
         = cast.to_positive_int(row[1], "Max output") / time_factor
     # x_border seperates the part fitted by a constant and the part
     # fitted by a gaussian
     self.x_border = cast.to_positive_int(row[2], "x_border") / time_factor
     self.A = cast.to_positive_float(row[3], "A")
     self.mu = cast.to_positive_int(row[4], "mu") / time_factor
     self.sig = cast.to_positive_float(row[5], "sig") / time_factor_sqrt
     self.y0 = cast.to_positive_float(row[6], "y0")
     self.A_po = cast.to_positive_float(row[7], "A_po")
     self.mu_po = cast.to_positive_int(row[8], "mu_po") / time_factor
     self.sig_po\
         = cast.to_positive_float(row[9], "sig_po") / time_factor_sqrt
     self.y_co = cast.to_positive_float(row[10], "y_co")
     self.surf_po = cast.to_positive_float(row[11], "surf_po")
     self.surf_co = cast.to_positive_float(row[12], "surf_co")
    def load_connections(self):
        """
        Reads information on suburb connection from connections.csv.
        """
        cast = Cast("Connection")
        self.traffic_network = nx.Graph()
        # add locations
        for location in self.locations.values():
            self.traffic_network.add_node(location.uid)
        # add edges
        csv_helper = CSVHelper("data", "connections.csv")
        for row in csv_helper.data:
            try:
                start_location_uid = int(row[0])
                start_location = self.locations[start_location_uid]
                end_location_uid = int(row[1])
                end_location = self.locations[end_location_uid]
            except ValueError:
                sys.exit("Connection not well defined for " + row[0] + " - " \
                         + row[1] + ".")
            flt_dist = self.direct_distance_between_locations(
                start_location, end_location)
            speed_lmt = cast.to_positive_float(row[2], "Speed limit")
            # TODO incorperate conversion of Dom's road levels to speed_lmt
            speed_lmt = 50  # in km/h

            self.traffic_network.add_edge(start_location.uid,
                                          end_location.uid,
                                          distance=flt_dist,
                                          speed_limit=speed_lmt,
                                          current_velocity=speed_lmt)
            self.traffic_network.add_edge(end_location.uid,
                                          start_location.uid,
                                          distance=flt_dist,
                                          speed_limit=speed_lmt,
                                          current_velocity=speed_lmt)
    def load_locations(self):
        """
        Reads information on individual suburbs from locations.csv.
        """
        cast = Cast("Location")
        self.locations = {}
        csv_helper = CSVHelper("data", "locations.csv")
        for row in csv_helper.data:
            uid = cast.to_positive_int(row[0], "Uid")
            cast.uid = uid
            name = row[2]
            longitude = cast.to_float(row[3], "Longitude")
            latitude = cast.to_float(row[4], "Latitude")
            population = cast.to_positive_int(row[5], "Population")
            commute_mean = cast.to_positive_float(row[6], "Commute mean")
            commute_std_dev = cast.to_positive_float(row[7], "Commute std dev")
            occupant_distribution \
                = cast.to_positive_int_list(row[8], "Occupant distribution")
            occupant_values \
                = cast.to_positive_int_list(row[9], "Occupant values")
            pv_capacity_mean \
                = cast.to_positive_float(row[10], "PV capacity mean")
            pv_capacity_std_dev \
                = cast.to_positive_float(row[11], "PV capacity std dev")
            battery_capacity_mean \
                = cast.to_positive_float(row[12], "Battery capacity mean")
            battery_capacity_std_dev\
                = cast.to_positive_float(row[13], "Battery capacity std dev")

            loc = Location(uid, name, longitude, latitude, population,
                           commute_mean, commute_std_dev,
                           occupant_distribution, occupant_values,
                           pv_capacity_mean, pv_capacity_std_dev,
                           battery_capacity_mean, battery_capacity_std_dev)
            # add public charger
            self.cpm.add_company(loc)

            self.locations[loc.uid] = loc
Exemple #6
0
    def __init__(self, clock):
        self.clock = clock

        # load hourly consumption data
        cast = Cast("Hourly Consumption")
        self.hourly_consumption = dict()
        csv_helper = CSVHelper("data", "hourly_consumption.csv")
        for row in csv_helper.data:
            hour = cast.to_positive_int(row[0], "Hour")
            season_it = self.clock.season * 3
            hourly_cons = []
            hourly_cons.append(
                cast.to_positive_float(row[season_it + 1], "10%"))
            hourly_cons.append(
                cast.to_positive_float(row[season_it + 2], "50%"))
            hourly_cons.append(
                cast.to_positive_float(row[season_it + 3], "90%"))
            self.hourly_consumption[hour] = hourly_cons

        # load deviation data for consumption
        cast = Cast("Consumption Deviation")
        self.consumption_deviation = dict()
        csv_helper = CSVHelper("data", "consumption_deviation.csv")
        for row in csv_helper.data:
            location_uid = cast.to_positive_int(row[0], "LocationUid")
            season_it = self.clock.season * 5
            cons_deviation = dict()
            cons_deviation[1] = cast.to_positive_float(row[season_it + 1],
                                                       "1PHH")
            cons_deviation[2] = cast.to_positive_float(row[season_it + 2],
                                                       "2PHH")
            cons_deviation[3] = cast.to_positive_float(row[season_it + 3],
                                                       "3PHH")
            cons_deviation[4] = cast.to_positive_float(row[season_it + 4],
                                                       "4PHH")
            cons_deviation[5] = cast.to_positive_float(row[season_it + 5],
                                                       "5PHH")
            self.consumption_deviation[location_uid] = cons_deviation

        #
        cast = Cast("Consumption Forecast Parameters")
        self.forecast_parameters = dict()
        hourly_forecast_parameters = dict()
        csv_helper = CSVHelper("data", "hourly_consumption_fit.csv")
        season_it = self.clock.season * 2 + 1
        for row in csv_helper.data:
            hour = cast.to_positive_int(row[0], "Hour")
            mu = cast.to_positive_float(row[season_it], "mu")
            sig = cast.to_positive_float(row[season_it + 1], "sig")
            hourly_forecast_parameters[hour] = [mu, sig]

        for time_step in range(0, 24 * 60, self.clock.time_step):
            hour_begin = time_step // 60
            hour_end = (time_step + self.clock.time_step) // 60
            hour_end_remainder = (time_step + self.clock.time_step) % 60

            same_hour = hour_begin == hour_end \
                        or (hour_begin == hour_end - 1 \
                            and hour_end_remainder == 0)

            if same_hour:
                mu_hour, sig_hour = hourly_forecast_parameters[hour_begin]
                mu_time_step = mu_hour / (self.clock.time_step / 60)
                sig_sqr_time_step = sig_hour**2 / (self.clock.time_step / 60)

                self.forecast_parameters[time_step] = [
                    mu_time_step, sig_sqr_time_step
                ]
            else:
                raise RuntimeError("Demand forecast for 60 % time_step != 0" +
                                   " not implemented")

        cur_mu, cur_sig_sqr = 0, 0
        for time in range(0, self.clock.forecast_horizon,
                          self.clock.time_step):
            cur_mu += self.forecast_parameters[time][0]
            cur_sig_sqr += self.forecast_parameters[time][0]**2

        self.forecast_mu, self.forecast_sig = cur_mu, math.sqrt(cur_sig_sqr)
    def __init__(self, parameters, clock, electricity_plan_manager,
                 car_model_manager):
        self.parameters = parameters
        self.clock = clock
        self.epm = electricity_plan_manager

        cast = Cast("Solar Irradation")
        self.irradiances = []
        file_name = "solar_irradiance_" \
                    + self.clock.season_names[self.clock.season] + ".csv"
        csv_helper = CSVHelper("data", file_name)
        it = 0
        resolution_irradiance = 0
        for row in csv_helper.data:
            if it == 0:
                resolution_irradiance \
                    = - cast.to_positive_int(row[0], "Elapsed time")
            if it == 1:
                resolution_irradiance += \
                    + cast.to_positive_int(row[0], "Elapsed time")
            tmp_irradiances = []
            for col in row[1:]:
                value = cast.to_positive_float(col, "Solar irradiance")
                tmp_irradiances.append(value)
            self.irradiances.append(tmp_irradiances)
            it += 1

        cast = Cast("Temperatures")
        self.temperatures = []
        file_name = "temperatures_" \
                    + self.clock.season_names[self.clock.season] + ".csv"
        csv_helper = CSVHelper("data", file_name)
        it = 0
        resolution_temperatures = 0
        for row in csv_helper.data:
            if it == 0:
                resolution_temperatures \
                    = - cast.to_positive_int(row[0], "Elapsed time")
            if it == 1:
                resolution_temperatures += \
                    + cast.to_positive_int(row[0], "Elpased time")
            tmp_temperatures = []
            for col in row[1:]:
                value = cast.to_positive_float(col, "Temperatures")
                tmp_temperatures.append(value)
            self.temperatures.append(tmp_temperatures)
            it += 1

        self.cur_irradiances = self.irradiances[0]
        self.cur_temperatures = self.temperatures[0]

        self.forecast_horizon = parameters.get_parameter(
            "forecast_horizon", "int")

        cast = Cast("Normed rooftop PV output fit parameters")
        self.fit_data = []
        file_name = "normed_rooftop_pv_output_fit_parameters.csv"
        csv_helper = CSVHelper("data", file_name)
        it = 0
        resolution_fit = 0
        for row in csv_helper.data:
            if it == 0:
                resolution_fit = -cast.to_positive_int(row[0], "Elapsed time")
            if it == 1:
                resolution_fit += cast.to_positive_int(row[0], "Elpased time")
            self.fit_data.append(GenerationForecast(self.clock, row))
            it += 1

        self.resolution_irradiance = resolution_irradiance
        self.resolution_temperatures = resolution_temperatures
        self.resolution_fit = resolution_fit

        self.forecast_mu, self.forecast_sig = 0.0, 0.0
        self.forecast_mu_po, self.forecast_sig_po_sqr = 0.0, 0.0
        self.max_output_co_sum, self.max_output_co_count = 0.0, 0
        for it, fit_data_point in enumerate(self.fit_data):
            if it * self.resolution_fit >= self.clock.forecast_horizon:
                break
            if fit_data_point.peak_dominates_constant():
                self.forecast_mu_po += fit_data_point.mu_po
                self.forecast_sig_po_sqr += fit_data_point.sig_po**2
            else:
                self.max_output_co_sum += fit_data_point.max_output
                self.max_output_co_count += 1

        avg_max_output_co = 0
        if self.max_output_co_count != 0:
            avg_max_output_co \
                = self.max_output_co_sum / self.max_output_co_count
        # we use Irwin-Hall to derive normal distribution from co parts
        self.forecast_mu = self.forecast_mu_po + avg_max_output_co / 2
        forecast_sig_co_sqr = (avg_max_output_co / 12)**2
        self.forecast_sig \
            = math.sqrt(self.forecast_sig_po_sqr + forecast_sig_co_sqr)
years = []
for data_point in data:
    date = data_point[0]
    year = cast.to_positive_int(date[0:4], "Year")
    if year not in years:
        years.append(year)
    month = cast.to_positive_int(date[4:6], "Month")
    season = ((month + 3) % 12) // 3
    day = cast.to_positive_int(date[6:8], "Day")
    # exclude leap days
    if month == 2 and day == 29:
        continue
    hour = cast.to_positive_int(date[8:10], "Hour")
    minute = cast.to_positive_int(date[10:12], "Minutes")
    irrad = cast.to_positive_int(data_point[1], "Irradiance")
    temp = cast.to_positive_float(data_point[2], "Temperature")

    # Zulu time to Australian Eastern Standard Time // UTC -> AEDT
    hour = (hour + 10) % 24
    if hour < 10:
        day = day + 1
        if day > days_in_month[month - 1]:
            day = 1
            month = month + 1
            if month > 12:
                month = 1
                year = year + 1

    elapsed_minutes_season = acc_days_season[season][get_month_it_in_season(
        month)] + day - 1
    elapsed_minutes_season = elapsed_minutes_season * 24 + hour