Beispiel #1
0
    def test_set_data(self, mock_store, mock_model):
        """should allow write access to output data
        """
        expected = np.array([[1.0]])
        data_handle = DataHandle(mock_store, 1, 2015, [2015, 2020], mock_model)

        data_handle.set_results("test", expected)
        assert data_handle["test"] == expected

        mock_store.write_results.assert_called_with(1, 'test_model', 'test',
                                                    expected, 'test_regions',
                                                    'test_intervals', 2015,
                                                    None, None)
Beispiel #2
0
    def save_decision_metrics(self, data_handle: DataHandle):
        """Compute decision metrics for the current system and save to disk

        Expects outputs for this wrapper to be defined with the same name as the
        list of attributed below

        Arguments
        ---------
        data_handle
        """
        technologies = self.outputs['rollout_costs'].dim_coords(
            'technology').ids
        exchanges = self.outputs['rollout_costs'].dim_coords('exchanges').ids

        attributes = [
            'rollout_costs', 'rollout_bcr', 'total_potential_benefit',
            'total_potential_bcr'
        ]

        for attribute in attributes:
            data = self.save_exchange_attribute(technologies, exchanges,
                                                attribute)
            data_handle.set_results(attribute, data)
Beispiel #3
0
    def simulate(self, data_handle: DataHandle):
        """Implement smif.SectorModel simulate
        """
        # -----
        # Start
        # -----
        now = data_handle.current_timestep
        total_cost = 0

        interventions = data_handle.get_current_interventions()

        dc_assets = []

        for name, intervention in interventions.items():
            if intervention['build_year'] == now:
                technology = intervention['technology']
                asset_id = intervention['id']
                exchange = [
                    exchange for exchange in self.system._exchanges
                    if exchange.id == asset_id
                ][0]
                total_cost += exchange.rollout_costs[technology]

                asset = (intervention['id'], intervention['technology'])
                dc_assets.append(asset)

        self.logger.debug(self.system.capacity('exchange'))

        data_handle.set_results('total_cost', total_cost)

        self.logger.debug("Upgrading dc assets with %s", dc_assets)
        self.system.upgrade(dc_assets)

        self.logger.debug(self.system.capacity('exchange'))

        adoption = self.update_adoption_desirability(data_handle)

        self.save_decision_metrics(data_handle)

        # -------------
        # Write outputs
        # -------------
        lad_names = self.outputs['lad_premises_with_fttp'].dim_coords(
            'lad_uk_2016').ids
        num_lads = len(lad_names)
        num_fttp = np.zeros((num_lads))
        num_fttdp = np.zeros((num_lads))
        num_fttc = np.zeros((num_lads))
        num_adsl = np.zeros((num_lads))

        coverage = self.system.coverage()
        for i, lad in enumerate(lad_names):
            if lad not in coverage:
                continue
            stats = coverage[lad]
            num_fttp[i] = stats['num_fttp']
            num_fttdp[i] = stats['num_fttdp']
            num_fttc[i] = stats['num_fttc']
            num_adsl[i] = stats['num_adsl']

        data_handle.set_results('lad_premises_with_fttp', num_fttp)
        data_handle.set_results('lad_premises_with_fttdp', num_fttdp)
        data_handle.set_results('lad_premises_with_fttc', num_fttc)
        data_handle.set_results('lad_premises_with_adsl', num_adsl)

        aggregate_coverage = self.system.aggregate_coverage('lad')

        perc_fttp = np.zeros((num_lads))
        perc_fttdp = np.zeros((num_lads))
        perc_fttc = np.zeros((num_lads))
        perc_docsis3 = np.zeros((num_lads))
        perc_adsl = np.zeros((num_lads))
        sum_of_premises = np.zeros((num_lads))

        for i, lad in enumerate(lad_names):
            if lad not in aggregate_coverage:
                continue
            datum = aggregate_coverage[lad]
            perc_fttp[i] = datum['percentage_of_premises_with_fttp']
            perc_fttdp[i] = datum['percentage_of_premises_with_fttdp']
            perc_fttc[i] = datum['percentage_of_premises_with_fttc']
            perc_docsis3[i] = datum['percentage_of_premises_with_docsis3']
            perc_adsl[i] = datum['percentage_of_premises_with_adsl']
            sum_of_premises[i] = datum['sum_of_premises']

        data_handle.set_results('percentage_of_premises_connected_with_fttp',
                                perc_fttp)
        data_handle.set_results('percentage_of_premises_connected_with_fttdp',
                                perc_fttdp)
        data_handle.set_results('percentage_of_premises_connected_with_fttc',
                                perc_fttc)
        data_handle.set_results(
            'percentage_of_premises_connected_with_docsis3', perc_docsis3)
        data_handle.set_results('percentage_of_premises_connected_with_adsl',
                                perc_adsl)