In [10]:
import h5py
import matplotlib.pylab as plt
from modest_image import imshow
%matplotlib inline

In [50]:
h5_fname = '/Volumes/wjlee_apl_2/2015_0901-10_80m.h5'

In [51]:
f=h5py.File(h5_fname,"r")

In [48]:
fig,ax = plt.subplots(1, sharex=True, sharey=True)
imshow(ax,f['Sv'][1,:,:],aspect='auto',vmax=-34,vmin=-80,interpolation='none')
ax.set_xlabel('time (UTC)')
ax.set_xticks(xticks)
ax.set_xticklabels(xticklabels, rotation=45, horizontalalignment='center')
ax.set_xlim(0, time_length)


Out[48]:
(0, 287203)

In [24]:
%matplotlib qt4


Warning: Cannot change to a different GUI toolkit: qt4. Using notebook instead.

In [62]:
import re,os

In [61]:
os.path.join


Out[61]:
['', '']

In [75]:
def plot_Sv(h5_fname,save_path):

    f = h5py.File(h5_fname,"r")

    # Get time stamp
    time_format = '%Y-%m-%d\n%H:%M:%S'
    time_length = f['data_times'].size
    # X axis label
    # subset the xticks so that we don't plot every one
    xticks = np.linspace(0, time_length, 11)
    xstep = int(round(xticks[1]))
    # format trans_array_time array so that it can be used to label the x-axis
    xticklabels = [i for i in num2date(f['data_times'][::xstep])] + [num2date(f['data_times'][-1])]
    xticklabels = [i.strftime(time_format) for i in xticklabels]

    # Plot figure
    print 'plotting figure...'
    fig, ax = plt.subplots(3, sharex=True)
    for ff in range(f['Sv'].shape[0]):
        imshow(ax[ff],f['Sv'][ff,:,:],aspect='auto',vmax=-34,vmin=-80,interpolation='none')
    ax[-1].set_xlabel('time (UTC)')
    ax[-1].set_xticks(xticks)
    ax[-1].set_xticklabels(xticklabels, rotation=45, horizontalalignment='center')
    #ax[-1].set_xlim(0, time_length)
    fig.set_figwidth(12)
    fig.set_figheight(10)

    # Save figure
    save_fname = os.path.join(save_path,h5_fname+'.png')
    print 'saving figure...'
    fig.savefig(filename)
    plt.close(fig)

In [76]:
save_path='/Volumes/wjlee_apl_2/'

In [77]:
plot_Sv(h5_fname,save_path)


plotting figure...
saving figure...
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-77-f1b954e47988> in <module>()
----> 1 plot_Sv(h5_fname,save_path)

<ipython-input-75-be88dbe27ee8> in plot_Sv(h5_fname, save_path)
     29     save_fname = os.path.join(save_path,h5_fname+'.png')
     30     print 'saving figure...'
---> 31     fig.savefig(filename)
     32     plt.close(fig)

NameError: global name 'filename' is not defined

In [ ]:


In [ ]:


In [30]:
from datetime import datetime
from matplotlib.dates import date2num, num2date
import numpy as np

In [40]:
time_format = '%Y-%m-%d\n%H:%M:%S'
        time_length = f['data_times'].size
        # X axis label
        # subset the xticks so that we don't plot every one
        xticks = np.linspace(0, time_length, 10)
        xstep = int(round(xticks[1]))
        # format trans_array_time array so that it can be used to label the x-axis
        xticklabels = [i for i in num2date(f['data_times'][::xstep])] + [num2date(f['data_times'][-1])]
        xticklabels = [i.strftime(time_format) for i in xticklabels]

In [41]:
xticklabels


Out[41]:
['2015-09-01\n00:00:00',
 '2015-09-02\n02:13:19',
 '2015-09-03\n05:06:31',
 '2015-09-04\n07:19:43',
 '2015-09-05\n10:12:59',
 '2015-09-06\n13:06:15',
 '2015-09-07\n15:19:31',
 '2015-09-08\n18:12:58',
 '2015-09-09\n21:06:23',
 '2015-09-10\n23:19:56',
 '2015-09-10\n23:19:59']

In [42]:
xticks


Out[42]:
array([      0.        ,   31911.44444444,   63822.88888889,
         95734.33333333,  127645.77777778,  159557.22222222,
        191468.66666667,  223380.11111111,  255291.55555556,  287203.        ])

In [ ]: