CEEMDAN and 写nc文件

做ceemdan分解并写入nc

# -*- coding: utf-8 -*-
"""
Created on Tue Jan 10 16:00:01 2017

@author: damtest
"""

import numpy as np
import pandas as pd
import netCDF4 as nc

from pyeemd import ceemdan
import os.path


fnc = nc.Dataset("/public/damtest/zy/data/station/cma.duan.sh.stn.73.year.mon.198001.201412.nc", "r")
sh=fnc.variables['sh']
stn=fnc.variables['stn']
ndims=sh.shape
nyear=ndims[0]
nmonth=ndims[1]
nstn=ndims[2]

data_in_memo=sh[:,:,:]
imfs=[]

for istn in range(nstn):
    data=data_in_memo.reshape((nyear*nmonth,nstn))[:,istn]
    imfs.append(ceemdan(data.filled(),ensemble_size=500))
    
sh_imfs=np.array(imfs)

try: ncfile.close()  # just to be safe, make sure dataset is not already open.
except: pass
ncfile = nc.Dataset('tp_sh_stat_monthly_ceemdan_1979-2014.nc',mode='w',format='NETCDF4_CLASSIC') 

stn_dim = ncfile.createDimension('stn', nstn)     # latitude axis
imf_dim = ncfile.createDimension('imf', 8)    # longitude axis
time_dim = ncfile.createDimension('time', None) # unlimited axis (can be appended to).

for dim in ncfile.dimensions.items():
    print(dim)

ncfile.title="tp_sh_stat_monthly_ceemdan_1979-2014"

stn_out = ncfile.createVariable('stn', np.float32, ('stn',))
stn_out.units = 'n'
stn_out.long_name = 'stn number'
imf_out = ncfile.createVariable('imf', np.float32, ('imf',))
imf_out.units = 'n'
imf_out.long_name = 'imf '
time_out = ncfile.createVariable('time', np.float32, ('time',))
time_out.units = 'months since 1979-01-01'
time_out.long_name = 'time'
# Define a 3D variable to hold the data
sh_imfs_out = ncfile.createVariable('sh_imfs',np.float64,('stn','imf','time')) # note: unlimited dimension is leftmost
sh_imfs_out.units = 'w/m^2' # degrees Kelvin
sh_imfs_out.standard_name = 'sh over TP' # this is a CF standard name

print(sh_imfs_out)
print("-- Some pre-defined attributes for variable temp:")
print("temp.dimensions:", sh_imfs_out.dimensions)
print("temp.shape:", sh_imfs_out.shape)
print("temp.dtype:", sh_imfs_out.dtype)
print("temp.ndim:", sh_imfs_out.ndim)

stn_out[:] = stn[:]
imf_out[:] = range(8)
time_out[:] = range(nyear*nmonth)
sh_imfs_out[:,:,:] = sh_imfs
print("-- Wrote data, temp.shape is now ", sh_imfs_out.shape)
ncfile.close()
print('Dataset is closed!')

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 目录 基础使用单向侦听双向聊天日常习惯 拓展使用正/反向域名解析传输⽂件/目录;加密传输端口扫描,获取banner...
    linx255阅读 4,353评论 0 1
  • netcat是网络工具中的瑞士军刀,它能通过TCP和UDP在网络中读写数据。通过与其他工具结合和重定向,你可以在脚...
    ssdsss阅读 5,742评论 0 0
  • 此文章转载~ Apache伪静态(Rewrite).htaccess文件详解 Htaccess(超文本访问)是一个...
    bornfreekiss阅读 9,622评论 0 6
  • 这个月又大出血了,兴趣班会员+工作室会员+20号的培训+淘宝添置的战衣、饰品,这些大数据,还不算细碎的小花销...
    Midge莉莉阅读 2,976评论 3 2
  • 那签上的肉,在烈火上炙烤, 曾经鲜草甘美,清泉泠冽, 不过,一缕青烟。 那焦灼出的泪滴啊, 只因记忆里的爱,太痴。...
    沈墨飞阅读 2,688评论 1 1