Beispiel #1
0
    def test_put_data(self):
        sim_name = self.get_sim_name()
        _df = self.data_client.get_full_input()
        self.data_client.destination.put_data(_df,
                                              sim_name,
                                              src_spec=Internal())
        _gcs_uri = self.data_client.destination.get_gcs_uri(sim_name)

        r_df = pd.read_parquet(_gcs_uri)
        cr_df = convert_spec(
            r_df,
            src_spec=self.data_client.destination.data_spec,
            dest_spec=Internal(),
            src_nullable=True,
            dest_nullable=False,
        )

        # remove states not in dest spec
        for _col in _df.columns:
            _state = [
                v["internal_state"] for k, v in
                self.data_client.destination.data_spec.full.spec.items()
                if v["internal_state"] == _col
            ]
            if not _state:
                _df = _df.drop(columns=[_col])

        pd.testing.assert_frame_equal(_df, cr_df)
    def test_put_data(self):
        sim_name = self.get_sim_name()
        _df = self.data_client.get_full_input()
        self.data_client.destination.put_data(_df, sim_name, src_spec=Internal())
        _fpath = os.path.join(
            self.data_client.destination.local_cache,
            self.data_client.destination.operator_name,
            sim_name + "." + self.data_client.destination.file_extension,
        )
        r_df = pd.read_parquet(_fpath)
        cr_df = convert_spec(
            r_df,
            src_spec=self.data_client.destination.data_spec,
            dest_spec=Internal(),
            src_nullable=True,
            dest_nullable=False,
        )

        # remove states not in dest spec
        for _col in _df.columns:
            _state = [
                v["internal_state"]
                for k, v in self.data_client.destination.data_spec.full.spec.items()
                if v["internal_state"] == _col
            ]
            if not _state:
                _df = _df.drop(columns=[_col])

        pd.testing.assert_frame_equal(_df, cr_df)
Beispiel #3
0
    def test_put_data(self):
        sim_name = self.get_sim_name()
        _df = self.data_client.get_full_input()
        self.data_client.destination.put_data(
            _df, sim_name, src_spec=Internal()
        )
        _gcs_uri = self.data_client.destination.get_gcs_uri(sim_name)

        r_df = pd.read_parquet(_gcs_uri)
        cr_df = convert_spec(
            r_df,
            src_spec=self.data_client.destination.data_spec,
            dest_spec=Internal(),
        )
        assert _df.equals(cr_df)
    def test_low_pass_filter(self):
        # test HVAC data returns dict of non-empty pd.DataFrame
        state_estimator_model = LowPassFilter(
            alpha_temperature=0.75, alpha_humidity=0.75
        )

        test_temperature = np.arange(-40, 60, 0.05)
        test_humidity = np.linspace(0, 100, len(test_temperature))
        test_motion = np.full(len(test_temperature), False)
        test_sim_time = np.arange(
            0,
            len(test_temperature) * self.step_size_seconds,
            self.step_size_seconds,
            dtype="int64",
        )

        test_sensor_data = pd.DataFrame.from_dict(
            {
                STATES.THERMOSTAT_TEMPERATURE: test_temperature,
                STATES.THERMOSTAT_HUMIDITY: test_humidity,
                STATES.THERMOSTAT_MOTION: test_humidity,
            }
        )

        state_estimator_model.initialize(
            start_utc=pd.Timestamp("now"),
            t_start=0,
            t_end=len(test_temperature) * self.step_size_seconds,
            t_step=self.step_size_seconds,
            data_spec=Internal(),
            categories_dict={},
        )

        for i in range(0, len(test_sim_time)):
            state_estimator_model.do_step(
                t_start=test_sim_time[i],
                t_step=self.step_size_seconds,
                step_sensor_input=test_sensor_data.iloc[i],
            )

        test_output = pd.DataFrame.from_dict(state_estimator_model.output)
        test_output = test_output.drop(axis="rows", index=len(test_sim_time))

        assert (
            pytest.approx(9.95837688446045)
            == test_output[STATES.THERMOSTAT_TEMPERATURE_ESTIMATE].mean()
        )
        assert (
            test_sensor_data[STATES.THERMOSTAT_TEMPERATURE].mean()
            > test_output[STATES.THERMOSTAT_TEMPERATURE_ESTIMATE].mean()
        )
        assert (
            pytest.approx(49.98334503173828)
            == test_output[STATES.THERMOSTAT_HUMIDITY_ESTIMATE].mean()
        )
        assert (
            test_sensor_data[STATES.THERMOSTAT_HUMIDITY].mean()
            > test_output[STATES.THERMOSTAT_HUMIDITY_ESTIMATE].mean()
        )
Beispiel #5
0
 def test_put_data(self):
     sim_name = self.get_sim_name()
     _df = self.data_client.get_full_input()
     self.data_client.destination.put_data(_df,
                                           sim_name,
                                           src_spec=Internal())
     _fpath = os.path.join(
         self.data_client.destination.local_cache,
         self.data_client.destination.operator_name,
         sim_name + "." + self.data_client.destination.file_extension,
     )
     r_df = pd.read_parquet(_fpath)
     cr_df = convert_spec(
         r_df,
         src_spec=self.data_client.destination.data_spec,
         dest_spec=Internal(),
     )
     assert _df.equals(cr_df)
 def get_data(self, sim_config):
     """Get local cache"""
     local_cache_file = self.get_local_cache_file(
         identifier=sim_config["identifier"]
     )
     _data = self.get_local_cache(local_cache_file)
     _data = self.drop_unused_columns(_data=_data)
     _data = convert_spec(
         df=_data, src_spec=self.data_spec, dest_spec=Internal(), copy=False
     )
     return _data
 def get_data(self, sim_config):
     # first check if file in local cache
     local_cache_file = self.get_local_cache_file(
         identifier=sim_config["identifier"])
     _data = self.get_local_cache(local_cache_file)
     if _data.empty:
         _data = self.get_gcs_cache(sim_config, local_cache_file)
     _data = self.drop_unused_columns(_data=_data)
     _data = convert_spec(df=_data,
                          src_spec=self.data_spec,
                          dest_spec=Internal())
     return _data
    def test_step_model(self, test_sim_config, building_model):
        """test that fmu can be simulated with pyfmi

        Note: if this test fails check ./Output_EPExport_Slave/Furnace_prep.err
        """
        start_utc = pd.Timestamp("2020-01-01", tz="utc")
        t_start = 0
        t_step = 300
        t_end = 86400.0
        ns = int(t_end / t_step)

        building_model.create_model_fmu(
            sim_config=test_sim_config,
            epw_path=building_model.epw_path,
            preprocess_check=False,
        )
        # need to recude t_end because of non-inclusion of last time step
        building_model.initialize(
            start_utc=start_utc,
            t_start=t_start,
            t_end=t_end - t_step,
            t_step=t_step,
            data_spec=Internal(),
            categories_dict={},
        )

        step_control_input = {
            STATES.AUXHEAT1: t_step,
            STATES.AUXHEAT2: 0,
            STATES.AUXHEAT3: 0,
            STATES.COMPCOOL1: 0,
            STATES.COMPCOOL2: 0,
            STATES.COMPHEAT1: 0,
            STATES.COMPHEAT2: 0,
            STATES.FAN_STAGE_ONE: t_step,
            STATES.FAN_STAGE_TWO: 0,
            STATES.FAN_STAGE_THREE: 0,
        }

        step_sensor_input = {STATES.THERMOSTAT_MOTION: False}

        for i in range(ns):
            building_model.do_step(
                t_start=building_model.output[STATES.SIMULATION_TIME][i],
                t_step=t_step,
                step_control_input=step_control_input,
                step_sensor_input=step_sensor_input,
                step_weather_input={},
            )
        assert (pytest.approx(33.394825, 0.01) == building_model.
                fmu_output["EAST_ZONE_zone_air_temperature"].mean())
    def test_make_epw_file(self):
        _start_utc = "2019-01-17"
        _end_utc = "2019-01-19"
        _step_size_seconds = 300
        _sim_step_size_seconds = 60

        _data = pd.DataFrame({
            STATES.DATE_TIME:
            pd.date_range(
                start=_start_utc,
                end=_end_utc,
                freq=f"{_sim_step_size_seconds}S",
                tz="utc",
            )
        })

        sim_config = Config.make_sim_config(
            identifier="511863952006",
            latitude=43.798577,
            longitude=-79.239087,
            start_utc=_start_utc,
            end_utc=_end_utc,
            min_sim_period="1D",
            sim_step_size_seconds=_sim_step_size_seconds,
            output_step_size_seconds=_step_size_seconds,
        ).iloc[0]

        _internal_timezone = DateTimeChannel.get_timezone(
            sim_config["latitude"], sim_config["longitude"])
        internal_spec = Internal()

        datetime_channel = DateTimeChannel(
            data=_data[internal_spec.intersect_columns(
                _data.columns, internal_spec.datetime.spec)],
            spec=internal_spec.datetime,
            latitude=sim_config["latitude"],
            longitude=sim_config["longitude"],
            internal_timezone=_internal_timezone,
        )

        weather_channel = WeatherChannel(
            data=pd.DataFrame(),
            spec=internal_spec,
            nrel_dev_api_key=os.environ.get("NREL_DEV_API_KEY"),
            nrel_dev_email=os.environ.get("NREL_DEV_EMAIL"),
            archive_tmy3_dir=os.environ.get("ARCHIVE_TMY3_DIR"),
            archive_tmy3_meta=os.environ.get("ARCHIVE_TMY3_META"),
            archive_tmy3_data_dir=os.environ.get("ARCHIVE_TMY3_DATA_DIR"),
            ep_tmy3_cache_dir=os.environ.get("EP_TMY3_CACHE_DIR"),
            nsrdb_cache_dir=os.environ.get("NSRDB_CACHE_DIR"),
            simulation_epw_dir=os.environ.get("SIMULATION_EPW_DIR"),
        )

        weather_channel.get_epw_data(sim_config, datetime_channel)

        epw_path = weather_channel.make_epw_file(
            sim_config=sim_config,
            datetime_channel=datetime_channel,
            epw_step_size_seconds=_step_size_seconds,
        )

        assert weather_channel.data.empty == False
        assert (pytest.approx(weather_channel.data[
            STATES.OUTDOOR_TEMPERATURE].mean()) == 1.78746962860115)