def get_period(start, end, peak, tsend):
    """Return the onset/decline period for a mhw.

    For onset if event starts on 1st day of timeseries, then:
       if peak on 1 st day of event, onset period -> 1 day
       else -> period=peak.
    In any other case period = peak + 0.5

    For decline if event ends on last day of timeseries, then:
       if peak on last day of event, onset period -> 1 day 
       else -> period=(end - start - peak).
    In any other case period = (end - start -peak) + 0.5
        
    Parameters
    ----------
    start: pandas Series
        Index of start of event along time axis
    end: pandas Series
        Index of end of event along time axis
    peak: pandas Series
        Index of peak of event respect the event itself
        -> index_peak - index_start
    tsend: int
        Index of last element of series

    Returns
    -------
    onset_period: pandas Series
        Period of onset of MHWs
    decline_period: pandas Series
        Period of decline of MHWs
    """

    esp = end - start - peak
    x = peak.where(peak != 0, 1)
    onset_period = x.where(start == 0, x + 0.5)
    y = esp.where(peak != tsend, 1)
    decline_period = y.where(end == tsend, y + 0.5)
    return onset_period, decline_period