<jupyter_start><jupyter_text>Some constant values<jupyter_code># Boltzman constant
k = 1.38e-23
# L-band receptors
receptor_serial={
'm062':{'band':'l', 'serial':4001},
'm063':{'band':'l', 'serial':4002},
'm031':{'band':'l', 'serial':4005},
'm034':{'band':'l', 'serial':4010},
'm024':{'band':'l', 'serial':4},
'm025':{'band':'l', 'serial':4003}}
# Name of directory containing noise diode model files
nd_models ='/var/kat/katconfig/user/noise-diode-models/mkat'<jupyter_output><empty_output><jupyter_text>Read observation file<jupyter_code>filename='/var/kat/archive/data/MeerKATAR1/telescope_products/2016/03/17/1458200956.h5'   # 20160317-0030
try:
    h5 = katdal.open(filename, quicklook=True)
except Exception as err_msg: raise SystemExit('An error as occured:\n%s' % err_msg)<jupyter_output><empty_output><jupyter_text>Using the noise models from EMSS calculationsApproximate Tsys $\approx$ Tant<jupyter_code>def modelTcal(noisefile, verbose=False):
    ##Read data from file
    fin = open(noisefile, 'r')
    # Read and ignore header line
    fin.readline()
    fin.readline()
    # Read model data [freq Hz, Te K]
    nd_freqs = []
    nd_temps = []
    for line in fin.readlines():
        try:
            noisemodel= numpy.array(line.strip().split(','), dtype=float)
        except: print line.strip()
        nd_freqs.append(noisemodel[0])
        nd_temps.append(noisemodel[1])
    fin.close()
    nd_freqs = numpy.array(nd_freqs)
    nd_temps = numpy.array(nd_temps)

    coefficients  = numpy.polyfit(nd_freqs, nd_temps, 1)
    polynomial    = numpy.poly1d(coefficients)
    Tcal_passband = numpy.array(polynomial(passband))

    return [nd_freqs, nd_temps, Tcal_passband]<jupyter_output><empty_output><jupyter_text>Display data<jupyter_code>h5.select()
target = h5.catalogue.targets[0].name
print "GPS observation: %s" % target
passband = h5.channel_freqs
ants = h5.ants

for ant_idx in range(len(ants)):
    ant = ants[ant_idx]
    print 'Observation data for antenna %s' % ant.name
    
    # approximate Tsys using Tant values from model files
    nd_file='rx.l.%d.h.csv'%receptor_serial[ant.name]['serial']
    [nd_freqs, nd_temps, Tcal_passband] = modelTcal(os.path.join(nd_models,nd_file))
    Tsys = numpy.mean(nd_temps)

    
    Ssys = 10.*numpy.log10(k*Tsys) + 30 # dBm/Hz
    print "Expected power spectral density of the system noise floor %.2d [dBm/Hz]" % Ssys
    
    h5.select()
    h5.select(ants=ant.name,corrprods='auto',scans='scan')
    scan_indices = h5.scan_indices
    
    for idx in range(len(scan_indices)):
        h5.select(scans=scan_indices[idx])
        d = scape.DataSet(h5, baseline="%s" % (ant.name,))
        if not d is None:
            d = d.select(flagkeep='~nd_on')
        data = d.scans[0].data[:,:,0]

        # power calibration scale factor
        buff_chan = len(passband)/10
        bp_floor =  (10*numpy.log10(numpy.median(numpy.abs(data), axis=0)))[buff_chan:-buff_chan].mean()
        delta_P = bp_floor - Ssys
        
        plt.figure(2*ant_idx,figsize = (15,5))
        plt.plot(passband/1e6, 10*numpy.log10(numpy.median(numpy.abs(data), axis=0))-delta_P, label='Scan %d'%idx)       
        plt.axis('tight')
        plt.xlabel('Feq [MHz]')
        plt.ylabel('Power [dBm/ch]')
        plt.title('Observation Spectrum %s'%ant.name)
        plt.legend(loc=0)
        plt.figure(2*ant_idx+1,figsize = (15,5))
        plt.subplot(1,3,idx+1)
        plt.plot(10*numpy.log10(numpy.median(numpy.abs(data), axis=1)))
        plt.axis('tight')
        plt.xlabel('Scans [#]')
        plt.ylabel('Power [arb dBm]')
        plt.title('Observation Scans %d'%idx)
        plt.subplots_adjust(wspace=None, hspace=None)<jupyter_output>WARNING:scape.kathdf5:Cannot find coupler noise diode H polarisation model for antenna m063 - using default.
WARNING:scape.kathdf5:Cannot find coupler noise diode V polarisation model for antenna m063 - using default.
WARNING:katdal.sensordata:Last data point for sensor 'Antennas/m063/pos_actual_scan_azim' arrives 0.364999 seconds before end of data set - extrapolation may lead to ridiculous values
WARNING:katdal.sensordata:Last data point for sensor 'Antennas/m063/pos_actual_scan_elev' arrives 0.114999 seconds before end of data set - extrapolation may lead to ridiculous values
WARNING:scape.kathdf5:Cannot find coupler noise diode H polarisation model for antenna m063 - using default.
WARNING:scape.kathdf5:Cannot find coupler noise diode V polarisation model for antenna m063 - using default.
WARNING:scape.kathdf5:Cannot find coupler noise diode H polarisation model for antenna m063 - using default.
WARNING:scape.kathdf5:Cannot find coupler noise diode V polarisation model for antenna [...]
{'fraction_non_alphanumeric': 0.13316315677515422, 'fraction_numerical': 0.036800680706232713, 'mean_word_length': 4.018143009605123, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '537905', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1796, 'n_tokens_neox': 1643, 'n_words': 349, 'path': 'AR1/gps_tests/jupyter_analysis/GPS Three Scan Analysis.ipynb', 'repo_name': 'ska-sa/katsdpscripts', 'size': '4701'}