簡體   English   中英

在多個日期范圍內對 netcdf 文件進行時間切片

[英]Time slice a netcdf file over multiple date ranges

我有一個 3 維 netcdf 文件(時間、緯度、經度),我想在其中對多個日期范圍進行時間切片。 像這樣在一個連續范圍內切片是可行的。

start_date = dt.datetime(2017,6,1,0)
end_date = dt.datetime(2017,8,31,0)

yyyy = dt.datetime.strftime(start_date,'%Y')
data_g = xr.open_dataset("/cfsr/data/"+yyyy+"/g."+yyyy+".0p5.anl.nc")

g = data_g['g'].isel(lev=15)
g = g.sel(time=slice(start_date1,end_date1))

這使我的 netcdf 文件保持三維,但現在只包含 2017 年 6 月到 2017 年 8 月的數據。現在,例如,假設我想包含 2017 年 10 月到 2017 年 11 月的數據。這可能嗎? 最終目標是取所有數據的平均值,這些數據將跨越不同年份的不同時間片。 我知道我可以通過創建一堆單獨的 arrays(g1、g2 等)來手動執行此操作,但我認為可能有更簡單的方法來執行此操作。

制作另一個切片並使用xarray.concat組合兩個子集,例如:

import xarray as xr

ds = xr.open_dataset('https://thredds.ucar.edu/thredds/dodsC/grib/NCEP/GFS/Global_onedeg/Best')
temp_var = ds.Temperature_isobaric.sel(isobaric6=100000)

g1 = temp_var.sel(time=slice('2020-04-28', '2020-04-30'))
g2 = temp_var.sel(time=slice('2020-05-06', '2020-05-07'))
combined = xr.concat([g1, g2], dim='time')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM