Exemplo n.º 1
0
def get_weather_source(site, use_cz2010=False):
    ''' Finds most relevant WeatherSource given project site.

    Parameters
    ----------
    site : eemeter.structures.ZIPCodeSite
        Site to match to weather source data.
    use_cz2010 : boolean, default False
        Indicates whether or not to use CZ2010 mapping.

    Returns
    -------
    weather_source : eemeter.weather.ISDWeatherSource or None
        Closest data-validated weather source in the same climate zone as
        project ZIP code, if available. If use_cz2010 is set, returns
        the ISDWeatherSource corresponding with the cz2010 station mapping.
        If no station can be found, returns None.
    '''

    zipcode = site.zipcode
    if use_cz2010:
        station = zipcode_to_cz2010_station(zipcode)
    else:
        station = zipcode_to_usaf_station(zipcode)

    if station is None:
        logger.error(
            "Could not find ISD station for zipcode {}."
            .format(zipcode)
        )
        return None

    logger.debug(
        "Mapped ZIP code {} to ISD station {}"
        .format(zipcode, station)
    )

    try:
        weather_source = ISDWeatherSource(station)
    except ValueError:
        logger.error(
            "Could not create ISDWeatherSource for station {}."
            .format(station)
        )
        return None

    logger.debug("Created ISDWeatherSource using station {}".format(station))

    return weather_source
Exemplo n.º 2
0
def get_weather_source(project):
    ''' Finds most relevant WeatherSource given project site.

    Parameters
    ----------
    project : eemeter.structures.Project
        Project for which to find weather source data.

    Returns
    -------
    weather_source : eemeter.weather.ISDWeatherSource
        Closest data-validated weather source in the same climate zone as
        project ZIP code, if available.
    '''

    zipcode = project.site.zipcode
    station = zipcode_to_usaf_station(zipcode)

    if station is None:
        logger.error(
            "Could not find ISD station for zipcode {}."
            .format(zipcode)
        )
        return None

    logger.info(
        "Mapped ZIP code {} to ISD station {}"
        .format(zipcode, station)
    )

    try:
        weather_source = ISDWeatherSource(station)
    except ValueError:
        logger.error(
            "Could not create ISDWeatherSource for station {}."
            .format(station)
        )
        return None

    logger.info("Created ISDWeatherSource using station {}".format(station))

    return weather_source
Exemplo n.º 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")
    hourly_index_utc = pd.DatetimeIndex(start=dates[0], periods = dates.shape[0] * 24, freq="H", tz=pytz.UTC)

    # 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_usaf_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)
    utc_offset = dateutil.parser.parse("2000-01-01T00:00:00" + utc_offset).tzinfo.utcoffset(None)
    temp_out = ws_hourly.indexed_temperatures(hourly_index_utc - utc_offset, "degF")
    temp_out.index = 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
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")
    hourly_index_utc = pd.DatetimeIndex(start=dates[0],
                                        periods=dates.shape[0] * 24,
                                        freq="H",
                                        tz=pytz.UTC)

    # 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_usaf_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)
    utc_offset = dateutil.parser.parse("2000-01-01T00:00:00" +
                                       utc_offset).tzinfo.utcoffset(None)
    temp_out = ws_hourly.indexed_temperatures(hourly_index_utc - utc_offset,
                                              "degF")
    temp_out.index = 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
Exemplo n.º 5
0
def test_zipcode_to_usaf_station():
    assert zipcode_to_usaf_station('82440') == '726700'
    assert zipcode_to_usaf_station('94403') == '745090'
Exemplo n.º 6
0
def test_zipcode_to_usaf_station():
    assert zipcode_to_usaf_station('82440') == '726700'
    assert zipcode_to_usaf_station('94403') == '994041'