示例#1
0
def test_zipcode_to_station(zipcode_station):
    zipcode, station = zipcode_station
    assert station == zipcode_to_station(zipcode)
示例#2
0
def test_zipcode_to_station(zipcode_station):
    zipcode, station = zipcode_station
    assert station == zipcode_to_station(zipcode)
示例#3
0
def get_single_thermostat(thermostat_id, zipcode, equipment_type, utc_offset, interval_data_filename):
    """ Load a single thermostat directly from an interval data file.

    Parameters
    ----------
    thermostat_id : str
        A unique identifier for the thermostat.
    zipcode : str
        The zipcode of the thermostat, e.g. `"01234"`.
    equipment_type : str
        The equipment type of the thermostat.
    utc_offset : str
        A string representing the UTC offset of the interval data, e.g. `"-0700"`.
        Could also be `"Z"` (UTC), or just `"+7"` (equivalent to `"+0700"`),
        or any other timezone format recognized by the library
        method dateutil.parser.parse.
    interval_data_filename : str
        The path to the CSV in which the interval data is stored.

    Returns
    -------
    thermostat : thermostat.Thermostat
        The loaded thermostat object.
    """
    df = pd.read_csv(interval_data_filename)

    heating, cooling, aux_emerg = _get_equipment_type(equipment_type)

    # load indices
    dates = pd.to_datetime(df["date"])
    daily_index = pd.DatetimeIndex(start=dates[0], periods = dates.shape[0], freq="D")
    hourly_index = pd.DatetimeIndex(start=dates[0], periods = dates.shape[0] * 24, freq="H")

    # raise an error if dates are not aligned
    if not all(dates == daily_index):
        message("Dates provided for thermostat_id={} may contain some "
                "which are out of order, missing, or duplicated.".format(thermostat_id))
        raise ValueError(message)

    # load hourly time series values
    temp_in = pd.Series(_get_hourly_block(df, "temp_in"), hourly_index)

    if heating:
        heating_setpoint = pd.Series(_get_hourly_block(df, "heating_setpoint"), hourly_index)
    else:
        heating_setpoint = None

    if cooling:
        cooling_setpoint = pd.Series(_get_hourly_block(df, "cooling_setpoint"), hourly_index)
    else:
        cooling_setpoint = None

    if aux_emerg:
        auxiliary_heat_runtime = pd.Series(_get_hourly_block(df, "auxiliary_heat_runtime"), hourly_index)
        emergency_heat_runtime = pd.Series(_get_hourly_block(df, "emergency_heat_runtime"), hourly_index)
    else:
        auxiliary_heat_runtime = None
        emergency_heat_runtime = None

    # load outdoor temperatures
    station = zipcode_to_station(zipcode)

    if station is None:
        message = "Could not locate a valid source of outdoor temperature " \
                "data for ZIP code {}".format(zipcode)
        raise ValueError(message)

    ws_hourly = ISDWeatherSource(station, daily_index[0].year, daily_index[-1].year)
    utc_offset = dateutil.parser.parse("2000-01-01T00:00:00" + utc_offset).tzinfo.utcoffset(None)
    temp_out = pd.Series(_get_outdoor_temperatures(daily_index, ws_hourly, utc_offset), hourly_index)

    # load daily time series values
    if cooling:
        cool_runtime = pd.Series(df["cool_runtime"].values, daily_index)
    else:
        cool_runtime = None
    if heating:
        heat_runtime = pd.Series(df["heat_runtime"].values, daily_index)
    else:
        heat_runtime = None

    # create thermostat instance
    thermostat = Thermostat(thermostat_id, equipment_type, zipcode, station,
            temp_in, temp_out, cooling_setpoint, heating_setpoint,
            cool_runtime, heat_runtime, auxiliary_heat_runtime,
            emergency_heat_runtime)
    return thermostat
示例#4
0
    parser.add_argument("data_config", type=str, help="Dataset configuration")
    parser.add_argument("project_csv", type=str, help="Project CSV location")
    parser.add_argument("consumption_csv",
                        type=str,
                        help="Consupmtion CSV location")
    parser.add_argument('--show-plots', action='store_true')
    args = parser.parse_args()

    data_config = configparser.ConfigParser()
    data_config.read(args.data_config)

    for section_name in data_config.sections():
        section = data_config[section_name]

        zipcode = section["zipcode"]
        station = zipcode_to_station(zipcode)
        n_projects = int(section["n_projects"])

        project_cost_k = float(section["project_cost_k"])
        project_cost_theta = float(section["project_cost_theta"])

        total_usage_pre_retrofit_k = float(
            section["total_usage_pre_retrofit_k"])
        total_usage_pre_retrofit_theta = float(
            section["total_usage_pre_retrofit_theta"])

        proportion_total_usage_pre_retrofit_gas_alpha = float(
            section["proportion_total_usage_pre_retrofit_gas_alpha"])
        proportion_total_usage_pre_retrofit_gas_beta = float(
            section["proportion_total_usage_pre_retrofit_gas_beta"])
if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("data_config", type=str, help="Dataset configuration")
    parser.add_argument("project_csv", type=str, help="Project CSV location")
    parser.add_argument("consumption_csv", type=str, help="Consupmtion CSV location")
    parser.add_argument('--show-plots', action='store_true')
    args = parser.parse_args()

    data_config = configparser.ConfigParser()
    data_config.read(args.data_config)

    for section_name in data_config.sections():
        section = data_config[section_name]

        zipcode = section["zipcode"]
        station = zipcode_to_station(zipcode)
        n_projects = int(section["n_projects"])

        project_cost_k = float(section["project_cost_k"])
        project_cost_theta = float(section["project_cost_theta"])

        total_usage_pre_retrofit_k = float(section["total_usage_pre_retrofit_k"])
        total_usage_pre_retrofit_theta = float(section["total_usage_pre_retrofit_theta"])

        proportion_total_usage_pre_retrofit_gas_alpha = float(section["proportion_total_usage_pre_retrofit_gas_alpha"])
        proportion_total_usage_pre_retrofit_gas_beta = float(section["proportion_total_usage_pre_retrofit_gas_beta"])

        proportion_total_savings_gas_alpha = float(section["proportion_total_savings_gas_alpha"])
        proportion_total_savings_gas_beta = float(section["proportion_total_savings_gas_beta"])

        total_proportion_savings_mean = float(section["total_proportion_savings_mean"])