立即注册 登录
气象家园 返回首页

主啊的个人空间 http://bbs.06climate.com/?69999 [收藏] [复制] [分享] [RSS]

日志

单个小时nc文件替换时间

已有 94 次阅读2023-6-14 23:06 |个人分类:python



import xarray as xr
import datetime as dt
import pandas as pd


timefile = "E:/xinzheng2021-2022/xinzheng/2021/20210101/XZ_2021010115.nc"

data = xr.open_dataset(timefile)
lat = data.lat
lon = data.lon

print("*-"*60)
print(data.time)
print("*-"*60)


tsc = data.Temperature_height_above_ground

i = dt.datetime.strptime(str(data["time"].values)[2:-12], '%Y-%m-%dT%H:%M:%S')
time = i + dt.timedelta(hours=8)
time = pd.DatetimeIndex([time])
print(time)
time = time.strftime('%Y-%m-%dT%H:%M:%S')
print(time)

tt = xr.DataArray(tsc, coords=[time,lat,lon], dims=['time','lat','lon'])
print("--"*60)
print(tt)
print("--"*60)

# https://vimsky.com/examples/usage/python-pandas-datetimeindex-strftime.html#:~:text=%E8%AF%A5%E5%87%BD%E6%95%B0%E8%BF%94%E5%9B%9E%E7%94%B1date_format%E6%8C%87%E5%AE%9A%E7%9A%84%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E7%B4%A2%E5%BC%95%EF%BC%8C%E8%AF%A5%E7%B4%A2%E5%BC%95%E6%94%AF%E6%8C%81%E4%B8%8Epython%E6%A0%87%E5%87%86%E5%BA%93%E7%9B%B8%E5%90%8C%E7%9A%84%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%A0%BC%E5%BC%8F%E3%80%82%20%E7%94%A8%E6%B3%95%EF%BC%9A,DatetimeIndex.%20strftime%20%28date_format%29
# https://zhuanlan.zhihu.com/p/575387527

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

返回顶部