def compute(self, level_control, pumping_stations): """Computes and returns the computed level control time series. Parameters: * level_control -- pair of (total incoming, total outgoing) time series * pumping_stations -- list of PumpingStation(s) to handle the water flow The total incoming and total outgoing level control volumes have to be assigned to the intakes and pumps that can be used for level control. This method computes that assignment and returns it as a dictionary of PumpingStation to SparseTimeseriesStub. The keys of the returned dictionary are the intakes and pumps that can be used for level control. The associated value is the level control time series. """ assignment = {} (incoming_timeseries, outgoing_timeseries) = level_control for pumping_station in pumping_stations: timeseries = None fraction = pumping_station.percentage / 100.0 if pumping_station.computed_level_control: if pumping_station.into: timeseries = multiply_timeseries(incoming_timeseries, fraction) else: timeseries = multiply_timeseries(outgoing_timeseries, fraction) if timeseries is None: continue assignment[pumping_station] = timeseries return assignment
def compute(self, start_date, end_date, level_control_timeseries, # pylint: disable=C0301, R0201 measured_timeseries): """Compute and return the sluice error time series. The sluice error on a specific day is defined as the sum of the (calculated) level control intakes and pumps values minus the sum of the measured (non level control) intakes and pumps values. This function returns the sluice error time series as a SparseTimeseriesStub. Parameters: * level_control_timeseries * list of calculated time series of the level control intakes and pumps * measured_timeseries * list of measured time series of the (non level control) intakes and pumps * start_date * first date for which to compute the sluice error * end_date * date after the last date for which to compute the sluice error """ sluice_error_timeseries = SparseTimeseriesStub() timeseries = level_control_timeseries + \ [multiply_timeseries(ts, -1.0) for ts in measured_timeseries] for date, value in add_timeseries(*timeseries).events(): # pylint: disable=C0301, W0142 if date < start_date: continue elif date < end_date: sluice_error_timeseries.add_value(date, value) else: break return sluice_error_timeseries
def get_impact_timeseries(self, start_date, end_date): """ Alleen fosfaat op dit moment""" if (self.outcome.has_key('impact') and self.outcome_info['impact']['start_date']==start_date and self.outcome_info['impact']['end_date']>=end_date): return self.outcome['impact'] else: logger.debug("Calculating impact (%s - %s)..." % ( start_date.strftime('%Y-%m-%d'), end_date.strftime('%Y-%m-%d'))) load, load_incremental = self.get_load_timeseries(start_date, end_date) impact = {} impact_incremental = {} factor = 1000.0 / float(self.configuration.open_water.surface) for key, timeserie in load.items(): impact_timeseries = multiply_timeseries(timeserie, factor) impact[key] = impact_timeseries for key, timeserie in load_incremental.items(): impact_timeseries = multiply_timeseries(timeserie, factor) impact_incremental[key] = impact_timeseries #store for later use (some kind of cache) self.outcome['impact'] = (impact, impact_incremental) self.outcome_info['impact'] = {} self.outcome_info['impact']['start_date'] = start_date self.outcome_info['impact']['end_date'] = end_date self.updated = True return impact, impact_incremental