def get_weather_sources(station):
    weather_source = GSODWeatherSource(station, 2007, 2015)
    weather_normal_source = TMY3WeatherSource(station)
    if weather_source.data == {} or weather_normal_source.data == {}:
        message = "Insufficient weather data for station {}. Please choose " \
                "a different weather station (by selecting a different " \
                "zipcode).".format(station)
    return weather_source, weather_normal_source
Beispiel #2
0
    def __init__(self,
                 location,
                 consumption=[],
                 baseline_period=None,
                 reporting_period=None,
                 other_periods=[],
                 weather_source=None,
                 weather_normal_source=None):
        self.location = location
        self.baseline_period = baseline_period
        self.reporting_period = reporting_period
        self.other_periods = other_periods

        if not type(consumption) == list:
            self.consumption = [consumption]
        else:
            self.consumption = consumption

        if not type(other_periods) == list:
            self.other_periods = [other_periods]
        else:
            self.other_periods = other_periods

        if location.station is None:
            message = (
                "Unable to create project; no valid weather station was found."
            )
            raise ValueError(message)

        if weather_source is None:
            weather_source = GSODWeatherSource(location.station)
        self.weather_source = weather_source

        if weather_normal_source is None:
            weather_normal_source = TMY3WeatherSource(location.station)
        self.weather_normal_source = weather_normal_source
Beispiel #3
0
def mock_tmy3_weather_source():
    tmp_url = "sqlite:///{}/weather_cache.db".format(tempfile.mkdtemp())
    ws = TMY3WeatherSource('724838', tmp_url, preload=False)
    ws.client = MockWeatherClient()
    ws._load_data()
    return ws
Beispiel #4
0
def test_bad_station():
    with pytest.raises(ValueError):
        TMY3WeatherSource("INVALID")
def mock_tmy3_weather_source():
    tmp_dir = tempfile.mkdtemp()
    ws = TMY3WeatherSource("724838", tmp_dir, preload=False)
    ws.client = MockWeatherClient()
    ws._load_data()
    return ws
Beispiel #6
0
def test_tmy3_weather_source_null():
    ws = TMY3WeatherSource("INVALID")
    assert_allclose(ws.tempC.values, np.zeros((365*24,)) * np.nan)
Beispiel #7
0
                        (42.3594006437094,-87.8581578622419,"60085"),
                        (None,None,"00000")])
def lat_long_zipcode(request):
    return request.param

@pytest.fixture(params=[('722874-93134',2012,2012),
                        ('722874',2012,2012)])
def gsod_weather_source(request):
    return request.param

@pytest.fixture(params=[('722874-93134',2012,2012),
                        ('722874',2012,2012)])
def isd_weather_source(request):
    return request.param

@pytest.fixture(params=[TMY3WeatherSource('722880')])
def tmy3_weather_source(request):
    return request.param

@pytest.fixture(params=[("60611","725340"),
                        ("91104","722880"),
                        ("02138","725090"),
                        ("60085","725347")])
def zipcode_to_station(request):
    return request.param


##### Tests #####

@pytest.mark.slow
def test_gsod_weather_source(periods, gsod_weather_source):
Beispiel #8
0
    def generate(self, location, period_elec, period_gas,
            baseline_period, reporting_period,
            noise_elec=None, noise_gas=None):
        """Returns a simple simulated project consisting of generated
        electricity and gas consumptions and estimated savings for each.

        Parameters
        ----------
        location : eemeter.location.Location
            Location of project
        """
        early_date = None
        late_date = None

        if not period_elec.closed or not period_gas.closed:
            message = "Periods of consumption must have start and end."
            raise ValueError(message)

        all_periods = [period_elec, period_gas, baseline_period,
                reporting_period]
        for period in all_periods:
            if early_date is None:
                early_date = period.start
            if late_date is None:
                late_date = period.end
            if period.start is not None and period.start < early_date:
                early_date = period.start
            if period.end is not None and late_date < period.end:
                late_date = period.end

        weather_source = GSODWeatherSource(location.station,early_date.year,
                late_date.year)
        weather_normal_source = TMY3WeatherSource(location.station)

        cd_elec, est_savings_elec, elec_bl_params, elec_rp_params = \
                self._generate_fuel_consumptions(
                        weather_source, weather_normal_source, period_elec,
                        self.electricity_model, self.elec_param_dists,
                        self.elec_param_delta_dists, noise_elec,
                        baseline_period, reporting_period,
                        "electricity", "kWh", self.temperature_unit_name)

        cd_gas, est_savings_gas, gas_bl_params, gas_rp_params = \
                self._generate_fuel_consumptions(
                        weather_source, weather_normal_source, period_gas,
                        self.gas_model, self.gas_param_dists,
                        self.gas_param_delta_dists, noise_gas,
                        baseline_period, reporting_period,
                        "natural_gas", "therm", self.temperature_unit_name)

        project = Project(location, [cd_elec, cd_gas], baseline_period,
                reporting_period)

        results = {
            "project": project,
            "electricity_estimated_savings": est_savings_elec,
            "natural_gas_estimated_savings": est_savings_gas,
            "electricity_pre_params": elec_bl_params,
            "natural_gas_pre_params": gas_bl_params,
            "electricity_post_params": elec_rp_params,
            "natural_gas_post_params": gas_rp_params,
        }

        return results
Beispiel #9
0
def test_real_load():
    ws = TMY3WeatherSource("725090")
    assert ws.tempC.shape == (8760, )
    assert ws.tempC.notnull().sum() == 8760
    def setUpTestData(cls):

        cls.user = User.objects.create_user('john', '*****@*****.**',
                                            'johnpassword')

        cls.project = create_project(
            spec={
                "project_id":
                "ABCD",
                "project_owner":
                cls.user.projectowner,
                "baseline_period_end":
                datetime(2012, 1, 1, tzinfo=pytz.UTC),
                "reporting_period_start":
                datetime(2012, 2, 1, tzinfo=pytz.UTC),
                "zipcode":
                "91104",
                "traces": [
                    {
                        "interpretation": "NG_C_S",
                        "unit": "THM",
                        "start": "2010-01-01",
                        "end": "2014-12-31",
                        "freq": "MS",
                        "value": 1,
                        "nans": set(range(0, 60, 20)),
                        "estimated": set(range(3, 60, 15)),
                    },
                    {
                        "interpretation": "NG_C_S",
                        "unit": "THM",
                        "start": "2011-09-01",
                        "end": "2014-12-31",
                        "freq": "D",
                        "value": 2,
                        "nans": set(range(0, 1000, 20)),
                        "estimated": set(range(3, 1000, 15)),
                    },
                    {
                        "interpretation": "E_C_S",
                        "unit": "KWH",
                        "start": "2011-01-01",
                        "end": "2014-12-31",
                        "freq": "15T",
                        "value": 0.04,
                        "nans": set(range(0, 96 * 365 * 4, 200)),
                        "estimated": set(range(3, 96 * 365 * 4, 150)),
                    },
                    {
                        "interpretation": "E_C_S",
                        "unit": "KWH",
                        "start": "2011-01-01",
                        "end": "2014-12-31",
                        "freq": "H",
                        "value": 0.4,
                        "nans": set(range(0, 96 * 365 * 4, 200)),
                        "estimated": set(range(3, 96 * 365 * 4, 150)),
                    },
                    {
                        "interpretation": "E_OSG_U",
                        "unit": "KWH",
                        "start": "2012-01-15",
                        "end": "2014-12-31",
                        "freq": "H",
                        "value": 0.3,
                        "nans": set(range(0, 96 * 365 * 4, 200)),
                        "estimated": set(range(3, 96 * 365 * 4, 150)),
                    },
                    {
                        "interpretation": "E_OSG_U",
                        "unit": "KWH",
                        "start": "2010-01-01",
                        "end": "2014-12-31",
                        "freq": "30T",
                        "value": 0.1,
                        "nans": set(range(0, 96 * 365 * 4, 200)),
                        "estimated": set(range(3, 96 * 365 * 4, 150)),
                    },
                ],
            })

        cls.project.run_meter()

        tmp_dir = tempfile.mkdtemp()
        wns = TMY3WeatherSource("724838", tmp_dir, preload=False)
        wns.client = MockWeatherClient()
        wns._load_data()
        cls.weather_normal_source = wns

        tmp_dir = tempfile.mkdtemp()
        ws = ISDWeatherSource("722880", tmp_dir)
        ws.client = MockWeatherClient()
        cls.weather_source = ws