utils.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:faampy 作者: ncasuk 项目源码 文件源码
def get_mpl_time(ds, *freq):
    """Return a float wihich is usabale for plt.plot_date from matplotlib.

    :param ds: core_faam dataset
    :type param: netCDF4.Dataset
    :param freq: frequency of the time stamp default=1; if freq > 1 a multidimensional array is returned
    :return: array containing the matplotlib timestamps
    :rtype: numpy.array

    >>> ds = netCDF4.Dataset('core_faam_20130403_v004_r0_b768.nc', 'r')
    >>> t_1hz = get_mpl_time(ds)
    >>> t_1hz.shape
    Out[1]: (37137,)
    >>> t_32hz = get_mpl_time(ds, 32)
    >>> t_32hz.shape
    Out[1]: (37137, 32)
    >>> plot_date(t_32hz.ravel(), ds.variables['U_C'][:].ravel(), 'b-')
    >>>

    """
    if 'Time' in ds.variables.keys():
        vtime=ds.variables['Time'][:]
    elif 'time' in ds.variables.keys():      
        vtime=ds.variables['time'][:]
    elif 'TIME' in ds.variables.keys():
        vtime=ds.variables['TIME'][:]
    #in old core files the 'Time' variable was c2alled PARA0515
    elif 'PARA0515' in ds.variables.keys():
        vtime=ds.variables['PARA0515'][:]
    else:
        return None
    vtime=np.array(vtime)
    if freq:
        rows = len(vtime)
        vtime = vtime.repeat(freq[0]).reshape((rows, freq[0])) + np.array(range(freq[0]), dtype=np.float64)/freq[0]
    result=np.float64(vtime/86400.) + np.float64(date2num(get_base_time(ds)))
    return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号