Exemple #1
0
    def _make_weather_nodes(self, model, weather, cost):

        if not isinstance(self.area, Parameter):
            raise ValueError(
                'Weather nodes can only be created if an area Parameter is given.'
            )

        rainfall = weather['rainfall'].astype(np.float64)
        rainfall_param = MonthlyProfileParameter(model, rainfall)

        evaporation = weather['evaporation'].astype(np.float64)
        evaporation_param = MonthlyProfileParameter(model, evaporation)

        # Assume rainfall/evap is mm/day
        # Need to convert:
        #   Mm2 -> m2
        #   mm/day -> m/day
        #   m3/day -> Mm3/day
        # TODO allow this to be configured
        const = ConstantParameter(model, 1e6 * 1e-3 * 1e-6)

        # Create the flow parameters multiplying area by rate of rainfall/evap
        rainfall_flow_param = AggregatedParameter(
            model, [rainfall_param, const, self.area], agg_func='product')
        evaporation_flow_param = AggregatedParameter(
            model, [evaporation_param, const, self.area], agg_func='product')

        # Create the nodes to provide the flows
        rainfall_node = Input(model,
                              '{}.rainfall'.format(self.name),
                              parent=self)
        rainfall_node.max_flow = rainfall_flow_param
        rainfall_node.cost = cost

        evporation_node = Output(model,
                                 '{}.evaporation'.format(self.name),
                                 parent=self)
        evporation_node.max_flow = evaporation_flow_param
        evporation_node.cost = cost

        rainfall_node.connect(self)
        self.connect(evporation_node)
        self.rainfall_node = rainfall_node
        self.evaporation_node = evporation_node

        # Finally record these flows
        self.rainfall_recorder = NumpyArrayNodeRecorder(
            model, rainfall_node, name=f'__{rainfall_node.name}__:rainfall')
        self.evaporation_recorder = NumpyArrayNodeRecorder(
            model,
            evporation_node,
            name=f'__{evporation_node.name}__:evaporation')
Exemple #2
0
    def _make_rainfall_node(self, model, rainfall, cost):

        if not isinstance(self.area, Parameter):
            log.warning(
                'Weather nodes can only be created if an area Parameter is given.'
            )
            return

        if rainfall is None:
            try:
                rainfall_param = load_parameter(model,
                                                f'__{self.name}__:rainfall')
            except KeyError:
                log.warning(
                    f"Please speficy a rainfall or a weather on node {self.name}"
                )
                return
        elif isinstance(rainfall, pd.DataFrame) or isinstance(
                rainfall, pd.Series):
            #assume it's a dataframe
            rainfall = rainfall.astype(np.float64)
            rainfall_param = MonthlyProfileParameter(model, rainfall)
        else:
            rainfall_param = rainfall

        # Create the flow parameters multiplying area by rate of rainfall/evap
        rainfall_flow_param = AggregatedParameter(
            model, [rainfall_param, self.const, self.area], agg_func='product')

        # Create the nodes to provide the flows
        rainfall_node = Input(model,
                              '{}.rainfall'.format(self.name),
                              parent=self)
        rainfall_node.max_flow = rainfall_flow_param
        rainfall_node.cost = cost

        rainfall_node.connect(self)
        self.rainfall_node = rainfall_node

        # Finally record these flows
        self.rainfall_recorder = NumpyArrayNodeRecorder(
            model, rainfall_node, name=f'__{rainfall_node.name}__:rainfall')