In [1]:
%matplotlib inline
In [17]:
from __future__ import print_function
import cPickle
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import peakTree
def lin2z(array):
return 10*np.log10(array)
def z2lin(array):
return 10**(array/10.)
peaks2vel = lambda vel, peaks: [(vel[peak[0]], vel[peak[1]]) for peak in peaks]
vel2str = lambda vel : ['({:4.2f} {:4.2f})'.format(*pair) for pair in vel]
lst2str = lambda lst : ['{:4.2f}'.format(e) for e in lst]
In [18]:
fname = 'example_spectra/mira_1438448249.0_4806.3.pickle'
with open(fname, 'rb') as f:
pixel = cPickle.load(f)
print(pixel.keys())
print(pixel['zspectrum'].min())
#pixel['noise_thres'] = pixel['zspectrum'].min()
pixel['noise_thres'] = z2lin(-53)
In [13]:
def plot(pixel, peaks, thresholds):
fig, ax = plt.subplots(1, figsize=(8.0, 4.5))
ax.axhline(lin2z(pixel['noise_thres']), color='gray', lw=1)
for thres in thresholds:
ax.axhline(thres, color='gray', lw=1)
ax.step(pixel['vel_list'], lin2z(pixel['zspectrum']),
':', color='red', label='cloud radar', where='mid', linewidth=1.3)
ax.step(pixel['vel_list'], lin2z(pixel['zcrossspectrum']),
':', color='firebrick', where='mid', linewidth=1.3)
ax.axvline(pixel['est_meanvel'], ls='dashed',
color='red', linewidth=1.1, label='original peak finder')
for peak in peaks:
# print('plotting peak ', peak)
ax.axvline(pixel['vel_list'][peak[0]], color='slategrey')
ax.axvline(pixel['vel_list'][peak[1]], color='slategrey')
ax.set_ylabel("Spectral Reflectivity [dBZ]", fontweight='semibold')
ax.set_xlabel("Velocity [m s$\\mathregular{^{-1}}$]", fontweight='semibold')
#ax.set_xlim([-7.5, 7.5])
ax.set_xlim([-6, 2])
#ax.set_ylim(bottom=-50)
ax.set_ylim(bottom=-70, top=0)
ax.tick_params(axis='both', which='major', labelsize=14,
width=2, length=4)
ax.tick_params(axis='both', which='minor', width=1.4, length=3)
ax.xaxis.set_major_locator(matplotlib.ticker.MultipleLocator(1))
ax.xaxis.set_minor_locator(matplotlib.ticker.MultipleLocator(0.5))
ax.legend(fontsize=11, numpoints=1, ncol=1)
ax.set_title("Spectrum at " + str(pixel['sel_timestamp']) +
" " + '{0:4d}m'.format(int(pixel['sel_height'])), fontweight='semibold', fontsize=13)
plt.tight_layout()
savename = str(pixel['sel_timestamp']) + "_" \
+ '{0:04d}'.format(int(pixel['sel_height'])) + "m_combined_spectra.png"
fig.savefig('example_spectra/' + savename, dpi=250)
In [20]:
peaks, ptpeak, threslist = peakTree.detect_peak_recursive(pixel['zspectrum'], pixel['noise_thres'], lambda thres: thres*1.5)
thres_list = [lin2z(thres) for thres in threslist]
print('threshold list ', ", ".join(lst2str(thres_list)))
plot(pixel, peaks, thres_list)
print('boundaries of the peaks [m/s]', ", ".join(vel2str(peaks2vel(pixel['vel_list'], peaks))))
In [ ]: