<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
Step1:  Getting Started with the Apollo Passive Seismic Data Archive
Nunn, C., Nakamura, Y., Kedar, S., Panning, M.P., submitted to Planetary Science Journal. A New Archive of Apollo’s Lunar Seismic Data.
The data are archived with the following DOI
Step3:  Notice that the raw seismogram is 
Step5:  In the next section, we will make a correction for the timing divergence. Taking the approximate onset time of the event, (1973-03-13T07
Step6:  It can be seen from the previous image the extent of the timing divergence. It many situations it may be necessary to do more than just correct the start times, but instead to reinterpolate the data. 
The real onset time will also be affected by the divergence between the sampling time and the timestamp.
<ASSISTANT_TASK:>
Python Code:
%pylab inline
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
from future.builtins import *  # NOQA
from datetime import timedelta
from obspy.core import read
from obspy.core.utcdatetime import UTCDateTime
from obspy.core.inventory import read_inventory
import numpy as np
from obspy.clients.fdsn.client import Client
import pdart.auth as auth
from pdart.util import linear_interpolation, timing_correction
from pdart.extra_plots.plot_timing_divergence import plot_timing
import matplotlib  
from matplotlib import pyplot as plt
plt.style.use('ggplot')
plt.rcParams['figure.figsize'] = 10, 4
plt.rcParams['lines.linewidth'] = 0.5
plt.rcParams['font.size'] = 12
SECONDS_PER_DAY=3600.*24
def raw_seismogram():
    View a raw seismogram.
    
    user=auth.user
    auth_password=auth.auth_password
    
    if user == '' or auth_password == '':
        print('Set user and auth_password in auth.py')
        return
    
    starttime= UTCDateTime('1973-03-13T07:30:00.0')
    endtime = UTCDateTime('1973-03-13T09:30:00.0')
    network='XA'
    station='S14'
    channel='MH1'
    location='*'
    client = Client("IRIS",user=user,password=auth_password)
    print(client)
    
    stream = client.get_waveforms(network=network, station=station, channel=channel, location=location, starttime=starttime, endtime=endtime)
    stream.plot(equal_scale=False,size=(1000,600),method='full')
    
raw_seismogram()
Explanation: Getting Started with the Apollo Passive Seismic Data Archive
Nunn, C., Nakamura, Y., Kedar, S., Panning, M.P., submitted to Planetary Science Journal. A New Archive of Apollo’s Lunar Seismic Data.
The data are archived with the following DOI: https://doi.org/10.7914/SN/XA_1969.
1) Connecting to IRIS and viewing a raw seismogram
2) Plotting a seismogram with the instrument response removed
3) Viewing the instrument response for a peaked mid-period seismogram.
4) Viewing the timing divergence 
5) Correcting for the timing divergence
End of explanation
# import pandas as pd
# series = pd.Series()
# print(series)
def view_Apollo(stream=None,starttime= UTCDateTime('1973-03-13T07:30:00.0'),endtime = UTCDateTime('1973-03-13T09:30:00.0'),
  network='XA',station='S14',channel='MH1',location='*',plot_seismogram=True,plot_response=False):
    Snippet to read in raw seismogram and remove the instrument response for Apollo.
    
    
    
    user=auth.user
    auth_password=auth.auth_password
    if user == '' or auth_password == '':
        print('Set user and auth_password in auth.py')
        return
    
    client = Client("IRIS",user=user,password=auth_password)
    # get the response file (wildcards allowed)
    inv = client.get_stations(starttime=starttime, endtime=endtime,
        network=network, sta=station, loc=location, channel=channel,
        level="response")
    if stream is None:
        stream = client.get_waveforms(network=network, station=station, channel=channel, location=location, starttime=starttime, endtime=endtime)
    else:
        stream.trim(starttime=starttime,endtime=endtime)
        
    
    for tr in stream:
        # interpolate across the gaps of one sample 
        linear_interpolation(tr,interpolation_limit=1)
    stream.merge()
    
    for tr in stream:
        # optionally interpolate across any gap 
        # for removing the instrument response from a seimogram, 
        # it is useful to get a mask, then interpolate across the gaps, 
        # then mask the trace again. 
        if tr.stats.channel in ['MH1', 'MH2', 'MHZ']:
            # add linear interpolation but keep the original mask
            original_mask = linear_interpolation(tr,interpolation_limit=None)
            # remove the instrument response
            pre_filt = [0.1,0.3,0.9,1.1]
            tr.remove_response(inventory=inv, pre_filt=pre_filt, output="DISP",
                       water_level=None, plot=plot_response)
            if plot_response:
                plt.show()
            # apply the mask back to the trace 
            tr.data = np.ma.masked_array(tr, mask=original_mask)
        elif tr.stats.channel in ['SHZ']:
            # add linear interpolation but keep the original mask
            original_mask = linear_interpolation(tr,interpolation_limit=None)
            # remove the instrument response
            pre_filt = [1,2,11,13] 
            tr.remove_response(inventory=inv, pre_filt=pre_filt, output="DISP",
                       water_level=None, plot=plot_response)
            if plot_response:
                plt.show()
            
            # apply the mask back to the trace 
            tr.data = np.ma.masked_array(tr, mask=original_mask)
    if plot_seismogram:
        stream.plot(equal_scale=False,size=(1000,600),method='full')
    
view_Apollo()
view_Apollo(plot_seismogram=False,plot_response=True)
def view_timing_divergence(starttime= UTCDateTime('1973-06-30T00:00:00.00000Z'),
  endtime = UTCDateTime('1973-07-01T00:00:00.00000Z'),network='XA',
  station='*',channel='ATT',location='*'):
    
    user=auth.user
    auth_password=auth.auth_password
    if user == '' or auth_password == '':
        print('Set user and auth_password in auth.py')
        return
    client = Client("IRIS",user=user,password=auth_password)
    stream = client.get_waveforms(network=network, station=station, channel=channel, location=location, starttime=starttime, endtime=endtime)
    plot_timing(stream=stream, start_time=starttime,end_time=endtime,save_fig=False)
view_timing_divergence()
Explanation: Notice that the raw seismogram is :
1) In digital units
2) That the gaps in the trace are replaced by -1. This is for performance reasons, especially for the short-period channel SHZ. 
Now we we plot the seismogram with the -1 values replaced. 
If there is only one missing value, we ask for it to be interpolated. But if there are more than one missing value, we
we mark it as a gap on the trace. 
The missing data must be dealt with before removing the instrument response.
End of explanation
   starttime= UTCDateTime('1973-03-13T07:30:00.0')
def get_traces():
    Get the traces
    
    user=auth.user
    auth_password=auth.auth_password
    
    if user == '' or auth_password == '':
        print('Set user and auth_password in auth.py')
        return
    
    starttime= UTCDateTime('1973-03-13T00:00:00.0')
    endtime = UTCDateTime('1973-03-14T00:00:00.0')
    network='XA'
    station='*'
    channel='*'
    location='*'
    client = Client("IRIS",user=user,password=auth_password)
    print(client)
    
    stream = client.get_waveforms(network=network, station=station, channel=channel, location=location, starttime=starttime, endtime=endtime)
    return stream
    
    
stream_before = get_traces()
print(stream_before)
# plot the timing divergence before correction
plot_timing(stream=stream_before, start_time=UTCDateTime('1973-03-13T00:00:00.0'),end_time=UTCDateTime('1973-03-13T12:00:00.0'),save_fig=False)
    
stream_after = stream_before.copy()
correction_time=UTCDateTime('1973-03-13T08:02:00.0')
timing_correction(stream_after,correction_time=correction_time)
# timing divergence after correction
plot_timing(stream=stream_after, start_time=UTCDateTime('1973-03-13T00:00:00.0'),end_time=UTCDateTime('1973-03-13T12:00:00.0'),save_fig=False)
Explanation: In the next section, we will make a correction for the timing divergence. Taking the approximate onset time of the event, (1973-03-13T07:30:00.0), we will shift the timings slightly. This will be useful when comparing the onset times.
End of explanation
print('End of Notebook')
Explanation: It can be seen from the previous image the extent of the timing divergence. It many situations it may be necessary to do more than just correct the start times, but instead to reinterpolate the data. 
The real onset time will also be affected by the divergence between the sampling time and the timestamp.
End of explanation
<END_TASK>