NC文件按时序维度拆分

更新时间:2023-07-14 10:42:33 阅读: 评论:0

NC⽂件按时序维度拆分
最近拿到了nc⽂件,每个nc⽂件⾥包括了⼀年多的数据,使⽤的时候⽆法识别时间维度,需要把nc⽂件按时间维度拆分为很多个nc⽂件。nc⽂件的结构
拆分代码如下
import xarray as xr
import os
from netCDF4 import Datat
import numpy as np
in_folder =r"F:\Data\流场数据\data"
out_folder =r"F:\Data\OceanCurrent"
#First import the netcdf4 library
弱电施工from netCDF4 import Datat  # /p/netcdf4-python/
# Read en existing NetCDF file and create a new one
# f is going to be the existing NetCDF file from where we want to import data
# and g is going to be the new file.
def ChangeNC(in_folder,out_folder):
for root, dirs, files in os.walk(in_folder):
for f in files:
path = os.path.join(root, f)
print(path)
file_in = Datat(path,'r')# r is for read only
time = file_in.variables["time"][:]# read time variable
u1 = file_in.variables["uwnd"][:]
v1 = file_in.variables["vwnd"][:]
latList = file_in.variables["latitude"][:]
lonList = file_in.variables["longitude"][:]
# print(u1,v1,time)
for i in range(len(time)):
# print(time[i])
print(v1[i][0], u1[i][0])
# print(i,type(f))
自行车包
此生不换歌词newName = f[:-3]+"_"+str(i)+".nc"
pathOut = os.path.join(out_folder, newName)# output file
# g = Datat(pathOut, 'w')  # w if for creating a file
outputfile = Datat(pathOut,'w',format='NETCDF3_CLASSIC')
lat = ateVariable('lat', np.float32,('lat'))
lon = ateVariable('lon', np.float32,('lon'))
time = ateVariable('time', np.float32,('time'))
u = ateVariable('U', np.float32,('lat','lon'))
v = ateVariable('V', np.float32,('lat','lon'))
lat.units ='degrees_north'
lat.long_name ='latitude'
lat.long_name ='latitude'
# _FillValue = NaN; // double
# :units = "degrees_north";
# :long_name = "Latitude";
lat.standard_name ="latitude"
汽车氙气灯
lat.point_spacing ="even"
lat.axis ="Y";
# :NAVO_code = 1; // int
lat._CoordinateAxisType ="Lat"
lon.units ='degrees_east'
带飞字的成语lon.long_name ='longitude'
lon.standard_name ="longitude";
# dulo = "360 degrees";
lon.axis ="X";
# :NAVO_code = 2; // int
lon._CoordinateAxisType ="Lon";团队名称创意
time.units ="hours since 1987-01-01 00:00:00"
time.long_name ="Time of analysis"
# u(time=72, depth=1, latitude=481, longitude=1201);
u.units ="m s-1";
u.long_name ="u-wind vector component at 10 meters"
关心则乱
u.height ="10 meters above a-surface";
u.standard_name ="eastward_wind";
v.units ="m s-1"
v.long_name ="v-wind vector component at 10 meters"
v.standard_name ="northward_wind"
v.height ="10 meters above a-surface"
美菱冰箱温度调节
# missing_value = NaN; // double
outputfile.variables['lon'][:]= lonList
# np.linspace(0, 360, 1201)
# outputfile.variables['lon'][:] = np.linspace(-180 + 0.5, 180 - 0.5, 1201)                outputfile.variables['lat'][:]= latList
# np.linspace(80, -80 , 481)
# np.array()file_in.variables['longitude'][:]
# np.linspace(-80, 80 , 481)
outputfile.variables['U'][:]= u1[i]
outputfile.variables['V'][:]= v1[i]
outputfile.variables['time'][:]= time[i:i +1]
outputfile.clo()
file_in.clo()
if __name__ =='__main__':
in_folder ="F:\\Data\\CCMP"
out_folder ="F:\\Data\\CCMP\\Daily"
for year in range(2019,2010,-1):
folder = in_folder +"\\"+str(year)
ChangeNC(folder, out_folder)

本文发布于:2023-07-14 10:42:33,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1081081.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:维度   时间   识别   拆分
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图