<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def peak_generation(self, mode):
 """Calculates cumulative peak generation of generators connected to underlying grids This is done instantaneously using bottom-up approach. Parameters mode: str determines which generators are included:: 'MV': Only generation capacities of MV level are considered. 'MVLV': Generation capacities of MV and LV are considered (= cumulative generation capacities in entire MVGD). Returns ------- float Cumulative peak generation """


        if mode == 'MV':
            return sum([_.capacity for _ in self.grid.generators()])

        elif mode == 'MVLV':
            # calc MV geno capacities
            cum_mv_peak_generation = sum([_.capacity for _ in self.grid.generators()])
            # calc LV geno capacities
            cum_lv_peak_generation = 0
            for load_area in self.grid.grid_district.lv_load_areas():
                cum_lv_peak_generation += load_area.peak_generation

            return cum_mv_peak_generation + cum_lv_peak_generation

        else:
            raise ValueError('parameter \'mode\' is invalid!')