Get sectoral peak load
481926
def peak_load(self):
        
        peak_load = pd.Series(self.consumption).mul(pd.Series(
            self.grid.network.config['peakload_consumption_ratio']).astype(
            float), fill_value=0)

        return peak_load
1187666
def getcoef(self):
        """"""

        global mp_Z_Y1
        return np.swapaxes(mp_Z_Y1, 0, self.xstep.cri.axisK+1)[0]
135878
def _onCoreModuleLoad(self, event):
        '''
        
        '''
        if not self._modelRuntsByBuid:
            return
        # Discard previously cached data. It will be computed upon the next
        # lift that needs it.
        self._modelRuntsByBuid = {}
        self._modelRuntsByPropValu = collections.defaultdict(list)
1022972
def calc_signal_power(params, fname, transient=200, Df=None, mlab=True, NFFT=1000,
                      noverlap=0, window=plt.mlab.window_hanning):
    '''
    

    '''


    if type(fname) is str and os.path.isfile(fname):
        #open file
        f = h5py.File(fname)
        data = f['data'].value
        srate = f['srate'].value 
        tvec = np.arange(data.shape[1]) * 1000. / srate
        f.close()
    elif type(fname) is np.ndarray:
        data = fname
        srate = 1000.
        tvec = np.arange(data.shape[1]) * 1000. / srate
    else:
        raise Exception, '{} not a file or array'.format(fname)
    
    # slice
    slica = (tvec >= transient)
    data = data[:,slica]

    # subtract mean
    dataT = data.T - data.mean(axis=1)
    data = dataT.T
    
    #extract PSD
    PSD=[]
    for i in np.arange(len(params.electrodeParams['z'])):
        if mlab:
            Pxx, freqs=plt.mlab.psd(data[i], NFFT=NFFT,
                                    Fs=srate, noverlap=noverlap, window=window)
        else:
            [freqs, Pxx] = helpers.powerspec([data[i,]], tbin= 1.,
                                        Df=Df, pointProcess=False)
            mask = np.where(freqs >= 0.)
            freqs = freqs[mask]
            Pxx = Pxx.flatten()
            Pxx = Pxx[mask]
            Pxx = Pxx/tvec[tvec >= transient].size**2
        PSD +=[Pxx.flatten()]
        
    PSD=np.array(PSD)

    return freqs, PSD
9367
def RMS_energy(frames):
    """"""
    f = frames.flatten()
    return N.sqrt(N.mean(f * f))
1038257
def get_elapsed(self, restart=True):
        '''
        
        '''
        end = time.time()
        span = end - self.__start
        if restart:
            self.__start = end
        return span
1227338
def example_stats(filename):
    

    nd = results.load_nd_from_pickle(filename=filename)

    nodes_df, edges_df = nd.to_dataframe()

    # get statistical numbers about grid
    stats = results.calculate_mvgd_stats(nd)

    # plot distribution of load/generation of subjacent LV grids
    stations = nodes_df[nodes_df['type'] == 'LV Station']
    f, axarr = plt.subplots(2, sharex=True)
    f.suptitle("Peak load (top) / peak generation capacity (bottom) at LV "
               "substations in kW")
    stations['peak_load'].hist(bins=20, alpha=0.5, ax=axarr[0])
    axarr[0].set_title("Peak load in kW")
    stations['generation_capacity'].hist(bins=20, alpha=0.5, ax=axarr[1])
    axarr[1].set_title("Peak generation capacity in kW")
    plt.show()

    # Introduction of report
    print("You are analyzing MV grid district {mvgd}\n".format(
        mvgd=int(stats.index.values)))

    # print all the calculated stats
    # this isn't a particularly beautiful format but it is
    # information rich
    with option_context('display.max_rows', None,
                        'display.max_columns', None,
                        'display.max_colwidth', -1):
        print(stats.T)
654433
def add_aggregated_peak_demand(self):
        """"""
        peak_load_aggregated = 0
        for lv_load_area in self.lv_load_areas():
            if lv_load_area.is_aggregated:
                peak_load_aggregated += lv_load_area.peak_load
        self.peak_load_aggregated = peak_load_aggregated
1029880
def monthly_wind_dirs(self):
        """"""
        mwd = zip(*self._monthly_wind_dirs)
        return [self._wind_dirs[mon.index(max(mon))] for mon in mwd]
1109536
def add_peak_demand(self):
        
        peak_load = peak_load_satellites = 0
        for lv_load_area in self.lv_load_areas():
            peak_load += lv_load_area.peak_load
            if lv_load_area.is_satellite:
                peak_load_satellites += lv_load_area.peak_load
        self.peak_load = peak_load
        self.peak_load_satellites = peak_load_satellites
287159
def usage_report(node)
      period_start = node.at('period_start')
      period_end = node.at('period_end')

      { :metric        => node['metric'].to_s.strip,
        :period        => node['period'].to_s.strip.to_sym,
        :period_start  => period_start ? period_start.content : '',
        :period_end    => period_end ? period_end.content : '',
        :current_value => node.at('current_value').content.to_i,
        :max_value     => node.at('max_value').content.to_i }
    end
839522
def get_consumption(self):
        """"""
        self.get_status()
        try:
            self.consumption = self.data['power']
        except TypeError:
            self.consumption = 0

        return self.consumption
177481
def current_sleep_breakdown(self):
        """"""
        try:
            stages = self.intervals[0]['stages']
            breakdown = {'awake': 0, 'light': 0, 'deep': 0, 'rem': 0}
            for stage in stages:
                if stage['stage'] == 'awake':
                    breakdown['awake'] += stage['duration']
                elif stage['stage'] == 'light':
                    breakdown['light'] += stage['duration']
                elif stage['stage'] == 'deep':
                    breakdown['deep'] += stage['duration']
                elif stage['stage'] == 'rem':
                    breakdown['rem'] += stage['duration']
        except KeyError:
            breakdown = None
        return breakdown
422222
def active_power(self):
        
        inst = self.load_instantaneous()
        values = [float(i['value']) for i in inst if i['key'].endswith('ActivePower')]
        return sum(values) / 1000
645583
function get_sector_list(sectors, start, fat_addrs, ssz, chkd) {
	var buf = [], buf_chain = [];
	if(!chkd) chkd = [];
	var modulus = ssz - 1, j = 0, jj = 0;
	for(j=start; j>=0;) {
		chkd[j] = true;
		buf[buf.length] = j;
		buf_chain.push(sectors[j]);
		var addr = fat_addrs[Math.floor(j*4/ssz)];
		jj = ((j*4) & modulus);
		if(ssz < 4 + jj) throw new Error("FAT boundary crossed: " + j + " 4 "+ssz);
		if(!sectors[addr]) break;
		j = __readInt32LE(sectors[addr], jj);
	}
	return {nodes: buf, data:__toBuffer([buf_chain])};
}
718431
def ramp_limits(network):
    
    carrier = ['coal', 'biomass', 'gas', 'oil', 'waste', 'lignite',
                       'uranium', 'geothermal']
    data = {'start_up_cost':[77, 57, 42, 57, 57, 77, 50, 57], #€/MW
            'start_up_fuel':[4.3, 2.8, 1.45, 2.8, 2.8, 4.3, 16.7, 2.8], #MWh/MW
            'min_up_time':[5, 2, 3, 2, 2, 5, 12, 2], 
            'min_down_time':[7, 2, 2, 2, 2, 7, 17, 2], 
# =============================================================================
#             'ramp_limit_start_up':[0.4, 0.4, 0.4, 0.4, 0.4, 0.6, 0.5, 0.4], 
#             'ramp_limit_shut_down':[0.4, 0.4, 0.4, 0.4, 0.4, 0.6, 0.5, 0.4] 
# =============================================================================
            'p_min_pu':[0.33, 0.38, 0.4, 0.38, 0.38, 0.5, 0.45, 0.38]
            }
    df = pd.DataFrame(data, index=carrier)
    fuel_costs = network.generators.marginal_cost.groupby(
            network.generators.carrier).mean()[carrier]
    df['start_up_fuel'] = df['start_up_fuel'] * fuel_costs
    df['start_up_cost'] = df['start_up_cost'] + df['start_up_fuel']
    df.drop('start_up_fuel', axis=1, inplace=True)
    for tech in df.index:
        for limit in df.columns:
            network.generators.loc[network.generators.carrier == tech, 
                                   limit] = df.loc[tech, limit]
    network.generators.start_up_cost = network.generators.start_up_cost\
                                        *network.generators.p_nom
    network.generators.committable = True
988585
def getChargeTimeElapsed(self):
    """"""
    command = '$GS'
    status = self.sendCommand(command)
    if int(status[1]) == 3:
      return int(status[2])
    else:
      return 0