def get_data_source(self, data_client_params):
        _source = None
        if data_client_params["is_local_source"]:
            _source = LocalSource(
                data_spec=data_client_params["source_data_spec"],
                local_cache=data_client_params["source_local_cache"],
            )
        elif data_client_params["is_gcs_source"]:
            if isinstance(
                data_client_params["source_data_spec"], DonateYourDataSpec
            ):
                _source = GCSDYDSource(
                    gcp_project=data_client_params["gcp_project"],
                    gcs_uri_base=data_client_params["gcs_uri_base"],
                    local_cache=data_client_params["source_local_cache"],
                )
            elif isinstance(
                data_client_params["source_data_spec"], FlatFilesSpec
            ):
                _source = GCSFlatFilesSource(
                    gcp_project=data_client_params["gcp_project"],
                    gcs_uri_base=data_client_params["gcs_uri_base"],
                    local_cache=data_client_params["source_local_cache"],
                )

        elif data_client_params["is_gbq_source"]:
            _source = GBQDataSource(
                data_spec=data_client_params["source_data_spec"],
                gcp_project=data_client_params["gcp_project"],
                gbq_table=data_client_params["gbq_table"],
                local_cache=data_client_params["source_local_cache"],
            )
        return _source
Beispiel #2
0
    def setup_class(cls):
        # initialize with data to avoid pulling multiple times

        cls.sim_config = Config.make_sim_config(
            identifier=[
                "DYD_dummy_data",
            ],  # test file
            latitude=33.481136,
            longitude=-112.078232,
            start_utc=[
                "2018-01-01 00:00:00",
            ],
            end_utc=[
                "2018-12-31 23:55:00",
            ],
            min_sim_period="3D",
            min_chunk_period="30D",
            sim_step_size_seconds=300,
            output_step_size_seconds=300,
        )

        cls.data_client = DataClient(
            source=LocalSource(
                local_cache=os.environ.get("LOCAL_CACHE_DIR"),
                data_spec=DonateYourDataSpec(),
            ),
            destination=LocalDestination(
                local_cache=os.environ.get("LOCAL_CACHE_DIR"),
                data_spec=DonateYourDataSpec(),
            ),
        )
        cls.data_client.sim_config = cls.sim_config.iloc[0]

        cls.data_client.get_data()
    def test_make_fmu(self, test_sim_config, building_model):
        """test that make_fmu produces fmu file"""
        dc = DataClient(
            source=LocalSource(
                local_cache=os.environ.get("LOCAL_CACHE_DIR"),
                data_spec=DonateYourDataSpec(),
            ),
            destination=LocalDestination(
                local_cache=os.environ.get("LOCAL_CACHE_DIR"),
                data_spec=DonateYourDataSpec(),
            ),
            nrel_dev_api_key=os.environ.get("NREL_DEV_API_KEY"),
            nrel_dev_email=os.environ.get("NREL_DEV_EMAIL"),
            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"),
            simulation_epw_dir=os.environ.get("SIMULATION_EPW_DIR"),
        )
        dc.sim_config = test_sim_config
        dc.get_data()

        fmu = building_model.create_model_fmu(
            sim_config=test_sim_config,
            weather_channel=dc.weather,
            datetime_channel=dc.datetime,
        )
        assert os.path.exists(fmu)

        # @pytest.mark.usefixtures("building_model")
        # def test_fmu_compliance(self, building_model):
        """test that fmu file is compliant with FMI."""
        output_path = os.path.join(os.environ.get("OUTPUT_DIR"),
                                   "compliance_check_output.csv")
        # use `bash expect` to run non-interactive
        # Note: if this test fails check ./Output_EPExport_Slave/Furnace_prep.err
        cmd = (
            "expect 'Press enter to continue.' {{ send '\r' }} |"
            f' {os.environ.get("EXT_DIR")}/FMUComplianceChecker/fmuCheck.linux64'
            f" -h {self.step_size}"
            " -s 172800"
            f" -o {output_path} {building_model.fmu_path}")
        logger.info("FMU compliance checker command:")
        logger.info(cmd)
        # shlex causes FMUComplianceChecker to run with options, use cmd string
        out = subprocess.run(cmd,
                             shell=True,
                             capture_output=False,
                             text=True,
                             input="\n")

        assert out.returncode == 0
Beispiel #4
0
    def setup_class(cls):
        # initialize with data to avoid pulling multiple times
        cls.sim_config = Config.make_sim_config(
            identifier=[
                "DYD_dummy_data",
            ],  # test file
            latitude=33.481136,
            longitude=-112.078232,
            start_utc=[
                "2018-01-01 00:00:00",
            ],
            end_utc=[
                "2018-12-31 23:55:00",
            ],
            min_sim_period="3D",
            min_chunk_period="30D",
            sim_step_size_seconds=300,
            output_step_size_seconds=300,
        )

        cls.data_clients = []
        cls.data_client = DataClient(
            source=LocalSource(
                local_cache=os.environ.get("LOCAL_CACHE_DIR"),
                data_spec=DonateYourDataSpec(),
            ),
            destination=LocalDestination(
                local_cache=os.environ.get("LOCAL_CACHE_DIR"),
                data_spec=DonateYourDataSpec(),
            ),
            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"),
            simulation_epw_dir=os.environ.get("SIMULATION_EPW_DIR"),
        )

        for _idx, _sim_config in cls.sim_config.iterrows():
            dc = copy.deepcopy(cls.data_client)
            dc.sim_config = _sim_config

            dc.get_data()

            cls.data_clients.append(dc)
Beispiel #5
0
    def setup_class(cls):
        # initialize with data to avoid pulling multiple times
        cls.sim_config = Config.make_sim_config(
            identifier=[
                "DYD_dummy_data",  # test file
            ],
            latitude=33.481136,
            longitude=-112.078232,
            start_utc=[
                "2018-01-01 00:00:00",
            ],
            end_utc=[
                "2018-12-31 23:55:00",
            ],
            min_sim_period="3D",
            min_chunk_period="30D",
            sim_step_size_seconds=300,
            output_step_size_seconds=300,
        )

        cls.data_client = DataClient(
            source=LocalSource(
                local_cache=os.environ.get("LOCAL_CACHE_DIR"),
                data_spec=DonateYourDataSpec(),
            ),
            destination=GCSDestination(
                gcp_project=os.environ.get("BCS_GOOGLE_CLOUD_PROJECT"),
                gcs_uri_base=os.environ.get("BCS_OUTPUT_GCS_URI_BASE"),
                data_spec=DonateYourDataSpec(),
                local_cache=None,
            ),
            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"),
            simulation_epw_dir=os.environ.get("SIMULATION_EPW_DIR"),
        )
        cls.data_client.sim_config = cls.sim_config.iloc[0]

        cls.data_client.get_data()