cp.py 文件源码

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

项目:faampy 作者: ncasuk 项目源码 文件源码
def read_core_cloud(ifile):
    """reads in the core cloud data and 

    :param str ifile: core cloud netcdf file
    :return: pandas.Dataframe
    :type return: pandas.Dataframe

    """
    ds = netCDF4.Dataset(ifile, 'r')
    vars = sorted(ds.variables.keys())
    vars.remove('Time')

    # create and indexed pandas DataFrame
    tindex = get_mpl_time(ds, 1)
    tindex = num2date(tindex.ravel())
    # initialize an empty Dataframe
    df = pd.DataFrame(index=tindex)
    for v in vars:
        shp = ds.variables[v].shape
        if not shp[0] == len(index):
            continue
        if len(shp) == 2:
            data = np.copy(ds.variables[v][:,0].data).ravel()
        else:
            data = np.copy(ds.variables[v][:])
        df_tmp = pd.DataFrame(data[:].ravel(), index=index, columns=[v,])
        df = pd.concat([df, df_tmp], axis=1)

    df[df == -9999.0] = np.nan  # set all missing values to nan
    t = df.index.values
    df['timestamp'] = t.astype('datetime64[s]')  # Converting index data type

    # TODO: Check that this is really necessary
    # set timezone to None otherwise there might be issues merging
    # this DataFrame with others    
    df.index.tz = None
    return df
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号