Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Returns
-------
out : dict
- "gross_savings": Total cumulative savings over reporting period.
"""
consumption_periods = consumption_data_reporting.periods()
consumption_reporting = consumption_data_reporting.to(energy_unit_str)[:-1]
observed_daily_temps = weather_source.daily_temperatures(
consumption_periods, self.temperature_unit_str)
consumption_estimates_baseline = self.model.transform( observed_daily_temps, model_params_baseline)
consumption_estimates_baseline *= np.array([p.timedelta.days for p in consumption_periods])
gross_savings = np.nansum(consumption_estimates_baseline -
consumption_reporting)
return {"gross_savings": gross_savings}
class AnnualizedGrossSavingsMeter(MeterBase):
"""Annualized gross savings accumulated since the completion of a retrofit
calculated by multiplying an annualized savings estimate by the number
of years since retrofit completion.
Parameters
----------
model : eemeter.model.AverageDailyTemperatureSensitivityModel
Model of energy usage
temperature_unit_str : str
Unit of temperature, usually "degC" or "degF".
"""
def __init__(self, model, temperature_unit_str, **kwargs):
super(AnnualizedGrossSavingsMeter,self).__init__(**kwargs)
self.model = model
self.temperature_unit_str = temperature_unit_str
"""Evaluates a ConsumptionHistory instance to determine the number of
unique days covered by consumption periods
Parameters
----------
consumption_data : eemeter.consumption.ConsumptionData
Target of time span analysis
Returns
-------
out : dict
- "time_span": the number of days covered by the consumption data.
"""
return { "time_span": consumption_data.total_days() }
class TotalHDDMeter(MeterBase):
"""Sums the total heating degree days observed over the course of a
ConsumptionHistory instance
Parameters
----------
base : int or float
The heating degree day base.
temperature_unit_str : {"degF", "degC"}
A string denoting the temperature unit to be used.
"""
def __init__(self,base,temperature_unit_str,**kwargs):
super(TotalHDDMeter,self).__init__(**kwargs)
self.base = base
self.temperature_unit_str = temperature_unit_str
def evaluate_raw(self, consumption_data, weather_source, **kwargs):
geographically and climatically similar to project as possible.
Returns
-------
out : dict
- "annualized_usage": annualized usage given temperature
sensitivity parameters and weather normals.
"""
daily_temps = weather_normal_source.annual_daily_temperatures(
self.temperature_unit_str)
average_daily_usage_estimate = self.model.transform(daily_temps, model_params)
annualized_usage = average_daily_usage_estimate * 365
return {"annualized_usage": annualized_usage}
class GrossSavingsMeter(MeterBase):
"""Calculates savings due to an efficiency retrofit or ECM for a particular
fuel type using a conterfactual usage estimate and actual usage.
Parameters
----------
model : eemeter.model.AverageDailyTemperatureSensitivityModel
Model of energy usage
temperature_unit_str : str
Unit of temperature, usually "degC" or "degF".
"""
def __init__(self, model, temperature_unit_str,
**kwargs):
super(GrossSavingsMeter, self).__init__(**kwargs)
self.model = model
self.temperature_unit_str = temperature_unit_str
for k,v in meter_result.items():
if k in result:
message = "unexpected repeated metric ({}) in {}. " \
"A different input_mapping or " \
"output_mapping may fix this overlap.".format(k,meter)
raise ValueError(message)
result[k] = v
return result
def _get_child_inputs(self):
inputs = []
for meter in self.sequence:
inputs.append(meter.get_inputs())
return inputs
class Condition(MeterBase):
"""Collects and returns a series of meter object evaluation outputs in
sequence, making the outputs of each meter available to those that
follow.
Parameters
----------
condition_parameter : str
The name of the parameter which contains a boolean on which to
condition.
success : eemeter.meter.MeterBase, optional
The meter to execute if the condition is True.
failure : eemeter.meter.MeterBase, optional
The meter to execute if the condition is False.
"""
def __init__(self,condition_parameter,success=None,failure=None,**kwargs):
Returns
-------
out : dict
A dictionary with a single key, 'output', which has the value of
the boolean result.
"""
output = True
for inpt in self.inputs:
boolean = kwargs.get(inpt)
if boolean is None:
message = "could not find input '{}'".format(inpt)
raise ValueError(message)
output = output and boolean
return {"output": output}
class Or(MeterBase):
"""Performs an OR operation on input parameters and returns the result.
Parameters
----------
inputs : array_like
Must contain the names of boolean parameters at least one of which must
be True in order for the output to be true.
"""
def __init__(self,inputs,**kwargs):
super(Or,self).__init__(**kwargs)
if len(inputs) == 0:
message = "requires at least one input."
raise ValueError(message)
self.inputs = inputs
def evaluate_mapped_inputs(self,**kwargs):
return {"consumption_data_no_estimated": cd_no_est}
class Debug(MeterBase):
def evaluate_raw(self,**kwargs):
"""Helpful for debugging meter instances - prints out kwargs for
inspection.
Returns
-------
out : {}
"""
print("DEBUG")
pprint(kwargs)
return {}
class DummyMeter(MeterBase):
def evaluate_raw(self, value, **kwargs):
"""Helpful for testing meters or creating simple pass through meters.
Parameters
----------
value : object
Value to return
Returns
-------
out : dict
Value stored on key "result".
"""
result = {"result": value}
return result
from .base import MeterBase
from eemeter.consumption import ConsumptionData
from datetime import datetime
from datetime import timedelta
from eemeter.evaluation import Period
import pytz
from itertools import chain
import numpy as np
import pandas as pd
class TemperatureSensitivityParameterOptimizationMeter(MeterBase):
"""Optimizes temperature senstivity parameter choices.
Parameters
----------
temperature_unit_str : str
Unit of temperature, usually "degC" or "degF".
model : eemeter.model.TemperatureSensitivityModel
Model of energy usage for which to optimize parameter choices.
"""
def __init__(self, temperature_unit_str, model, **kwargs):
super(TemperatureSensitivityParameterOptimizationMeter,
self).__init__(**kwargs)
self.temperature_unit_str = temperature_unit_str
self.model = model
def __init__(self,sequence,**kwargs):
super(Sequence,self).__init__(**kwargs)
assert all([issubclass(meter.__class__,MeterBase)
for meter in sequence])
self.sequence = sequence
- "other_periods": list of eemeter.evaluation.Period objects
- "weather_source": eemeter.weather.GSODWeatherSource
- "weather_normal_source": eemeter.weather.TMY3WeatherSource
"""
attributes = {
"location": project.location,
"consumption": project.consumption,
"baseline_period": project.baseline_period,
"reporting_period": project.reporting_period,
"other_periods": project.other_periods,
"weather_source": project.weather_source,
"weather_normal_source": project.weather_normal_source,
}
return attributes
class ProjectConsumptionDataBaselineReporting(MeterBase):
""" Splits project consumption data by period and fuel.
"""
def evaluate_raw(self, project, **kwargs):
""" Creates a list of tagged ConsumptionData objects for each of this
project's fuel types in the baseline period and the reporting period.
Parameters
----------
project : eemeter.project.Project
Project instance from which to get consumption data.
Returns
-------
out : dict
- "consumption": list of tagged ConsumptionData instances.
Returns
-------
out : dict
Collected outputs from either the success or the failure meter.
"""
if data_collection.get_data(**self.condition).value:
meter = self.success
else:
meter = self.failure
if meter is None:
return DataCollection()
else:
return meter.evaluate(data_collection)
class Switch(MeterBase):
"""Switches between cases of values of a particular parameter.
Parameters
----------
target : dict
The search criteria for a parameter on which to switch.
Example::
{
"name": "input1",
"tags": ["tag1", "tag2"]
}
cases : dict
A dictionary of meters to execute depending on the value of the target